This commit is contained in:
parent
4ff8d15e2c
commit
78963d6b7c
3 changed files with 117 additions and 4 deletions
|
@ -4,9 +4,14 @@ export default function GenerateCommandInteractionMock(options?: {
|
||||||
subcommand?: string,
|
subcommand?: string,
|
||||||
}): CommandInteraction {
|
}): CommandInteraction {
|
||||||
return {
|
return {
|
||||||
|
deferReply: jest.fn(),
|
||||||
|
editReply: jest.fn(),
|
||||||
isChatInputCommand: jest.fn().mockReturnValue(true),
|
isChatInputCommand: jest.fn().mockReturnValue(true),
|
||||||
options: {
|
options: {
|
||||||
getSubcommand: jest.fn().mockReturnValue(options?.subcommand),
|
getSubcommand: jest.fn().mockReturnValue(options?.subcommand),
|
||||||
},
|
},
|
||||||
|
user: {
|
||||||
|
id: "userId",
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
|
@ -19,8 +19,13 @@ export type ButtonInteraction = {
|
||||||
}
|
}
|
||||||
|
|
||||||
export type CommandInteraction = {
|
export type CommandInteraction = {
|
||||||
|
deferReply: jest.Func,
|
||||||
|
editReply: jest.Func,
|
||||||
isChatInputCommand: jest.Func,
|
isChatInputCommand: jest.Func,
|
||||||
options: {
|
options: {
|
||||||
getSubcommand: jest.Func,
|
getSubcommand: jest.Func,
|
||||||
},
|
},
|
||||||
|
user: {
|
||||||
|
id: string,
|
||||||
|
},
|
||||||
}
|
}
|
|
@ -1,7 +1,110 @@
|
||||||
describe("GIVEN valid conditions", () => {
|
import { CommandInteraction } from "discord.js";
|
||||||
test.todo("EXPECT user.RemoveCurrency to be called");
|
import Drop from "../../src/commands/drop";
|
||||||
|
import GenerateCommandInteractionMock from "../__functions__/discord.js/GenerateCommandInteractionMock";
|
||||||
|
import { CommandInteraction as CommandInteractionMock } from "../__types__/discord.js";
|
||||||
|
import { CoreClient } from "../../src/client/client";
|
||||||
|
import Config from "../../src/database/entities/app/Config";
|
||||||
|
import User from "../../src/database/entities/app/User";
|
||||||
|
import GetCardsHelper from "../../src/helpers/DropHelpers/GetCardsHelper";
|
||||||
|
import Inventory from "../../src/database/entities/app/Inventory";
|
||||||
|
import DropEmbedHelper from "../../src/helpers/DropHelpers/DropEmbedHelper";
|
||||||
|
import CardConstants from "../../src/constants/CardConstants";
|
||||||
|
|
||||||
test.todo("GIVEN user is saved");
|
jest.mock("../../src/database/entities/app/Config");
|
||||||
|
jest.mock("../../src/database/entities/app/User");
|
||||||
|
jest.mock("../../src/helpers/DropHelpers/GetCardsHelper");
|
||||||
|
jest.mock("../../src/database/entities/app/Inventory");
|
||||||
|
jest.mock("../../src/helpers/DropHelpers/DropEmbedHelper");
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
(Config.GetValue as jest.Mock).mockResolvedValue("false");
|
||||||
});
|
});
|
||||||
|
|
||||||
test.todo("GIVEN user.RemoveCurrency fails, EXPECT error replied");
|
describe("execute", () => {
|
||||||
|
describe("GIVEN user is in the database", () => {
|
||||||
|
let interaction: CommandInteractionMock;
|
||||||
|
let user: User;
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
// Arrange
|
||||||
|
CoreClient.AllowDrops = true;
|
||||||
|
|
||||||
|
interaction = GenerateCommandInteractionMock();
|
||||||
|
|
||||||
|
user = {
|
||||||
|
RemoveCurrency: jest.fn().mockReturnValue(true),
|
||||||
|
Save: jest.fn(),
|
||||||
|
} as unknown as User;
|
||||||
|
|
||||||
|
(User.FetchOneById as jest.Mock).mockResolvedValue(user);
|
||||||
|
(GetCardsHelper.FetchCard as jest.Mock).mockResolvedValue({
|
||||||
|
card: {
|
||||||
|
path: "https://google.com/",
|
||||||
|
}
|
||||||
|
});
|
||||||
|
(Inventory.FetchOneByCardNumberAndUserId as jest.Mock).mockResolvedValue({
|
||||||
|
Quantity: 1,
|
||||||
|
});
|
||||||
|
(DropEmbedHelper.GenerateDropEmbed as jest.Mock).mockResolvedValue({
|
||||||
|
type: "Embed",
|
||||||
|
});
|
||||||
|
(DropEmbedHelper.GenerateDropButtons as jest.Mock).mockResolvedValue({
|
||||||
|
type: "Button",
|
||||||
|
});
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const drop = new Drop();
|
||||||
|
await drop.execute(interaction as unknown as CommandInteraction);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("EXPECT user to be fetched", () => {
|
||||||
|
expect(User.FetchOneById).toHaveBeenCalledTimes(1);
|
||||||
|
expect(User.FetchOneById).toHaveBeenCalledWith(User, "userId");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("EXPECT user.RemoveCurrency to be called", () => {
|
||||||
|
expect(user.RemoveCurrency).toHaveBeenCalledTimes(1);
|
||||||
|
expect(user.RemoveCurrency).toHaveBeenCalledWith(CardConstants.ClaimCost);
|
||||||
|
});
|
||||||
|
|
||||||
|
test.todo("EXPECT user to be saved");
|
||||||
|
|
||||||
|
test.todo("EXPECT random card to be fetched");
|
||||||
|
|
||||||
|
test.todo("EXPECT interaction to be deferred");
|
||||||
|
|
||||||
|
test.todo("EXPECT Inventory.FetchOneByCardNumberAndUserId to be called");
|
||||||
|
|
||||||
|
test.todo("EXPECT DropEmbedHelper.GenerateDropEmbed to be called");
|
||||||
|
|
||||||
|
test.todo("EXPECT DropEmbedHelper.GenerateDropButtons to be called");
|
||||||
|
|
||||||
|
test.todo("EXPECT interaction to be edited");
|
||||||
|
|
||||||
|
describe("AND randomCard path is not a url", () => {
|
||||||
|
test.todo("EXPECT image read from file system");
|
||||||
|
|
||||||
|
test.todo("EXPECT files on the embed to contain the image as an attachment");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("GIVEN user is not in the database", () => {
|
||||||
|
test.todo("EXPECT new user to be created");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("GIVEN user.RemoveCurrency fails", () => {
|
||||||
|
test.todo("EXPECT error replied");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("GIVEN randomCard returns null", () => {
|
||||||
|
test.todo("EXPECT error logged");
|
||||||
|
|
||||||
|
test.todo("EXPECT error replied");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("GIVEN the code throws an error", () => {
|
||||||
|
test.todo("EXPECT error logged");
|
||||||
|
|
||||||
|
test.todo("EXPECT interaction edited with error");
|
||||||
|
});
|
||||||
|
});
|
Loading…
Add table
Reference in a new issue