Compare commits
No commits in common. "952e7901ba6c3dc8bbc69f13498237fcca7d3714" and "43751e5b021a3eff3bb8fcd501572191c9114ab0" have entirely different histories.
952e7901ba
...
43751e5b02
9 changed files with 19 additions and 299 deletions
|
@ -8,7 +8,7 @@
|
||||||
"clean": "rm -rf node_modules/ dist/",
|
"clean": "rm -rf node_modules/ dist/",
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"start": "node ./dist/vylbot",
|
"start": "node ./dist/vylbot",
|
||||||
"test": "jest",
|
"test": "jest .",
|
||||||
"db:up": "typeorm migration:run -d dist/database/dataSources/appDataSource.js",
|
"db:up": "typeorm migration:run -d dist/database/dataSources/appDataSource.js",
|
||||||
"db:down": "typeorm migration:revert -d dist/database/dataSources/appDataSource.js",
|
"db:down": "typeorm migration:revert -d dist/database/dataSources/appDataSource.js",
|
||||||
"db:create": "typeorm migration:create ./src/database/migrations",
|
"db:create": "typeorm migration:create ./src/database/migrations",
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import {ButtonInteraction} from "discord.js";
|
import {ButtonInteraction} from "discord.js";
|
||||||
import {ButtonEvent} from "../../type/buttonEvent";
|
import {ButtonEvent} from "../type/buttonEvent";
|
||||||
import List from "./moons/list";
|
import List from "./moons/list";
|
||||||
|
|
||||||
export default class Moons extends ButtonEvent {
|
export default class Moons extends ButtonEvent {
|
|
@ -1,7 +1,7 @@
|
||||||
import {ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, EmbedBuilder} from "discord.js";
|
import {ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, EmbedBuilder} from "discord.js";
|
||||||
import Moon from "../../../database/entities/304276391837302787/Moon";
|
import Moon from "../../database/entities/304276391837302787/Moon";
|
||||||
import EmbedColours from "../../../constants/EmbedColours";
|
import EmbedColours from "../../constants/EmbedColours";
|
||||||
import UserSetting from "../../../database/entities/UserSetting";
|
import UserSetting from "../../database/entities/UserSetting";
|
||||||
|
|
||||||
export default async function List(interaction: ButtonInteraction) {
|
export default async function List(interaction: ButtonInteraction) {
|
||||||
if (!interaction.guild) return;
|
if (!interaction.guild) return;
|
|
@ -42,7 +42,7 @@ import MessageCreate from "./events/MessageEvents/MessageCreate";
|
||||||
|
|
||||||
// Button Event Imports
|
// Button Event Imports
|
||||||
import Verify from "./buttonEvents/verify";
|
import Verify from "./buttonEvents/verify";
|
||||||
import MoonsButtonEvent from "./buttonEvents/304276391837302787/moons";
|
import MoonsButtonEvent from "./buttonEvents/moons";
|
||||||
|
|
||||||
export default class Registry {
|
export default class Registry {
|
||||||
public static RegisterCommands() {
|
public static RegisterCommands() {
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
describe("GIVEN interaction action is list", () => {
|
|
||||||
test.todo("EXPECT List function to be called");
|
|
||||||
});
|
|
|
@ -1,17 +0,0 @@
|
||||||
describe("constructor", () => {
|
|
||||||
test.todo("EXPECT CommandBuilder to be defined correctly");
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("execute", () => {
|
|
||||||
describe("GIVEN interaction is not a chat input command", () => {
|
|
||||||
test.todo("EXPECT nothing to happen");
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("GIVEN interaction subcommand is list", () => {
|
|
||||||
test.todo("EXPECT ListMoons to be called");
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("GIVEN interaction subcommand is add", () => {
|
|
||||||
test.todo("EXPECT AddMoon to be called");
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -1,40 +0,0 @@
|
||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
||||||
|
|
||||||
exports[`GIVEN happy flow EXPECT interaction to be replied 1`] = `
|
|
||||||
{
|
|
||||||
"components": [
|
|
||||||
{
|
|
||||||
"components": [
|
|
||||||
{
|
|
||||||
"custom_id": "moons list userId -1",
|
|
||||||
"disabled": true,
|
|
||||||
"emoji": undefined,
|
|
||||||
"label": "Previous",
|
|
||||||
"style": 1,
|
|
||||||
"type": 2,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"custom_id": "moons list userId 01",
|
|
||||||
"disabled": true,
|
|
||||||
"emoji": undefined,
|
|
||||||
"label": "Next",
|
|
||||||
"style": 1,
|
|
||||||
"type": 2,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
"type": 1,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
"embeds": [
|
|
||||||
{
|
|
||||||
"color": 3166394,
|
|
||||||
"description": "**1 -** Test Descriptio",
|
|
||||||
"footer": {
|
|
||||||
"icon_url": undefined,
|
|
||||||
"text": "Page 01 of 1 · 0 moons",
|
|
||||||
},
|
|
||||||
"title": "undefined's Moons",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
`;
|
|
|
@ -1,249 +1,29 @@
|
||||||
import { ActionRowBuilder, APIEmbed, ButtonBuilder, CommandInteraction, EmbedBuilder, InteractionReplyOptions } from "discord.js";
|
|
||||||
import List from "../../../../src/commands/304276391837302787/moons/list";
|
|
||||||
import Moon from "../../../../src/database/entities/304276391837302787/Moon";
|
|
||||||
import UserSetting from "../../../../src/database/entities/UserSetting";
|
|
||||||
|
|
||||||
describe("GIVEN happy flow", () => {
|
|
||||||
let repliedWith: InteractionReplyOptions | undefined;
|
|
||||||
|
|
||||||
const interaction = {
|
|
||||||
reply: jest.fn((options) => {
|
|
||||||
repliedWith = options;
|
|
||||||
}),
|
|
||||||
options: {
|
|
||||||
get: jest.fn()
|
|
||||||
.mockReturnValueOnce(undefined) // User
|
|
||||||
.mockReturnValue({
|
|
||||||
value: "0",
|
|
||||||
}), // Page
|
|
||||||
},
|
|
||||||
user: {
|
|
||||||
id: "userId",
|
|
||||||
}
|
|
||||||
} as unknown as CommandInteraction;
|
|
||||||
|
|
||||||
beforeAll(async () => {
|
|
||||||
Moon.FetchPaginatedMoonsByUserId = jest.fn().mockResolvedValue([
|
|
||||||
[
|
|
||||||
{
|
|
||||||
MoonNumber: 1,
|
|
||||||
Description: "Test Description",
|
|
||||||
}
|
|
||||||
],
|
|
||||||
1,
|
|
||||||
]);
|
|
||||||
|
|
||||||
UserSetting.FetchOneByKey = jest.fn().mockResolvedValue({
|
|
||||||
Value: "0",
|
|
||||||
});
|
|
||||||
|
|
||||||
await List(interaction);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("EXPECT interaction to be replied", () => {
|
|
||||||
expect(interaction.reply).toHaveBeenCalledTimes(1);
|
|
||||||
expect(repliedWith).toMatchSnapshot();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("GIVEN moons returned is empty", () => {
|
describe("GIVEN moons returned is empty", () => {
|
||||||
let repliedWith: InteractionReplyOptions | undefined;
|
test.todo("EXPECT none description");
|
||||||
|
|
||||||
const interaction = {
|
|
||||||
reply: jest.fn((options) => {
|
|
||||||
repliedWith = options;
|
|
||||||
}),
|
|
||||||
options: {
|
|
||||||
get: jest.fn()
|
|
||||||
.mockReturnValueOnce(undefined) // User
|
|
||||||
.mockReturnValue({
|
|
||||||
value: "0",
|
|
||||||
}), // Page
|
|
||||||
},
|
|
||||||
user: {
|
|
||||||
id: "userId",
|
|
||||||
}
|
|
||||||
} as unknown as CommandInteraction;
|
|
||||||
|
|
||||||
beforeAll(async () => {
|
|
||||||
Moon.FetchPaginatedMoonsByUserId = jest.fn().mockResolvedValue([
|
|
||||||
[],
|
|
||||||
0,
|
|
||||||
]);
|
|
||||||
|
|
||||||
UserSetting.FetchOneByKey = jest.fn().mockResolvedValue({
|
|
||||||
Value: "0",
|
|
||||||
});
|
|
||||||
|
|
||||||
await List(interaction);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("EXPECT none description", () => {
|
|
||||||
expect(repliedWith).toBeDefined();
|
|
||||||
|
|
||||||
expect(repliedWith!.embeds).toBeDefined();
|
|
||||||
expect(repliedWith!.embeds!.length).toBe(1);
|
|
||||||
|
|
||||||
const repliedWithEmbed = repliedWith!.embeds![0] as EmbedBuilder;
|
|
||||||
|
|
||||||
expect(repliedWithEmbed.data.description).toBe("*none*");
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("GIVEN it is the first page", () => {
|
describe("GIVEN it is the first page", () => {
|
||||||
let repliedWith: InteractionReplyOptions | undefined;
|
test.todo("EXPECT Previous button to be disabled");
|
||||||
|
|
||||||
const interaction = {
|
|
||||||
reply: jest.fn((options) => {
|
|
||||||
repliedWith = options;
|
|
||||||
}),
|
|
||||||
options: {
|
|
||||||
get: jest.fn()
|
|
||||||
.mockReturnValueOnce(undefined) // User
|
|
||||||
.mockReturnValue({
|
|
||||||
value: "0",
|
|
||||||
}), // Page
|
|
||||||
},
|
|
||||||
user: {
|
|
||||||
id: "userId",
|
|
||||||
}
|
|
||||||
} as unknown as CommandInteraction;
|
|
||||||
|
|
||||||
beforeAll(async () => {
|
|
||||||
Moon.FetchPaginatedMoonsByUserId = jest.fn().mockResolvedValue([
|
|
||||||
[
|
|
||||||
{
|
|
||||||
MoonNumber: 1,
|
|
||||||
Description: "Test Description",
|
|
||||||
}
|
|
||||||
],
|
|
||||||
1,
|
|
||||||
]);
|
|
||||||
|
|
||||||
UserSetting.FetchOneByKey = jest.fn().mockResolvedValue({
|
|
||||||
Value: "0",
|
|
||||||
});
|
|
||||||
|
|
||||||
await List(interaction);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("EXPECT Previous button to be disabled", () => {
|
|
||||||
expect(repliedWith).toBeDefined();
|
|
||||||
|
|
||||||
expect(repliedWith!.components).toBeDefined();
|
|
||||||
expect(repliedWith!.components!.length).toBe(1);
|
|
||||||
|
|
||||||
const repliedWithRow = repliedWith!.components![0] as ActionRowBuilder<ButtonBuilder>;
|
|
||||||
|
|
||||||
expect(repliedWithRow.components[0].data.disabled).toBe(true);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("GIVEN it is the last page", () => {
|
describe("GIVEN it is the last page", () => {
|
||||||
let repliedWith: InteractionReplyOptions | undefined;
|
test.todo("EXPECT Next button to be disabled");
|
||||||
|
|
||||||
const interaction = {
|
|
||||||
reply: jest.fn((options) => {
|
|
||||||
repliedWith = options;
|
|
||||||
}),
|
|
||||||
options: {
|
|
||||||
get: jest.fn()
|
|
||||||
.mockReturnValueOnce(undefined) // User
|
|
||||||
.mockReturnValue({
|
|
||||||
value: "0",
|
|
||||||
}), // Page
|
|
||||||
},
|
|
||||||
user: {
|
|
||||||
id: "userId",
|
|
||||||
}
|
|
||||||
} as unknown as CommandInteraction;
|
|
||||||
|
|
||||||
beforeAll(async () => {
|
|
||||||
Moon.FetchPaginatedMoonsByUserId = jest.fn().mockResolvedValue([
|
|
||||||
[
|
|
||||||
{
|
|
||||||
MoonNumber: 1,
|
|
||||||
Description: "Test Description",
|
|
||||||
}
|
|
||||||
],
|
|
||||||
1,
|
|
||||||
]);
|
|
||||||
|
|
||||||
UserSetting.FetchOneByKey = jest.fn().mockResolvedValue({
|
|
||||||
Value: "0",
|
|
||||||
});
|
|
||||||
|
|
||||||
await List(interaction);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("EXPECT Next button to be disabled", () => {
|
|
||||||
expect(repliedWith).toBeDefined();
|
|
||||||
|
|
||||||
expect(repliedWith!.components).toBeDefined();
|
|
||||||
expect(repliedWith!.components!.length).toBe(1);
|
|
||||||
|
|
||||||
const repliedWithRow = repliedWith!.components![0] as ActionRowBuilder<ButtonBuilder>;
|
|
||||||
|
|
||||||
expect(repliedWithRow.components[1].data.disabled).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("GIVEN moon count is greater than the amount of moons in the database", () => {
|
describe("GIVEN moon count is greater than the amount of moons in the database", () => {
|
||||||
beforeAll(async () => {
|
test.todo("EXPECT untracked counter to be shown");
|
||||||
UserSetting.FetchOneByKey = jest.fn().mockResolvedValue({
|
|
||||||
Value: "2",
|
|
||||||
});
|
|
||||||
|
|
||||||
await List(interaction);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("EXPECT untracked counter to be shown", () => {
|
|
||||||
const repliedWithEmbed = repliedWith!.embeds![0] as EmbedBuilder;
|
|
||||||
|
|
||||||
expect(repliedWithEmbed.data.description).toContain("...plus 1 more untracked");
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("GIVEN moon count is empty", () => {
|
describe("GIVEN moon count is empty", () => {
|
||||||
let repliedWith: InteractionReplyOptions | undefined;
|
test.todo("EXPECT Next button to be disabled");
|
||||||
|
|
||||||
const interaction = {
|
describe("GIVEN moon count is greater than the amount of moons in the database", () => {
|
||||||
reply: jest.fn((options) => {
|
test.todo("EXPECT untracked counter to be shown");
|
||||||
repliedWith = options;
|
|
||||||
}),
|
|
||||||
options: {
|
|
||||||
get: jest.fn()
|
|
||||||
.mockReturnValueOnce(undefined) // User
|
|
||||||
.mockReturnValue({
|
|
||||||
value: "0",
|
|
||||||
}), // Page
|
|
||||||
},
|
|
||||||
user: {
|
|
||||||
id: "userId",
|
|
||||||
}
|
|
||||||
} as unknown as CommandInteraction;
|
|
||||||
|
|
||||||
beforeAll(async () => {
|
|
||||||
Moon.FetchPaginatedMoonsByUserId = jest.fn().mockResolvedValue([
|
|
||||||
[],
|
|
||||||
0,
|
|
||||||
]);
|
|
||||||
|
|
||||||
UserSetting.FetchOneByKey = jest.fn().mockResolvedValue({
|
|
||||||
Value: "0",
|
|
||||||
});
|
|
||||||
|
|
||||||
await List(interaction);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("EXPECT Next button to be disabled", () => {
|
|
||||||
expect(repliedWith).toBeDefined();
|
|
||||||
|
|
||||||
expect(repliedWith!.components).toBeDefined();
|
|
||||||
expect(repliedWith!.components!.length).toBe(1);
|
|
||||||
|
|
||||||
const repliedWithRow = repliedWith!.components![0] as ActionRowBuilder<ButtonBuilder>;
|
|
||||||
|
|
||||||
expect(repliedWithRow.components[1].data.disabled).toBe(true);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test.todo("EXPECT interaction to be replied");
|
||||||
|
|
||||||
|
test.todo("EXPECT embed to be replied");
|
||||||
|
|
||||||
|
test.todo("EXPECT row to be replied");
|
||||||
|
|
Loading…
Reference in a new issue