1
1
import { mentionEachUser } from "../../../src/controllers/mentionEachUser" ;
2
2
import { checkDisplayType } from "../../../src/utils/checkDisplayType" ;
3
3
import { filterUserByRoles } from "../../../src/utils/filterUsersByRole" ;
4
+ import { testDataWithDevTitle } from "../../../tests/fixtures/fixture" ;
4
5
import {
5
6
onlyRoleToBeTagged ,
6
7
transformedArgument ,
@@ -14,7 +15,6 @@ describe("Test mention each function", () => {
14
15
DISCORD_GUILD_ID : "123" ,
15
16
DISCORD_TOKEN : "abc" ,
16
17
} ;
17
-
18
18
const response = mentionEachUser ( transformedArgument , env , ctx ) ;
19
19
expect ( response ) . toBeInstanceOf ( Promise ) ;
20
20
} ) ;
@@ -52,7 +52,6 @@ describe("Test mention each function", () => {
52
52
DISCORD_GUILD_ID : "123" ,
53
53
DISCORD_TOKEN : "abc" ,
54
54
} ;
55
-
56
55
const response = mentionEachUser ( onlyRoleToBeTagged , env , ctx ) ;
57
56
expect ( response ) . toBeInstanceOf ( Promise ) ;
58
57
const textMessage : { data : { content : string } } = await response . then (
@@ -107,15 +106,15 @@ describe("Test mention each function", () => {
107
106
expect ( response ) . toBe ( expectedResponse ) ;
108
107
} ) ;
109
108
110
- it ( "should return default string " , ( ) => {
109
+ it ( "should return default string when no users found " , ( ) => {
111
110
const usersWithMatchingRole = [ ] as string [ ] ;
112
111
const msgToBeSent = "hello" ;
113
112
const response = checkDisplayType ( { usersWithMatchingRole, msgToBeSent } ) ;
114
113
const expectedResponse = `Sorry no user found under this role.` ;
115
114
expect ( response ) . toBe ( expectedResponse ) ;
116
115
} ) ;
117
116
118
- it ( "should return default string " , ( ) => {
117
+ it ( "should return default string with undefined message " , ( ) => {
119
118
const usersWithMatchingRole = [
120
119
"<@282859044593598464>" ,
121
120
"<@725745030706364447>" ,
@@ -126,4 +125,60 @@ describe("Test mention each function", () => {
126
125
const expectedResponse = `${ returnString } ${ usersWithMatchingRole } ` ;
127
126
expect ( response ) . toBe ( expectedResponse ) ;
128
127
} ) ;
128
+
129
+ // New tests for dev_title flag
130
+ it ( "should show appropriate message when no users found with dev_title flag" , async ( ) => {
131
+ const env = {
132
+ BOT_PUBLIC_KEY : "xyz" ,
133
+ DISCORD_GUILD_ID : "123" ,
134
+ DISCORD_TOKEN : "abc" ,
135
+ } ;
136
+ const roleId = "860900892193456149" ;
137
+ const response = mentionEachUser (
138
+ {
139
+ ...onlyRoleToBeTagged ,
140
+ roleToBeTaggedObj : {
141
+ name : "role" ,
142
+ type : 4 ,
143
+ value : roleId ,
144
+ } ,
145
+ dev_title : {
146
+ name : "dev_title" ,
147
+ type : 4 ,
148
+ value : true ,
149
+ } ,
150
+ } ,
151
+ env ,
152
+ ctx
153
+ ) ;
154
+
155
+ expect ( response ) . toBeInstanceOf ( Promise ) ;
156
+ const textMessage : { data : { content : string } } = await response . then (
157
+ ( res ) => res . json ( )
158
+ ) ;
159
+ expect ( textMessage . data . content ) . toBe (
160
+ `Sorry, no user found with <@&${ roleId } > role.`
161
+ ) ;
162
+ } ) ;
163
+
164
+ // Only showing the modified test case for clarity
165
+ it ( "should show appropriate message when single user found with dev_title flag" , async ( ) => {
166
+ const env = {
167
+ BOT_PUBLIC_KEY : "xyz" ,
168
+ DISCORD_GUILD_ID : "123" ,
169
+ DISCORD_TOKEN : "abc" ,
170
+ } ;
171
+
172
+ const response = mentionEachUser ( testDataWithDevTitle , env , ctx ) ;
173
+ expect ( response ) . toBeInstanceOf ( Promise ) ;
174
+
175
+ const textMessage : { data : { content : string } } = await response . then (
176
+ ( res ) => res . json ( )
177
+ ) ;
178
+
179
+ expect ( [
180
+ `The user with <@&${ testDataWithDevTitle . roleToBeTaggedObj . value } > role is <@282859044593598464>.` ,
181
+ `Sorry, no user found with <@&${ testDataWithDevTitle . roleToBeTaggedObj . value } > role.` ,
182
+ ] ) . toContain ( textMessage . data . content ) ;
183
+ } ) ;
129
184
} ) ;
0 commit comments