Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(deleteById): test for deleteById
- Loading branch information
1 parent
82a7676
commit c30ea85
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
}); | ||
}); | ||
}); | ||
}); |