Skip to content

Commit

Permalink
move some lines to fixtures from test
Browse files Browse the repository at this point in the history
  • Loading branch information
RishiChaubey31 committed Nov 1, 2024
1 parent 47b865d commit dd57bc0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
13 changes: 13 additions & 0 deletions tests/fixtures/fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,3 +370,16 @@ export const overdueTaskUsers = {
},
],
};
export const testDataWithDevTitle = {
channelId: 123,
roleToBeTaggedObj: {
name: "role",
type: 4,
value: "860900892193456149",
},
dev_title: {
name: "dev_title",
type: 4,
value: true,
},
};
25 changes: 4 additions & 21 deletions tests/unit/handlers/mentionEachUser.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { mentionEachUser } from "../../../src/controllers/mentionEachUser";
import { checkDisplayType } from "../../../src/utils/checkDisplayType";
import { filterUserByRoles } from "../../../src/utils/filterUsersByRole";
import { testDataWithDevTitle } from "../../../tests/fixtures/fixture";
import {
onlyRoleToBeTagged,
transformedArgument,
Expand Down Expand Up @@ -167,35 +168,17 @@ describe("Test mention each function", () => {
DISCORD_GUILD_ID: "123",
DISCORD_TOKEN: "abc",
};
const roleId = "860900892193456149";

// Create the test data with exactly one user
const testData = {
channelId: 123,
roleToBeTaggedObj: {
name: "role",
type: 4,
value: roleId,
},
dev_title: {
name: "dev_title",
type: 4,
value: true,
},
};

const response = mentionEachUser(testData, env, ctx);
const response = mentionEachUser(testDataWithDevTitle, env, ctx);
expect(response).toBeInstanceOf(Promise);

const textMessage: { data: { content: string } } = await response.then(
(res) => res.json()
);

// Since we can't mock getMembersInServer, both these messages are valid
// depending on whether users are found or not
expect([
`The user with <@&${roleId}> role is <@282859044593598464>.`,
`Sorry, no user found with <@&${roleId}> role.`,
`The user with <@&${testDataWithDevTitle.roleToBeTaggedObj.value}> role is <@282859044593598464>.`,
`Sorry, no user found with <@&${testDataWithDevTitle.roleToBeTaggedObj.value}> role.`,
]).toContain(textMessage.data.content);
});
});

0 comments on commit dd57bc0

Please sign in to comment.