@@ -25,9 +25,15 @@ describe("Test mention each function", () => {
25
25
DISCORD_GUILD_ID : "123" ,
26
26
DISCORD_TOKEN : "abc" ,
27
27
} ;
28
+ const roleId = "123456789" ;
28
29
const response = mentionEachUser (
29
30
{
30
31
...onlyRoleToBeTagged ,
32
+ roleToBeTaggedObj : {
33
+ name : "roleToBeTagged" ,
34
+ type : 3 ,
35
+ value : roleId ,
36
+ } ,
31
37
dev : {
32
38
name : "dev" ,
33
39
type : 4 ,
@@ -42,7 +48,7 @@ describe("Test mention each function", () => {
42
48
( res ) => res . json ( )
43
49
) ;
44
50
expect ( textMessage . data . content ) . toBe (
45
- " Sorry no user found under this role."
51
+ ` Sorry no user found under <@& ${ roleId } > role.`
46
52
) ;
47
53
} ) ;
48
54
@@ -52,14 +58,25 @@ describe("Test mention each function", () => {
52
58
DISCORD_GUILD_ID : "123" ,
53
59
DISCORD_TOKEN : "abc" ,
54
60
} ;
55
-
56
- const response = mentionEachUser ( onlyRoleToBeTagged , env , ctx ) ;
61
+ const roleId = "123456789" ;
62
+ const response = mentionEachUser (
63
+ {
64
+ ...onlyRoleToBeTagged ,
65
+ roleToBeTaggedObj : {
66
+ name : "roleToBeTagged" ,
67
+ type : 3 ,
68
+ value : roleId ,
69
+ } ,
70
+ } ,
71
+ env ,
72
+ ctx
73
+ ) ;
57
74
expect ( response ) . toBeInstanceOf ( Promise ) ;
58
75
const textMessage : { data : { content : string } } = await response . then (
59
76
( res ) => res . json ( )
60
77
) ;
61
78
expect ( textMessage . data . content ) . toBe (
62
- " Sorry no user found under this role."
79
+ ` Sorry no user found under <@& ${ roleId } > role.`
63
80
) ;
64
81
} ) ;
65
82
@@ -162,4 +179,43 @@ describe("Test mention each function", () => {
162
179
const response = checkDisplayType ( { usersWithMatchingRole, msgToBeSent } ) ;
163
180
expect ( response ) . toBe ( "Sorry no user found under this role." ) ;
164
181
} ) ;
182
+
183
+ it ( "should return message when only one user found" , async ( ) => {
184
+ const env = {
185
+ BOT_PUBLIC_KEY : "xyz" ,
186
+ DISCORD_GUILD_ID : "123" ,
187
+ DISCORD_TOKEN : "abc" ,
188
+ } ;
189
+
190
+ const roleId = "123456789" ;
191
+ const userId = "256859044593598464" ;
192
+
193
+ const mockUserData = [
194
+ {
195
+ roles : [ "123456789" ] ,
196
+ user : { id : userId } ,
197
+ } ,
198
+ ] ;
199
+
200
+ const onlyRoleToBeTagged = {
201
+ roleToBeTaggedObj : {
202
+ name : "roleToBeTagged" ,
203
+ type : 3 ,
204
+ value : roleId ,
205
+ } ,
206
+ channelId : 12345 ,
207
+ } ;
208
+
209
+ // Call mentionEachUser and pass in the mock user data
210
+ const response = await mentionEachUser ( onlyRoleToBeTagged , env , ctx , mockUserData ) ;
211
+
212
+ // Extract the message content from the response
213
+ const textMessage : { data : { content : string } } = await response . json ( ) ;
214
+
215
+ // Construct the expected response based on the function logic
216
+ const expectedResponse = `The user with <@&${ roleId } > role is: <@${ userId } >` ;
217
+
218
+ // Assert that the response message content matches the expected output
219
+ expect ( textMessage . data . content ) . toBe ( expectedResponse ) ;
220
+ } ) ;
165
221
} ) ;
0 commit comments