@@ -537,4 +537,59 @@ describe("Task Based Status Updates", function () {
537
537
) ;
538
538
} ) ;
539
539
} ) ;
540
+
541
+ describe ( "PATCH Update User Status on Task Assignment by SuperUser" , function ( ) {
542
+ let userId1 , user2Name , superUserId , superUserJwt , taskArr ;
543
+ const reqBody = { } ;
544
+
545
+ beforeEach ( async function ( ) {
546
+ userId1 = await addUser ( userData [ 6 ] ) ;
547
+ superUserId = await addUser ( userData [ 4 ] ) ;
548
+ superUserJwt = authService . generateAuthToken ( { userId : superUserId } ) ;
549
+ await addUser ( userData [ 0 ] ) ;
550
+ user2Name = userData [ 0 ] . username ;
551
+ taskArr = allTasks ( ) ;
552
+ const sampleTask1 = taskArr [ 0 ] ;
553
+ sampleTask1 . assignee = userId1 ;
554
+ sampleTask1 . createdBy = superUserId ;
555
+ await firestore . collection ( "tasks" ) . doc ( "taskid123" ) . set ( sampleTask1 ) ;
556
+ const statusData = generateStatusDataForState ( userId1 , userState . ACTIVE ) ;
557
+ await firestore . collection ( "usersStatus" ) . doc ( "userStatusDoc001" ) . set ( statusData ) ;
558
+ } ) ;
559
+
560
+ afterEach ( async function ( ) {
561
+ await cleanDb ( ) ;
562
+ } ) ;
563
+
564
+ it ( "Update the old assignee status to IDLE on task reassignment if no tasks is in progress in their name" , async function ( ) {
565
+ reqBody . assignee = user2Name ;
566
+ const res = await chai
567
+ . request ( app )
568
+ . patch ( `/tasks/taskid123?userStatusFlag=true` )
569
+ . set ( "cookie" , `${ cookieName } =${ superUserJwt } ` )
570
+ . send ( reqBody ) ;
571
+ expect ( res . status ) . to . equal ( 204 ) ;
572
+ const userStatus002Data = ( await userStatusModel . doc ( "userStatusDoc001" ) . get ( ) ) . data ( ) ;
573
+ expect ( userStatus002Data ) . to . have . keys ( [ "userId" , "currentStatus" ] ) ;
574
+ expect ( userStatus002Data . currentStatus . state ) . to . equal ( userState . IDLE ) ;
575
+ } ) ;
576
+
577
+ it ( "Should maintain the old assignee status to ACTIVE on task reassignment if another task is in progress in their name" , async function ( ) {
578
+ const sampleTask2 = taskArr [ 1 ] ;
579
+ sampleTask2 . assignee = userId1 ;
580
+ sampleTask2 . createdBy = superUserId ;
581
+ await firestore . collection ( "tasks" ) . doc ( "taskid234" ) . set ( sampleTask2 ) ;
582
+
583
+ reqBody . assignee = user2Name ;
584
+ const res = await chai
585
+ . request ( app )
586
+ . patch ( `/tasks/taskid123?userStatusFlag=true` )
587
+ . set ( "cookie" , `${ cookieName } =${ superUserJwt } ` )
588
+ . send ( reqBody ) ;
589
+ expect ( res . status ) . to . equal ( 204 ) ;
590
+ const userStatus002Data = ( await userStatusModel . doc ( "userStatusDoc001" ) . get ( ) ) . data ( ) ;
591
+ expect ( userStatus002Data ) . to . have . keys ( [ "userId" , "currentStatus" ] ) ;
592
+ expect ( userStatus002Data . currentStatus . state ) . to . equal ( userState . ACTIVE ) ;
593
+ } ) ;
594
+ } ) ;
540
595
} ) ;
0 commit comments