This commit is contained in:
parent
e557540d70
commit
1f5965ae79
4 changed files with 238 additions and 7 deletions
|
@ -0,0 +1,69 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`constructor EXPECT CommandBuilder to be defined correctly 1`] = `
|
||||
{
|
||||
"contexts": undefined,
|
||||
"default_member_permissions": undefined,
|
||||
"default_permission": undefined,
|
||||
"description": "View and create moons",
|
||||
"description_localizations": undefined,
|
||||
"dm_permission": undefined,
|
||||
"integration_types": undefined,
|
||||
"name": "moons",
|
||||
"name_localizations": undefined,
|
||||
"nsfw": undefined,
|
||||
"options": [
|
||||
{
|
||||
"description": "List moons you have obtained",
|
||||
"description_localizations": undefined,
|
||||
"name": "list",
|
||||
"name_localizations": undefined,
|
||||
"options": [
|
||||
{
|
||||
"description": "The user to view (Defaults to yourself)",
|
||||
"description_localizations": undefined,
|
||||
"name": "user",
|
||||
"name_localizations": undefined,
|
||||
"required": false,
|
||||
"type": 6,
|
||||
},
|
||||
{
|
||||
"autocomplete": undefined,
|
||||
"choices": undefined,
|
||||
"description": "The page to start with",
|
||||
"description_localizations": undefined,
|
||||
"max_value": undefined,
|
||||
"min_value": undefined,
|
||||
"name": "page",
|
||||
"name_localizations": undefined,
|
||||
"required": false,
|
||||
"type": 10,
|
||||
},
|
||||
],
|
||||
"type": 1,
|
||||
},
|
||||
{
|
||||
"description": "Add a moon to your count!",
|
||||
"description_localizations": undefined,
|
||||
"name": "add",
|
||||
"name_localizations": undefined,
|
||||
"options": [
|
||||
{
|
||||
"autocomplete": undefined,
|
||||
"choices": undefined,
|
||||
"description": "What deserved a moon?",
|
||||
"description_localizations": undefined,
|
||||
"max_length": undefined,
|
||||
"min_length": undefined,
|
||||
"name": "description",
|
||||
"name_localizations": undefined,
|
||||
"required": true,
|
||||
"type": 3,
|
||||
},
|
||||
],
|
||||
"type": 1,
|
||||
},
|
||||
],
|
||||
"type": 1,
|
||||
}
|
||||
`;
|
|
@ -1,17 +1,113 @@
|
|||
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();
|
||||
});
|
||||
|
||||
describe("constructor", () => {
|
||||
test.todo("EXPECT CommandBuilder to be defined correctly");
|
||||
let moons: Moons;
|
||||
|
||||
beforeEach(() => {
|
||||
moons = new Moons();
|
||||
});
|
||||
|
||||
test("EXPECT CommandBuilder to be defined correctly", () => {
|
||||
expect(moons.CommandBuilder).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
describe("execute", () => {
|
||||
describe("GIVEN interaction is not a chat input command", () => {
|
||||
test.todo("EXPECT nothing to happen");
|
||||
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();
|
||||
});
|
||||
});
|
||||
|
||||
describe("GIVEN interaction subcommand is list", () => {
|
||||
test.todo("EXPECT ListMoons to be called");
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
describe("GIVEN interaction subcommand is add", () => {
|
||||
test.todo("EXPECT AddMoon to be called");
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue