@@ -32,7 +32,8 @@ describe('Tasks', function () {
32
32
startedOn : 4567 ,
33
33
status : 'active' ,
34
34
percentCompleted : 10 ,
35
- participants : [ appOwner . username ] ,
35
+ participants : [ ] ,
36
+ assignee : appOwner . username ,
36
37
completionAward : { [ DINERO ] : 3 , [ NEELAM ] : 300 } ,
37
38
lossRate : { [ DINERO ] : 1 } ,
38
39
isNoteworthy : true
@@ -115,7 +116,13 @@ describe('Tasks', function () {
115
116
expect ( res . body . message ) . to . equal ( 'Tasks returned successfully!' )
116
117
expect ( res . body . tasks ) . to . be . a ( 'array' )
117
118
const taskWithParticipants = res . body . tasks [ 0 ]
118
- expect ( taskWithParticipants . participants ) . to . have . members ( [ appOwner . username ] )
119
+
120
+ if ( taskWithParticipants . type === 'group' ) {
121
+ expect ( taskWithParticipants . participants ) . to . include ( appOwner . username )
122
+ } else {
123
+ expect ( taskWithParticipants . assignee ) . to . equal ( appOwner . username )
124
+ }
125
+
119
126
return done ( )
120
127
} )
121
128
} )
@@ -249,4 +256,42 @@ describe('Tasks', function () {
249
256
} )
250
257
} )
251
258
} )
259
+
260
+ describe ( 'GET /tasks/:username' , function ( ) {
261
+ it ( 'Should return 200 when username is valid' , function ( done ) {
262
+ chai
263
+ . request ( app )
264
+ . get ( `/tasks/${ appOwner . username } ` )
265
+ . end ( ( err , res ) => {
266
+ if ( err ) { return done ( err ) }
267
+ expect ( res ) . to . have . status ( 200 )
268
+ expect ( res . body ) . to . be . a ( 'object' )
269
+ expect ( res . body . message ) . to . equal ( 'Tasks returned successfully!' )
270
+
271
+ const task1 = res . body . tasks [ 0 ]
272
+
273
+ if ( task1 . type === 'group' ) {
274
+ expect ( task1 . participants ) . to . include ( appOwner . username )
275
+ } else {
276
+ expect ( task1 . assignee ) . to . equal ( appOwner . username )
277
+ }
278
+
279
+ expect ( res . body . tasks ) . to . be . a ( 'array' )
280
+ return done ( )
281
+ } )
282
+ } )
283
+
284
+ it ( 'Should return 404 when username is invalid' , function ( done ) {
285
+ chai
286
+ . request ( app )
287
+ . get ( '/tasks/dummyUser' )
288
+ . end ( ( err , res ) => {
289
+ if ( err ) { return done ( err ) }
290
+ expect ( res ) . to . have . status ( 404 )
291
+ expect ( res . body ) . to . be . a ( 'object' )
292
+ expect ( res . body . message ) . to . equal ( 'User doesn\'t exist' )
293
+ return done ( )
294
+ } )
295
+ } )
296
+ } )
252
297
} )
0 commit comments