Update tests
This commit is contained in:
parent
6f42cfb8f6
commit
34964af78e
6 changed files with 92 additions and 101 deletions
|
@ -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}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
};
|
||||
}
|
|
@ -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(() => {
|
||||
|
@ -121,15 +107,3 @@ test("GIVEN user.RemoveCurrency fails, EXPECT error", async () => {
|
|||
|
||||
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");
|
|
@ -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");
|
||||
});
|
|
@ -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");
|
||||
});
|
|
@ -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");
|
||||
});
|
Loading…
Reference in a new issue