11import { mentionEachUser } from "../../../src/controllers/mentionEachUser" ;
22import { checkDisplayType } from "../../../src/utils/checkDisplayType" ;
33import { filterUserByRoles } from "../../../src/utils/filterUsersByRole" ;
4+ import { testDataWithDevTitle } from "../../../tests/fixtures/fixture" ;
45import {
56 onlyRoleToBeTagged ,
67 transformedArgument ,
@@ -14,7 +15,6 @@ describe("Test mention each function", () => {
1415 DISCORD_GUILD_ID : "123" ,
1516 DISCORD_TOKEN : "abc" ,
1617 } ;
17-
1818 const response = mentionEachUser ( transformedArgument , env , ctx ) ;
1919 expect ( response ) . toBeInstanceOf ( Promise ) ;
2020 } ) ;
@@ -52,7 +52,6 @@ describe("Test mention each function", () => {
5252 DISCORD_GUILD_ID : "123" ,
5353 DISCORD_TOKEN : "abc" ,
5454 } ;
55-
5655 const response = mentionEachUser ( onlyRoleToBeTagged , env , ctx ) ;
5756 expect ( response ) . toBeInstanceOf ( Promise ) ;
5857 const textMessage : { data : { content : string } } = await response . then (
@@ -107,15 +106,15 @@ describe("Test mention each function", () => {
107106 expect ( response ) . toBe ( expectedResponse ) ;
108107 } ) ;
109108
110- it ( "should return default string " , ( ) => {
109+ it ( "should return default string when no users found " , ( ) => {
111110 const usersWithMatchingRole = [ ] as string [ ] ;
112111 const msgToBeSent = "hello" ;
113112 const response = checkDisplayType ( { usersWithMatchingRole, msgToBeSent } ) ;
114113 const expectedResponse = `Sorry no user found under this role.` ;
115114 expect ( response ) . toBe ( expectedResponse ) ;
116115 } ) ;
117116
118- it ( "should return default string " , ( ) => {
117+ it ( "should return default string with undefined message " , ( ) => {
119118 const usersWithMatchingRole = [
120119 "<@282859044593598464>" ,
121120 "<@725745030706364447>" ,
@@ -126,4 +125,60 @@ describe("Test mention each function", () => {
126125 const expectedResponse = `${ returnString } ${ usersWithMatchingRole } ` ;
127126 expect ( response ) . toBe ( expectedResponse ) ;
128127 } ) ;
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+ } ) ;
129184} ) ;
0 commit comments