1
1
import config from "../../../config/config" ;
2
+ import { UNAUTHORIZED_TO_CREATE_ONBOARDING_EXTENSION_REQUEST } from "../../../src/constants/responses" ;
2
3
import { DISCORD_BASE_URL } from "../../../src/constants/urls" ;
3
4
import { generateDiscordAuthToken } from "../../../src/utils/authTokenGenerator" ;
4
5
import {
@@ -18,7 +19,6 @@ describe("createOnboaringExtension", () => {
18
19
} ;
19
20
const discordReplyUrl = `${ DISCORD_BASE_URL } /channels/${ args . channelId } /messages` ;
20
21
const base_url = config ( env ) . RDS_BASE_API_URL ;
21
- const errorContent = `<@${ args . discordId } > Error occurred while creating onboarding extension request.` ;
22
22
const createOnboardingExtensionUrl = `${ base_url } /requests?dev=true` ;
23
23
let fetchSpy : jest . SpyInstance ;
24
24
let authToken : string ;
@@ -27,7 +27,6 @@ describe("createOnboaringExtension", () => {
27
27
userId : args . userId ,
28
28
type : "ONBOARDING" ,
29
29
numberOfDays : args . numberOfDays ,
30
- requestedBy : args . discordId ,
31
30
reason : args . reason ,
32
31
} ;
33
32
@@ -47,33 +46,21 @@ describe("createOnboaringExtension", () => {
47
46
jest . restoreAllMocks ( ) ;
48
47
} ) ;
49
48
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
+ ) ;
73
57
} ) ;
74
58
75
59
it ( "should call fetch with success response" , async ( ) => {
60
+ args . userId = undefined ;
61
+ requestData . userId = args . discordId ;
76
62
await createOnboardingExtension ( args , guildEnv ) ;
63
+
77
64
expect ( global . fetch ) . toHaveBeenCalledTimes ( 2 ) ;
78
65
expect ( global . fetch ) . toHaveBeenCalledWith ( createOnboardingExtensionUrl , {
79
66
method : "POST" ,
@@ -83,6 +70,5 @@ describe("createOnboaringExtension", () => {
83
70
} ,
84
71
body : JSON . stringify ( requestData ) ,
85
72
} ) ;
86
- expect ( utils . sendReplyInDiscordChannel ) . toHaveBeenCalledTimes ( 1 ) ;
87
73
} ) ;
88
74
} ) ;
0 commit comments