@@ -20,6 +20,7 @@ const config = require("config");
20
20
const { TASK_REQUEST_TYPE } = require ( "../../constants/taskRequests" ) ;
21
21
const usersUtils = require ( "../../utils/users" ) ;
22
22
const githubService = require ( "../../services/githubService" ) ;
23
+ const { userState } = require ( "../../constants/userStatus" ) ;
23
24
24
25
const cookieName = config . get ( "userToken.cookieName" ) ;
25
26
@@ -391,7 +392,7 @@ describe("Task Requests", function () {
391
392
let activeUserId , oooUserId ;
392
393
393
394
describe ( "When the user is super user" , function ( ) {
394
- before ( async function ( ) {
395
+ beforeEach ( async function ( ) {
395
396
userId = await addUser ( member ) ;
396
397
activeUserId = await addUser ( activeMember ) ;
397
398
oooUserId = await addUser ( member2 ) ;
@@ -407,6 +408,10 @@ describe("Task Requests", function () {
407
408
await userStatusModel . updateUserStatus ( oooUserId , { ...oooUserStatus } ) ;
408
409
await taskRequestsModel . addOrUpdate ( taskId , userId ) ;
409
410
} ) ;
411
+ afterEach ( async function ( ) {
412
+ sinon . restore ( ) ;
413
+ await cleanDb ( ) ;
414
+ } ) ;
410
415
411
416
it ( "should match response for successfull approval" , function ( done ) {
412
417
sinon . stub ( taskRequestsModel , "approveTaskRequest" ) . resolves ( { approvedTo : member . username } ) ;
@@ -518,6 +523,38 @@ describe("Task Requests", function () {
518
523
return done ( ) ;
519
524
} ) ;
520
525
} ) ;
526
+ describe ( "Checks the user status" , function ( ) {
527
+ it ( "Should change the user status to ACTIVE when request is successful" , async function ( ) {
528
+ sinon . stub ( taskRequestsModel , "approveTaskRequest" ) . resolves ( { approvedTo : member . username } ) ;
529
+ const res = await chai
530
+ . request ( app )
531
+ . patch ( "/taskRequests/approve" )
532
+ . set ( "cookie" , `${ cookieName } =${ jwt } ` )
533
+ . send ( {
534
+ taskRequestId : taskId ,
535
+ userId,
536
+ } ) ;
537
+
538
+ expect ( res ) . to . have . status ( 200 ) ;
539
+ const userStatus = await userStatusModel . getUserStatus ( userId ) ;
540
+ expect ( userStatus . data . currentStatus . state ) . to . be . equal ( userState . ACTIVE ) ;
541
+ } ) ;
542
+ it ( "Should not change the user status to ACTIVE when request is unsuccessful" , async function ( ) {
543
+ sinon . stub ( taskRequestsModel , "approveTaskRequest" ) . resolves ( { isTaskRequestInvalid : true } ) ;
544
+ const res = await chai
545
+ . request ( app )
546
+ . patch ( "/taskRequests/approve" )
547
+ . set ( "cookie" , `${ cookieName } =${ jwt } ` )
548
+ . send ( {
549
+ taskRequestId : taskId ,
550
+ userId,
551
+ } ) ;
552
+
553
+ expect ( res ) . to . have . status ( 400 ) ;
554
+ const userStatus = await userStatusModel . getUserStatus ( userId ) ;
555
+ expect ( userStatus . data . currentStatus . state ) . to . be . equal ( userState . IDLE ) ;
556
+ } ) ;
557
+ } ) ;
521
558
} ) ;
522
559
523
560
describe ( "When the user is not super user" , function ( ) {
0 commit comments