11import config from "../../../config/config" ;
2+ import { UNAUTHORIZED_TO_CREATE_ONBOARDING_EXTENSION_REQUEST } from "../../../src/constants/responses" ;
23import { DISCORD_BASE_URL } from "../../../src/constants/urls" ;
34import { generateDiscordAuthToken } from "../../../src/utils/authTokenGenerator" ;
45import {
@@ -18,7 +19,6 @@ describe("createOnboaringExtension", () => {
1819 } ;
1920 const discordReplyUrl = `${ DISCORD_BASE_URL } /channels/${ args . channelId } /messages` ;
2021 const base_url = config ( env ) . RDS_BASE_API_URL ;
21- const errorContent = `<@${ args . discordId } > Error occurred while creating onboarding extension request.` ;
2222 const createOnboardingExtensionUrl = `${ base_url } /requests?dev=true` ;
2323 let fetchSpy : jest . SpyInstance ;
2424 let authToken : string ;
@@ -27,7 +27,6 @@ describe("createOnboaringExtension", () => {
2727 userId : args . userId ,
2828 type : "ONBOARDING" ,
2929 numberOfDays : args . numberOfDays ,
30- requestedBy : args . discordId ,
3130 reason : args . reason ,
3231 } ;
3332
@@ -47,33 +46,21 @@ describe("createOnboaringExtension", () => {
4746 jest . restoreAllMocks ( ) ;
4847 } ) ;
4948
50- it ( "should call fetch with error response" , async ( ) => {
51- fetchSpy . mockImplementation ( ( ) => {
52- throw new Error ( ) ;
53- } ) ;
54- try {
55- await createOnboardingExtension ( args , guildEnv ) ;
56- } catch ( err ) {
57- expect ( global . fetch ) . toHaveBeenCalledTimes ( 2 ) ;
58- expect ( global . fetch ) . toHaveBeenCalledWith ( createOnboardingExtensionUrl , {
59- method : "POST" ,
60- headers : {
61- "Content-Type" : "application/json" ,
62- Authorization : `Bearer ${ authToken } ` ,
63- } ,
64- body : JSON . stringify ( requestData ) ,
65- } ) ;
66- expect ( utils . sendReplyInDiscordChannel ) . toHaveBeenCalledTimes ( 1 ) ;
67- expect ( utils . sendReplyInDiscordChannel ) . toHaveBeenCalledWith (
68- discordReplyUrl ,
69- errorContent ,
70- guildEnv
71- ) ;
72- }
49+ it ( "should call sendReplyInDiscordChannel with error content" , async ( ) => {
50+ await createOnboardingExtension ( args , guildEnv ) ;
51+ expect ( utils . sendReplyInDiscordChannel ) . toHaveBeenCalledTimes ( 1 ) ;
52+ expect ( utils . sendReplyInDiscordChannel ) . toHaveBeenCalledWith (
53+ discordReplyUrl ,
54+ `<@${ args . discordId } > ${ UNAUTHORIZED_TO_CREATE_ONBOARDING_EXTENSION_REQUEST } ` ,
55+ guildEnv
56+ ) ;
7357 } ) ;
7458
7559 it ( "should call fetch with success response" , async ( ) => {
60+ args . userId = undefined ;
61+ requestData . userId = args . discordId ;
7662 await createOnboardingExtension ( args , guildEnv ) ;
63+
7764 expect ( global . fetch ) . toHaveBeenCalledTimes ( 2 ) ;
7865 expect ( global . fetch ) . toHaveBeenCalledWith ( createOnboardingExtensionUrl , {
7966 method : "POST" ,
@@ -83,6 +70,5 @@ describe("createOnboaringExtension", () => {
8370 } ,
8471 body : JSON . stringify ( requestData ) ,
8572 } ) ;
86- expect ( utils . sendReplyInDiscordChannel ) . toHaveBeenCalledTimes ( 1 ) ;
8773 } ) ;
8874} ) ;
0 commit comments