@@ -5,6 +5,7 @@ import 'mocha'; // tslint:disable-line:no-import-side-effect
55import DuplicateKeyError from '../utils/errors/DuplicateKeyError' ;
66import FailingMigrationError from '../utils/errors/FailingMigrationError' ;
77import MissingMigrationError from '../utils/errors/MissingMigrationError' ;
8+ import assertDateOrder from '../utils/tests/assertDateOrder' ;
89import assertLocked from '../utils/tests/assertLocked' ;
910import createMigrationProcess from '../utils/tests/createMigrationProcess' ;
1011import createTestDownMigration from '../utils/tests/createTestDownMigration' ;
@@ -57,19 +58,26 @@ const testRollback: TestFactory = (createService) => {
5758 await assertRejects ( promise , FailingMigrationError ) ;
5859 } ) ;
5960
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+ ] ) ;
6368 await service . migrate ( ) ;
6469 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 [ ] ) ;
6674 } ) ;
6775
6876 it ( 'should not process rollback for a unprocessed migration' , async ( ) => {
6977 const { process, getProcessed } = createMigrationProcess ( ) ;
7078 const service = createService ( [ createTestDownMigration ( process ) ] ) ;
7179 await service . rollback ( ) ;
72- assert . equal ( getProcessed ( ) , false ) ;
80+ assert . equal ( getProcessed ( ) , undefined ) ;
7381 } ) ;
7482
7583 it ( 'should skip unprocessed migrations after processed migrations' , async ( ) => {
@@ -80,8 +88,8 @@ const testRollback: TestFactory = (createService) => {
8088 createTestDownMigration ( unskippedProcess . process , unskippableKey ) ,
8189 createTestDownMigration ( skippedProcess . process ) ,
8290 ] ) . 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 ) ;
8593 } ) ;
8694
8795 it ( 'should skip unprocessed migrations before processed migrations' , async ( ) => {
@@ -92,8 +100,8 @@ const testRollback: TestFactory = (createService) => {
92100 createTestDownMigration ( skippedProcess . process ) ,
93101 createTestDownMigration ( unskippedProcess . process , unskippableKey ) ,
94102 ] ) . 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 ) ;
97105 } ) ;
98106
99107 it ( 'should error when migrations are locked' , async ( ) => {
0 commit comments