From d9d0243c3c3e31e465434ff9663c8f6dd739b47e Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Tue, 10 Dec 2024 11:07:55 +0000 Subject: [PATCH 1/8] Use node 20 --- .forgejo/workflows/production.yml | 2 +- .forgejo/workflows/stage.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.forgejo/workflows/production.yml b/.forgejo/workflows/production.yml index d939ef7..110f5e8 100644 --- a/.forgejo/workflows/production.yml +++ b/.forgejo/workflows/production.yml @@ -16,7 +16,7 @@ jobs: - name: Use Node.js uses: actions/setup-node@v4 with: - node-version: 18.x + node-version: 20.x - run: yarn install --frozen-lockfile - run: yarn build - run: yarn test diff --git a/.forgejo/workflows/stage.yml b/.forgejo/workflows/stage.yml index 51b5fb9..149a78e 100644 --- a/.forgejo/workflows/stage.yml +++ b/.forgejo/workflows/stage.yml @@ -16,7 +16,7 @@ jobs: - name: Use Node.js uses: actions/setup-node@v4 with: - node-version: 18.x + node-version: 20.x - run: yarn install --frozen-lockfile - run: yarn build - run: yarn test From b8623398a61d2b51b4bc31dd5091dbd665e2abad Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Sun, 19 Jan 2025 15:07:40 +0000 Subject: [PATCH 2/8] Implement ability to add images in the drop via an external url --- src/buttonEvents/Reroll.ts | 15 +++++++++++---- src/commands/drop.ts | 15 +++++++++++---- src/commands/stage/dropnumber.ts | 20 ++++++++++---------- src/commands/stage/droprarity.ts | 22 ++++++++++------------ src/commands/view.ts | 20 +++++++++----------- src/helpers/CardDropHelperMetadata.ts | 10 ++++++++-- 6 files changed, 59 insertions(+), 43 deletions(-) diff --git a/src/buttonEvents/Reroll.ts b/src/buttonEvents/Reroll.ts index 12578db..dc9622a 100644 --- a/src/buttonEvents/Reroll.ts +++ b/src/buttonEvents/Reroll.ts @@ -51,10 +51,17 @@ export default class Reroll extends ButtonEvent { try { AppLogger.LogVerbose("Button/Reroll", `Sending next drop: ${randomCard.card.id} (${randomCard.card.name})`); - const image = readFileSync(path.join(process.env.DATA_DIR!, "cards", randomCard.card.path)); - const imageFileName = randomCard.card.path.split("/").pop()!; + const files = []; + let imageFileName = ""; - const attachment = new AttachmentBuilder(image, { name: imageFileName }); + if (!(randomCard.card.path.startsWith("http://") || randomCard.card.path.startsWith("https://"))) { + const image = readFileSync(path.join(process.env.DATA_DIR!, "cards", randomCard.card.path)); + imageFileName = randomCard.card.path.split("/").pop()!; + + const attachment = new AttachmentBuilder(image, { name: imageFileName }); + + files.push(attachment); + } const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, randomCard.card.id); const quantityClaimed = inventory ? inventory.Quantity : 0; @@ -67,7 +74,7 @@ export default class Reroll extends ButtonEvent { await interaction.editReply({ embeds: [ embed ], - files: [ attachment ], + files: files, components: [ row ], }); diff --git a/src/commands/drop.ts b/src/commands/drop.ts index 6f74d3a..66558e3 100644 --- a/src/commands/drop.ts +++ b/src/commands/drop.ts @@ -59,10 +59,17 @@ export default class Drop extends Command { await interaction.deferReply(); try { - const image = readFileSync(path.join(process.env.DATA_DIR!, "cards", randomCard.card.path)); - const imageFileName = randomCard.card.path.split("/").pop()!; + const files = []; + let imageFileName = ""; - const attachment = new AttachmentBuilder(image, { name: imageFileName }); + if (!(randomCard.card.path.startsWith("http://") || randomCard.card.path.startsWith("https://"))) { + const image = readFileSync(path.join(process.env.DATA_DIR!, "cards", randomCard.card.path)); + imageFileName = randomCard.card.path.split("/").pop()!; + + const attachment = new AttachmentBuilder(image, { name: imageFileName }); + + files.push(attachment); + } const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, randomCard.card.id); const quantityClaimed = inventory ? inventory.Quantity : 0; @@ -75,7 +82,7 @@ export default class Drop extends Command { await interaction.editReply({ embeds: [ embed ], - files: [ attachment ], + files: files, components: [ row ], }); diff --git a/src/commands/stage/dropnumber.ts b/src/commands/stage/dropnumber.ts index 0642327..750210d 100644 --- a/src/commands/stage/dropnumber.ts +++ b/src/commands/stage/dropnumber.ts @@ -43,20 +43,20 @@ export default class Dropnumber extends Command { const series = CoreClient.Cards .find(x => x.cards.includes(card))!; - let image: Buffer; - const imageFileName = card.path.split("/").pop()!; + const files = []; + let imageFileName = ""; - try { - image = readFileSync(path.join(process.env.DATA_DIR!, "cards", card.path)); - } catch { - await interaction.reply(`Unable to fetch image for card ${card.id}`); - return; + if (!(card.path.startsWith("http://") || card.path.startsWith("https://"))) { + const image = readFileSync(path.join(process.env.DATA_DIR!, "cards", card.path)); + imageFileName = card.path.split("/").pop()!; + + const attachment = new AttachmentBuilder(image, { name: imageFileName }); + + files.push(attachment); } await interaction.deferReply(); - const attachment = new AttachmentBuilder(image, { name: imageFileName }); - const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, card.id); const quantityClaimed = inventory ? inventory.Quantity : 0; @@ -69,7 +69,7 @@ export default class Dropnumber extends Command { try { await interaction.editReply({ embeds: [ embed ], - files: [ attachment ], + files: files, components: [ row ], }); } catch (e) { diff --git a/src/commands/stage/droprarity.ts b/src/commands/stage/droprarity.ts index be0a62d..0e95db0 100644 --- a/src/commands/stage/droprarity.ts +++ b/src/commands/stage/droprarity.ts @@ -46,20 +46,18 @@ export default class Droprarity extends Command { return; } - let image: Buffer; - const imageFileName = card.card.path.split("/").pop()!; + const files = []; + let imageFileName = ""; - try { - image = readFileSync(path.join(process.env.DATA_DIR!, "cards", card.card.path)); - } catch { - await interaction.reply(`Unable to fetch image for card ${card.card.id}`); - return; + if (!(card.card.path.startsWith("http://") || card.card.path.startsWith("https://"))) { + const image = readFileSync(path.join(process.env.DATA_DIR!, "cards", card.card.path)); + imageFileName = card.card.path.split("/").pop()!; + + const attachment = new AttachmentBuilder(image, { name: imageFileName }); + + files.push(attachment); } - await interaction.deferReply(); - - const attachment = new AttachmentBuilder(image, { name: imageFileName }); - const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, card.card.id); const quantityClaimed = inventory ? inventory.Quantity : 0; @@ -72,7 +70,7 @@ export default class Droprarity extends Command { try { await interaction.editReply({ embeds: [ embed ], - files: [ attachment ], + files: files, components: [ row ], }); } catch (e) { diff --git a/src/commands/view.ts b/src/commands/view.ts index ce6f9cb..0e29db5 100644 --- a/src/commands/view.ts +++ b/src/commands/view.ts @@ -43,22 +43,20 @@ export default class View extends Command { const series = CoreClient.Cards .find(x => x.cards.includes(card))!; - let image: Buffer; - const imageFileName = card.path.split("/").pop()!; + const files = []; + let imageFileName = ""; - try { - image = readFileSync(path.join(process.env.DATA_DIR!, "cards", card.path)); - } catch { - AppLogger.LogError("Commands/View", `Unable to fetch image for card ${card.id}.`); + if (!(card.path.startsWith("http://") || card.path.startsWith("https://"))) { + const image = readFileSync(path.join(process.env.DATA_DIR!, "cards", card.path)); + imageFileName = card.path.split("/").pop()!; - await interaction.reply(`Unable to fetch image for card ${card.id}.`); - return; + const attachment = new AttachmentBuilder(image, { name: imageFileName }); + + files.push(attachment); } await interaction.deferReply(); - const attachment = new AttachmentBuilder(image, { name: imageFileName }); - const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, card.id); const quantityClaimed = inventory ? inventory.Quantity : 0; @@ -67,7 +65,7 @@ export default class View extends Command { try { await interaction.editReply({ embeds: [ embed ], - files: [ attachment ], + files: files, }); } catch (e) { AppLogger.LogError("Commands/View", `Error sending view for card ${card.id}: ${e}`); diff --git a/src/helpers/CardDropHelperMetadata.ts b/src/helpers/CardDropHelperMetadata.ts index bc59e93..342f347 100644 --- a/src/helpers/CardDropHelperMetadata.ts +++ b/src/helpers/CardDropHelperMetadata.ts @@ -89,7 +89,7 @@ export default class CardDropHelperMetadata { const hexCode = Number("0x" + drop.card.colour); if (hexCode) { - colour = hexCode; + colour = hexCode; } else { AppLogger.LogWarn("CardDropHelperMetadata/GenerateDropEmbed", `Card's colour override is invalid: ${drop.card.id}, ${drop.card.colour}`); } @@ -97,12 +97,18 @@ export default class CardDropHelperMetadata { AppLogger.LogWarn("CardDropHelperMetadata/GenerateDropEmbed", `Card's colour override is invalid: ${drop.card.id}, ${drop.card.colour}`); } + let imageUrl = `attachment://${imageFileName}`; + + if (drop.card.path.startsWith("http://") || drop.card.path.startsWith("https://")) { + imageUrl = drop.card.path; + } + const embed = new EmbedBuilder() .setTitle(drop.card.name) .setDescription(description) .setFooter({ text: `${CardRarityToString(drop.card.type)} · ${drop.card.id}` }) .setColor(colour) - .setImage(`attachment://${imageFileName}`) + .setImage(imageUrl) .addFields([ { name: "Claimed", From c53e09f510fc5968ef6bff765d61c8bf730ed083 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Sun, 19 Jan 2025 15:09:17 +0000 Subject: [PATCH 3/8] 0.8.3 --- .env.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 4515de6..44016d2 100644 --- a/.env.example +++ b/.env.example @@ -7,7 +7,7 @@ # any secret values. BOT_TOKEN= -BOT_VER=0.8.2 +BOT_VER=0.8.3 BOT_AUTHOR=Vylpes BOT_OWNERID=147392775707426816 BOT_CLIENTID=682942374040961060 From ce0bc15c029d9b37138a60cae4b2fe9db9f4e719 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Sun, 19 Jan 2025 15:11:41 +0000 Subject: [PATCH 4/8] v0.8.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 69f3158..d7178df 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "card-drop", - "version": "0.8.2", + "version": "0.8.3", "main": "./dist/bot.js", "typings": "./dist", "scripts": { From 3e81f8ce1d4b01fb5fc4e4ee710b5ed95fa34202 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Sun, 19 Jan 2025 15:19:28 +0000 Subject: [PATCH 5/8] Update id command from merge --- src/commands/id.ts | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/commands/id.ts b/src/commands/id.ts index ae924a6..ea37965 100644 --- a/src/commands/id.ts +++ b/src/commands/id.ts @@ -43,22 +43,20 @@ export default class Id extends Command { const series = CoreClient.Cards .find(x => x.cards.includes(card))!; - let image: Buffer; - const imageFileName = card.path.split("/").pop()!; + const files = []; + let imageFileName = ""; - try { - image = readFileSync(path.join(process.env.DATA_DIR!, "cards", card.path)); - } catch { - AppLogger.LogError("Commands/View", `Unable to fetch image for card ${card.id}.`); + if (!(card.path.startsWith("http://") || card.path.startsWith("https://"))) { + const image = readFileSync(path.join(process.env.DATA_DIR!, "cards", card.path)); + imageFileName = card.path.split("/").pop()!; - await interaction.reply(`Unable to fetch image for card ${card.id}.`); - return; + const attachment = new AttachmentBuilder(image, { name: imageFileName }); + + files.push(attachment); } await interaction.deferReply(); - const attachment = new AttachmentBuilder(image, { name: imageFileName }); - const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, card.id); const quantityClaimed = inventory ? inventory.Quantity : 0; @@ -67,7 +65,7 @@ export default class Id extends Command { try { await interaction.editReply({ embeds: [ embed ], - files: [ attachment ], + files: files, }); } catch (e) { AppLogger.LogError("Commands/View", `Error sending view for card ${card.id}: ${e}`); From 6f42cfb8f6d511a1da295b8f19bc35734ca2e0fe Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Wed, 22 Jan 2025 17:50:15 +0000 Subject: [PATCH 6/8] Implement merge change --- src/helpers/DropHelpers/DropEmbedHelper.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/helpers/DropHelpers/DropEmbedHelper.ts b/src/helpers/DropHelpers/DropEmbedHelper.ts index ba1ba47..c739de7 100644 --- a/src/helpers/DropHelpers/DropEmbedHelper.ts +++ b/src/helpers/DropHelpers/DropEmbedHelper.ts @@ -24,12 +24,18 @@ export default class DropEmbedHelper { AppLogger.LogWarn("CardDropHelperMetadata/GenerateDropEmbed", `Card's colour override is invalid: ${drop.card.id}, ${drop.card.colour}`); } + let imageUrl = `attachment://${imageFileName}`; + + if (drop.card.path.startsWith("http://") || drop.card.path.startsWith("https://")) { + imageUrl = drop.card.path; + } + const embed = new EmbedBuilder() .setTitle(drop.card.name) .setDescription(description) .setFooter({ text: `${CardRarityToString(drop.card.type)} · ${drop.card.id}` }) .setColor(colour) - .setImage(`attachment://${imageFileName}`) + .setImage(imageUrl) .addFields([ { name: "Claimed", From 34964af78ec628287ba63bd1d661830c0eedd557 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Wed, 22 Jan 2025 18:05:49 +0000 Subject: [PATCH 7/8] Update tests --- src/buttonEvents/Effects.ts | 3 + .../GenerateButtonInteractionMock.ts | 21 ++++++ tests/buttonEvents/Claim.test.ts | 34 ++-------- tests/buttonEvents/Effects.test.ts | 67 ++++++++++++++++++- tests/commands/effects.test.ts | 27 -------- tests/helpers/EffectHelper.test.ts | 41 ------------ 6 files changed, 92 insertions(+), 101 deletions(-) create mode 100644 tests/__functions__/discord.js/GenerateButtonInteractionMock.ts delete mode 100644 tests/commands/effects.test.ts delete mode 100644 tests/helpers/EffectHelper.test.ts diff --git a/src/buttonEvents/Effects.ts b/src/buttonEvents/Effects.ts index f185009..0f9686b 100644 --- a/src/buttonEvents/Effects.ts +++ b/src/buttonEvents/Effects.ts @@ -2,6 +2,7 @@ import { ButtonInteraction } from "discord.js"; import { ButtonEvent } from "../type/buttonEvent"; import List from "./Effects/List"; import Use from "./Effects/Use"; +import AppLogger from "../client/appLogger"; export default class Effects extends ButtonEvent { public override async execute(interaction: ButtonInteraction) { @@ -14,6 +15,8 @@ export default class Effects extends ButtonEvent { case "use": await Use.Execute(interaction); break; + default: + AppLogger.LogError("Buttons/Effects", `Unknown action, ${action}`); } } } diff --git a/tests/__functions__/discord.js/GenerateButtonInteractionMock.ts b/tests/__functions__/discord.js/GenerateButtonInteractionMock.ts new file mode 100644 index 0000000..a1024ee --- /dev/null +++ b/tests/__functions__/discord.js/GenerateButtonInteractionMock.ts @@ -0,0 +1,21 @@ +import { ButtonInteraction } from "../../__types__/discord.js"; + +export default function GenerateButtonInteractionMock(): ButtonInteraction { + return { + guild: {}, + guildId: "guildId", + channel: { + isSendable: jest.fn().mockReturnValue(true), + send: jest.fn(), + }, + deferUpdate: jest.fn(), + editReply: jest.fn(), + message: { + createdAt: new Date(1000 * 60 * 27), + }, + user: { + id: "userId", + }, + customId: "customId", + }; +} \ No newline at end of file diff --git a/tests/buttonEvents/Claim.test.ts b/tests/buttonEvents/Claim.test.ts index 226cee0..d9e7e6f 100644 --- a/tests/buttonEvents/Claim.test.ts +++ b/tests/buttonEvents/Claim.test.ts @@ -2,6 +2,7 @@ import { ButtonInteraction, TextChannel } from "discord.js"; import Claim from "../../src/buttonEvents/Claim"; import { ButtonInteraction as ButtonInteractionType } from "../__types__/discord.js"; import User from "../../src/database/entities/app/User"; +import GenerateButtonInteractionMock from "../__functions__/discord.js/GenerateButtonInteractionMock"; jest.mock("../../src/client/appLogger"); @@ -11,23 +12,8 @@ beforeEach(() => { jest.useFakeTimers(); jest.setSystemTime(1000 * 60 * 30); - interaction = { - guild: {}, - guildId: "guildId", - channel: { - isSendable: jest.fn().mockReturnValue(true), - send: jest.fn(), - }, - deferUpdate: jest.fn(), - editReply: jest.fn(), - message: { - createdAt: new Date(1000 * 60 * 27), - }, - user: { - id: "userId", - }, - customId: "claim cardNumber claimId droppedBy userId", - }; + interaction = GenerateButtonInteractionMock(); + interaction.customId = "claim cardNumber claimId droppedBy userId"; }); afterAll(() => { @@ -120,16 +106,4 @@ test("GIVEN user.RemoveCurrency fails, EXPECT error", async () => { expect(interaction.channel!.send).toHaveBeenCalledWith("[object Object], Not enough currency! You need 10 currency, you have 5!"); expect(interaction.editReply).not.toHaveBeenCalled(); -}); - -test.todo("GIVEN the card has already been claimed, EXPECT error"); - -test.todo("GIVEN the current drop is the latest AND the current user is NOT the one who dropped it, EXPECT error"); - -test.todo("GIVEN the user already has the card in their inventory, EXPECT the entity quantity to be +1"); - -test.todo("GIVEN user does NOT have the card in their inventory, EXPECT a new entity to be created"); - -test.todo("GIVEN card can not be found in the bot, EXPECT error logged"); - -test.todo("EXPECT message to be edited"); \ No newline at end of file +}); \ No newline at end of file diff --git a/tests/buttonEvents/Effects.test.ts b/tests/buttonEvents/Effects.test.ts index 18ccc31..f1f86be 100644 --- a/tests/buttonEvents/Effects.test.ts +++ b/tests/buttonEvents/Effects.test.ts @@ -1,5 +1,66 @@ -test.todo("GIVEN action is list, EXPECT list function to be called"); +import { ButtonInteraction } from "discord.js"; +import Effects from "../../src/buttonEvents/Effects"; +import GenerateButtonInteractionMock from "../__functions__/discord.js/GenerateButtonInteractionMock"; +import { ButtonInteraction as ButtonInteractionType } from "../__types__/discord.js"; +import List from "../../src/buttonEvents/Effects/List"; +import Use from "../../src/buttonEvents/Effects/Use"; +import AppLogger from "../../src/client/appLogger"; -test.todo("GIVEN action is use, EXPECT use function to be called"); +jest.mock("../../src/client/appLogger"); +jest.mock("../../src/buttonEvents/Effects/List"); +jest.mock("../../src/buttonEvents/Effects/Use"); -test.todo("GIVEN action is unknown, EXPECT nothing to be called"); \ No newline at end of file +let interaction: ButtonInteractionType; + +beforeEach(() => { + jest.resetAllMocks(); + + interaction = GenerateButtonInteractionMock(); + interaction.customId = "effects"; +}); + +test("GIVEN action is list, EXPECT list function to be called", async () => { + // Arrange + interaction.customId = "effects list"; + + // Act + const effects = new Effects(); + await effects.execute(interaction as unknown as ButtonInteraction); + + // Assert + expect(List).toHaveBeenCalledTimes(1); + expect(List).toHaveBeenCalledWith(interaction); + + expect(Use.Execute).not.toHaveBeenCalled(); +}); + +test("GIVEN action is use, EXPECT use function to be called", async () => { + // Arrange + interaction.customId = "effects use"; + + // Act + const effects = new Effects(); + await effects.execute(interaction as unknown as ButtonInteraction); + + // Assert + expect(Use.Execute).toHaveBeenCalledTimes(1); + expect(Use.Execute).toHaveBeenCalledWith(interaction); + + expect(List).not.toHaveBeenCalled(); +}); + +test("GIVEN action is invalid, EXPECT nothing to be called", async () => { + // Arrange + interaction.customId = "effects invalid"; + + // Act + const effects = new Effects(); + await effects.execute(interaction as unknown as ButtonInteraction); + + // Assert + expect(List).not.toHaveBeenCalled(); + expect(Use.Execute).not.toHaveBeenCalled(); + + expect(AppLogger.LogError).toHaveBeenCalledTimes(1); + expect(AppLogger.LogError).toHaveBeenCalledWith("Buttons/Effects", "Unknown action, invalid"); +}); \ No newline at end of file diff --git a/tests/commands/effects.test.ts b/tests/commands/effects.test.ts deleted file mode 100644 index 20c8f35..0000000 --- a/tests/commands/effects.test.ts +++ /dev/null @@ -1,27 +0,0 @@ -describe("constructor", () => { - test.todo("EXPECT CommandBuilder to be defined"); -}); - -describe("execute", () => { - test.todo("GIVEN interaction is NOT a ChatInputCommand, EXPECT nothing to happen"); - - test.todo("GIVEN subcommand is list, EXPECT list function to be called"); - - test.todo("GIVEN subcommand is use, EXPECT use function to be called"); -}); - -describe("List", () => { - test.todo("GIVEN pageOption is null, EXPECT page to default to 0"); - - test.todo("GIVEN pageOption.value is undefined, EXPECT page to default to 0"); - - test.todo("EXPECT interaction to be replied"); -}); - -describe("Use", () => { - test.todo("GIVEN effectDetail is not found, EXPECT error"); - - test.todo("GIVEN user can not use effect, EXPECT error"); - - test.todo("EXPECT interaction to be replied"); -}); \ No newline at end of file diff --git a/tests/helpers/EffectHelper.test.ts b/tests/helpers/EffectHelper.test.ts deleted file mode 100644 index e41c2bc..0000000 --- a/tests/helpers/EffectHelper.test.ts +++ /dev/null @@ -1,41 +0,0 @@ -describe("AddEffectToUserInventory", () => { - test.todo("GIVEN effect is found in database, EXPECT effect unused to be incremented"); - - test.todo("GIVEN effect is NOT found in database, EXPECT new effect to be created"); -}); - -describe("UseEffect", () => { - test.todo("GIVEN user can not use effect, EXPECT false returned"); - - test.todo("GIVEN user has effect, EXPECT entity to be updated AND true returned"); -}); - -describe("CanUseEffect", () => { - test.todo("GIVEN effect is not in database, EXPECT false returned"); - - test.todo("GIVEN user does not have any of the effect unused, EXPECT false returned"); - - test.todo("GIVEN effectDetail can not be found, EXPECT false returned"); - - test.todo("GIVEN effect has NOT passed the cooldown, EXPECT false returned"); - - test.todo("GIVEN effect has passed the cooldown, EXPECT true returned"); - - test.todo("GIVEN effect does not have a WhenExpires date supplied, EXPECT true returned"); -}); - -describe("HasEffect", () => { - test.todo("GIVEN effect is NOT found in database, EXPECT false returned"); - - test.todo("GIVEN effect does NOT have an expiry date, EXPECT false returned"); - - test.todo("GIVEN effect.WhenExpires is in the future, EXPECT false returned"); - - test.todo("GIVEN effect.WhenExpires is in the past, EXPECT true returned"); -}); - -describe("GenerateEffectEmbed", () => { - test.todo("GIVEN user has no effects, EXPECT embed to be generated"); - - test.todo("GIVEN user has some effects, EXPECT embed to be generated"); -}); \ No newline at end of file From 1106585f581342eb87f34a7dcde90133838e3c0c Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Wed, 22 Jan 2025 18:08:05 +0000 Subject: [PATCH 8/8] Fix linter issues --- tests/__types__/discord.js.ts | 2 +- tests/buttonEvents/Effects/Use.test.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/__types__/discord.js.ts b/tests/__types__/discord.js.ts index 22c3291..6506b1d 100644 --- a/tests/__types__/discord.js.ts +++ b/tests/__types__/discord.js.ts @@ -1,5 +1,5 @@ export type ButtonInteraction = { - guild: {} | null, + guild: object | null, guildId: string | null, channel: { isSendable: jest.Func, diff --git a/tests/buttonEvents/Effects/Use.test.ts b/tests/buttonEvents/Effects/Use.test.ts index d5618cc..86391cc 100644 --- a/tests/buttonEvents/Effects/Use.test.ts +++ b/tests/buttonEvents/Effects/Use.test.ts @@ -1,4 +1,4 @@ -import { ButtonInteraction, EmbedBuilder, InteractionResponse } from "discord.js"; +import { ButtonInteraction, InteractionResponse, InteractionUpdateOptions, MessagePayload } from "discord.js"; import Use from "../../../src/buttonEvents/Effects/Use"; import { mock } from "jest-mock-extended"; import AppLogger from "../../../src/client/appLogger"; @@ -82,7 +82,7 @@ describe("UseConfirm", () => { // Arrange interaction.customId += " unclaimed"; interaction.user.id = "userId"; - interaction.update.mockImplementation(async (opts: any) => { + interaction.update.mockImplementation(async (opts: string | MessagePayload | InteractionUpdateOptions) => { updatedWith = opts; return mock>(); @@ -133,7 +133,7 @@ describe("UseCancel", () => { // Arrange interaction.customId += " unclaimed"; interaction.user.id = "userId"; - interaction.update.mockImplementation(async (opts: any) => { + interaction.update.mockImplementation(async (opts: string | MessagePayload | InteractionUpdateOptions) => { updatedWith = opts; return mock>();