Add entry command tests
This commit is contained in:
parent
946422b2ac
commit
00f6a60a43
1 changed files with 103 additions and 5 deletions
|
@ -1,13 +1,111 @@
|
||||||
|
import { CommandInteraction, EmbedBuilder, PermissionsBitField, SlashCommandBuilder } from "discord.js";
|
||||||
|
import Entry from "../../../src/commands/501231711271780357/entry";
|
||||||
|
import SettingsHelper from "../../../src/helpers/SettingsHelper";
|
||||||
|
import EmbedColours from "../../../src/constants/EmbedColours";
|
||||||
|
|
||||||
describe('constructor', () => {
|
describe('constructor', () => {
|
||||||
test.todo("EXPECT properties to be set");
|
test("EXPECT properties to be set", () => {
|
||||||
|
const entry = new Entry();
|
||||||
|
|
||||||
|
expect(entry.CommandBuilder).toBeDefined();
|
||||||
|
|
||||||
|
const commandBuilder = entry.CommandBuilder as SlashCommandBuilder;
|
||||||
|
|
||||||
|
expect(commandBuilder.name).toBe("entry");
|
||||||
|
expect(commandBuilder.description).toBe("Sends the entry embed");
|
||||||
|
expect(commandBuilder.default_member_permissions).toBe(PermissionsBitField.Flags.ModerateMembers.toString());
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("execute", () => {
|
describe("execute", () => {
|
||||||
test.todo("EXPECT entry embed to be sent");
|
test("EXPECT entry embed to be sent", async () => {
|
||||||
|
let sentWith;
|
||||||
|
|
||||||
test.todo("GIVEN interaction.guildId is null, EXPECT error");
|
const interaction = {
|
||||||
|
guildId: "guildId",
|
||||||
|
channel: {
|
||||||
|
send: jest.fn().mockImplementation((options) => {
|
||||||
|
sentWith = options;
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
} as unknown as CommandInteraction;
|
||||||
|
|
||||||
test.todo("GIVEN interaction.channel is null, EXPECT error");
|
SettingsHelper.GetSetting = jest.fn().mockResolvedValue("channelId");
|
||||||
|
|
||||||
test.todo("GIVEN channels.rules setting is not set, EXPECT channel id to be defaulted");
|
const entry = new Entry();
|
||||||
|
await entry.execute(interaction);
|
||||||
|
|
||||||
|
expect(SettingsHelper.GetSetting).toHaveBeenCalledTimes(1);
|
||||||
|
expect(SettingsHelper.GetSetting).toHaveBeenCalledWith("channels.rules", "guildId");
|
||||||
|
|
||||||
|
expect(interaction.channel!.send).toHaveBeenCalledTimes(1);
|
||||||
|
expect(sentWith).toBeDefined();
|
||||||
|
expect(sentWith!.embeds).toBeDefined();
|
||||||
|
expect(sentWith!.embeds.length).toBe(1);
|
||||||
|
|
||||||
|
const embed = sentWith!.embeds[0] as EmbedBuilder;
|
||||||
|
|
||||||
|
expect(embed.data.color).toBe(EmbedColours.Ok);
|
||||||
|
expect(embed.data.title).toBe("Welcome");
|
||||||
|
expect(embed.data.description).toBe("Welcome to the server! Please make sure to read the rules in the <#channelId> channel and type the code found there in here to proceed to the main part of the server.");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("GIVEN interaction.guildId is null, EXPECT error", async () => {
|
||||||
|
const interaction = {
|
||||||
|
guildId: null,
|
||||||
|
} as unknown as CommandInteraction;
|
||||||
|
|
||||||
|
SettingsHelper.GetSetting = jest.fn();
|
||||||
|
|
||||||
|
const entry = new Entry();
|
||||||
|
await entry.execute(interaction);
|
||||||
|
|
||||||
|
expect(SettingsHelper.GetSetting).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("GIVEN interaction.channel is null, EXPECT error", async () => {
|
||||||
|
const interaction = {
|
||||||
|
guildId: "guildId",
|
||||||
|
channel: null,
|
||||||
|
} as unknown as CommandInteraction;
|
||||||
|
|
||||||
|
SettingsHelper.GetSetting = jest.fn();
|
||||||
|
|
||||||
|
const entry = new Entry();
|
||||||
|
await entry.execute(interaction);
|
||||||
|
|
||||||
|
expect(SettingsHelper.GetSetting).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("GIVEN channels.rules setting is not set, EXPECT channel id to be defaulted", async () => {
|
||||||
|
let sentWith;
|
||||||
|
|
||||||
|
const interaction = {
|
||||||
|
guildId: "guildId",
|
||||||
|
channel: {
|
||||||
|
send: jest.fn().mockImplementation((options) => {
|
||||||
|
sentWith = options;
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
} as unknown as CommandInteraction;
|
||||||
|
|
||||||
|
SettingsHelper.GetSetting = jest.fn().mockResolvedValue(undefined);
|
||||||
|
|
||||||
|
const entry = new Entry();
|
||||||
|
await entry.execute(interaction);
|
||||||
|
|
||||||
|
expect(SettingsHelper.GetSetting).toHaveBeenCalledTimes(1);
|
||||||
|
expect(SettingsHelper.GetSetting).toHaveBeenCalledWith("channels.rules", "guildId");
|
||||||
|
|
||||||
|
expect(interaction.channel!.send).toHaveBeenCalledTimes(1);
|
||||||
|
expect(sentWith).toBeDefined();
|
||||||
|
expect(sentWith!.embeds).toBeDefined();
|
||||||
|
expect(sentWith!.embeds.length).toBe(1);
|
||||||
|
|
||||||
|
const embed = sentWith!.embeds[0] as EmbedBuilder;
|
||||||
|
|
||||||
|
expect(embed.data.color).toBe(EmbedColours.Ok);
|
||||||
|
expect(embed.data.title).toBe("Welcome");
|
||||||
|
expect(embed.data.description).toBe("Welcome to the server! Please make sure to read the rules in the <#rules> channel and type the code found there in here to proceed to the main part of the server.");
|
||||||
|
});
|
||||||
});
|
});
|
Loading…
Reference in a new issue