2024-02-03 19:29:28 +00:00
|
|
|
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, CommandInteraction, EmbedBuilder, InteractionReplyOptions,SlashCommandBuilder } from "discord.js";
|
2022-04-24 14:46:37 +01:00
|
|
|
import About from "../../src/commands/about";
|
2024-02-03 19:29:28 +00:00
|
|
|
import EmbedColours from "../../src/constants/EmbedColours";
|
2022-04-24 14:46:37 +01:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
process.env = {};
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Constructor', () => {
|
|
|
|
test('Expect values set', () => {
|
2024-02-03 19:29:28 +00:00
|
|
|
const command = new About();
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2024-02-03 19:29:28 +00:00
|
|
|
expect(command.CommandBuilder).toBeDefined();
|
|
|
|
|
|
|
|
const commandBuilder = command.CommandBuilder as SlashCommandBuilder;
|
|
|
|
|
|
|
|
expect(commandBuilder.name).toBe("about");
|
|
|
|
expect(commandBuilder.description).toBe("About VylBot");
|
2022-04-24 14:46:37 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Execute', () => {
|
2024-02-03 19:29:28 +00:00
|
|
|
test('GIVEN ABOUT_FUNDING and ABOUT_REPO are NOT present in env var, EXPECT embed to be sent without buttons', async () => {
|
|
|
|
// Setup
|
|
|
|
let replyOptions: InteractionReplyOptions | undefined;
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2024-02-03 19:29:28 +00:00
|
|
|
const interaction = {
|
|
|
|
reply: jest.fn((options: InteractionReplyOptions) => {
|
|
|
|
replyOptions = options;
|
|
|
|
}),
|
|
|
|
} as unknown as CommandInteraction;
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2024-02-03 19:29:28 +00:00
|
|
|
// Execution
|
|
|
|
process.env.BOT_VER = "VERSION";
|
|
|
|
process.env.BOT_AUTHOR = "AUTHOR";
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2024-02-03 19:29:28 +00:00
|
|
|
const command = new About();
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2024-02-03 19:29:28 +00:00
|
|
|
await command.execute(interaction);
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2024-02-03 19:29:28 +00:00
|
|
|
// Assertion
|
|
|
|
expect(interaction.reply).toHaveBeenCalledTimes(1);
|
|
|
|
expect(replyOptions).toBeDefined();
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2024-02-03 19:29:28 +00:00
|
|
|
expect(replyOptions?.embeds).toBeDefined();
|
|
|
|
expect(replyOptions?.embeds?.length).toBe(1);
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2024-02-03 19:29:28 +00:00
|
|
|
expect(replyOptions?.components).toBeDefined();
|
|
|
|
expect(replyOptions?.components?.length).toBe(0);
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2024-02-03 19:29:28 +00:00
|
|
|
const repliedEmbed = replyOptions?.embeds![0] as EmbedBuilder;
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2024-02-03 19:29:28 +00:00
|
|
|
expect(repliedEmbed.data.color).toBe(EmbedColours.Ok);
|
|
|
|
expect(repliedEmbed.data.title).toBe("About");
|
|
|
|
expect(repliedEmbed.data.description).toBe("Discord Bot made by Vylpes");
|
|
|
|
expect(repliedEmbed.data.fields?.length).toBe(2);
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2024-02-03 19:29:28 +00:00
|
|
|
const repliedEmbedVersionField = repliedEmbed.data.fields![0];
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2024-02-03 19:29:28 +00:00
|
|
|
expect(repliedEmbedVersionField.name).toBe("Version");
|
|
|
|
expect(repliedEmbedVersionField.value).toBe("VERSION");
|
|
|
|
expect(repliedEmbedVersionField.inline).toBeTruthy();
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2024-02-03 19:29:28 +00:00
|
|
|
const repliedEmbedAuthorField = repliedEmbed.data.fields![1];
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2024-02-03 19:29:28 +00:00
|
|
|
expect(repliedEmbedAuthorField.name).toBe("Author");
|
|
|
|
expect(repliedEmbedAuthorField.value).toBe("AUTHOR");
|
|
|
|
expect(repliedEmbedAuthorField.inline).toBeTruthy();
|
2022-04-24 14:46:37 +01:00
|
|
|
});
|
|
|
|
|
2024-02-03 19:29:28 +00:00
|
|
|
test('GIVEN ABOUT_FUNDING is present in env var, EXPECT funding button to be sent', async () => {
|
|
|
|
// Setup
|
|
|
|
let replyOptions: InteractionReplyOptions | undefined;
|
|
|
|
|
|
|
|
const interaction = {
|
|
|
|
reply: jest.fn((options: InteractionReplyOptions) => {
|
|
|
|
replyOptions = options;
|
|
|
|
}),
|
|
|
|
} as unknown as CommandInteraction;
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2024-02-03 19:29:28 +00:00
|
|
|
// Execution
|
|
|
|
process.env.BOT_VER = "VERSION";
|
|
|
|
process.env.BOT_AUTHOR = "AUTHOR";
|
|
|
|
process.env.ABOUT_FUNDING = "https://ko-fi.com/vylpes";
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2024-02-03 19:29:28 +00:00
|
|
|
const command = new About();
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2024-02-03 19:29:28 +00:00
|
|
|
await command.execute(interaction);
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2024-02-03 19:29:28 +00:00
|
|
|
// Assertion
|
|
|
|
expect(replyOptions?.components?.length).toBe(1);
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2024-02-03 19:29:28 +00:00
|
|
|
const repliedRow = replyOptions?.components![0] as ActionRowBuilder<ButtonBuilder>;
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2024-02-03 19:29:28 +00:00
|
|
|
expect(repliedRow.components?.length).toBe(1);
|
|
|
|
|
|
|
|
const repliedRowFundingComponent = repliedRow.components![0] as any;
|
|
|
|
|
|
|
|
expect(repliedRowFundingComponent.data.url).toBe("https://ko-fi.com/vylpes");
|
|
|
|
expect(repliedRowFundingComponent.data.label).toBe("Funding");
|
|
|
|
expect(repliedRowFundingComponent.data.style).toBe(ButtonStyle.Link);
|
2022-04-24 14:46:37 +01:00
|
|
|
});
|
|
|
|
|
2024-02-03 19:29:28 +00:00
|
|
|
test('GIVEN ABOUT_REPO is present in env var, EXPECT funding button to be sent', async () => {
|
|
|
|
// Setup
|
|
|
|
let replyOptions: InteractionReplyOptions | undefined;
|
|
|
|
|
|
|
|
const interaction = {
|
|
|
|
reply: jest.fn((options: InteractionReplyOptions) => {
|
|
|
|
replyOptions = options;
|
|
|
|
}),
|
|
|
|
} as unknown as CommandInteraction;
|
|
|
|
|
|
|
|
// Execution
|
|
|
|
process.env.BOT_VER = "VERSION";
|
|
|
|
process.env.BOT_AUTHOR = "AUTHOR";
|
|
|
|
process.env.ABOUT_REPO = "https://gitea.vylpes.xyz/rabbitlabs/vylbot-app";
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2024-02-03 19:29:28 +00:00
|
|
|
const command = new About();
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2024-02-03 19:29:28 +00:00
|
|
|
await command.execute(interaction);
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2024-02-03 19:29:28 +00:00
|
|
|
// Assertion
|
|
|
|
expect(replyOptions?.components?.length).toBe(1);
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2024-02-03 19:29:28 +00:00
|
|
|
const repliedRow = replyOptions?.components![0] as ActionRowBuilder<ButtonBuilder>;
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2024-02-03 19:29:28 +00:00
|
|
|
expect(repliedRow.components?.length).toBe(1);
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2024-02-03 19:29:28 +00:00
|
|
|
const repliedRowRepoComponent = repliedRow.components![0] as any;
|
|
|
|
|
|
|
|
expect(repliedRowRepoComponent.data.url).toBe("https://gitea.vylpes.xyz/rabbitlabs/vylbot-app");
|
|
|
|
expect(repliedRowRepoComponent.data.label).toBe("Repo");
|
|
|
|
expect(repliedRowRepoComponent.data.style).toBe(ButtonStyle.Link);
|
2022-04-24 14:46:37 +01:00
|
|
|
});
|
|
|
|
|
2024-02-03 19:29:28 +00:00
|
|
|
test('GIVEN ABOUT_REPO AND ABOUT_FUNDING is present in env var, EXPECT funding button to be sent', async () => {
|
|
|
|
// Setup
|
|
|
|
let replyOptions: InteractionReplyOptions | undefined;
|
|
|
|
|
|
|
|
const interaction = {
|
|
|
|
reply: jest.fn((options: InteractionReplyOptions) => {
|
|
|
|
replyOptions = options;
|
|
|
|
}),
|
|
|
|
} as unknown as CommandInteraction;
|
|
|
|
|
|
|
|
// Execution
|
|
|
|
process.env.BOT_VER = "VERSION";
|
|
|
|
process.env.BOT_AUTHOR = "AUTHOR";
|
|
|
|
process.env.ABOUT_REPO = "https://gitea.vylpes.xyz/rabbitlabs/vylbot-app";
|
|
|
|
process.env.ABOUT_FUNDING = "https://ko-fi.com/vylpes";
|
|
|
|
|
|
|
|
const command = new About();
|
|
|
|
|
|
|
|
await command.execute(interaction);
|
|
|
|
|
|
|
|
// Assertion
|
|
|
|
expect(replyOptions?.components?.length).toBe(1);
|
|
|
|
|
|
|
|
const repliedRow = replyOptions?.components![0] as ActionRowBuilder<ButtonBuilder>;
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2024-02-03 19:29:28 +00:00
|
|
|
expect(repliedRow.components?.length).toBe(2);
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2024-02-03 19:29:28 +00:00
|
|
|
const repliedRowRepoComponent = repliedRow.components![0] as any;
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2024-02-03 19:29:28 +00:00
|
|
|
expect(repliedRowRepoComponent.data.url).toBe("https://gitea.vylpes.xyz/rabbitlabs/vylbot-app");
|
|
|
|
expect(repliedRowRepoComponent.data.label).toBe("Repo");
|
|
|
|
expect(repliedRowRepoComponent.data.style).toBe(ButtonStyle.Link);
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2024-02-03 19:29:28 +00:00
|
|
|
const repliedRowFundingComponent = repliedRow.components![1] as any;
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2024-02-03 19:29:28 +00:00
|
|
|
expect(repliedRowFundingComponent.data.url).toBe("https://ko-fi.com/vylpes");
|
|
|
|
expect(repliedRowFundingComponent.data.label).toBe("Funding");
|
|
|
|
expect(repliedRowFundingComponent.data.style).toBe(ButtonStyle.Link);
|
2022-04-24 14:46:37 +01:00
|
|
|
});
|
|
|
|
});
|