@@ -296,7 +296,7 @@ describe("UserStatus", function () {
296
296
it ( "Should store the User Status in the collection" , function ( done ) {
297
297
chai
298
298
. request ( app )
299
- . patch ( `/users/status/self ` )
299
+ . patch ( `/users/status/${ testUserId } ` )
300
300
. set ( "Cookie" , `${ cookieName } =${ testUserJwt } ` )
301
301
. send ( userStatusDataForOooState )
302
302
. end ( ( err , res ) => {
@@ -329,6 +329,24 @@ describe("UserStatus", function () {
329
329
} ) ;
330
330
} ) ;
331
331
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
+
332
350
// Skipping this as the users are not allowed to mark them as active or idle. Will remove the test while removing the feature flag.
333
351
// eslint-disable-next-line mocha/no-skipped-tests
334
352
it . skip ( "Should update the User Status" , function ( done ) {
@@ -350,7 +368,7 @@ describe("UserStatus", function () {
350
368
it ( "Should update the User Status without reason for short duration" , function ( done ) {
351
369
chai
352
370
. request ( app )
353
- . patch ( `/users/status/self ` )
371
+ . patch ( `/users/status/${ userId } ` )
354
372
. set ( "cookie" , `${ cookieName } =${ jwt } ` )
355
373
. send ( oooStatusDataForShortDuration )
356
374
. end ( ( err , res ) => {
@@ -398,10 +416,27 @@ describe("UserStatus", function () {
398
416
} ) ;
399
417
} ) ;
400
418
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
+
401
436
it ( "Should return 400 for incorrect state value" , function ( done ) {
402
437
chai
403
438
. request ( app )
404
- . patch ( `/users/status/self ` )
439
+ . patch ( `/users/status/${ testUserId } ` )
405
440
. set ( "cookie" , `${ cookieName } =${ testUserJwt } ` )
406
441
. send ( generateUserStatusData ( "IN_OFFICE" , Date . now ( ) , Date . now ( ) ) )
407
442
. end ( ( err , res ) => {
@@ -421,7 +456,7 @@ describe("UserStatus", function () {
421
456
const untilDate = Date . now ( ) + 4 * 24 * 60 * 60 * 1000 ;
422
457
chai
423
458
. request ( app )
424
- . patch ( `/users/status/self ` )
459
+ . patch ( `/users/status/${ testUserId } ` )
425
460
. set ( "cookie" , `${ cookieName } =${ testUserJwt } ` )
426
461
. send ( generateUserStatusData ( "OOO" , Date . now ( ) , Date . now ( ) , untilDate , "" ) )
427
462
. end ( ( err , res ) => {
@@ -442,7 +477,7 @@ describe("UserStatus", function () {
442
477
const fromDate = Date . now ( ) - 4 * 24 * 60 * 60 * 1000 ;
443
478
chai
444
479
. request ( app )
445
- . patch ( `/users/status/self ` )
480
+ . patch ( `/users/status/${ testUserId } ` )
446
481
. set ( "cookie" , `${ cookieName } =${ testUserJwt } ` )
447
482
. send ( generateUserStatusData ( "OOO" , Date . now ( ) , fromDate , "" , "" ) )
448
483
. end ( ( err , res ) => {
@@ -464,7 +499,7 @@ describe("UserStatus", function () {
464
499
const untilDate = Date . now ( ) + 5 * 24 * 60 * 60 * 1000 ;
465
500
chai
466
501
. request ( app )
467
- . patch ( `/users/status/self ` )
502
+ . patch ( `/users/status/${ testUserId } ` )
468
503
. set ( "cookie" , `${ cookieName } =${ testUserJwt } ` )
469
504
. send ( generateUserStatusData ( "OOO" , Date . now ( ) , fromDate , untilDate , "Semester Exams" ) )
470
505
. end ( ( err , res ) => {
@@ -493,7 +528,7 @@ describe("UserStatus", function () {
493
528
let untilDateInUTC = convertTimestampToUTCStartOrEndOfDay ( untilDate , true ) ;
494
529
const response2 = await chai
495
530
. request ( app )
496
- . patch ( `/users/status/self ` )
531
+ . patch ( `/users/status/${ testUserId } ` )
497
532
. set ( "Cookie" , `${ cookieName } =${ testUserJwt } ` )
498
533
. send ( generateUserStatusData ( "OOO" , Date . now ( ) , fromDate , untilDate , "Vacation Trip" ) ) ;
499
534
expect ( response2 ) . to . have . status ( 200 ) ;
@@ -510,7 +545,7 @@ describe("UserStatus", function () {
510
545
untilDateInUTC = convertTimestampToUTCStartOrEndOfDay ( untilDate , true ) ;
511
546
const response3 = await chai
512
547
. request ( app )
513
- . patch ( `/users/status/self ` )
548
+ . patch ( `/users/status/${ testUserId } ` )
514
549
. set ( "Cookie" , `${ cookieName } =${ testUserJwt } ` )
515
550
. send ( generateUserStatusData ( "OOO" , Date . now ( ) , fromDate , untilDate , "New plan for vacation Trip" ) ) ;
516
551
expect ( response3 ) . to . have . status ( 200 ) ;
@@ -521,7 +556,10 @@ describe("UserStatus", function () {
521
556
expect ( response3 . body . data . futureStatus . until ) . to . equal ( untilDateInUTC ) ; // 5th Dec 2022
522
557
523
558
// 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 } ` ) ;
525
563
expect ( response4 ) . to . have . status ( 200 ) ;
526
564
expect ( response4 . body ) . to . be . a ( "object" ) ;
527
565
expect ( response4 . body . message ) . to . equal ( "User Status found successfully." ) ;
@@ -541,7 +579,7 @@ describe("UserStatus", function () {
541
579
let untilDateInUTC = convertTimestampToUTCStartOrEndOfDay ( untilDate , true ) ;
542
580
const response1 = await chai
543
581
. request ( app )
544
- . patch ( `/users/status/self ` )
582
+ . patch ( `/users/status/${ testUserId } ` )
545
583
. set ( "Cookie" , `${ cookieName } =${ testUserJwt } ` )
546
584
. send ( generateUserStatusData ( "OOO" , Date . now ( ) , fromDate , untilDate , "Vacation Trip" ) ) ;
547
585
expect ( response1 ) . to . have . status ( 201 ) ;
@@ -558,7 +596,7 @@ describe("UserStatus", function () {
558
596
untilDateInUTC = convertTimestampToUTCStartOrEndOfDay ( untilDate , true ) ;
559
597
const response2 = await chai
560
598
. request ( app )
561
- . patch ( `/users/status/self ` )
599
+ . patch ( `/users/status/${ testUserId } ` )
562
600
. set ( "Cookie" , `${ cookieName } =${ testUserJwt } ` )
563
601
. send ( generateUserStatusData ( "OOO" , Date . now ( ) , fromDate , untilDate , "Changed plan for vacation Trip" ) ) ;
564
602
expect ( response2 ) . to . have . status ( 200 ) ;
0 commit comments