@@ -43,7 +43,7 @@ describe("Test mention each function", () => {
4343 ( res ) => res . json ( )
4444 ) ;
4545 expect ( textMessage . data . content ) . toBe (
46- `Sorry no user found under <@&${ roleId } > role.`
46+ `Sorry no user found with <@&${ roleId } > role.`
4747 ) ;
4848 } ) ;
4949
@@ -60,7 +60,7 @@ describe("Test mention each function", () => {
6060 ( res ) => res . json ( )
6161 ) ;
6262 expect ( textMessage . data . content ) . toBe (
63- `Sorry no user found under <@&${ roleId } > role.`
63+ `Sorry no user found with <@&${ roleId } > role.`
6464 ) ;
6565 } ) ;
6666
@@ -108,11 +108,16 @@ describe("Test mention each function", () => {
108108 expect ( response ) . toBe ( expectedResponse ) ;
109109 } ) ;
110110
111- it ( "should return default string " , ( ) => {
112- const usersWithMatchingRole = [ ] as string [ ] ;
111+ it ( "should return default string" , ( ) => {
112+ const roleId = "1118201414078976192" ;
113+ const usersWithMatchingRole : string [ ] = [ ] ;
113114 const msgToBeSent = "hello" ;
114- const response = checkDisplayType ( { usersWithMatchingRole, msgToBeSent } ) ;
115- 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.` ;
116121 expect ( response ) . toBe ( expectedResponse ) ;
117122 } ) ;
118123
@@ -128,37 +133,18 @@ describe("Test mention each function", () => {
128133 expect ( response ) . toBe ( expectedResponse ) ;
129134 } ) ;
130135
131- it ( "should handle custom message when provided" , async ( ) => {
132- const env = {
133- BOT_PUBLIC_KEY : "xyz" ,
134- DISCORD_GUILD_ID : "123" ,
135- DISCORD_TOKEN : "abc" ,
136- } ;
137- const customArg = {
138- ...transformedArgument ,
139- displayMessageObj : {
140- name : "displayMessage" ,
141- type : 3 ,
142- value : "Custom message:" ,
143- } ,
144- } ;
145- const response = mentionEachUser ( customArg , env , ctx ) ;
146- expect ( response ) . toBeInstanceOf ( Promise ) ;
147- const textMessage : { data : { content : string } } = await response . then (
148- ( res ) => res . json ( )
149- ) ;
150- expect ( textMessage . data . content ) . toContain ( "Custom message:" ) ;
151- } ) ;
152-
153- it ( "should handle message with no matching users" , ( ) => {
154- const usersWithMatchingRole = [ ] as string [ ] ;
155- const roleId = "1118201414078976192" ;
156- const msgToBeSent = "No users found:" ;
157- const response = checkDisplayType ( { usersWithMatchingRole, msgToBeSent } ) ;
158- const modifiedResponse = response . replace ( "this" , `<@&${ roleId } >` ) ;
159- expect ( modifiedResponse ) . toBe (
160- `Sorry no user found under <@&${ roleId } > role.`
161- ) ;
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+ } ) ;
162148 } ) ;
163149 it ( "should handle case when only one user found" , ( ) => {
164150 const roleId = "860900892193456149" ;
@@ -175,9 +161,9 @@ describe("Test mention each function", () => {
175161 } ,
176162 ] ;
177163 const response = filterUserByRoles ( optionsArray , roleId ) ;
178- const message = `The user with <@&${ roleId } > roles is: ${ response } ` ;
164+ const message = `The user with <@&${ roleId } > role is: ${ response } ` ;
179165 expect ( message ) . toBe (
180- `The user with <@&${ roleId } > roles is: <@${ optionsArray [ 0 ] . user . id } >`
166+ `The user with <@&${ roleId } > role is: <@${ optionsArray [ 0 ] . user . id } >`
181167 ) ;
182168 } ) ;
183169} ) ;
0 commit comments