Skip to content

Commit dd57bc0

Browse files
move some lines to fixtures from test
1 parent 47b865d commit dd57bc0

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

tests/fixtures/fixture.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,3 +370,16 @@ export const overdueTaskUsers = {
370370
},
371371
],
372372
};
373+
export const testDataWithDevTitle = {
374+
channelId: 123,
375+
roleToBeTaggedObj: {
376+
name: "role",
377+
type: 4,
378+
value: "860900892193456149",
379+
},
380+
dev_title: {
381+
name: "dev_title",
382+
type: 4,
383+
value: true,
384+
},
385+
};

tests/unit/handlers/mentionEachUser.test.ts

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { mentionEachUser } from "../../../src/controllers/mentionEachUser";
22
import { checkDisplayType } from "../../../src/utils/checkDisplayType";
33
import { filterUserByRoles } from "../../../src/utils/filterUsersByRole";
4+
import { testDataWithDevTitle } from "../../../tests/fixtures/fixture";
45
import {
56
onlyRoleToBeTagged,
67
transformedArgument,
@@ -167,35 +168,17 @@ describe("Test mention each function", () => {
167168
DISCORD_GUILD_ID: "123",
168169
DISCORD_TOKEN: "abc",
169170
};
170-
const roleId = "860900892193456149";
171-
172-
// Create the test data with exactly one user
173-
const testData = {
174-
channelId: 123,
175-
roleToBeTaggedObj: {
176-
name: "role",
177-
type: 4,
178-
value: roleId,
179-
},
180-
dev_title: {
181-
name: "dev_title",
182-
type: 4,
183-
value: true,
184-
},
185-
};
186171

187-
const response = mentionEachUser(testData, env, ctx);
172+
const response = mentionEachUser(testDataWithDevTitle, env, ctx);
188173
expect(response).toBeInstanceOf(Promise);
189174

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

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

0 commit comments

Comments
 (0)