-
Notifications
You must be signed in to change notification settings - Fork 0
/
findById.js
41 lines (35 loc) · 1.15 KB
/
findById.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// 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: FIND BY ID', () => { // eslint-disable-line
before(async () => { // eslint-disable-line
await knex.seed.run();
});
it('Existing id', async () => { // eslint-disable-line
const results = await coffee.findById(1);
assert.equal(typeof results, 'object');
assert.equal(results.id, 1);
});
it('non exiting id', (done) => { // eslint-disable-line
coffee.findById(-1).then(() => {
done('SHOULD NOT GET HERE');
}).catch((err) => {
assert.equal(err.code, 400);
assert.equal(err.fullMessage.routine, 'unexistantID');
done();
});
});
it('Not valid id ', (done) => { // eslint-disable-line
coffee.findById('what is this').then(() => {
done('SHOULD NOT GET HERE');
}).catch((err) => {
assert.equal(err.code, 400);
assert.equal(err.fullMessage.routine, 'pg_atoi');
done();
});
});
});