2024-12-14 18:04:04 +00:00
|
|
|
import { ChatInputCommandInteraction, CommandInteraction } from "discord.js";
|
|
|
|
import Moons from "../../../src/commands/304276391837302787/moons";
|
|
|
|
import * as AddMoon from "../../../src/commands/304276391837302787/moons/add";
|
|
|
|
import * as ListMoons from "../../../src/commands/304276391837302787/moons/list";
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.resetAllMocks();
|
|
|
|
});
|
|
|
|
|
2024-11-01 14:52:38 +00:00
|
|
|
describe("constructor", () => {
|
2024-12-14 18:04:04 +00:00
|
|
|
let moons: Moons;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
moons = new Moons();
|
|
|
|
});
|
|
|
|
|
|
|
|
test("EXPECT CommandBuilder to be defined correctly", () => {
|
|
|
|
expect(moons.CommandBuilder).toMatchSnapshot();
|
|
|
|
});
|
2024-11-01 14:52:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("execute", () => {
|
|
|
|
describe("GIVEN interaction is not a chat input command", () => {
|
2024-12-14 18:04:04 +00:00
|
|
|
const moons = new Moons();
|
|
|
|
|
|
|
|
let interaction: CommandInteraction;
|
|
|
|
|
|
|
|
let listMoonsSpy: jest.SpyInstance;
|
|
|
|
let addMoonSpy: jest.SpyInstance;
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
listMoonsSpy = jest.spyOn(ListMoons, "default");
|
|
|
|
addMoonSpy = jest.spyOn(AddMoon, "default");
|
|
|
|
|
|
|
|
interaction = {
|
|
|
|
isChatInputCommand: jest.fn().mockReturnValue(false),
|
|
|
|
} as unknown as CommandInteraction;
|
|
|
|
|
|
|
|
await moons.execute(interaction);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("EXPECT interaction.isChatInputCommand to have been called", () => {
|
|
|
|
expect(interaction.isChatInputCommand).toHaveBeenCalledTimes(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("EXPECT nothing to happen", () => {
|
|
|
|
expect(listMoonsSpy).not.toHaveBeenCalled();
|
|
|
|
expect(addMoonSpy).not.toHaveBeenCalled();
|
|
|
|
});
|
2024-11-01 14:52:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("GIVEN interaction subcommand is list", () => {
|
2024-12-14 18:04:04 +00:00
|
|
|
const moons = new Moons();
|
|
|
|
|
|
|
|
let interaction: ChatInputCommandInteraction;
|
|
|
|
|
|
|
|
let listMoonsSpy: jest.SpyInstance;
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
listMoonsSpy = jest.spyOn(ListMoons, "default")
|
|
|
|
.mockImplementation();
|
|
|
|
|
|
|
|
interaction = {
|
|
|
|
isChatInputCommand: jest.fn().mockReturnValue(true),
|
|
|
|
options: {
|
|
|
|
getSubcommand: jest.fn().mockReturnValue("list"),
|
|
|
|
},
|
|
|
|
} as unknown as ChatInputCommandInteraction;
|
|
|
|
|
|
|
|
await moons.execute(interaction);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("EXPECT interaction.options.getSubcommand to have been called", () => {
|
|
|
|
expect(interaction.options.getSubcommand).toHaveBeenCalledTimes(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("EXPECT ListMoons to be called", () => {
|
|
|
|
expect(listMoonsSpy).toHaveBeenCalledTimes(1);
|
|
|
|
expect(listMoonsSpy).toHaveBeenCalledWith(interaction);
|
|
|
|
});
|
2024-11-01 14:52:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("GIVEN interaction subcommand is add", () => {
|
2024-12-14 18:04:04 +00:00
|
|
|
const moons = new Moons();
|
|
|
|
|
|
|
|
let interaction: ChatInputCommandInteraction;
|
|
|
|
|
|
|
|
let addMoonSpy: jest.SpyInstance;
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
addMoonSpy = jest.spyOn(AddMoon, "default")
|
|
|
|
.mockImplementation();
|
|
|
|
|
|
|
|
interaction = {
|
|
|
|
isChatInputCommand: jest.fn().mockReturnValue(true),
|
|
|
|
options: {
|
|
|
|
getSubcommand: jest.fn().mockReturnValue("add"),
|
|
|
|
},
|
|
|
|
} as unknown as ChatInputCommandInteraction;
|
|
|
|
|
|
|
|
await moons.execute(interaction);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("EXPECT interaction.options.getSubcommand to have been called", () => {
|
|
|
|
expect(interaction.options.getSubcommand).toHaveBeenCalledTimes(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("EXPECT AddMoon to be called", () => {
|
|
|
|
expect(addMoonSpy).toHaveBeenCalledTimes(1);
|
|
|
|
expect(addMoonSpy).toHaveBeenCalledWith(interaction);
|
|
|
|
});
|
2024-11-01 14:52:38 +00:00
|
|
|
});
|
|
|
|
});
|