@@ -19,15 +19,21 @@ describe("Test mention each function", () => {
19
19
expect ( response ) . toBeInstanceOf ( Promise ) ;
20
20
} ) ;
21
21
22
- it ( "should run without displayMessageObj argument" , async ( ) => {
22
+ it ( "should run without displayMessageObj argument in dev mode " , async ( ) => {
23
23
const env = {
24
24
BOT_PUBLIC_KEY : "xyz" ,
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 ,
32
+ dev : {
33
+ name : "dev" ,
34
+ type : 4 ,
35
+ value : true ,
36
+ } ,
31
37
} ,
32
38
env ,
33
39
ctx
@@ -37,7 +43,7 @@ describe("Test mention each function", () => {
37
43
( res ) => res . json ( )
38
44
) ;
39
45
expect ( textMessage . data . content ) . toBe (
40
- " Sorry no user found under this role."
46
+ ` Sorry no user found with <@& ${ roleId } > role.`
41
47
) ;
42
48
} ) ;
43
49
@@ -47,14 +53,14 @@ describe("Test mention each function", () => {
47
53
DISCORD_GUILD_ID : "123" ,
48
54
DISCORD_TOKEN : "abc" ,
49
55
} ;
50
-
56
+ const roleId = "1118201414078976192" ;
51
57
const response = mentionEachUser ( onlyRoleToBeTagged , env , ctx ) ;
52
58
expect ( response ) . toBeInstanceOf ( Promise ) ;
53
59
const textMessage : { data : { content : string } } = await response . then (
54
60
( res ) => res . json ( )
55
61
) ;
56
62
expect ( textMessage . data . content ) . toBe (
57
- " Sorry no user found under this role."
63
+ ` Sorry no user found with <@& ${ roleId } > role.`
58
64
) ;
59
65
} ) ;
60
66
@@ -102,11 +108,16 @@ describe("Test mention each function", () => {
102
108
expect ( response ) . toBe ( expectedResponse ) ;
103
109
} ) ;
104
110
105
- it ( "should return default string " , ( ) => {
106
- const usersWithMatchingRole = [ ] as string [ ] ;
111
+ it ( "should return default string" , ( ) => {
112
+ const roleId = "1118201414078976192" ;
113
+ const usersWithMatchingRole : string [ ] = [ ] ;
107
114
const msgToBeSent = "hello" ;
108
- const response = checkDisplayType ( { usersWithMatchingRole, msgToBeSent } ) ;
109
- const expectedResponse = `Sorry no user found under this role.` ;
115
+ const response = checkDisplayType ( {
116
+ usersWithMatchingRole,
117
+ msgToBeSent,
118
+ roleId,
119
+ } ) ;
120
+ const expectedResponse = `Sorry no user found with <@&${ roleId } > role.` ;
110
121
expect ( response ) . toBe ( expectedResponse ) ;
111
122
} ) ;
112
123
@@ -121,4 +132,38 @@ describe("Test mention each function", () => {
121
132
const expectedResponse = `${ returnString } ${ usersWithMatchingRole } ` ;
122
133
expect ( response ) . toBe ( expectedResponse ) ;
123
134
} ) ;
135
+
136
+ describe ( "checkDisplayType" , ( ) => {
137
+ it ( "should handle message with no matching users" , ( ) => {
138
+ const usersWithMatchingRole : string [ ] = [ ] ;
139
+ const roleId = "1118201414078976192" ;
140
+ const msgToBeSent = "No users found:" ;
141
+ const response = checkDisplayType ( {
142
+ usersWithMatchingRole,
143
+ msgToBeSent,
144
+ roleId,
145
+ } ) ;
146
+ expect ( response ) . toBe ( `Sorry no user found with <@&${ roleId } > role.` ) ;
147
+ } ) ;
148
+ } ) ;
149
+ it ( "should handle case when only one user found" , ( ) => {
150
+ const roleId = "860900892193456149" ;
151
+ const optionsArray = [
152
+ {
153
+ roles : [
154
+ "890520255934377985" ,
155
+ "860900892193456149" ,
156
+ "845302148878565406" ,
157
+ ] ,
158
+ user : {
159
+ id : "282859044593598464" ,
160
+ } ,
161
+ } ,
162
+ ] ;
163
+ const response = filterUserByRoles ( optionsArray , roleId ) ;
164
+ const message = `The user with <@&${ roleId } > role is: ${ response } ` ;
165
+ expect ( message ) . toBe (
166
+ `The user with <@&${ roleId } > role is: <@${ optionsArray [ 0 ] . user . id } >`
167
+ ) ;
168
+ } ) ;
124
169
} ) ;
0 commit comments