/
down-tests.js
155 lines (125 loc) · 3.96 KB
/
down-tests.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
"use strict";
var _timestamp = require("../src/utils/timestamp")
, _mocha = require("mocha")
, _should = require("should")
, _down = require("../src/commands/down")
, _helper = require("./test-helper")
, _clog = require("clog")
, _clogConfig = require("../configs/clog-config").none();
describe("Down Command", function(){
describe("Error Cases", function(){
it("should output an error if the migrations directory does not exist.", function(){
var errorWasCalled = false;
_clog.error = function(){ errorWasCalled = true;};
_down();
errorWasCalled.should.be.true;
});
it("should output an error if the required migration was not provided.", function(){
var errorWasCalled = false;
_clog.error = function(){ errorWasCalled = true;};
_helper.createRelativeDirectory("./migrations");
_down();
errorWasCalled.should.be.true;
_helper.deleteRelativeDirectory("./migrations");
});
it("should output an error if the required migration was provided but does not exist.", function(){
var errorWasCalled = false;
_clog.error = function(){ errorWasCalled = true;};
_helper.createRelativeDirectory("./migrations");
_down("doesntExist.js");
errorWasCalled.should.be.true;
_helper.deleteRelativeDirectory("./migrations");
});
it("should output an error if an exception is thrown within a migration", function(){
var count = 1
, path = "./migrations";
_helper.errorMigrationSetup(path, count);
_helper.createMigrationTrackerFile(path, "201206301747E0.js");
var errorWasCalled = false;
_clog.error = function(){ errorWasCalled = true;};
_down(0);
errorWasCalled.should.be.true;
_helper.deleteRelativeDirectory(path);
});
});
describe("Migrating Down", function(){
var count = 3
, path = "./migrations";
beforeEach(function(done){
_helper.downMigrationSetup(path, count);
_helper.createMigrationTrackerFile(path, "20120630174702.js");
done();
});
afterEach(function(done){
_helper.deleteRelativeDirectory(path);
done();
});
it("should migrate to the initial version if 0 is passed in.", function(){
var migrationCounter = 0;
_clog.test = function(){
migrationCounter++;
};
_down("0");
migrationCounter.should.equal(3);
});
it("should migrate to the specified version if less than current version.", function(){
var migrationCounter = 0;
_clog.test = function(){
migrationCounter++;
};
_down("20120630174700.js");
migrationCounter.should.equal(2);
});
it("should not migrate to the specified version if newer than current version.", function(){
var migrationCounter = 0;
_clog.test = function(){
migrationCounter++;
};
_down("20120630174723.js");
migrationCounter.should.equal(0);
});
});
describe("Asynchronous Down Migration", function(){
var count = 3
, path = "./migrations";
beforeEach(function(done){
_helper.asyncMigrationSetup(path, count);
_helper.createMigrationTrackerFile(path, "20120630174722.js");
done();
});
afterEach(function(done){
_helper.deleteRelativeDirectory(path);
done();
});
it("should migrate to the initial version if 0 is passed in.", function(done){
var migrationCounter = 0;
_clog.test = function(){
migrationCounter++;
};
_down("0", function(){
migrationCounter.should.equal(3);
done();
});
});
it("should migrate to the specified version if less than current version.", function(done){
var migrationCounter = 0;
_clog.test = function(){
migrationCounter++;
};
_down("20120630174720.js", function(){
migrationCounter.should.equal(2);
done();
});
});
it("should not migrate to the specified version if newer than current version.", function(done){
var migrationCounter = 0;
_clog.test = function(){
migrationCounter++;
};
_down("20120630174723.js", function(){
migrationCounter.should.equal(0);
done();
});
});
});
});