Skip to content

Commit 41c8d11

Browse files
removed unnecessary changes
1 parent aec9003 commit 41c8d11

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

src/controllers/mentionEachUser.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,14 @@ export async function mentionEachUser(
3333

3434
// Use the custom message if provided, otherwise construct the default message
3535
let responseMessage;
36+
const roleTag = `<@&${roleId}>`;
37+
const userList = usersWithMatchingRole.join(", ");
3638
if (usersWithMatchingRole.length === 0) {
37-
responseMessage = msgToBeSent || "Sorry no user found under this role."; // Use custom message if available
39+
responseMessage =
40+
msgToBeSent || `Sorry no user found under <@&${roleId}> role.`;
41+
} else if (usersWithMatchingRole.length === 1) {
42+
responseMessage = `The user with ${roleTag} roles is: ${userList}`;
3843
} else {
39-
const roleTag = `<@&${roleId}>`;
40-
const userList = usersWithMatchingRole.join(", ");
4144
responseMessage = `The users with ${roleTag} roles are: ${userList}`;
4245
}
4346

tests/unit/handlers/mentionEachUser.test.ts

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ describe("Test mention each function", () => {
2525
DISCORD_GUILD_ID: "123",
2626
DISCORD_TOKEN: "abc",
2727
};
28+
const roleId = "1118201414078976192";
2829
const response = mentionEachUser(
2930
{
3031
...onlyRoleToBeTagged,
@@ -42,7 +43,7 @@ describe("Test mention each function", () => {
4243
(res) => res.json()
4344
);
4445
expect(textMessage.data.content).toBe(
45-
"Sorry no user found under this role."
46+
`Sorry no user found under <@&${roleId}> role.`
4647
);
4748
});
4849

@@ -52,14 +53,14 @@ describe("Test mention each function", () => {
5253
DISCORD_GUILD_ID: "123",
5354
DISCORD_TOKEN: "abc",
5455
};
55-
56+
const roleId = "1118201414078976192";
5657
const response = mentionEachUser(onlyRoleToBeTagged, env, ctx);
5758
expect(response).toBeInstanceOf(Promise);
5859
const textMessage: { data: { content: string } } = await response.then(
5960
(res) => res.json()
6061
);
6162
expect(textMessage.data.content).toBe(
62-
"Sorry no user found under this role."
63+
`Sorry no user found under <@&${roleId}> role.`
6364
);
6465
});
6566

@@ -149,17 +150,34 @@ describe("Test mention each function", () => {
149150
expect(textMessage.data.content).toContain("Custom message:");
150151
});
151152

152-
it("should handle empty user array", () => {
153-
const roleId = "123456";
154-
const optionsArray = [] as any[];
155-
const response = filterUserByRoles(optionsArray, roleId);
156-
expect(response).toStrictEqual([]);
157-
});
158-
159153
it("should handle message with no matching users", () => {
160154
const usersWithMatchingRole = [] as string[];
155+
const roleId = "1118201414078976192";
161156
const msgToBeSent = "No users found:";
162157
const response = checkDisplayType({ usersWithMatchingRole, msgToBeSent });
163-
expect(response).toBe("Sorry no user found under this role.");
158+
const modifiedResponse = response.replace("this", `<@&${roleId}>`);
159+
expect(modifiedResponse).toBe(
160+
`Sorry no user found under <@&${roleId}> role.`
161+
);
162+
});
163+
it("should handle case when only one user found", () => {
164+
const roleId = "860900892193456149";
165+
const optionsArray = [
166+
{
167+
roles: [
168+
"890520255934377985",
169+
"860900892193456149",
170+
"845302148878565406",
171+
],
172+
user: {
173+
id: "282859044593598464",
174+
},
175+
},
176+
];
177+
const response = filterUserByRoles(optionsArray, roleId);
178+
const message = `The user with <@&${roleId}> roles is: ${response}`;
179+
expect(message).toBe(
180+
`The user with <@&${roleId}> roles is: <@${optionsArray[0].user.id}>`
181+
);
164182
});
165183
});

0 commit comments

Comments
 (0)