-
Notifications
You must be signed in to change notification settings - Fork 8
/
MigratState.js
86 lines (80 loc) · 3.22 KB
/
MigratState.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
var assert = require('chai').assert;
var MigratState = require('../lib/MigratState.js');
var MigratMigration = require('../lib/MigratMigration.js');
describe('MigratState', function() {
describe('.add()', function() {
it('should add entry', function() {
var state = new MigratState();
var migration = new MigratMigration({filename: '1414006573678-UPPERCASE.js'});
state.add(migration);
assert.property(state.state, '1414006573678-uppercase.js');
assert.notProperty(state.state, '1414006573678-UPPERCASE.js');
assert.isNumber(state.state['1414006573678-uppercase.js']);
});
it('should throw if not a MigratMigration instance', function() {
var state = new MigratState();
assert.throws(function() {
state.add({filename: '1414006573678-valid.js'});
}, /MigratMigration/);
});
});
describe('.remove()', function() {
it('should remove entry', function() {
var state = new MigratState({'1414006573678-uppercase.js': 1414006573678});
assert.property(state.state, '1414006573678-uppercase.js');
var migration = new MigratMigration({filename: '1414006573678-UPPERCASE.js'});
state.remove(migration);
assert.notProperty(state.state, '1414006573678-uppercase.js');
});
it('should throw if not a MigratMigration instance', function() {
var state = new MigratState();
assert.throws(function() {
state.remove({filename: '1414006573678-valid.js'});
}, /MigratMigration/);
});
});
describe('.exists()', function() {
it('should return true if entry found (case-insensitive)', function() {
var state = new MigratState({'1414006573678-uppercase.js': 1414006573678});
var migration = new MigratMigration({filename: '1414006573678-UPPERCASE.js'});
assert.isTrue(state.exists(migration));
});
it('should return false if entry not found', function() {
var state = new MigratState({'1414006573678-somethingelse.js': 1414006573678});
var migration = new MigratMigration({filename: '1414006573678-valid.js'});
assert.isFalse(state.exists(migration));
});
it('should throw if not a MigratMigration instance', function() {
var state = new MigratState();
assert.throws(function() {
state.exists({filename: '1414006573678-valid.js'});
}, /MigratMigration/);
});
});
describe('.serialize()', function() {
it('should return valid JSON string', function() {
var state;
state = new MigratState();
assert.equal(state.serialize(), '{}');
state = new MigratState({'1414006573678-valid.js': 1414006573678});
assert.equal(state.serialize(), '{"1414006573678-valid.js":1414006573678}');
});
});
describe('.unserialize()', function() {
it('should return MigratState object', function() {
var state;
state = MigratState.unserialize('null');
assert.instanceOf(state, MigratState);
assert.deepEqual(state.state, {});
state = MigratState.unserialize(null);
assert.instanceOf(state, MigratState);
assert.deepEqual(state.state, {});
state = MigratState.unserialize('{}');
assert.instanceOf(state, MigratState);
assert.deepEqual(state.state, {});
state = MigratState.unserialize('{"1414006573678-valid.js":1414006573678}');
assert.instanceOf(state, MigratState);
assert.deepEqual(state.state, {'1414006573678-valid.js': 1414006573678});
});
});
});