vylbot-app/tests/commands/304276391837302787/moons.test.ts

113 lines
3.6 KiB
TypeScript
Raw Normal View History

Split up moon counter from the database (#489) # Description Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. - Create a separate moon counter to track how many moons a user has - This is so we can start a user at a specific counter - Added to the list command a counter to specify how many moons aren't being tracked with the bot #300 ## Type of change Please delete options that are not relevant. - [x] New feature (non-breaking change which adds functionality) # How Has This Been Tested? Please describe the tests that you ran to verify the changes. Provide instructions so we can reproduce. Please also list any relevant details to your test configuration. # Checklist - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that provide my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules Reviewed-on: https://git.vylpes.xyz/RabbitLabs/vylbot-app/pulls/489 Reviewed-by: VylpesTester <tester@vylpes.com> Co-authored-by: Ethan Lane <ethan@vylpes.com> Co-committed-by: Ethan Lane <ethan@vylpes.com>
2025-02-03 17:42:11 +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();
});
describe("constructor", () => {
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", () => {
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", () => {
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", () => {
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);
});
});
});