WIP: Start creating tests for confirmation button event
Some checks failed
Test / build (push) Failing after 39s
Some checks failed
Test / build (push) Failing after 39s
This commit is contained in:
parent
416e30c042
commit
f745fdfbca
4 changed files with 95 additions and 5 deletions
|
@ -3,8 +3,10 @@ import Buy from "../../../src/buttonEvents/Effects/Buy";
|
|||
import GenerateButtonInteractionMock from "../../__functions__/discord.js/GenerateButtonInteractionMock";
|
||||
import { ButtonInteraction as ButtonInteractionType } from "../../__types__/discord.js";
|
||||
import AppLogger from "../../../src/client/appLogger";
|
||||
import EffectHelper from "../../../src/helpers/EffectHelper";
|
||||
|
||||
jest.mock("../../../src/client/appLogger");
|
||||
jest.mock("../../../src/helpers/EffectHelper");
|
||||
|
||||
let interaction: ButtonInteractionType;
|
||||
|
||||
|
@ -21,7 +23,8 @@ describe("Execute", () => {
|
|||
// Arrange
|
||||
interaction.customId += " confirm";
|
||||
|
||||
const confirmSpy = jest.spyOn(Buy as any, "Confirm");
|
||||
const confirmSpy = jest.spyOn(Buy as any, "Confirm")
|
||||
.mockImplementation();
|
||||
|
||||
// Act
|
||||
await Buy.Execute(interaction as unknown as ButtonInteraction);
|
||||
|
@ -37,13 +40,14 @@ describe("Execute", () => {
|
|||
// Arrange
|
||||
interaction.customId += " cancel";
|
||||
|
||||
const cancelSpy = jest.spyOn(Buy as any, "Cancel");
|
||||
const cancelSpy = jest.spyOn(Buy as any, "Cancel")
|
||||
.mockImplementation();
|
||||
|
||||
// Act
|
||||
await Buy.Execute(interaction as unknown as ButtonInteraction);
|
||||
|
||||
// Assert
|
||||
expect(cancelSpy).toHaveBeenCalledTimes(1);
|
||||
expect(cancelSpy).toHaveBeenCalledTimes(1)
|
||||
expect(cancelSpy).toHaveBeenCalledWith(interaction);
|
||||
|
||||
expect(AppLogger.LogError).not.toHaveBeenCalled();
|
||||
|
@ -53,8 +57,10 @@ describe("Execute", () => {
|
|||
// Arrange
|
||||
interaction.customId += " invalid";
|
||||
|
||||
const confirmSpy = jest.spyOn(Buy as any, "Confirm");
|
||||
const cancelSpy = jest.spyOn(Buy as any, "Cancel");
|
||||
const confirmSpy = jest.spyOn(Buy as any, "Confirm")
|
||||
.mockImplementation();
|
||||
const cancelSpy = jest.spyOn(Buy as any, "Cancel")
|
||||
.mockImplementation();
|
||||
|
||||
// Act
|
||||
await Buy.Execute(interaction as unknown as ButtonInteraction);
|
||||
|
@ -67,3 +73,52 @@ describe("Execute", () => {
|
|||
expect(cancelSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("Confirm", () => {
|
||||
beforeEach(() => {
|
||||
interaction.customId += " confirm";
|
||||
});
|
||||
|
||||
test("EXPECT success embed generated", async () => {
|
||||
// Assert
|
||||
interaction.customId += " id 1";
|
||||
|
||||
const embed = {
|
||||
id: "embed",
|
||||
};
|
||||
const row = {
|
||||
id: "row",
|
||||
};
|
||||
|
||||
(EffectHelper.GenerateEffectBuyEmbed as jest.Mock).mockResolvedValue({
|
||||
embed,
|
||||
row,
|
||||
});
|
||||
|
||||
// Act
|
||||
await Buy.Execute(interaction as unknown as ButtonInteraction);
|
||||
|
||||
// Assert
|
||||
expect(interaction.update).toHaveBeenCalledTimes(1);
|
||||
expect(interaction.update).toHaveBeenCalledWith({
|
||||
embeds: [ embed ],
|
||||
components: [ row ],
|
||||
});
|
||||
|
||||
expect(EffectHelper.GenerateEffectBuyEmbed).toHaveBeenCalledTimes(1);
|
||||
expect(EffectHelper.GenerateEffectBuyEmbed).toHaveBeenCalledWith("userId", "id", 1, true);
|
||||
|
||||
expect(interaction.reply).not.toHaveBeenCalled();
|
||||
expect(AppLogger.LogError).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test.todo("GIVEN id is not supplied, EXPECT error");
|
||||
|
||||
test.todo("GIVEN quantity is not supplied, EXPECT error");
|
||||
|
||||
test.todo("GIVEN quantity is not a number, EXPECT error");
|
||||
|
||||
test.todo("GIVEN quantity is 0, EXPECT error");
|
||||
|
||||
test.todo("GIVEN GenerateEffectBuyEmbed returns with a string, EXPECT error replied");
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue