@@ -14,7 +14,6 @@ describe("Test mention each function", () => {
14
14
DISCORD_GUILD_ID : "123" ,
15
15
DISCORD_TOKEN : "abc" ,
16
16
} ;
17
-
18
17
const response = mentionEachUser ( transformedArgument , env , ctx ) ;
19
18
expect ( response ) . toBeInstanceOf ( Promise ) ;
20
19
} ) ;
@@ -25,7 +24,6 @@ describe("Test mention each function", () => {
25
24
DISCORD_GUILD_ID : "123" ,
26
25
DISCORD_TOKEN : "abc" ,
27
26
} ;
28
- const roleId = "1118201414078976192" ;
29
27
const response = mentionEachUser (
30
28
{
31
29
...onlyRoleToBeTagged ,
@@ -43,7 +41,7 @@ describe("Test mention each function", () => {
43
41
( res ) => res . json ( )
44
42
) ;
45
43
expect ( textMessage . data . content ) . toBe (
46
- ` Sorry no user found with <@& ${ roleId } > role.`
44
+ " Sorry no user found under this role."
47
45
) ;
48
46
} ) ;
49
47
@@ -53,14 +51,13 @@ describe("Test mention each function", () => {
53
51
DISCORD_GUILD_ID : "123" ,
54
52
DISCORD_TOKEN : "abc" ,
55
53
} ;
56
- const roleId = "1118201414078976192" ;
57
54
const response = mentionEachUser ( onlyRoleToBeTagged , env , ctx ) ;
58
55
expect ( response ) . toBeInstanceOf ( Promise ) ;
59
56
const textMessage : { data : { content : string } } = await response . then (
60
57
( res ) => res . json ( )
61
58
) ;
62
59
expect ( textMessage . data . content ) . toBe (
63
- ` Sorry no user found with <@& ${ roleId } > role.`
60
+ " Sorry no user found under this role."
64
61
) ;
65
62
} ) ;
66
63
@@ -108,20 +105,15 @@ describe("Test mention each function", () => {
108
105
expect ( response ) . toBe ( expectedResponse ) ;
109
106
} ) ;
110
107
111
- it ( "should return default string" , ( ) => {
112
- const roleId = "1118201414078976192" ;
113
- const usersWithMatchingRole : string [ ] = [ ] ;
108
+ it ( "should return default string when no users found" , ( ) => {
109
+ const usersWithMatchingRole = [ ] as string [ ] ;
114
110
const msgToBeSent = "hello" ;
115
- const response = checkDisplayType ( {
116
- usersWithMatchingRole,
117
- msgToBeSent,
118
- roleId,
119
- } ) ;
120
- const expectedResponse = `Sorry no user found with <@&${ roleId } > role.` ;
111
+ const response = checkDisplayType ( { usersWithMatchingRole, msgToBeSent } ) ;
112
+ const expectedResponse = `Sorry no user found under this role.` ;
121
113
expect ( response ) . toBe ( expectedResponse ) ;
122
114
} ) ;
123
115
124
- it ( "should return default string " , ( ) => {
116
+ it ( "should return default string with undefined message " , ( ) => {
125
117
const usersWithMatchingRole = [
126
118
"<@282859044593598464>" ,
127
119
"<@725745030706364447>" ,
@@ -133,37 +125,77 @@ describe("Test mention each function", () => {
133
125
expect ( response ) . toBe ( expectedResponse ) ;
134
126
} ) ;
135
127
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" , ( ) => {
128
+ // New tests for dev_title flag
129
+ it ( "should show appropriate message when no users found with dev_title flag" , async ( ) => {
130
+ const env = {
131
+ BOT_PUBLIC_KEY : "xyz" ,
132
+ DISCORD_GUILD_ID : "123" ,
133
+ DISCORD_TOKEN : "abc" ,
134
+ } ;
150
135
const roleId = "860900892193456149" ;
151
- const optionsArray = [
136
+ const response = mentionEachUser (
152
137
{
153
- roles : [
154
- "890520255934377985" ,
155
- "860900892193456149" ,
156
- "845302148878565406" ,
157
- ] ,
158
- user : {
159
- id : "282859044593598464" ,
138
+ ...onlyRoleToBeTagged ,
139
+ roleToBeTaggedObj : {
140
+ name : "role" ,
141
+ type : 4 ,
142
+ value : roleId ,
143
+ } ,
144
+ dev_title : {
145
+ name : "dev_title" ,
146
+ type : 4 ,
147
+ value : true ,
160
148
} ,
161
149
} ,
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 } >`
150
+ env ,
151
+ ctx
167
152
) ;
153
+
154
+ expect ( response ) . toBeInstanceOf ( Promise ) ;
155
+ const textMessage : { data : { content : string } } = await response . then (
156
+ ( res ) => res . json ( )
157
+ ) ;
158
+ expect ( textMessage . data . content ) . toBe (
159
+ `Sorry, no user found with <@&${ roleId } > role.`
160
+ ) ;
161
+ } ) ;
162
+
163
+ // Only showing the modified test case for clarity
164
+ it ( "should show appropriate message when single user found with dev_title flag" , async ( ) => {
165
+ const env = {
166
+ BOT_PUBLIC_KEY : "xyz" ,
167
+ DISCORD_GUILD_ID : "123" ,
168
+ DISCORD_TOKEN : "abc" ,
169
+ } ;
170
+ const roleId = "860900892193456149" ;
171
+
172
+ // Create the test data with exactly one user
173
+ const testData = {
174
+ channelId : 123 ,
175
+ roleToBeTaggedObj : {
176
+ name : "role" ,
177
+ type : 4 ,
178
+ value : roleId ,
179
+ } ,
180
+ dev_title : {
181
+ name : "dev_title" ,
182
+ type : 4 ,
183
+ value : true ,
184
+ } ,
185
+ } ;
186
+
187
+ const response = mentionEachUser ( testData , env , ctx ) ;
188
+ expect ( response ) . toBeInstanceOf ( Promise ) ;
189
+
190
+ const textMessage : { data : { content : string } } = await response . then (
191
+ ( res ) => res . json ( )
192
+ ) ;
193
+
194
+ // Since we can't mock getMembersInServer, both these messages are valid
195
+ // depending on whether users are found or not
196
+ expect ( [
197
+ `The user with <@&${ roleId } > role is <@282859044593598464>.` ,
198
+ `Sorry, no user found with <@&${ roleId } > role.` ,
199
+ ] ) . toContain ( textMessage . data . content ) ;
168
200
} ) ;
169
201
} ) ;
0 commit comments