Create use effect command (#419)
# 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. #380 ## Type of change Please delete options that are not relevant. - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update # 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 provde 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: #419 Reviewed-by: VylpesTester <tester@vylpes.com> Co-authored-by: Ethan Lane <ethan@vylpes.com> Co-committed-by: Ethan Lane <ethan@vylpes.com>
This commit is contained in:
parent
3e81f8ce1d
commit
a3248e978a
42 changed files with 1241 additions and 1133 deletions
|
@ -1,127 +1,66 @@
|
|||
import {ButtonInteraction} from "discord.js";
|
||||
import { ButtonInteraction } from "discord.js";
|
||||
import Effects from "../../src/buttonEvents/Effects";
|
||||
import EffectHelper from "../../src/helpers/EffectHelper";
|
||||
import GenerateButtonInteractionMock from "../__functions__/discord.js/GenerateButtonInteractionMock";
|
||||
import { ButtonInteraction as ButtonInteractionType } from "../__types__/discord.js";
|
||||
import List from "../../src/buttonEvents/Effects/List";
|
||||
import Use from "../../src/buttonEvents/Effects/Use";
|
||||
import AppLogger from "../../src/client/appLogger";
|
||||
|
||||
describe("execute", () => {
|
||||
describe("GIVEN action in custom id is list", () => {
|
||||
const interaction = {
|
||||
customId: "effects list",
|
||||
} as unknown as ButtonInteraction;
|
||||
jest.mock("../../src/client/appLogger");
|
||||
jest.mock("../../src/buttonEvents/Effects/List");
|
||||
jest.mock("../../src/buttonEvents/Effects/Use");
|
||||
|
||||
let listSpy: jest.SpyInstance;
|
||||
let interaction: ButtonInteractionType;
|
||||
|
||||
beforeAll(async () => {
|
||||
const effects = new Effects();
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks();
|
||||
|
||||
listSpy = jest.spyOn(effects as unknown as {"List": () => object}, "List")
|
||||
.mockImplementation();
|
||||
|
||||
await effects.execute(interaction);
|
||||
});
|
||||
|
||||
test("EXPECT list function to be called", () => {
|
||||
expect(listSpy).toHaveBeenCalledTimes(1);
|
||||
expect(listSpy).toHaveBeenCalledWith(interaction);
|
||||
});
|
||||
});
|
||||
interaction = GenerateButtonInteractionMock();
|
||||
interaction.customId = "effects";
|
||||
});
|
||||
|
||||
describe("List", () => {
|
||||
let interaction: ButtonInteraction;
|
||||
test("GIVEN action is list, EXPECT list function to be called", async () => {
|
||||
// Arrange
|
||||
interaction.customId = "effects list";
|
||||
|
||||
const embed = {
|
||||
name: "Embed",
|
||||
};
|
||||
// Act
|
||||
const effects = new Effects();
|
||||
await effects.execute(interaction as unknown as ButtonInteraction);
|
||||
|
||||
const row = {
|
||||
name: "Row",
|
||||
};
|
||||
// Assert
|
||||
expect(List).toHaveBeenCalledTimes(1);
|
||||
expect(List).toHaveBeenCalledWith(interaction);
|
||||
|
||||
beforeEach(() => {
|
||||
interaction = {
|
||||
customId: "effects list",
|
||||
user: {
|
||||
id: "userId",
|
||||
},
|
||||
update: jest.fn(),
|
||||
reply: jest.fn(),
|
||||
} as unknown as ButtonInteraction;
|
||||
});
|
||||
|
||||
describe("GIVEN page is a valid number", () => {
|
||||
beforeEach(async () => {
|
||||
interaction.customId += " 1";
|
||||
|
||||
EffectHelper.GenerateEffectEmbed = jest.fn()
|
||||
.mockResolvedValue({
|
||||
embed,
|
||||
row,
|
||||
});
|
||||
|
||||
const effects = new Effects();
|
||||
|
||||
await effects.execute(interaction);
|
||||
});
|
||||
|
||||
test("EXPECT EffectHelper.GenerateEffectEmbed to be called", () => {
|
||||
expect(EffectHelper.GenerateEffectEmbed).toHaveBeenCalledTimes(1);
|
||||
expect(EffectHelper.GenerateEffectEmbed).toHaveBeenCalledWith("userId", 1);
|
||||
});
|
||||
|
||||
test("EXPECT interaction to be updated", () => {
|
||||
expect(interaction.update).toHaveBeenCalledTimes(1);
|
||||
expect(interaction.update).toHaveBeenCalledWith({
|
||||
embeds: [ embed ],
|
||||
components: [ row ],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("GIVEN page in custom id is not supplied", () => {
|
||||
beforeEach(async () => {
|
||||
EffectHelper.GenerateEffectEmbed = jest.fn()
|
||||
.mockResolvedValue({
|
||||
embed,
|
||||
row,
|
||||
});
|
||||
|
||||
const effects = new Effects();
|
||||
|
||||
await effects.execute(interaction);
|
||||
});
|
||||
|
||||
test("EXPECT interaction to be replied with error", () => {
|
||||
expect(interaction.reply).toHaveBeenCalledTimes(1);
|
||||
expect(interaction.reply).toHaveBeenCalledWith("Page option is not a valid number");
|
||||
});
|
||||
|
||||
test("EXPECT interaction to not be updated", () => {
|
||||
expect(interaction.update).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("GIVEN page in custom id is not a number", () => {
|
||||
beforeEach(async () => {
|
||||
interaction.customId += " test";
|
||||
|
||||
EffectHelper.GenerateEffectEmbed = jest.fn()
|
||||
.mockResolvedValue({
|
||||
embed,
|
||||
row,
|
||||
});
|
||||
|
||||
const effects = new Effects();
|
||||
|
||||
await effects.execute(interaction);
|
||||
});
|
||||
|
||||
test("EXPECT interaction to be replied with error", () => {
|
||||
expect(interaction.reply).toHaveBeenCalledTimes(1);
|
||||
expect(interaction.reply).toHaveBeenCalledWith("Page option is not a valid number");
|
||||
});
|
||||
|
||||
test("EXPECT interaction to not be updated", () => {
|
||||
expect(interaction.update).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
expect(Use.Execute).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test("GIVEN action is use, EXPECT use function to be called", async () => {
|
||||
// Arrange
|
||||
interaction.customId = "effects use";
|
||||
|
||||
// Act
|
||||
const effects = new Effects();
|
||||
await effects.execute(interaction as unknown as ButtonInteraction);
|
||||
|
||||
// Assert
|
||||
expect(Use.Execute).toHaveBeenCalledTimes(1);
|
||||
expect(Use.Execute).toHaveBeenCalledWith(interaction);
|
||||
|
||||
expect(List).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test("GIVEN action is invalid, EXPECT nothing to be called", async () => {
|
||||
// Arrange
|
||||
interaction.customId = "effects invalid";
|
||||
|
||||
// Act
|
||||
const effects = new Effects();
|
||||
await effects.execute(interaction as unknown as ButtonInteraction);
|
||||
|
||||
// Assert
|
||||
expect(List).not.toHaveBeenCalled();
|
||||
expect(Use.Execute).not.toHaveBeenCalled();
|
||||
|
||||
expect(AppLogger.LogError).toHaveBeenCalledTimes(1);
|
||||
expect(AppLogger.LogError).toHaveBeenCalledWith("Buttons/Effects", "Unknown action, invalid");
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue