@@ -16,6 +16,7 @@ const firestore = require("../../utils/firestore");
1616const userData = require ( "../fixtures/user/user" ) ( ) ;
1717const userModel = firestore . collection ( "users" ) ;
1818const tasksModel = firestore . collection ( "tasks" ) ;
19+ const discordServices = require ( "../../services/discordService" ) ;
1920const { EXTERNAL_ACCOUNTS_POST_ACTIONS } = require ( "../../constants/external-accounts" ) ;
2021chai . use ( chaiHttp ) ;
2122const cookieName = config . get ( "userToken.cookieName" ) ;
@@ -537,6 +538,8 @@ describe("External Accounts", function () {
537538 expect ( getUserResponseBeforeUpdate . body ) . to . not . have . property ( "discordId" ) ;
538539 expect ( getUserResponseBeforeUpdate . body ) . to . not . have . property ( "discordJoinedAt" ) ;
539540
541+ const removeRoleFromUserStub = Sinon . stub ( discordServices , "removeRoleFromUser" ) . resolves ( ) ;
542+
540543 const response = await chai
541544 . request ( app )
542545 . patch ( `/external-accounts/link/${ externalAccountData [ 2 ] . token } ` )
@@ -553,6 +556,27 @@ describe("External Accounts", function () {
553556 expect ( updatedUserDetails . body . roles . in_discord ) . to . equal ( true ) ;
554557 expect ( updatedUserDetails . body ) . to . have . property ( "discordId" ) ;
555558 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 ( ) ;
556580 } ) ;
557581 } ) ;
558582} ) ;
0 commit comments