From dd57bc073521af313a7a78f7c498d6648a429b07 Mon Sep 17 00:00:00 2001 From: RishiChaubey31 Date: Sat, 2 Nov 2024 00:55:30 +0530 Subject: [PATCH] move some lines to fixtures from test --- tests/fixtures/fixture.ts | 13 +++++++++++ tests/unit/handlers/mentionEachUser.test.ts | 25 ++++----------------- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/tests/fixtures/fixture.ts b/tests/fixtures/fixture.ts index c5d9855f..8602c71c 100644 --- a/tests/fixtures/fixture.ts +++ b/tests/fixtures/fixture.ts @@ -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, + }, +}; diff --git a/tests/unit/handlers/mentionEachUser.test.ts b/tests/unit/handlers/mentionEachUser.test.ts index 8f3f5f69..c73bfb68 100644 --- a/tests/unit/handlers/mentionEachUser.test.ts +++ b/tests/unit/handlers/mentionEachUser.test.ts @@ -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, @@ -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); }); });