Update tests

This commit is contained in:
Ethan Lane 2025-01-22 18:05:49 +00:00
parent 6f42cfb8f6
commit 34964af78e
6 changed files with 92 additions and 101 deletions

View file

@ -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");
});

View file

@ -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");
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");
});