Compare commits
No commits in common. "0584d0304b9320332703470db2dcad2bc9f10fe3" and "32cc731442a4084fef4e6730a6a693b4168d5387" have entirely different histories.
0584d0304b
...
32cc731442
3 changed files with 13 additions and 246 deletions
|
@ -1,5 +1,4 @@
|
||||||
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;
|
||||||
|
@ -26,8 +25,7 @@ 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);
|
||||||
});
|
});
|
||||||
|
@ -42,122 +40,24 @@ describe("execute", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("GIVEN subcommand is list", () => {
|
describe("GIVEN subcommand is list", () => {
|
||||||
let interaction: any;
|
test.todo("EXPECT list function to be called");
|
||||||
|
|
||||||
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", () => {
|
||||||
beforeEach(async () => {
|
test.todo("EXPECT EffectHelper.GenerateEffectEmbed to have been called with page");
|
||||||
interaction.options.get = jest.fn().mockReturnValueOnce({
|
|
||||||
value: "2",
|
|
||||||
});
|
|
||||||
|
|
||||||
await effects.execute(interaction);
|
test.todo("EXPECT interaction to have been replied");
|
||||||
});
|
|
||||||
|
|
||||||
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", () => {
|
||||||
beforeEach(async () => {
|
test.todo("EXPECT EffectHelper.GenerateEffectEmbed to have been called with page of 1");
|
||||||
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", () => {
|
||||||
beforeEach(async () => {
|
test.todo("EXPECT EffectHelper.GenerateEffectEmbed to have been called with a page of 1");
|
||||||
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);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -281,87 +281,25 @@ describe("HasEffect", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("GenerateEffectEmbed", () => {
|
describe("GenerateEffectEmbed", () => {
|
||||||
beforeEach(async () => {
|
test.todo("EXPECT UserEffect.FetchAllByUserIdPaginated to be called");
|
||||||
UserEffect.FetchAllByUserIdPaginated = jest.fn()
|
|
||||||
.mockResolvedValue([
|
|
||||||
[],
|
|
||||||
0,
|
|
||||||
]);
|
|
||||||
|
|
||||||
await EffectHelper.GenerateEffectEmbed("userId", 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("EXPECT UserEffect.FetchAllByUserIdPaginated to be called", () => {
|
|
||||||
expect(UserEffect.FetchAllByUserIdPaginated).toHaveBeenCalledTimes(1);
|
|
||||||
expect(UserEffect.FetchAllByUserIdPaginated).toHaveBeenCalledWith("userId", 0, 10);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("GIVEN there are no effects returned", () => {
|
describe("GIVEN there are no effects returned", () => {
|
||||||
let result: any;
|
test.todo("EXPECT embed generated");
|
||||||
|
|
||||||
beforeEach(async () => {
|
test.todo("EXPECT row generated");
|
||||||
UserEffect.FetchAllByUserIdPaginated = jest.fn()
|
|
||||||
.mockResolvedValue([
|
|
||||||
[],
|
|
||||||
0,
|
|
||||||
]);
|
|
||||||
|
|
||||||
result = await EffectHelper.GenerateEffectEmbed("userId", 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("EXPECT result returned", () => {
|
|
||||||
expect(result).toMatchSnapshot();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("GIVEN there are effects returned", () => {
|
describe("GIVEN there are effects returned", () => {
|
||||||
let result: any;
|
test.todo("EXPECT embed generated");
|
||||||
|
|
||||||
beforeEach(async () => {
|
test.todo("EXPECT row generated");
|
||||||
UserEffect.FetchAllByUserIdPaginated = jest.fn()
|
|
||||||
.mockResolvedValue([
|
|
||||||
[
|
|
||||||
{
|
|
||||||
Name: "name",
|
|
||||||
Unused: 1,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
1,
|
|
||||||
]);
|
|
||||||
|
|
||||||
result = await EffectHelper.GenerateEffectEmbed("userId", 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("EXPECT result returned", () => {
|
|
||||||
expect(result).toMatchSnapshot();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("AND it is the first page", () => {
|
describe("AND it is the first page", () => {
|
||||||
beforeEach(async () => {
|
test.todo("EXPECT Previous button to be disabled");
|
||||||
result = await EffectHelper.GenerateEffectEmbed("userId", 1)
|
|
||||||
});
|
|
||||||
|
|
||||||
test("EXPECT Previous button to be disabled", () => {
|
|
||||||
const button = result.row.components[0].data;
|
|
||||||
|
|
||||||
expect(button).toBeDefined();
|
|
||||||
expect(button.label).toBe("Previous");
|
|
||||||
expect(button.disabled).toBe(true);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("AND it is the last page", () => {
|
describe("AND it is the last page", () => {
|
||||||
beforeEach(async () => {
|
test.todo("EXPECT Next button to be disabled");
|
||||||
result = await EffectHelper.GenerateEffectEmbed("userId", 1)
|
|
||||||
});
|
|
||||||
|
|
||||||
test("EXPECT Next button to be disabled", () => {
|
|
||||||
const button = result.row.components[1].data;
|
|
||||||
|
|
||||||
expect(button).toBeDefined();
|
|
||||||
expect(button.label).toBe("Next");
|
|
||||||
expect(button.disabled).toBe(true);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,71 +0,0 @@
|
||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
||||||
|
|
||||||
exports[`GenerateEffectEmbed GIVEN there are effects returned EXPECT result returned 1`] = `
|
|
||||||
{
|
|
||||||
"embed": {
|
|
||||||
"color": 3166394,
|
|
||||||
"description": "name x1",
|
|
||||||
"footer": {
|
|
||||||
"icon_url": undefined,
|
|
||||||
"text": "Page 1 of 1",
|
|
||||||
},
|
|
||||||
"title": "Effects",
|
|
||||||
},
|
|
||||||
"row": {
|
|
||||||
"components": [
|
|
||||||
{
|
|
||||||
"custom_id": "effects list 0",
|
|
||||||
"disabled": true,
|
|
||||||
"emoji": undefined,
|
|
||||||
"label": "Previous",
|
|
||||||
"style": 1,
|
|
||||||
"type": 2,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"custom_id": "effects list 2",
|
|
||||||
"disabled": true,
|
|
||||||
"emoji": undefined,
|
|
||||||
"label": "Next",
|
|
||||||
"style": 1,
|
|
||||||
"type": 2,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
"type": 1,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`GenerateEffectEmbed GIVEN there are no effects returned EXPECT result returned 1`] = `
|
|
||||||
{
|
|
||||||
"embed": {
|
|
||||||
"color": 3166394,
|
|
||||||
"description": "*none*",
|
|
||||||
"footer": {
|
|
||||||
"icon_url": undefined,
|
|
||||||
"text": "Page 1 of 1",
|
|
||||||
},
|
|
||||||
"title": "Effects",
|
|
||||||
},
|
|
||||||
"row": {
|
|
||||||
"components": [
|
|
||||||
{
|
|
||||||
"custom_id": "effects list 0",
|
|
||||||
"disabled": true,
|
|
||||||
"emoji": undefined,
|
|
||||||
"label": "Previous",
|
|
||||||
"style": 1,
|
|
||||||
"type": 2,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"custom_id": "effects list 2",
|
|
||||||
"disabled": true,
|
|
||||||
"emoji": undefined,
|
|
||||||
"label": "Next",
|
|
||||||
"style": 1,
|
|
||||||
"type": 2,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
"type": 1,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
`;
|
|
Loading…
Add table
Add a link
Reference in a new issue