forked from sqlpad/sqlpad
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseed-data-path.js
More file actions
63 lines (57 loc) · 2.17 KB
/
seed-data-path.js
File metadata and controls
63 lines (57 loc) · 2.17 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
51
52
53
54
55
56
57
58
59
60
61
62
63
const assert = require('assert');
const TestUtils = require('../utils');
describe('seedDataPath', function () {
it('Loads files as expected', async function () {
const utils = new TestUtils({
seedDataPath: './test/fixtures/seed-data',
});
await utils.init();
const queries = await utils.models.queries.findAll();
assert.strictEqual(queries.length, 2);
const query1 = queries.find((q) => q.id === 'seed-query-1');
assert(query1);
const queryAcls = await utils.models.sequelizeDb.QueryAcl.findAll({
where: { queryId: 'seed-query-1' },
});
assert.equal(queryAcls.length, 3);
const connections = await utils.models.connections.findAll();
assert.equal(connections.length, 1);
assert.strictEqual(connections[0].id, 'seed-connection-1');
// Users were auto created
assert(u1);
assert(queryAcls.find((acl) => acl.userId === u1.id));
});
it('Handles child directories with no valid files', async function () {
const utils = new TestUtils({
seedDataPath: './test/fixtures/seed-data-empty-child',
});
await utils.init();
const queries = await utils.models.queries.findAll();
assert.strictEqual(queries.length, 0);
});
it('Handles directory that does not exist', async function () {
const utils = new TestUtils({
seedDataPath: './test/fixtures/does-not-exist',
});
await utils.init();
const queries = await utils.models.queries.findAll();
assert.strictEqual(queries.length, 0);
});
it('throws for invalid data', async function () {
const utils = new TestUtils({
seedDataPath: './test/fixtures/seed-data-bad-file',
});
await assert.rejects(() => utils.init());
const queries = await utils.models.queries.findAll();
assert.strictEqual(queries.length, 0);
});
it('throws for multiple acl user specifiers', async function () {
const utils = new TestUtils({
seedDataPath: './test/fixtures/seed-data-bad-query-2',
});
await assert.rejects(() => utils.init());
const queries = await utils.models.queries.findAll();
assert.strictEqual(queries.length, 0);
});
});