Add effects command tests
This commit is contained in:
parent
32cc731442
commit
5302d57a89
1 changed files with 106 additions and 6 deletions
|
@ -1,4 +1,5 @@
|
||||||
import Effects from "../../src/commands/effects";
|
import Effects from "../../src/commands/effects";
|
||||||
|
import EffectHelper from "../../src/helpers/EffectHelper";
|
||||||
|
|
||||||
describe("constructor", () => {
|
describe("constructor", () => {
|
||||||
let effects: Effects;
|
let effects: Effects;
|
||||||
|
@ -25,7 +26,8 @@ describe("execute", () => {
|
||||||
|
|
||||||
const effects = new Effects();
|
const effects = new Effects();
|
||||||
|
|
||||||
listSpy = jest.spyOn(effects as any, "List");
|
listSpy = jest.spyOn(effects as any, "List")
|
||||||
|
.mockImplementation();
|
||||||
|
|
||||||
await effects.execute(interaction);
|
await effects.execute(interaction);
|
||||||
});
|
});
|
||||||
|
@ -40,24 +42,122 @@ describe("execute", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("GIVEN subcommand is list", () => {
|
describe("GIVEN subcommand is list", () => {
|
||||||
test.todo("EXPECT list function to be called");
|
let interaction: any;
|
||||||
|
|
||||||
|
let listSpy: any;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
interaction = {
|
||||||
|
isChatInputCommand: jest.fn().mockReturnValue(true),
|
||||||
|
options: {
|
||||||
|
getSubcommand: jest.fn().mockReturnValue("list"),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const effects = new Effects();
|
||||||
|
|
||||||
|
listSpy = jest.spyOn(effects as any, "List")
|
||||||
|
.mockImplementation();
|
||||||
|
|
||||||
|
await effects.execute(interaction);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("EXPECT subcommand function to be called", () => {
|
||||||
|
expect(interaction.options.getSubcommand).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("EXPECT list function to be called", () => {
|
||||||
|
expect(listSpy).toHaveBeenCalledTimes(1);
|
||||||
|
expect(listSpy).toHaveBeenCalledWith(interaction);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("List", () => {
|
describe("List", () => {
|
||||||
|
let effects: Effects = new Effects();
|
||||||
|
let interaction: any;
|
||||||
|
|
||||||
|
const embed = {
|
||||||
|
name: "embed",
|
||||||
|
};
|
||||||
|
|
||||||
|
const row = {
|
||||||
|
name: "row",
|
||||||
|
};
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
interaction = {
|
||||||
|
isChatInputCommand: jest.fn().mockReturnValue(true),
|
||||||
|
options: {
|
||||||
|
getSubcommand: jest.fn().mockReturnValue("list"),
|
||||||
|
},
|
||||||
|
reply: jest.fn(),
|
||||||
|
user: {
|
||||||
|
id: "userId",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const effects = new Effects();
|
||||||
|
|
||||||
|
EffectHelper.GenerateEffectEmbed = jest.fn().mockReturnValue({
|
||||||
|
embed,
|
||||||
|
row,
|
||||||
|
});
|
||||||
|
|
||||||
|
jest.spyOn(effects as any, "List")
|
||||||
|
.mockImplementation();
|
||||||
|
});
|
||||||
|
|
||||||
describe("GIVEN page option is supplied", () => {
|
describe("GIVEN page option is supplied", () => {
|
||||||
describe("AND page is a valid number", () => {
|
describe("AND page is a valid number", () => {
|
||||||
test.todo("EXPECT EffectHelper.GenerateEffectEmbed to have been called with page");
|
beforeEach(async () => {
|
||||||
|
interaction.options.get = jest.fn().mockReturnValueOnce({
|
||||||
|
value: "2",
|
||||||
|
});
|
||||||
|
|
||||||
test.todo("EXPECT interaction to have been replied");
|
await effects.execute(interaction);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("EXPECT EffectHelper.GenerateEffectEmbed to have been called with page", () => {
|
||||||
|
expect(EffectHelper.GenerateEffectEmbed).toHaveBeenCalledTimes(1);
|
||||||
|
expect(EffectHelper.GenerateEffectEmbed).toHaveBeenCalledWith("userId", 2);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("EXPECT interaction to have been replied", () => {
|
||||||
|
expect(interaction.reply).toHaveBeenCalledTimes(1);
|
||||||
|
expect(interaction.reply).toHaveBeenCalledWith({
|
||||||
|
embeds: [ embed ],
|
||||||
|
components: [ row ],
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("AND page is not a valid number", () => {
|
describe("AND page is not a valid number", () => {
|
||||||
test.todo("EXPECT EffectHelper.GenerateEffectEmbed to have been called with page of 1");
|
beforeEach(async () => {
|
||||||
|
interaction.options.get = jest.fn().mockReturnValueOnce({
|
||||||
|
value: "test",
|
||||||
|
});
|
||||||
|
|
||||||
|
await effects.execute(interaction);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("EXPECT EffectHelper.GenerateEffectEmbed to have been called with page of 1", () => {
|
||||||
|
expect(EffectHelper.GenerateEffectEmbed).toHaveBeenCalledTimes(1);
|
||||||
|
expect(EffectHelper.GenerateEffectEmbed).toHaveBeenCalledWith("userId", 1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("GIVEN page option is not supplied", () => {
|
describe("GIVEN page option is not supplied", () => {
|
||||||
test.todo("EXPECT EffectHelper.GenerateEffectEmbed to have been called with a page of 1");
|
beforeEach(async () => {
|
||||||
|
interaction.options.get = jest.fn().mockReturnValueOnce(undefined);
|
||||||
|
|
||||||
|
await effects.execute(interaction);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("EXPECT EffectHelper.GenerateEffectEmbed to have been called with page of 1", () => {
|
||||||
|
expect(EffectHelper.GenerateEffectEmbed).toHaveBeenCalledTimes(1);
|
||||||
|
expect(EffectHelper.GenerateEffectEmbed).toHaveBeenCalledWith("userId", 1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue