WIP: Create add moon command tests
All checks were successful
Test / build (push) Successful in 18s

This commit is contained in:
Ethan Lane 2024-11-07 19:38:16 +00:00
parent 554c274a7f
commit 056783bc44
5 changed files with 226 additions and 32 deletions

View file

@ -0,0 +1,41 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`GIVEN happy flow EXPECT embed to be updated 1`] = `
[
{
"color": 3166394,
"description": "**1 -** Test Descriptio",
"footer": {
"icon_url": undefined,
"text": "Page 1 of 1 · 0 moons",
},
"title": "username's Moons",
},
]
`;
exports[`GIVEN happy flow EXPECT row to be updated 1`] = `
[
{
"components": [
{
"custom_id": "moons list userId -1",
"disabled": true,
"emoji": undefined,
"label": "Previous",
"style": 1,
"type": 2,
},
{
"custom_id": "moons list userId 1",
"disabled": true,
"emoji": undefined,
"label": "Next",
"style": 1,
"type": 2,
},
],
"type": 1,
},
]
`;

View file

@ -1,8 +1,65 @@
import {ButtonInteraction, EmbedBuilder} from "discord.js";
import {ActionRowBuilder, ButtonBuilder, ButtonInteraction, EmbedBuilder} from "discord.js";
import List from "../../../../src/buttonEvents/304276391837302787/moons/list";
import UserSetting from "../../../../src/database/entities/UserSetting";
import Moon from "../../../../src/database/entities/304276391837302787/Moon";
describe("GIVEN happy flow", () => {
let updatedWithEmbeds: EmbedBuilder[] | undefined;
let updatedWithRows: ActionRowBuilder<ButtonBuilder>[] | undefined;
const interaction = {
guild: {
members: {
cache: {
find: jest.fn().mockReturnValue({
user: {
username: "username",
},
}),
},
},
},
reply: jest.fn(),
update: jest.fn((options: any) => {
updatedWithEmbeds = options.embeds;
updatedWithRows = options.components;
}),
customId: "moons list userId 0",
} as unknown as ButtonInteraction;
beforeAll(async () => {
UserSetting.FetchOneByKey = jest.fn();
Moon.FetchPaginatedMoonsByUserId = jest.fn().mockResolvedValue([
[
{
MoonNumber: 1,
Description: "Test Description",
}
],
1,
]);
await List(interaction);
});
test("EXPECT moons to be fetched", () => {
expect(Moon.FetchPaginatedMoonsByUserId).toHaveBeenCalledTimes(1);
expect(Moon.FetchPaginatedMoonsByUserId).toHaveBeenCalledWith("userId", 10, 0);
});
test("EXPECT interaction.update to be called", () => {
expect(interaction.update).toHaveBeenCalledTimes(1);
});
test("EXPECT embed to be updated", () => {
expect(updatedWithEmbeds).toMatchSnapshot();
});
test("EXPECT row to be updated", () => {
expect(updatedWithRows).toMatchSnapshot();
});
});
describe("GIVEN interaction.guild is null", () => {
const interaction = {
guild: null,
@ -205,31 +262,7 @@ describe("GIVEN no moons on current page", () => {
test("EXPECT description to say so", () => {
expect(updatedWith).toBeDefined();
expect(updatedWith?.length).toBe(1);
expect(updatedWith![0].data.description).toBe("*none*");
});
});
describe("GIVEN happy flow", () => {
test.todo("EXPECT moons to be fetched");
test.todo("EXPECT embed to be updated");
test.todo("EXPECT row to be updated");
describe("GIVEN it is the first page", () => {
test.todo("EXPECT Previous button to be disabled");
});
describe("GIVEN it is the last page", () => {
test.todo("EXPECT Next button to be disabled");
describe("GIVEN there are more moons in the counter than in the database", () => {
test.todo("EXPECT untracked counter to be present");
});
});
describe("GIVEN no moons on the current page", () => {
test.todo("EXPECT Next button to be disabled");
});
});