This commit is contained in:
parent
31cc9e056a
commit
d794b30bb5
10 changed files with 204 additions and 176 deletions
23
tests/buttonEvents/Claim.test.ts
Normal file
23
tests/buttonEvents/Claim.test.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
test.todo("GIVEN interaction.guild is null, EXPECT nothing to happen");
|
||||
|
||||
test.todo("GIVEN interaction.guildId is null, EXPECT nothing to happen");
|
||||
|
||||
test.todo("GIVEN interaction.channel is null, EXPECT nothing to happen");
|
||||
|
||||
test.todo("GIVEN channel is not sendable, EXPECT nothing to happen");
|
||||
|
||||
test.todo("GIVEN interaction.message was created more than 5 minutes ago, EXPECT error");
|
||||
|
||||
test.todo("GIVEN user.RemoveCurrency fails, EXPECT error");
|
||||
|
||||
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");
|
|
@ -1,135 +1,5 @@
|
|||
import { ActionRowBuilder, ButtonBuilder, ButtonInteraction, EmbedBuilder } from "discord.js";
|
||||
import Effects from "../../src/buttonEvents/Effects";
|
||||
import EffectHelper from "../../src/helpers/EffectHelper";
|
||||
import { EffectDetails } from "../../src/constants/EffectDetails";
|
||||
import TimeLengthInput from "../../src/helpers/TimeLengthInput";
|
||||
test.todo("GIVEN action is list, EXPECT list function to be called");
|
||||
|
||||
describe("Effects", () => {
|
||||
let interaction: ButtonInteraction;
|
||||
let effects: Effects;
|
||||
test.todo("GIVEN action is use, EXPECT use function to be called");
|
||||
|
||||
beforeEach(() => {
|
||||
interaction = {
|
||||
customId: "effects list 1",
|
||||
user: { id: "123" },
|
||||
reply: jest.fn(),
|
||||
update: jest.fn(),
|
||||
} as unknown as ButtonInteraction;
|
||||
effects = new Effects();
|
||||
});
|
||||
|
||||
it("should call List method when action is 'list'", async () => {
|
||||
const listSpy = jest.spyOn(effects, "List").mockImplementation(async () => {});
|
||||
|
||||
await effects.execute(interaction);
|
||||
|
||||
expect(listSpy).toHaveBeenCalledWith(interaction);
|
||||
});
|
||||
|
||||
it("should call Use method when action is 'use'", async () => {
|
||||
interaction.customId = "effects use confirm 1";
|
||||
const useSpy = jest.spyOn(effects, "Use").mockImplementation(async () => {});
|
||||
|
||||
await effects.execute(interaction);
|
||||
|
||||
expect(useSpy).toHaveBeenCalledWith(interaction);
|
||||
});
|
||||
|
||||
it("should reply with error message when page option is not a valid number", async () => {
|
||||
interaction.customId = "effects list invalid";
|
||||
await effects.execute(interaction);
|
||||
|
||||
expect(interaction.reply).toHaveBeenCalledWith("Page option is not a valid number");
|
||||
});
|
||||
|
||||
it("should update interaction with generated embed and row", async () => {
|
||||
const mockEmbed = {
|
||||
embed: new EmbedBuilder(),
|
||||
row: new ActionRowBuilder<ButtonBuilder>()
|
||||
};
|
||||
|
||||
jest.spyOn(EffectHelper, "GenerateEffectEmbed").mockResolvedValue(mockEmbed);
|
||||
|
||||
await effects.List(interaction);
|
||||
|
||||
expect(interaction.update).toHaveBeenCalledWith({
|
||||
embeds: [mockEmbed.embed],
|
||||
components: [mockEmbed.row],
|
||||
});
|
||||
});
|
||||
|
||||
it("should call UseConfirm method when subaction is 'confirm'", async () => {
|
||||
interaction.customId = "effects use confirm 1";
|
||||
const useConfirmSpy = jest.spyOn(effects, "UseConfirm").mockImplementation(async () => {});
|
||||
|
||||
await effects.Use(interaction);
|
||||
|
||||
expect(useConfirmSpy).toHaveBeenCalledWith(interaction);
|
||||
});
|
||||
|
||||
it("should call UseCancel method when subaction is 'cancel'", async () => {
|
||||
interaction.customId = "effects use cancel 1";
|
||||
const useCancelSpy = jest.spyOn(effects, "UseCancel").mockImplementation(async () => {});
|
||||
|
||||
await effects.Use(interaction);
|
||||
|
||||
expect(useCancelSpy).toHaveBeenCalledWith(interaction);
|
||||
});
|
||||
|
||||
it("should reply with error message when effect detail is not found in UseConfirm", async () => {
|
||||
interaction.customId = "effects use confirm invalid";
|
||||
await effects.UseConfirm(interaction);
|
||||
|
||||
expect(interaction.reply).toHaveBeenCalledWith("Effect not found in system!");
|
||||
});
|
||||
|
||||
it("should reply with error message when effect detail is not found in UseCancel", async () => {
|
||||
interaction.customId = "effects use cancel invalid";
|
||||
await effects.UseCancel(interaction);
|
||||
|
||||
expect(interaction.reply).toHaveBeenCalledWith("Effect not found in system!");
|
||||
});
|
||||
|
||||
it("should update interaction with embed and row when effect is used successfully", async () => {
|
||||
const mockEffectDetail = { id: "1", friendlyName: "Test Effect", duration: 1000, cost: 10, cooldown: 5000 };
|
||||
const mockResult = true;
|
||||
|
||||
jest.spyOn(EffectDetails, "get").mockReturnValue(mockEffectDetail);
|
||||
jest.spyOn(EffectHelper, "UseEffect").mockResolvedValue(mockResult);
|
||||
|
||||
await effects.UseConfirm(interaction);
|
||||
|
||||
expect(interaction.update).toHaveBeenCalledWith(expect.objectContaining({
|
||||
embeds: expect.any(Array),
|
||||
components: expect.any(Array),
|
||||
}));
|
||||
});
|
||||
|
||||
it("should reply with error message when effect is not used successfully", async () => {
|
||||
const mockEffectDetail = { id: "1", friendlyName: "Test Effect", duration: 1000, cost: 0, cooldown: 0 };
|
||||
const mockResult = false;
|
||||
|
||||
jest.spyOn(EffectDetails, "get").mockReturnValue(mockEffectDetail);
|
||||
jest.spyOn(EffectHelper, "UseEffect").mockResolvedValue(mockResult);
|
||||
|
||||
await effects.UseConfirm(interaction);
|
||||
|
||||
expect(interaction.reply).toHaveBeenCalledWith("Unable to use effect! Please make sure you have it in your inventory and is not on cooldown");
|
||||
});
|
||||
|
||||
it("should update interaction with embed and row when effect use is cancelled", async () => {
|
||||
const mockEffectDetail = { id: "1", friendlyName: "Test Effect", duration: 1000, cost: 0, cooldown: 0 };
|
||||
|
||||
jest.spyOn(EffectDetails, "get").mockReturnValue(mockEffectDetail);
|
||||
jest.spyOn(TimeLengthInput, "ConvertFromMilliseconds").mockReturnValue({
|
||||
GetLengthShort: () => "1s",
|
||||
} as TimeLengthInput);
|
||||
|
||||
await effects.UseCancel(interaction);
|
||||
|
||||
expect(interaction.update).toHaveBeenCalledWith(expect.objectContaining({
|
||||
embeds: expect.any(Array),
|
||||
components: expect.any(Array),
|
||||
}));
|
||||
});
|
||||
});
|
||||
test.todo("GIVEN action is unknown, EXPECT nothing to be called");
|
3
tests/buttonEvents/Effects/List.test.ts
Normal file
3
tests/buttonEvents/Effects/List.test.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
test.todo("GIVEN pageOption is NOT a number, EXPECT error");
|
||||
|
||||
test.todo("GIVEN pageOption is a number, EXPECT interaction updated");
|
21
tests/buttonEvents/Effects/Use.test.ts
Normal file
21
tests/buttonEvents/Effects/Use.test.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
describe("Use", () => {
|
||||
test.todo("GIVEN subaction is confirm, EXPECT UseConfirm to be called");
|
||||
|
||||
test.todo("GIVEN subaction is cancel, EXPECT UseCancel to be called");
|
||||
|
||||
test.todo("GIVEN subaction is unknown, EXPECT nothing to be called");
|
||||
});
|
||||
|
||||
describe("UseConfirm", () => {
|
||||
test.todo("GIVEN effectDetail is not found, EXPECT error");
|
||||
|
||||
test.todo("GIVEN EffectHelper.UseEffect failed, EXPECT error");
|
||||
|
||||
test.todo("GIVEN EffectHelper.UseEffect succeeded, EXPECT interaction updated");
|
||||
});
|
||||
|
||||
describe("UseCancel", () => {
|
||||
test.todo("GIVEN effectDetail is not found, EXPECT error");
|
||||
|
||||
test.todo("GIVEN effectDetail is found, EXPECT interaction updated");
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue