@@ -296,7 +296,7 @@ describe("UserStatus", function () {
296296 it ( "Should store the User Status in the collection" , function ( done ) {
297297 chai
298298 . request ( app )
299- . patch ( `/users/status/self ` )
299+ . patch ( `/users/status/${ testUserId } ` )
300300 . set ( "Cookie" , `${ cookieName } =${ testUserJwt } ` )
301301 . send ( userStatusDataForOooState )
302302 . end ( ( err , res ) => {
@@ -329,6 +329,24 @@ describe("UserStatus", function () {
329329 } ) ;
330330 } ) ;
331331
332+ it ( "Should store the User Status in the collection when requested by User" , function ( done ) {
333+ chai
334+ . request ( app )
335+ . patch ( `/users/status/${ testUserId } ` )
336+ . set ( "Cookie" , `${ cookieName } =${ testUserJwt } ` )
337+ . send ( userStatusDataForOooState )
338+ . end ( ( err , res ) => {
339+ if ( err ) {
340+ return done ( err ) ;
341+ }
342+ expect ( res ) . to . have . status ( 201 ) ;
343+ expect ( res . body ) . to . be . a ( "object" ) ;
344+ expect ( res . body . message ) . to . equal ( "User Status created successfully." ) ;
345+ expect ( res . body . data . currentStatus . state ) . to . equal ( "OOO" ) ;
346+ return done ( ) ;
347+ } ) ;
348+ } ) ;
349+
332350 // Skipping this as the users are not allowed to mark them as active or idle. Will remove the test while removing the feature flag.
333351 // eslint-disable-next-line mocha/no-skipped-tests
334352 it . skip ( "Should update the User Status" , function ( done ) {
@@ -350,7 +368,7 @@ describe("UserStatus", function () {
350368 it ( "Should update the User Status without reason for short duration" , function ( done ) {
351369 chai
352370 . request ( app )
353- . patch ( `/users/status/self ` )
371+ . patch ( `/users/status/${ userId } ` )
354372 . set ( "cookie" , `${ cookieName } =${ jwt } ` )
355373 . send ( oooStatusDataForShortDuration )
356374 . end ( ( err , res ) => {
@@ -398,10 +416,27 @@ describe("UserStatus", function () {
398416 } ) ;
399417 } ) ;
400418
419+ it ( "Should return 401 for unauthorized request for user and superuser" , function ( done ) {
420+ chai
421+ . request ( app )
422+ . patch ( `/users/status/${ testUserId } ` )
423+ . set ( "cookie" , `${ cookieName } =${ jwt } ` )
424+ . send ( userStatusDataForOooState )
425+ . end ( ( err , res ) => {
426+ if ( err ) {
427+ return done ( err ) ;
428+ }
429+ expect ( res ) . to . have . status ( 401 ) ;
430+ expect ( res . body ) . to . be . a ( "object" ) ;
431+ expect ( res . body . message ) . to . equal ( "You are not authorized to perform this action." ) ;
432+ return done ( ) ;
433+ } ) ;
434+ } ) ;
435+
401436 it ( "Should return 400 for incorrect state value" , function ( done ) {
402437 chai
403438 . request ( app )
404- . patch ( `/users/status/self ` )
439+ . patch ( `/users/status/${ testUserId } ` )
405440 . set ( "cookie" , `${ cookieName } =${ testUserJwt } ` )
406441 . send ( generateUserStatusData ( "IN_OFFICE" , Date . now ( ) , Date . now ( ) ) )
407442 . end ( ( err , res ) => {
@@ -421,7 +456,7 @@ describe("UserStatus", function () {
421456 const untilDate = Date . now ( ) + 4 * 24 * 60 * 60 * 1000 ;
422457 chai
423458 . request ( app )
424- . patch ( `/users/status/self ` )
459+ . patch ( `/users/status/${ testUserId } ` )
425460 . set ( "cookie" , `${ cookieName } =${ testUserJwt } ` )
426461 . send ( generateUserStatusData ( "OOO" , Date . now ( ) , Date . now ( ) , untilDate , "" ) )
427462 . end ( ( err , res ) => {
@@ -442,7 +477,7 @@ describe("UserStatus", function () {
442477 const fromDate = Date . now ( ) - 4 * 24 * 60 * 60 * 1000 ;
443478 chai
444479 . request ( app )
445- . patch ( `/users/status/self ` )
480+ . patch ( `/users/status/${ testUserId } ` )
446481 . set ( "cookie" , `${ cookieName } =${ testUserJwt } ` )
447482 . send ( generateUserStatusData ( "OOO" , Date . now ( ) , fromDate , "" , "" ) )
448483 . end ( ( err , res ) => {
@@ -464,7 +499,7 @@ describe("UserStatus", function () {
464499 const untilDate = Date . now ( ) + 5 * 24 * 60 * 60 * 1000 ;
465500 chai
466501 . request ( app )
467- . patch ( `/users/status/self ` )
502+ . patch ( `/users/status/${ testUserId } ` )
468503 . set ( "cookie" , `${ cookieName } =${ testUserJwt } ` )
469504 . send ( generateUserStatusData ( "OOO" , Date . now ( ) , fromDate , untilDate , "Semester Exams" ) )
470505 . end ( ( err , res ) => {
@@ -493,7 +528,7 @@ describe("UserStatus", function () {
493528 let untilDateInUTC = convertTimestampToUTCStartOrEndOfDay ( untilDate , true ) ;
494529 const response2 = await chai
495530 . request ( app )
496- . patch ( `/users/status/self ` )
531+ . patch ( `/users/status/${ testUserId } ` )
497532 . set ( "Cookie" , `${ cookieName } =${ testUserJwt } ` )
498533 . send ( generateUserStatusData ( "OOO" , Date . now ( ) , fromDate , untilDate , "Vacation Trip" ) ) ;
499534 expect ( response2 ) . to . have . status ( 200 ) ;
@@ -510,7 +545,7 @@ describe("UserStatus", function () {
510545 untilDateInUTC = convertTimestampToUTCStartOrEndOfDay ( untilDate , true ) ;
511546 const response3 = await chai
512547 . request ( app )
513- . patch ( `/users/status/self ` )
548+ . patch ( `/users/status/${ testUserId } ` )
514549 . set ( "Cookie" , `${ cookieName } =${ testUserJwt } ` )
515550 . send ( generateUserStatusData ( "OOO" , Date . now ( ) , fromDate , untilDate , "New plan for vacation Trip" ) ) ;
516551 expect ( response3 ) . to . have . status ( 200 ) ;
@@ -521,7 +556,10 @@ describe("UserStatus", function () {
521556 expect ( response3 . body . data . futureStatus . until ) . to . equal ( untilDateInUTC ) ; // 5th Dec 2022
522557
523558 // Checking the current status
524- const response4 = await chai . request ( app ) . get ( `/users/status/self` ) . set ( "Cookie" , `${ cookieName } =${ testUserJwt } ` ) ;
559+ const response4 = await chai
560+ . request ( app )
561+ . get ( `/users/status/${ testUserId } ` )
562+ . set ( "Cookie" , `${ cookieName } =${ testUserJwt } ` ) ;
525563 expect ( response4 ) . to . have . status ( 200 ) ;
526564 expect ( response4 . body ) . to . be . a ( "object" ) ;
527565 expect ( response4 . body . message ) . to . equal ( "User Status found successfully." ) ;
@@ -541,7 +579,7 @@ describe("UserStatus", function () {
541579 let untilDateInUTC = convertTimestampToUTCStartOrEndOfDay ( untilDate , true ) ;
542580 const response1 = await chai
543581 . request ( app )
544- . patch ( `/users/status/self ` )
582+ . patch ( `/users/status/${ testUserId } ` )
545583 . set ( "Cookie" , `${ cookieName } =${ testUserJwt } ` )
546584 . send ( generateUserStatusData ( "OOO" , Date . now ( ) , fromDate , untilDate , "Vacation Trip" ) ) ;
547585 expect ( response1 ) . to . have . status ( 201 ) ;
@@ -558,7 +596,7 @@ describe("UserStatus", function () {
558596 untilDateInUTC = convertTimestampToUTCStartOrEndOfDay ( untilDate , true ) ;
559597 const response2 = await chai
560598 . request ( app )
561- . patch ( `/users/status/self ` )
599+ . patch ( `/users/status/${ testUserId } ` )
562600 . set ( "Cookie" , `${ cookieName } =${ testUserJwt } ` )
563601 . send ( generateUserStatusData ( "OOO" , Date . now ( ) , fromDate , untilDate , "Changed plan for vacation Trip" ) ) ;
564602 expect ( response2 ) . to . have . status ( 200 ) ;
0 commit comments