Skip to content

Commit

Permalink
test(deleteById): test for deleteById
Browse files Browse the repository at this point in the history
  • Loading branch information
afontainec committed Jul 25, 2020
1 parent 82a7676 commit c30ea85
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions test/models/table/delete/deleteById.js
@@ -0,0 +1,42 @@
// During the test the env variable is set to test
process.env.NODE_ENV = 'test';

// Require the dev-dependencies
const { assert } = require('chai');
const knex = require('../../../../knex');
const Coffee = require('../../../../models/coffee-example');


// Our parent block
describe('TABLE GATEWAY: deleteById', () => { // eslint-disable-line
before(async () => { // eslint-disable-line
await knex.seed.run();
});

it('With valid id', async () => { // eslint-disable-line
const all = await Coffee.count();
const deleted = await Coffee.deleteById(1);
const results = await Coffee.count();
assert.equal(results, all - 1);
assert.isNotArray(deleted);
assert.equal(deleted.id, 1);
});
it('returnAsQuery', async () => { // eslint-disable-line
const query = Coffee.deleteById(1, { returnAsQuery: true });
assert.equal(query.toString(), 'delete from "coffee" where "id" = 1 returning *');
});

describe('Malicious happy path', () => { // eslint-disable-line
before(async () => { // eslint-disable-line
await knex.seed.run();
});

it('Invalid type', (done) => { // eslint-disable-line
Coffee.deleteById('invalid type').then(() => {
done('SHOULD NOT GET HERE');
}).catch(() => {
done();
});
});
});
});

0 comments on commit c30ea85

Please sign in to comment.