@@ -16,6 +16,7 @@ const firestore = require("../../utils/firestore");
16
16
const userData = require ( "../fixtures/user/user" ) ( ) ;
17
17
const userModel = firestore . collection ( "users" ) ;
18
18
const tasksModel = firestore . collection ( "tasks" ) ;
19
+ const discordServices = require ( "../../services/discordService" ) ;
19
20
const { EXTERNAL_ACCOUNTS_POST_ACTIONS } = require ( "../../constants/external-accounts" ) ;
20
21
chai . use ( chaiHttp ) ;
21
22
const cookieName = config . get ( "userToken.cookieName" ) ;
@@ -537,6 +538,8 @@ describe("External Accounts", function () {
537
538
expect ( getUserResponseBeforeUpdate . body ) . to . not . have . property ( "discordId" ) ;
538
539
expect ( getUserResponseBeforeUpdate . body ) . to . not . have . property ( "discordJoinedAt" ) ;
539
540
541
+ const removeRoleFromUserStub = Sinon . stub ( discordServices , "removeRoleFromUser" ) . resolves ( ) ;
542
+
540
543
const response = await chai
541
544
. request ( app )
542
545
. patch ( `/external-accounts/link/${ externalAccountData [ 2 ] . token } ` )
@@ -553,6 +556,27 @@ describe("External Accounts", function () {
553
556
expect ( updatedUserDetails . body . roles . in_discord ) . to . equal ( true ) ;
554
557
expect ( updatedUserDetails . body ) . to . have . property ( "discordId" ) ;
555
558
expect ( updatedUserDetails . body ) . to . have . property ( "discordJoinedAt" ) ;
559
+
560
+ removeRoleFromUserStub . restore ( ) ;
561
+ } ) ;
562
+
563
+ it ( "Should return 500 when unverified role deletion failed" , async function ( ) {
564
+ await externalAccountsModel . addExternalAccountData ( externalAccountData [ 2 ] ) ;
565
+
566
+ const removeRoleFromUserStub = Sinon . stub ( discordServices , "removeRoleFromUser" ) . rejects ( ) ;
567
+
568
+ const response = await chai
569
+ . request ( app )
570
+ . patch ( `/external-accounts/link/${ externalAccountData [ 2 ] . token } ` )
571
+ . query ( { action : EXTERNAL_ACCOUNTS_POST_ACTIONS . DISCORD_USERS_SYNC } )
572
+ . set ( "Cookie" , `${ cookieName } =${ newUserJWT } ` ) ;
573
+
574
+ expect ( response ) . to . have . status ( 500 ) ;
575
+ expect ( response . body ) . to . be . an ( "object" ) ;
576
+ expect ( response . body ) . to . have . property ( "message" ) ;
577
+ expect ( response . body . message ) . to . equal ( `Role Deletion failed. Please contact admin.` ) ;
578
+
579
+ removeRoleFromUserStub . restore ( ) ;
556
580
} ) ;
557
581
} ) ;
558
582
} ) ;
0 commit comments