@@ -24,6 +24,40 @@ const superUser = userData[4];
24
24
25
25
let jwt , superUserJwt ;
26
26
27
+ const taskData = [
28
+ {
29
+ title : "Test task" ,
30
+ type : "feature" ,
31
+ endsOn : 1234 ,
32
+ startedOn : 4567 ,
33
+ status : "IN_PROGRESS" ,
34
+ percentCompleted : 10 ,
35
+ participants : [ ] ,
36
+ assignee : appOwner . username ,
37
+ completionAward : { [ DINERO ] : 3 , [ NEELAM ] : 300 } ,
38
+ lossRate : { [ DINERO ] : 1 } ,
39
+ isNoteworthy : true ,
40
+ isCollapsed : true ,
41
+ } ,
42
+ {
43
+ title : "Test task" ,
44
+ purpose : "To Test mocha" ,
45
+ featureUrl : "<testUrl>" ,
46
+ type : "group" ,
47
+ links : [ "test1" ] ,
48
+ endsOn : 1234 ,
49
+ startedOn : 54321 ,
50
+ status : "completed" ,
51
+ percentCompleted : 10 ,
52
+ dependsOn : [ "d12" , "d23" ] ,
53
+ participants : [ appOwner . username ] ,
54
+ completionAward : { [ DINERO ] : 3 , [ NEELAM ] : 300 } ,
55
+ lossRate : { [ DINERO ] : 1 } ,
56
+ isNoteworthy : false ,
57
+ assignee : appOwner . username ,
58
+ } ,
59
+ ] ;
60
+
27
61
describe ( "Tasks" , function ( ) {
28
62
let taskId1 , taskId ;
29
63
@@ -33,40 +67,6 @@ describe("Tasks", function () {
33
67
jwt = authService . generateAuthToken ( { userId } ) ;
34
68
superUserJwt = authService . generateAuthToken ( { userId : superUserId } ) ;
35
69
36
- const taskData = [
37
- {
38
- title : "Test task" ,
39
- type : "feature" ,
40
- endsOn : 1234 ,
41
- startedOn : 4567 ,
42
- status : "IN_PROGRESS" ,
43
- percentCompleted : 10 ,
44
- participants : [ ] ,
45
- assignee : appOwner . username ,
46
- completionAward : { [ DINERO ] : 3 , [ NEELAM ] : 300 } ,
47
- lossRate : { [ DINERO ] : 1 } ,
48
- isNoteworthy : true ,
49
- isCollapsed : true ,
50
- } ,
51
- {
52
- title : "Test task" ,
53
- purpose : "To Test mocha" ,
54
- featureUrl : "<testUrl>" ,
55
- type : "group" ,
56
- links : [ "test1" ] ,
57
- endsOn : 1234 ,
58
- startedOn : 54321 ,
59
- status : "completed" ,
60
- percentCompleted : 10 ,
61
- dependsOn : [ "d12" , "d23" ] ,
62
- participants : [ appOwner . username ] ,
63
- completionAward : { [ DINERO ] : 3 , [ NEELAM ] : 300 } ,
64
- lossRate : { [ DINERO ] : 1 } ,
65
- isNoteworthy : false ,
66
- assignee : appOwner . username ,
67
- } ,
68
- ] ;
69
-
70
70
// Add the active task
71
71
taskId = ( await tasks . updateTask ( taskData [ 0 ] ) ) . taskId ;
72
72
taskId1 = taskId ;
@@ -184,6 +184,11 @@ describe("Tasks", function () {
184
184
} ) ;
185
185
186
186
describe ( "GET /tasks" , function ( ) {
187
+ before ( async function ( ) {
188
+ await tasks . updateTask ( { ...taskData [ 0 ] , createdAt : 1621717694 , updatedAt : 1700680830 } ) ;
189
+ await tasks . updateTask ( { ...taskData [ 1 ] , createdAt : 1621717694 , updatedAt : 1700775753 } ) ;
190
+ } ) ;
191
+
187
192
it ( "Should get all the list of tasks" , function ( done ) {
188
193
chai
189
194
. request ( app )
@@ -348,7 +353,6 @@ describe("Tasks", function () {
348
353
if ( err ) {
349
354
return done ( err ) ;
350
355
}
351
-
352
356
expect ( res ) . to . have . status ( 200 ) ;
353
357
expect ( res . body ) . to . be . a ( "object" ) ;
354
358
expect ( res . body . message ) . to . equal ( "Tasks returned successfully!" ) ;
@@ -409,7 +413,7 @@ describe("Tasks", function () {
409
413
matchingTasks . forEach ( ( task ) => {
410
414
expect ( task . title . toLowerCase ( ) ) . to . include ( searchTerm . toLowerCase ( ) ) ;
411
415
} ) ;
412
- expect ( matchingTasks ) . to . have . length ( 4 ) ;
416
+ expect ( matchingTasks ) . to . have . length ( 6 ) ;
413
417
414
418
return done ( ) ;
415
419
} ) ;
@@ -448,6 +452,26 @@ describe("Tasks", function () {
448
452
return done ( ) ;
449
453
} ) ;
450
454
} ) ;
455
+ it ( "Should get paginated tasks ordered by updatedAt in desc order " , function ( done ) {
456
+ chai
457
+ . request ( app )
458
+ . get ( "/tasks?dev=true&size=5&page=0" )
459
+ . end ( ( err , res ) => {
460
+ if ( err ) {
461
+ return done ( err ) ;
462
+ }
463
+ expect ( res ) . to . have . status ( 200 ) ;
464
+ expect ( res . body ) . to . be . a ( "object" ) ;
465
+ expect ( res . body . message ) . to . equal ( "Tasks returned successfully!" ) ;
466
+ expect ( res . body . tasks ) . to . be . a ( "array" ) ;
467
+ const tasks = res . body . tasks ;
468
+ // Check if Tasks are returned in desc order of updatedAt field
469
+ for ( let i = 0 ; i < tasks . length - 1 ; i ++ ) {
470
+ expect ( tasks [ + i ] . updatedAt ) . to . be . greaterThanOrEqual ( tasks [ i + 1 ] . updatedAt ) ;
471
+ }
472
+ return done ( ) ;
473
+ } ) ;
474
+ } ) ;
451
475
} ) ;
452
476
453
477
describe ( "GET /tasks/:id/details" , function ( ) {
0 commit comments