@@ -1196,12 +1196,12 @@ describe("Tasks", function () {
1196
1196
jwt = authService . generateAuthToken ( { userId } ) ;
1197
1197
superUserJwt = authService . generateAuthToken ( { userId : superUserId } ) ;
1198
1198
// Add the active task
1199
- taskId = ( await tasks . updateTask ( tasksData [ 0 ] ) ) . taskId ;
1200
- taskId = ( await tasks . updateTask ( tasksData [ 1 ] ) ) . taskId ;
1201
- taskId = ( await tasks . updateTask ( tasksData [ 3 ] ) ) . taskId ;
1202
- taskId = ( await tasks . updateTask ( tasksData [ 4 ] ) ) . taskId ;
1203
- taskId = ( await tasks . updateTask ( tasksData [ 5 ] ) ) . taskId ;
1204
- taskId = ( await tasks . updateTask ( tasksData [ 6 ] ) ) . taskId ;
1199
+ await tasks . updateTask ( tasksData [ 0 ] ) ;
1200
+ await tasks . updateTask ( tasksData [ 1 ] ) ;
1201
+ await tasks . updateTask ( tasksData [ 3 ] ) ;
1202
+ await tasks . updateTask ( tasksData [ 4 ] ) ;
1203
+ await tasks . updateTask ( tasksData [ 5 ] ) ;
1204
+ await tasks . updateTask ( tasksData [ 6 ] ) ;
1205
1205
} ) ;
1206
1206
afterEach ( async function ( ) {
1207
1207
await cleanDb ( ) ;
@@ -1213,17 +1213,41 @@ describe("Tasks", function () {
1213
1213
1214
1214
// TASK createdAt and updatedAt migration script
1215
1215
it ( "Should update status createdAt and updatedAt" , async function ( ) {
1216
+ // Add new tasks with createdAt and updatedAt present
1217
+ await tasks . updateTask ( { ...tasksData [ 7 ] , createdAt : null , updatedAt : null } ) ;
1218
+ await tasks . updateTask ( { ...tasksData [ 8 ] , createdAt : null , updatedAt : null } ) ;
1219
+ await tasks . updateTask ( { ...tasksData [ 9 ] , updatedAt : null } ) ;
1220
+ await tasks . updateTask ( { ...tasksData [ 10 ] , createdAt : null } ) ;
1216
1221
const res = await chai . request ( app ) . post ( "/tasks/migration" ) . set ( "cookie" , `${ cookieName } =${ superUserJwt } ` ) . send ( {
1217
1222
action : "ADD" ,
1218
1223
field : "CREATED_AT+UPDATED_AT" ,
1219
1224
} ) ;
1220
1225
expect ( res ) . to . have . status ( 200 ) ;
1226
+ expect ( res . body . totalTasks ) . to . be . equal ( 10 ) ;
1227
+ expect ( res . body . totalTaskToBeUpdate ) . to . be . equal ( 4 ) ;
1228
+ expect ( res . body . totalTasksUpdated ) . to . be . equal ( 4 ) ;
1221
1229
expect ( res . body . totalFailedTasks ) . to . be . equal ( 0 ) ;
1230
+ expect ( res . body . failedTasksIds ) . to . deep . equal ( [ ] ) ;
1231
+ } ) ;
1232
+
1233
+ it ( "Should update status createdAt and updatedAt, if filed doesn't exists" , async function ( ) {
1234
+ const res = await chai . request ( app ) . post ( "/tasks/migration" ) . set ( "cookie" , `${ cookieName } =${ superUserJwt } ` ) . send ( {
1235
+ action : "ADD" ,
1236
+ field : "CREATED_AT+UPDATED_AT" ,
1237
+ } ) ;
1238
+ expect ( res ) . to . have . status ( 200 ) ;
1222
1239
expect ( res . body . totalTasks ) . to . be . equal ( 6 ) ;
1240
+ expect ( res . body . totalTaskToBeUpdate ) . to . be . equal ( 0 ) ;
1241
+ expect ( res . body . totalTasksUpdated ) . to . be . equal ( 0 ) ;
1242
+ expect ( res . body . totalFailedTasks ) . to . be . equal ( 0 ) ;
1223
1243
expect ( res . body . failedTasksIds ) . to . deep . equal ( [ ] ) ;
1224
1244
} ) ;
1225
1245
1226
1246
it ( "should return failed stats if firestore batch operations fail for adding createdAt and updatedAt" , async function ( ) {
1247
+ await tasks . updateTask ( { ...tasksData [ 7 ] , createdAt : null , updatedAt : null } ) ;
1248
+ await tasks . updateTask ( { ...tasksData [ 8 ] , createdAt : null , updatedAt : null } ) ;
1249
+ await tasks . updateTask ( { ...tasksData [ 9 ] , updatedAt : null } ) ;
1250
+ await tasks . updateTask ( { ...tasksData [ 10 ] , createdAt : null } ) ;
1227
1251
const stub = sinon . stub ( firestore , "batch" ) ;
1228
1252
stub . returns ( {
1229
1253
update : function ( ) { } ,
@@ -1236,9 +1260,11 @@ describe("Tasks", function () {
1236
1260
field : "CREATED_AT+UPDATED_AT" ,
1237
1261
} ) ;
1238
1262
expect ( res ) . to . have . status ( 200 ) ;
1239
- expect ( res . body . totalFailedTasks ) . to . be . equal ( 6 ) ;
1240
- expect ( res . body . totalTasks ) . to . be . equal ( 6 ) ;
1241
- expect ( res . body . failedTasksIds . length ) . to . equal ( 6 ) ;
1263
+ expect ( res . body . totalTasks ) . to . be . equal ( 10 ) ;
1264
+ expect ( res . body . totalTaskToBeUpdate ) . to . be . equal ( 4 ) ;
1265
+ expect ( res . body . totalTasksUpdated ) . to . be . equal ( 0 ) ;
1266
+ expect ( res . body . totalFailedTasks ) . to . be . equal ( 4 ) ;
1267
+ expect ( res . body . failedTasksIds . length ) . to . equal ( 4 ) ;
1242
1268
} ) ;
1243
1269
} ) ;
1244
1270
} ) ;
0 commit comments