-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostgresStrategy.test.js
More file actions
50 lines (42 loc) · 1.5 KB
/
postgresStrategy.test.js
File metadata and controls
50 lines (42 loc) · 1.5 KB
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
42
43
44
45
46
47
48
49
50
const { equal, deepEqual, ok } = require('assert');
const PostgresStrategy = require('./src/db/strategies/postgresSQLStrategy');
const Context = require('./src/db/strategies/base/contextStrategy');
const MOCK_HEROI_CADASTRAR = { nome: 'Gaviao Negro', poder: 'flexas' };
const MOCK_HEROI_ATUALIZAR = { nome: 'Mulher Gavião', poder: 'grito' };
const context = new Context(new PostgresStrategy());
describe('PostgreSQL Strategy', function() {
this.timeout(Infinity);
before(async () => {
await context.delete();
await context.create(MOCK_HEROI_CADASTRAR);
await context.create(MOCK_HEROI_ATUALIZAR);
});
it('PostgresSQL connection', async () => {
const result = await context.isConnected();
equal(result, true);
});
it('cadastrar', async () => {
const result = await context.create(MOCK_HEROI_CADASTRAR);
delete result.dataValues.id;
deepEqual(result.dataValues, MOCK_HEROI_CADASTRAR);
});
it('listar', async () => {
const [result] = await context.read(MOCK_HEROI_CADASTRAR);
delete result.id;
deepEqual(result, MOCK_HEROI_CADASTRAR);
});
it('atualizar', async () => {
const [result] = await context.read({});
const novoItem = {
...MOCK_HEROI_CADASTRAR,
nome: 'Mulher Maravilha',
};
const [update] = await context.update(result.id, novoItem);
deepEqual(update, 1);
});
it('remover', async () => {
const [item] = await context.read({});
const result = await context.delete(item.id);
deepEqual(result, 1);
});
});