2024-12-06 18:08:15 +00:00
|
|
|
import {ChatInputCommandInteraction} from "discord.js";
|
2024-12-01 20:13:26 +00:00
|
|
|
import Effects from "../../src/commands/effects";
|
2024-12-02 18:40:19 +00:00
|
|
|
import EffectHelper from "../../src/helpers/EffectHelper";
|
2024-12-01 20:13:26 +00:00
|
|
|
|
2024-11-30 16:38:02 +00:00
|
|
|
describe("constructor", () => {
|
2024-12-01 20:13:26 +00:00
|
|
|
let effects: Effects;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
effects = new Effects();
|
|
|
|
});
|
|
|
|
|
|
|
|
test("EXPECT CommandBuilder to be defined", () => {
|
|
|
|
expect(effects.CommandBuilder).toMatchSnapshot();
|
|
|
|
});
|
2024-11-30 16:38:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("execute", () => {
|
|
|
|
describe("GIVEN interaction is not a chat input command", () => {
|
2024-12-06 18:08:15 +00:00
|
|
|
let interaction: ChatInputCommandInteraction;
|
2024-12-01 20:13:26 +00:00
|
|
|
|
2024-12-06 18:08:15 +00:00
|
|
|
let listSpy: jest.SpyInstance;
|
2024-12-01 20:13:26 +00:00
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
interaction = {
|
|
|
|
isChatInputCommand: jest.fn().mockReturnValue(false),
|
2024-12-06 18:08:15 +00:00
|
|
|
} as unknown as ChatInputCommandInteraction;
|
2024-12-01 20:13:26 +00:00
|
|
|
|
|
|
|
const effects = new Effects();
|
|
|
|
|
2024-12-06 18:08:15 +00:00
|
|
|
listSpy = jest.spyOn(effects as unknown as {"List": () => object}, "List")
|
2024-12-02 18:40:19 +00:00
|
|
|
.mockImplementation();
|
2024-12-01 20:13:26 +00:00
|
|
|
|
|
|
|
await effects.execute(interaction);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("EXPECT isChatInputCommand to have been called", () => {
|
|
|
|
expect(interaction.isChatInputCommand).toHaveBeenCalledTimes(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("EXPECT nothing to happen", () => {
|
|
|
|
expect(listSpy).not.toHaveBeenCalled();
|
|
|
|
});
|
2024-11-30 16:38:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("GIVEN subcommand is list", () => {
|
2024-12-06 18:08:15 +00:00
|
|
|
let interaction: ChatInputCommandInteraction;
|
2024-12-02 18:40:19 +00:00
|
|
|
|
2024-12-06 18:08:15 +00:00
|
|
|
let listSpy: jest.SpyInstance;
|
2024-12-02 18:40:19 +00:00
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
interaction = {
|
|
|
|
isChatInputCommand: jest.fn().mockReturnValue(true),
|
|
|
|
options: {
|
|
|
|
getSubcommand: jest.fn().mockReturnValue("list"),
|
|
|
|
},
|
2024-12-06 18:08:15 +00:00
|
|
|
} as unknown as ChatInputCommandInteraction;
|
2024-12-02 18:40:19 +00:00
|
|
|
|
|
|
|
const effects = new Effects();
|
|
|
|
|
2024-12-06 18:08:15 +00:00
|
|
|
listSpy = jest.spyOn(effects as unknown as {"List": () => object}, "List")
|
2024-12-02 18:40:19 +00:00
|
|
|
.mockImplementation();
|
|
|
|
|
|
|
|
await effects.execute(interaction);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("EXPECT subcommand function to be called", () => {
|
|
|
|
expect(interaction.options.getSubcommand).toHaveBeenCalledTimes(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("EXPECT list function to be called", () => {
|
|
|
|
expect(listSpy).toHaveBeenCalledTimes(1);
|
|
|
|
expect(listSpy).toHaveBeenCalledWith(interaction);
|
|
|
|
});
|
2024-11-30 16:38:02 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("List", () => {
|
2024-12-06 18:08:15 +00:00
|
|
|
const effects: Effects = new Effects();
|
|
|
|
let interaction: ChatInputCommandInteraction;
|
2024-12-02 18:40:19 +00:00
|
|
|
|
|
|
|
const embed = {
|
|
|
|
name: "embed",
|
|
|
|
};
|
|
|
|
|
|
|
|
const row = {
|
|
|
|
name: "row",
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
interaction = {
|
|
|
|
isChatInputCommand: jest.fn().mockReturnValue(true),
|
|
|
|
options: {
|
|
|
|
getSubcommand: jest.fn().mockReturnValue("list"),
|
|
|
|
},
|
|
|
|
reply: jest.fn(),
|
|
|
|
user: {
|
|
|
|
id: "userId",
|
|
|
|
},
|
2024-12-06 18:08:15 +00:00
|
|
|
} as unknown as ChatInputCommandInteraction;
|
2024-12-02 18:40:19 +00:00
|
|
|
|
|
|
|
const effects = new Effects();
|
|
|
|
|
|
|
|
EffectHelper.GenerateEffectEmbed = jest.fn().mockReturnValue({
|
|
|
|
embed,
|
|
|
|
row,
|
|
|
|
});
|
|
|
|
|
2024-12-06 18:08:15 +00:00
|
|
|
jest.spyOn(effects as unknown as {"List": () => object}, "List")
|
2024-12-02 18:40:19 +00:00
|
|
|
.mockImplementation();
|
|
|
|
});
|
|
|
|
|
2024-11-30 16:38:02 +00:00
|
|
|
describe("GIVEN page option is supplied", () => {
|
|
|
|
describe("AND page is a valid number", () => {
|
2024-12-02 18:40:19 +00:00
|
|
|
beforeEach(async () => {
|
|
|
|
interaction.options.get = jest.fn().mockReturnValueOnce({
|
|
|
|
value: "2",
|
|
|
|
});
|
|
|
|
|
|
|
|
await effects.execute(interaction);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("EXPECT EffectHelper.GenerateEffectEmbed to have been called with page", () => {
|
|
|
|
expect(EffectHelper.GenerateEffectEmbed).toHaveBeenCalledTimes(1);
|
|
|
|
expect(EffectHelper.GenerateEffectEmbed).toHaveBeenCalledWith("userId", 2);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("EXPECT interaction to have been replied", () => {
|
|
|
|
expect(interaction.reply).toHaveBeenCalledTimes(1);
|
|
|
|
expect(interaction.reply).toHaveBeenCalledWith({
|
|
|
|
embeds: [ embed ],
|
|
|
|
components: [ row ],
|
|
|
|
});
|
|
|
|
});
|
2024-11-30 16:38:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("AND page is not a valid number", () => {
|
2024-12-02 18:40:19 +00:00
|
|
|
beforeEach(async () => {
|
|
|
|
interaction.options.get = jest.fn().mockReturnValueOnce({
|
|
|
|
value: "test",
|
|
|
|
});
|
|
|
|
|
|
|
|
await effects.execute(interaction);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("EXPECT EffectHelper.GenerateEffectEmbed to have been called with page of 1", () => {
|
|
|
|
expect(EffectHelper.GenerateEffectEmbed).toHaveBeenCalledTimes(1);
|
|
|
|
expect(EffectHelper.GenerateEffectEmbed).toHaveBeenCalledWith("userId", 1);
|
|
|
|
});
|
2024-11-30 16:38:02 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("GIVEN page option is not supplied", () => {
|
2024-12-02 18:40:19 +00:00
|
|
|
beforeEach(async () => {
|
|
|
|
interaction.options.get = jest.fn().mockReturnValueOnce(undefined);
|
|
|
|
|
|
|
|
await effects.execute(interaction);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("EXPECT EffectHelper.GenerateEffectEmbed to have been called with page of 1", () => {
|
|
|
|
expect(EffectHelper.GenerateEffectEmbed).toHaveBeenCalledTimes(1);
|
|
|
|
expect(EffectHelper.GenerateEffectEmbed).toHaveBeenCalledWith("userId", 1);
|
|
|
|
});
|
2024-11-30 16:38:02 +00:00
|
|
|
});
|
|
|
|
});
|