Add verify and button tests
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
69ef94dbb5
commit
4e9ec89108
3 changed files with 223 additions and 32 deletions
|
@ -1,7 +1,70 @@
|
|||
import Button from "../../../src/client/interactionCreate/button";
|
||||
import { CoreClient } from "../../../src/client/client";
|
||||
import ButtonEventItem from "../../../src/contracts/ButtonEventItem";
|
||||
import { ButtonInteraction } from "discord.js";
|
||||
import { ButtonEvent } from "../../../src/type/buttonEvent";
|
||||
|
||||
describe('onButtonClicked', () => {
|
||||
test.todo("EXPECT button event to be executed");
|
||||
let item: ButtonEventItem;
|
||||
let interaction: ButtonInteraction;
|
||||
|
||||
test.todo("GIVEN interaction is not a button, EXEPCT nothing to happen");
|
||||
beforeEach(() => {
|
||||
item = {
|
||||
ButtonId: "buttonId",
|
||||
Event: {
|
||||
execute: jest.fn(),
|
||||
} as unknown as ButtonEvent,
|
||||
} as unknown as ButtonEventItem;
|
||||
|
||||
test.todo("GIVEN button event is not registered, EXPECT error");
|
||||
interaction = {
|
||||
reply: jest.fn(),
|
||||
isButton: true,
|
||||
customId: "buttonId test",
|
||||
} as unknown as ButtonInteraction;
|
||||
|
||||
CoreClient.buttonEvents = [ item ];
|
||||
});
|
||||
|
||||
test("EXPECT button event to be executed", async () => {
|
||||
await Button.onButtonClicked(interaction);
|
||||
|
||||
expect(item.Event.execute).toHaveBeenCalledTimes(1);
|
||||
expect(item.Event.execute).toHaveBeenCalledWith(interaction);
|
||||
|
||||
expect(interaction.reply).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test("GIVEN interaction is not a button, EXEPCT nothing to happen", async () => {
|
||||
interaction = {
|
||||
reply: jest.fn(),
|
||||
isButton: false,
|
||||
} as unknown as ButtonInteraction;
|
||||
|
||||
await Button.onButtonClicked(interaction);
|
||||
|
||||
expect(item.Event.execute).not.toHaveBeenCalled();
|
||||
expect(interaction.reply).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test("GIVEN no button event is registered, EXPECT error", async () => {
|
||||
CoreClient.buttonEvents = [];
|
||||
|
||||
await Button.onButtonClicked(interaction);
|
||||
|
||||
expect(interaction.reply).toHaveBeenCalledTimes(1);
|
||||
expect(interaction.reply).toHaveBeenCalledWith("Event not found.");
|
||||
|
||||
expect(item.Event.execute).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test("GIVEN button event is not registered, EXPECT error", async () => {
|
||||
interaction.customId = "anotherButtonId test";
|
||||
|
||||
await Button.onButtonClicked(interaction);
|
||||
|
||||
expect(interaction.reply).toHaveBeenCalledTimes(1);
|
||||
expect(interaction.reply).toHaveBeenCalledWith("Event not found.");
|
||||
|
||||
expect(item.Event.execute).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue