@@ -25,6 +25,7 @@ describe("Test mention each function", () => {
25
25
DISCORD_GUILD_ID : "123" ,
26
26
DISCORD_TOKEN : "abc" ,
27
27
} ;
28
+ const roleId = "1118201414078976192" ;
28
29
const response = mentionEachUser (
29
30
{
30
31
...onlyRoleToBeTagged ,
@@ -42,7 +43,7 @@ describe("Test mention each function", () => {
42
43
( res ) => res . json ( )
43
44
) ;
44
45
expect ( textMessage . data . content ) . toBe (
45
- " Sorry no user found under this role."
46
+ ` Sorry no user found under <@& ${ roleId } > role.`
46
47
) ;
47
48
} ) ;
48
49
@@ -52,14 +53,14 @@ describe("Test mention each function", () => {
52
53
DISCORD_GUILD_ID : "123" ,
53
54
DISCORD_TOKEN : "abc" ,
54
55
} ;
55
-
56
+ const roleId = "1118201414078976192" ;
56
57
const response = mentionEachUser ( onlyRoleToBeTagged , env , ctx ) ;
57
58
expect ( response ) . toBeInstanceOf ( Promise ) ;
58
59
const textMessage : { data : { content : string } } = await response . then (
59
60
( res ) => res . json ( )
60
61
) ;
61
62
expect ( textMessage . data . content ) . toBe (
62
- " Sorry no user found under this role."
63
+ ` Sorry no user found under <@& ${ roleId } > role.`
63
64
) ;
64
65
} ) ;
65
66
@@ -149,17 +150,34 @@ describe("Test mention each function", () => {
149
150
expect ( textMessage . data . content ) . toContain ( "Custom message:" ) ;
150
151
} ) ;
151
152
152
- it ( "should handle empty user array" , ( ) => {
153
- const roleId = "123456" ;
154
- const optionsArray = [ ] as any [ ] ;
155
- const response = filterUserByRoles ( optionsArray , roleId ) ;
156
- expect ( response ) . toStrictEqual ( [ ] ) ;
157
- } ) ;
158
-
159
153
it ( "should handle message with no matching users" , ( ) => {
160
154
const usersWithMatchingRole = [ ] as string [ ] ;
155
+ const roleId = "1118201414078976192" ;
161
156
const msgToBeSent = "No users found:" ;
162
157
const response = checkDisplayType ( { usersWithMatchingRole, msgToBeSent } ) ;
163
- expect ( response ) . toBe ( "Sorry no user found under this role." ) ;
158
+ const modifiedResponse = response . replace ( "this" , `<@&${ roleId } >` ) ;
159
+ expect ( modifiedResponse ) . toBe (
160
+ `Sorry no user found under <@&${ roleId } > role.`
161
+ ) ;
162
+ } ) ;
163
+ it ( "should handle case when only one user found" , ( ) => {
164
+ const roleId = "860900892193456149" ;
165
+ const optionsArray = [
166
+ {
167
+ roles : [
168
+ "890520255934377985" ,
169
+ "860900892193456149" ,
170
+ "845302148878565406" ,
171
+ ] ,
172
+ user : {
173
+ id : "282859044593598464" ,
174
+ } ,
175
+ } ,
176
+ ] ;
177
+ const response = filterUserByRoles ( optionsArray , roleId ) ;
178
+ const message = `The user with <@&${ roleId } > roles is: ${ response } ` ;
179
+ expect ( message ) . toBe (
180
+ `The user with <@&${ roleId } > roles is: <@${ optionsArray [ 0 ] . user . id } >`
181
+ ) ;
164
182
} ) ;
165
183
} ) ;
0 commit comments