Compare commits
No commits in common. "32cc731442a4084fef4e6730a6a693b4168d5387" and "6e6b2a0af61cf0c9ce3f274d90ecb3e47a544537" have entirely different histories.
32cc731442
...
6e6b2a0af6
3 changed files with 9 additions and 183 deletions
|
@ -1,127 +1,25 @@
|
||||||
import {ButtonInteraction} from "discord.js";
|
|
||||||
import Effects from "../../src/buttonEvents/Effects";
|
|
||||||
import EffectHelper from "../../src/helpers/EffectHelper";
|
|
||||||
|
|
||||||
describe("execute", () => {
|
describe("execute", () => {
|
||||||
describe("GIVEN action in custom id is list", () => {
|
describe("GIVEN action in custom id is list", () => {
|
||||||
let interaction = {
|
test.todo("EXPECT list function to be called");
|
||||||
customId: "effects list",
|
|
||||||
} as unknown as ButtonInteraction;
|
|
||||||
|
|
||||||
let listSpy: any;
|
|
||||||
|
|
||||||
beforeAll(async () => {
|
|
||||||
const effects = new Effects();
|
|
||||||
|
|
||||||
listSpy = jest.spyOn(effects as any, "List")
|
|
||||||
.mockImplementation(() => {});
|
|
||||||
|
|
||||||
await effects.execute(interaction);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("EXPECT list function to be called", () => {
|
|
||||||
expect(listSpy).toHaveBeenCalledTimes(1);
|
|
||||||
expect(listSpy).toHaveBeenCalledWith(interaction);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("List", () => {
|
describe("List", () => {
|
||||||
let interaction: any;
|
|
||||||
|
|
||||||
const embed = {
|
|
||||||
name: "Embed",
|
|
||||||
};
|
|
||||||
|
|
||||||
const row = {
|
|
||||||
name: "Row",
|
|
||||||
};
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
interaction = {
|
|
||||||
customId: "effects list",
|
|
||||||
user: {
|
|
||||||
id: "userId",
|
|
||||||
},
|
|
||||||
update: jest.fn(),
|
|
||||||
reply: jest.fn(),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("GIVEN page is a valid number", () => {
|
describe("GIVEN page is a valid number", () => {
|
||||||
beforeEach(async () => {
|
test.todo("EXPECT EffectHelper.GenerateEffectEmbed to be called");
|
||||||
interaction.customId += " 1";
|
|
||||||
|
|
||||||
EffectHelper.GenerateEffectEmbed = jest.fn()
|
test.todo("EXPECT interaction to be updated");
|
||||||
.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", () => {
|
describe("GIVEN page in custom id is not supplied", () => {
|
||||||
beforeEach(async () => {
|
test.todo("EXPECT interaction to be replied with error");
|
||||||
EffectHelper.GenerateEffectEmbed = jest.fn()
|
|
||||||
.mockResolvedValue({
|
|
||||||
embed,
|
|
||||||
row,
|
|
||||||
});
|
|
||||||
|
|
||||||
const effects = new Effects();
|
test.todo("EXPECT interaction to not be updated");
|
||||||
|
|
||||||
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", () => {
|
describe("GIVEN page in custom id is not a number", () => {
|
||||||
beforeEach(async () => {
|
test.todo("EXPECT interaction to be replied with error");
|
||||||
interaction.customId += " test";
|
|
||||||
|
|
||||||
EffectHelper.GenerateEffectEmbed = jest.fn()
|
test.todo("EXPECT interaction to not be updated");
|
||||||
.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();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,40 +0,0 @@
|
||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
||||||
|
|
||||||
exports[`constructor EXPECT CommandBuilder to be defined 1`] = `
|
|
||||||
{
|
|
||||||
"contexts": undefined,
|
|
||||||
"default_member_permissions": undefined,
|
|
||||||
"default_permission": undefined,
|
|
||||||
"description": "Effects",
|
|
||||||
"description_localizations": undefined,
|
|
||||||
"dm_permission": undefined,
|
|
||||||
"integration_types": undefined,
|
|
||||||
"name": "effects",
|
|
||||||
"name_localizations": undefined,
|
|
||||||
"nsfw": undefined,
|
|
||||||
"options": [
|
|
||||||
{
|
|
||||||
"description": "List all effects I have",
|
|
||||||
"description_localizations": undefined,
|
|
||||||
"name": "list",
|
|
||||||
"name_localizations": undefined,
|
|
||||||
"options": [
|
|
||||||
{
|
|
||||||
"autocomplete": undefined,
|
|
||||||
"choices": undefined,
|
|
||||||
"description": "The page number",
|
|
||||||
"description_localizations": undefined,
|
|
||||||
"max_value": undefined,
|
|
||||||
"min_value": 1,
|
|
||||||
"name": "page",
|
|
||||||
"name_localizations": undefined,
|
|
||||||
"required": false,
|
|
||||||
"type": 10,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
"type": 1,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
"type": 1,
|
|
||||||
}
|
|
||||||
`;
|
|
|
@ -1,42 +1,10 @@
|
||||||
import Effects from "../../src/commands/effects";
|
|
||||||
|
|
||||||
describe("constructor", () => {
|
describe("constructor", () => {
|
||||||
let effects: Effects;
|
test.todo("EXPECT CommandBuilder to be defined");
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
effects = new Effects();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("EXPECT CommandBuilder to be defined", () => {
|
|
||||||
expect(effects.CommandBuilder).toMatchSnapshot();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("execute", () => {
|
describe("execute", () => {
|
||||||
describe("GIVEN interaction is not a chat input command", () => {
|
describe("GIVEN interaction is not a chat input command", () => {
|
||||||
let interaction: any;
|
test.todo("EXPECT nothing to happen");
|
||||||
|
|
||||||
let listSpy: any;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
interaction = {
|
|
||||||
isChatInputCommand: jest.fn().mockReturnValue(false),
|
|
||||||
};
|
|
||||||
|
|
||||||
const effects = new Effects();
|
|
||||||
|
|
||||||
listSpy = jest.spyOn(effects as any, "List");
|
|
||||||
|
|
||||||
await effects.execute(interaction);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("EXPECT isChatInputCommand to have been called", () => {
|
|
||||||
expect(interaction.isChatInputCommand).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("EXPECT nothing to happen", () => {
|
|
||||||
expect(listSpy).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("GIVEN subcommand is list", () => {
|
describe("GIVEN subcommand is list", () => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue