-
Notifications
You must be signed in to change notification settings - Fork 14
/
withSequentialMigrationNumberFormat.js
63 lines (50 loc) · 1.58 KB
/
withSequentialMigrationNumberFormat.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'use strict';
const tap = require('tap');
const expect = require('expect.js');
const pEachSeries = require('p-each-series');
const testUtils = require('../../../testUtils');
tap.mochaGlobals();
describe('migrator create with sequential migration number format', () => {
let migrator;
let testEnv;
before(() => {
return Promise.resolve()
.then(() => {
return testUtils.createEnv({
migratorParams: {init: true, connect: true}
});
})
.then((createdTestEnv) => {
testEnv = createdTestEnv;
migrator = testEnv.migrator;
});
});
const baseNames = ['first', 'second', 'third', 'second'];
let names = [];
after(() => testUtils.removeMigrations({migrator, names}));
after(() => testUtils.destroyEnv(testEnv));
it('should create migrations without errors', () => {
return Promise.resolve()
.then(() => testUtils.createMigrations({migrator, baseNames}))
.then((migrationNames) => {
names = migrationNames;
});
});
it('created migrations should have sequential numbers', () => {
const expectedNames = baseNames.map((baseName, index) => {
return `${String(index + 1)}_${baseName}`;
});
expect(names).eql(expectedNames);
});
it('created migrations should exist', () => {
return migrator.checkMigrationsExists(names);
});
it('created migrations should be loadable', () => {
return pEachSeries(names, (name) => migrator.loadMigration(name));
});
it('created migrations should be listed as `new`', () => {
return Promise.resolve()
.then(() => migrator.getNewMigrationNames())
.then((newNames) => expect(newNames).eql(names));
});
});