@@ -5,6 +5,7 @@ import 'mocha'; // tslint:disable-line:no-import-side-effect
5
5
import DuplicateKeyError from '../utils/errors/DuplicateKeyError' ;
6
6
import FailingMigrationError from '../utils/errors/FailingMigrationError' ;
7
7
import MissingMigrationError from '../utils/errors/MissingMigrationError' ;
8
+ import assertDateOrder from '../utils/tests/assertDateOrder' ;
8
9
import assertLocked from '../utils/tests/assertLocked' ;
9
10
import createMigrationProcess from '../utils/tests/createMigrationProcess' ;
10
11
import createTestDownMigration from '../utils/tests/createTestDownMigration' ;
@@ -57,19 +58,26 @@ const testRollback: TestFactory = (createService) => {
57
58
await assertRejects ( promise , FailingMigrationError ) ;
58
59
} ) ;
59
60
60
- it ( 'should process rollback for a processed migration' , async ( ) => {
61
- const { process, getProcessed } = createMigrationProcess ( ) ;
62
- const service = createService ( [ createTestDownMigration ( process ) ] ) ;
61
+ it ( 'should process rollbacks for processed migrations in reverse order' , async ( ) => {
62
+ const firstProcess = createMigrationProcess ( ) ;
63
+ const secondProcess = createMigrationProcess ( ) ;
64
+ const service = createService ( [
65
+ createTestDownMigration ( firstProcess . process , 'firstMigration' ) ,
66
+ createTestDownMigration ( secondProcess . process , 'secondMigration' ) ,
67
+ ] ) ;
63
68
await service . migrate ( ) ;
64
69
await service . rollback ( ) ;
65
- assert . equal ( getProcessed ( ) , true ) ;
70
+ assert . notEqual ( firstProcess . getProcessed ( ) , undefined ) ;
71
+ assert . notEqual ( secondProcess . getProcessed ( ) , undefined ) ;
72
+ const processes = [ secondProcess . getProcessed ( ) , firstProcess . getProcessed ( ) ] ;
73
+ assertDateOrder ( processes as Date [ ] ) ;
66
74
} ) ;
67
75
68
76
it ( 'should not process rollback for a unprocessed migration' , async ( ) => {
69
77
const { process, getProcessed } = createMigrationProcess ( ) ;
70
78
const service = createService ( [ createTestDownMigration ( process ) ] ) ;
71
79
await service . rollback ( ) ;
72
- assert . equal ( getProcessed ( ) , false ) ;
80
+ assert . equal ( getProcessed ( ) , undefined ) ;
73
81
} ) ;
74
82
75
83
it ( 'should skip unprocessed migrations after processed migrations' , async ( ) => {
@@ -80,8 +88,8 @@ const testRollback: TestFactory = (createService) => {
80
88
createTestDownMigration ( unskippedProcess . process , unskippableKey ) ,
81
89
createTestDownMigration ( skippedProcess . process ) ,
82
90
] ) . rollback ( ) ;
83
- assert . equal ( skippedProcess . getProcessed ( ) , false ) ;
84
- assert . equal ( unskippedProcess . getProcessed ( ) , true ) ;
91
+ assert . equal ( skippedProcess . getProcessed ( ) , undefined ) ;
92
+ assert . notEqual ( unskippedProcess . getProcessed ( ) , undefined ) ;
85
93
} ) ;
86
94
87
95
it ( 'should skip unprocessed migrations before processed migrations' , async ( ) => {
@@ -92,8 +100,8 @@ const testRollback: TestFactory = (createService) => {
92
100
createTestDownMigration ( skippedProcess . process ) ,
93
101
createTestDownMigration ( unskippedProcess . process , unskippableKey ) ,
94
102
] ) . rollback ( ) ;
95
- assert . equal ( skippedProcess . getProcessed ( ) , false ) ;
96
- assert . equal ( unskippedProcess . getProcessed ( ) , true ) ;
103
+ assert . equal ( skippedProcess . getProcessed ( ) , undefined ) ;
104
+ assert . notEqual ( unskippedProcess . getProcessed ( ) , undefined ) ;
97
105
} ) ;
98
106
99
107
it ( 'should error when migrations are locked' , async ( ) => {
0 commit comments