This commit is contained in:
parent
554c274a7f
commit
056783bc44
5 changed files with 226 additions and 32 deletions
|
@ -0,0 +1,25 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`GIVEN happy flow EXPECT embed to be replied 1`] = `
|
||||
[
|
||||
{
|
||||
"color": 5294200,
|
||||
"description": "**2 -** Test Description",
|
||||
"thumbnail": {
|
||||
"url": "https://cdn.discordapp.com/emojis/374131312182689793.webp?size=96&quality=lossless",
|
||||
},
|
||||
"title": "undefined Got A Moon!",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`GIVEN happy flow EXPECT moon to be saved 1`] = `
|
||||
{
|
||||
"Description": "Test Description",
|
||||
"Id": Any<String>,
|
||||
"MoonNumber": 2,
|
||||
"UserId": "userId",
|
||||
"WhenCreated": Any<Date>,
|
||||
"WhenUpdated": Any<Date>,
|
||||
}
|
||||
`;
|
|
@ -1,3 +1,84 @@
|
|||
import { CommandInteraction, EmbedBuilder } from "discord.js";
|
||||
import AddMoon from "../../../../src/commands/304276391837302787/moons/add";
|
||||
import Moon from "../../../../src/database/entities/304276391837302787/Moon";
|
||||
import UserSetting from "../../../../src/database/entities/UserSetting";
|
||||
|
||||
describe("GIVEN happy flow", () => {
|
||||
let repliedWithEmbed: EmbedBuilder[] | undefined;
|
||||
let savedMoon: Moon | undefined;
|
||||
|
||||
const interaction = {
|
||||
reply: jest.fn((options: any) => {
|
||||
repliedWithEmbed = options.embeds;
|
||||
}),
|
||||
options: {
|
||||
get: jest.fn()
|
||||
.mockReturnValueOnce({
|
||||
value: "Test Description",
|
||||
}),
|
||||
},
|
||||
user: {
|
||||
id: "userId",
|
||||
},
|
||||
} as unknown as CommandInteraction;
|
||||
|
||||
const userSetting = {
|
||||
Value: 1,
|
||||
UpdateValue: jest.fn(),
|
||||
Save: jest.fn(),
|
||||
};
|
||||
|
||||
beforeAll(async () => {
|
||||
Moon.FetchMoonCountByUserId = jest.fn().mockResolvedValue(1);
|
||||
Moon.prototype.Save = jest.fn().mockImplementation((_, entity: Moon) => {
|
||||
savedMoon = entity;
|
||||
});
|
||||
|
||||
UserSetting.FetchOneByKey = jest.fn().mockResolvedValue(userSetting);
|
||||
|
||||
await AddMoon(interaction);
|
||||
});
|
||||
|
||||
test("EXPECT description option to have been fetched", () => {
|
||||
expect(interaction.options.get).toHaveBeenCalledTimes(1);
|
||||
expect(interaction.options.get).toHaveBeenCalledWith("description", true);
|
||||
});
|
||||
|
||||
test("EXPECT UserSetting to have been fetched", () => {
|
||||
expect(UserSetting.FetchOneByKey).toHaveBeenCalledTimes(1);
|
||||
expect(UserSetting.FetchOneByKey).toHaveBeenCalledWith("userId", "moons");
|
||||
});
|
||||
|
||||
test("EXPECT moonCount to be updated +1", () => {
|
||||
expect(userSetting.UpdateValue).toHaveBeenCalledTimes(1);
|
||||
expect(userSetting.UpdateValue).toHaveBeenCalledWith("2");
|
||||
});
|
||||
|
||||
test("EXPECT setting to be saved", () => {
|
||||
expect(userSetting.Save).toHaveBeenCalledTimes(1);
|
||||
expect(userSetting.Save).toHaveBeenCalledWith(UserSetting, userSetting);
|
||||
});
|
||||
|
||||
test("EXPECT moon to be saved", () => {
|
||||
expect(Moon.prototype.Save).toHaveBeenCalledTimes(1);
|
||||
expect(Moon.prototype.Save).toHaveBeenCalledWith(Moon, expect.any(Moon));
|
||||
|
||||
expect(savedMoon).toBeDefined();
|
||||
expect(savedMoon).toMatchSnapshot({
|
||||
Id: expect.any(String),
|
||||
WhenCreated: expect.any(Date),
|
||||
WhenUpdated: expect.any(Date),
|
||||
});
|
||||
});
|
||||
|
||||
test("EXPECT embed to be replied", () => {
|
||||
expect(interaction.reply).toHaveBeenCalledTimes(1);
|
||||
|
||||
expect(repliedWithEmbed).toBeDefined();
|
||||
expect(repliedWithEmbed).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
describe("GIVEN description is null", () => {
|
||||
test.todo("EXPECT error replied");
|
||||
});
|
||||
|
@ -12,8 +93,4 @@ describe("GIVEN moon count setting exists", () => {
|
|||
|
||||
describe("GIVEN moon count setting does not exist", () => {
|
||||
test.todo("EXPECT new entity to be created");
|
||||
});
|
||||
|
||||
test.todo("EXPECT setting to be saved");
|
||||
|
||||
test.todo("EXPECT embed to be replied");
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue