vylbot-app/tests/client/util.test.ts

333 lines
11 KiB
TypeScript
Raw Normal View History

2024-03-25 17:59:34 +00:00
import discordjs, { Client, REST, Routes, SlashCommandBuilder } from "discord.js";
2024-03-25 17:31:45 +00:00
import { Util } from "../../src/client/util";
import { CoreClient } from "../../src/client/client";
import { Command } from "../../src/type/command";
2024-03-25 17:59:34 +00:00
import IEventItem from "../../src/contracts/IEventItem";
import { EventType } from "../../src/constants/EventType";
2024-03-25 17:31:45 +00:00
beforeEach(() => {
jest.resetAllMocks();
jest.resetModules();
process.env = {};
});
2024-02-03 19:29:28 +00:00
describe("loadSlashCommands", () => {
2024-03-25 17:31:45 +00:00
test("EXPECT slash commands to be loaded to the discord API", () => {
process.env.BOT_TOKEN = "token";
process.env.BOT_CLIENTID = "clientid";
const client = {
guilds: {
cache: {
has: jest.fn().mockReturnValue(true),
}
}
} as unknown as Client;
2024-03-25 17:59:34 +00:00
const setTokenPutMock = jest.fn();
const setTokenMock = jest.fn().mockReturnValue({
put: setTokenPutMock,
});
REST.prototype.setToken = setTokenMock;
Routes.applicationCommands = jest.fn().mockReturnValue("command url");
Routes.applicationGuildCommands = jest.fn().mockReturnValue("guild command url");
2024-03-25 17:31:45 +00:00
CoreClient.commandItems = [
{
Name: "global",
Command: {
CommandBuilder: {
name: "global"
} as SlashCommandBuilder,
} as Command,
},
{
Name: "server-specific",
Command: {
CommandBuilder: {
name: "server",
} as SlashCommandBuilder,
} as Command,
ServerId: "123",
}
];
const util = new Util();
util.loadSlashCommands(client);
2024-03-25 17:59:34 +00:00
expect(setTokenMock).toHaveBeenCalledWith("token");
2024-03-25 17:31:45 +00:00
2024-03-25 17:59:34 +00:00
expect(setTokenPutMock).toHaveBeenCalledTimes(2);
expect(setTokenPutMock).toHaveBeenCalledWith("command url", { body: [ CoreClient.commandItems[0].Command.CommandBuilder ] });
expect(setTokenPutMock).toHaveBeenCalledWith("guild command url", { body: [ CoreClient.commandItems[1].Command.CommandBuilder ]});
2024-03-25 17:31:45 +00:00
expect(client.guilds.cache.has).toHaveBeenCalledTimes(1);
expect(client.guilds.cache.has).toHaveBeenCalledWith("123");
expect(Routes.applicationCommands).toHaveBeenCalledTimes(1);
expect(Routes.applicationCommands).toHaveBeenCalledWith("clientid");
expect(Routes.applicationGuildCommands).toHaveBeenCalledTimes(1);
expect(Routes.applicationGuildCommands).toHaveBeenCalledWith("clientid", "123");
});
v3.0 (#145) * Change rules.txt to rules.json (#31) * Migrate to yarn * Add role configs to config template * Install packges and setup typescript * Migrate entry point * Migrate about command * Migrate ban command * Migrate clear command * Migrate kick command * Migrate mute command * Migrate poll command * Migrate bunny command * Update required roles checker * Migrate role command * Migrate unmute command * Migrate warn command * Migrate eval command * Migrate help command * Migrate rules command * Migrate events to typescript * Update about command to use the PublicEmbed class * Update ErrorMessage to ChannelNotFound * Update messageDelete event to ignore bots * Feature/74 merge vylbot core (#80) * Merge VylBot-Core * Update commands to new system * Fix issue where events would not load * Feature/12 create tests (#102) * Fix tests * Update coverage * Remove unrequired mock files * Add about command test * Update about tests * Ban command tests * eval command tests * Start help command tests * Add help command tests * Add kick command tests * Mute command tests * Poll command tests * Add role command tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add rules command tests * Add unmute command tests * Add warn command tests * Add MemberEvents tests * Add GuildMemberUpdate tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add MessageEvents tests * Add StringTools test Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add embed tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add GitHub Actions Signed-off-by: Ethan Lane <ethan@vylpes.com> * Move to tslint Signed-off-by: Ethan Lane <ethan@vylpes.com> * Remove tslint Signed-off-by: Ethan Lane <ethan@vylpes.com> * Remove linting script Signed-off-by: Ethan Lane <ethan@vylpes.com> * Update rules with blog website and event spoilers rule" (#106) Signed-off-by: Ethan Lane <ethan@vylpes.com> * Containerise bot (#107) * Add moderator names to audit reason (#108) * Feature/48 database (#114) * Add database and default values * Add ability to save a setting to the database * Get commands and events to use database * Setup and config command * Update commands to check roles per server * Different rules per server Signed-off-by: Ethan Lane <ethan@vylpes.com> * Different prefix per server Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add verification system Signed-off-by: Ethan Lane <ethan@vylpes.com> * Disabled commands per server * Add devmode for default prefix * Update embeds * Fix broken tests * Feature/66 add different commands per server (#122) * Add ability for server exclusive commands * Add MankBot server-exclusive commands * Add lobby entity to database * Add documentation * Add setup command for lobby (#123) * Update bot to discord.js v13 (#125) * Update bot to discord.js v13 * Remove debug code * 110 commandshelp about command errors which causes command to not run (#126) * Change onMessage to onMessageCreate * Fix help command * Add override for bot owner and server owner (#135) * Change help command so exclusive commands can only be seen for the server they're assigned to (#136) * Change parsing to not crash if invalid (#142) * 137 role command cannot read properties of undefined (#141) * Fix issue with bot crashing * Fix server prefix not showing * Add easy way to configure role command * Move help text to its own directory * Make role config command to use role id * Get lobby command to use IDs instead of names (#144) Co-authored-by: Vylpes <getgravitysoftware@gmail.com>
2022-04-24 14:46:37 +01:00
2024-03-25 17:59:34 +00:00
test("GIVEN bot is not in a guild for a server command, EXPECT this to be ignored", () => {
process.env.BOT_TOKEN = "token";
process.env.BOT_CLIENTID = "clientid";
const client = {
guilds: {
cache: {
has: jest.fn().mockReturnValue(false),
}
}
} as unknown as Client;
const setTokenPutMock = jest.fn();
const setTokenMock = jest.fn().mockReturnValue({
put: setTokenPutMock,
});
REST.prototype.setToken = setTokenMock;
Routes.applicationCommands = jest.fn().mockReturnValue("command url");
Routes.applicationGuildCommands = jest.fn().mockReturnValue("guild command url");
CoreClient.commandItems = [
{
Name: "server-specific",
Command: {
CommandBuilder: {
name: "server",
} as SlashCommandBuilder,
} as Command,
ServerId: "123",
}
];
const util = new Util();
util.loadSlashCommands(client);
expect(Routes.applicationGuildCommands).not.toHaveBeenCalled();
});
v3.0 (#145) * Change rules.txt to rules.json (#31) * Migrate to yarn * Add role configs to config template * Install packges and setup typescript * Migrate entry point * Migrate about command * Migrate ban command * Migrate clear command * Migrate kick command * Migrate mute command * Migrate poll command * Migrate bunny command * Update required roles checker * Migrate role command * Migrate unmute command * Migrate warn command * Migrate eval command * Migrate help command * Migrate rules command * Migrate events to typescript * Update about command to use the PublicEmbed class * Update ErrorMessage to ChannelNotFound * Update messageDelete event to ignore bots * Feature/74 merge vylbot core (#80) * Merge VylBot-Core * Update commands to new system * Fix issue where events would not load * Feature/12 create tests (#102) * Fix tests * Update coverage * Remove unrequired mock files * Add about command test * Update about tests * Ban command tests * eval command tests * Start help command tests * Add help command tests * Add kick command tests * Mute command tests * Poll command tests * Add role command tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add rules command tests * Add unmute command tests * Add warn command tests * Add MemberEvents tests * Add GuildMemberUpdate tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add MessageEvents tests * Add StringTools test Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add embed tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add GitHub Actions Signed-off-by: Ethan Lane <ethan@vylpes.com> * Move to tslint Signed-off-by: Ethan Lane <ethan@vylpes.com> * Remove tslint Signed-off-by: Ethan Lane <ethan@vylpes.com> * Remove linting script Signed-off-by: Ethan Lane <ethan@vylpes.com> * Update rules with blog website and event spoilers rule" (#106) Signed-off-by: Ethan Lane <ethan@vylpes.com> * Containerise bot (#107) * Add moderator names to audit reason (#108) * Feature/48 database (#114) * Add database and default values * Add ability to save a setting to the database * Get commands and events to use database * Setup and config command * Update commands to check roles per server * Different rules per server Signed-off-by: Ethan Lane <ethan@vylpes.com> * Different prefix per server Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add verification system Signed-off-by: Ethan Lane <ethan@vylpes.com> * Disabled commands per server * Add devmode for default prefix * Update embeds * Fix broken tests * Feature/66 add different commands per server (#122) * Add ability for server exclusive commands * Add MankBot server-exclusive commands * Add lobby entity to database * Add documentation * Add setup command for lobby (#123) * Update bot to discord.js v13 (#125) * Update bot to discord.js v13 * Remove debug code * 110 commandshelp about command errors which causes command to not run (#126) * Change onMessage to onMessageCreate * Fix help command * Add override for bot owner and server owner (#135) * Change help command so exclusive commands can only be seen for the server they're assigned to (#136) * Change parsing to not crash if invalid (#142) * 137 role command cannot read properties of undefined (#141) * Fix issue with bot crashing * Fix server prefix not showing * Add easy way to configure role command * Move help text to its own directory * Make role config command to use role id * Get lobby command to use IDs instead of names (#144) Co-authored-by: Vylpes <getgravitysoftware@gmail.com>
2022-04-24 14:46:37 +01:00
});
2024-02-03 19:29:28 +00:00
describe("loadEvents", () => {
2024-03-25 17:59:34 +00:00
test("GIVEN event type is channelCreate, EXPECT event function to be executed", () => {
const client = {
on: jest.fn(),
} as unknown as Client;
const events: IEventItem[] = [
{
EventType: EventType.ChannelCreate,
ExecutionFunction: jest.fn(),
}
];
const util = new Util();
util.loadEvents(client, events);
expect(client.on).toHaveBeenCalledTimes(1);
expect(client.on).toHaveBeenCalledWith("channelCreate", expect.any(Function));
});
test("GIVEN event type is channelDelete, EXPECT event function to be executed", () => {
const client = {
on: jest.fn(),
} as unknown as Client;
const events: IEventItem[] = [
{
EventType: EventType.ChannelDelete,
ExecutionFunction: jest.fn(),
}
];
const util = new Util();
util.loadEvents(client, events);
expect(client.on).toHaveBeenCalledTimes(1);
expect(client.on).toHaveBeenCalledWith("channelDelete", expect.any(Function));
});
test("GIVEN event type is channelUpdate, EXPECT event function to be executed", () => {
const client = {
on: jest.fn(),
} as unknown as Client;
const events: IEventItem[] = [
{
EventType: EventType.ChannelUpdate,
ExecutionFunction: jest.fn(),
}
];
const util = new Util();
util.loadEvents(client, events);
expect(client.on).toHaveBeenCalledTimes(1);
expect(client.on).toHaveBeenCalledWith("channelUpdate", expect.any(Function));
});
test("GIVEN event type is guildBanAdd, EXPECT event function to be executed", () => {
const client = {
on: jest.fn(),
} as unknown as Client;
const events: IEventItem[] = [
{
EventType: EventType.GuildBanAdd,
ExecutionFunction: jest.fn(),
}
];
const util = new Util();
util.loadEvents(client, events);
expect(client.on).toHaveBeenCalledTimes(1);
expect(client.on).toHaveBeenCalledWith("guildBanAdd", expect.any(Function));
});
test("GIVEN event type is guildBanRemove, EXPECT event function to be executed", () => {
const client = {
on: jest.fn(),
} as unknown as Client;
const events: IEventItem[] = [
{
EventType: EventType.GuildBanRemove,
ExecutionFunction: jest.fn(),
}
];
const util = new Util();
util.loadEvents(client, events);
v3.0 (#145) * Change rules.txt to rules.json (#31) * Migrate to yarn * Add role configs to config template * Install packges and setup typescript * Migrate entry point * Migrate about command * Migrate ban command * Migrate clear command * Migrate kick command * Migrate mute command * Migrate poll command * Migrate bunny command * Update required roles checker * Migrate role command * Migrate unmute command * Migrate warn command * Migrate eval command * Migrate help command * Migrate rules command * Migrate events to typescript * Update about command to use the PublicEmbed class * Update ErrorMessage to ChannelNotFound * Update messageDelete event to ignore bots * Feature/74 merge vylbot core (#80) * Merge VylBot-Core * Update commands to new system * Fix issue where events would not load * Feature/12 create tests (#102) * Fix tests * Update coverage * Remove unrequired mock files * Add about command test * Update about tests * Ban command tests * eval command tests * Start help command tests * Add help command tests * Add kick command tests * Mute command tests * Poll command tests * Add role command tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add rules command tests * Add unmute command tests * Add warn command tests * Add MemberEvents tests * Add GuildMemberUpdate tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add MessageEvents tests * Add StringTools test Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add embed tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add GitHub Actions Signed-off-by: Ethan Lane <ethan@vylpes.com> * Move to tslint Signed-off-by: Ethan Lane <ethan@vylpes.com> * Remove tslint Signed-off-by: Ethan Lane <ethan@vylpes.com> * Remove linting script Signed-off-by: Ethan Lane <ethan@vylpes.com> * Update rules with blog website and event spoilers rule" (#106) Signed-off-by: Ethan Lane <ethan@vylpes.com> * Containerise bot (#107) * Add moderator names to audit reason (#108) * Feature/48 database (#114) * Add database and default values * Add ability to save a setting to the database * Get commands and events to use database * Setup and config command * Update commands to check roles per server * Different rules per server Signed-off-by: Ethan Lane <ethan@vylpes.com> * Different prefix per server Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add verification system Signed-off-by: Ethan Lane <ethan@vylpes.com> * Disabled commands per server * Add devmode for default prefix * Update embeds * Fix broken tests * Feature/66 add different commands per server (#122) * Add ability for server exclusive commands * Add MankBot server-exclusive commands * Add lobby entity to database * Add documentation * Add setup command for lobby (#123) * Update bot to discord.js v13 (#125) * Update bot to discord.js v13 * Remove debug code * 110 commandshelp about command errors which causes command to not run (#126) * Change onMessage to onMessageCreate * Fix help command * Add override for bot owner and server owner (#135) * Change help command so exclusive commands can only be seen for the server they're assigned to (#136) * Change parsing to not crash if invalid (#142) * 137 role command cannot read properties of undefined (#141) * Fix issue with bot crashing * Fix server prefix not showing * Add easy way to configure role command * Move help text to its own directory * Make role config command to use role id * Get lobby command to use IDs instead of names (#144) Co-authored-by: Vylpes <getgravitysoftware@gmail.com>
2022-04-24 14:46:37 +01:00
2024-03-25 17:59:34 +00:00
expect(client.on).toHaveBeenCalledTimes(1);
expect(client.on).toHaveBeenCalledWith("guildBanRemove", expect.any(Function));
});
v3.0 (#145) * Change rules.txt to rules.json (#31) * Migrate to yarn * Add role configs to config template * Install packges and setup typescript * Migrate entry point * Migrate about command * Migrate ban command * Migrate clear command * Migrate kick command * Migrate mute command * Migrate poll command * Migrate bunny command * Update required roles checker * Migrate role command * Migrate unmute command * Migrate warn command * Migrate eval command * Migrate help command * Migrate rules command * Migrate events to typescript * Update about command to use the PublicEmbed class * Update ErrorMessage to ChannelNotFound * Update messageDelete event to ignore bots * Feature/74 merge vylbot core (#80) * Merge VylBot-Core * Update commands to new system * Fix issue where events would not load * Feature/12 create tests (#102) * Fix tests * Update coverage * Remove unrequired mock files * Add about command test * Update about tests * Ban command tests * eval command tests * Start help command tests * Add help command tests * Add kick command tests * Mute command tests * Poll command tests * Add role command tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add rules command tests * Add unmute command tests * Add warn command tests * Add MemberEvents tests * Add GuildMemberUpdate tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add MessageEvents tests * Add StringTools test Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add embed tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add GitHub Actions Signed-off-by: Ethan Lane <ethan@vylpes.com> * Move to tslint Signed-off-by: Ethan Lane <ethan@vylpes.com> * Remove tslint Signed-off-by: Ethan Lane <ethan@vylpes.com> * Remove linting script Signed-off-by: Ethan Lane <ethan@vylpes.com> * Update rules with blog website and event spoilers rule" (#106) Signed-off-by: Ethan Lane <ethan@vylpes.com> * Containerise bot (#107) * Add moderator names to audit reason (#108) * Feature/48 database (#114) * Add database and default values * Add ability to save a setting to the database * Get commands and events to use database * Setup and config command * Update commands to check roles per server * Different rules per server Signed-off-by: Ethan Lane <ethan@vylpes.com> * Different prefix per server Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add verification system Signed-off-by: Ethan Lane <ethan@vylpes.com> * Disabled commands per server * Add devmode for default prefix * Update embeds * Fix broken tests * Feature/66 add different commands per server (#122) * Add ability for server exclusive commands * Add MankBot server-exclusive commands * Add lobby entity to database * Add documentation * Add setup command for lobby (#123) * Update bot to discord.js v13 (#125) * Update bot to discord.js v13 * Remove debug code * 110 commandshelp about command errors which causes command to not run (#126) * Change onMessage to onMessageCreate * Fix help command * Add override for bot owner and server owner (#135) * Change help command so exclusive commands can only be seen for the server they're assigned to (#136) * Change parsing to not crash if invalid (#142) * 137 role command cannot read properties of undefined (#141) * Fix issue with bot crashing * Fix server prefix not showing * Add easy way to configure role command * Move help text to its own directory * Make role config command to use role id * Get lobby command to use IDs instead of names (#144) Co-authored-by: Vylpes <getgravitysoftware@gmail.com>
2022-04-24 14:46:37 +01:00
2024-03-25 17:59:34 +00:00
test("GIVEN event type is guildCreate, EXPECT event function to be executed", () => {
const client = {
on: jest.fn(),
} as unknown as Client;
const events: IEventItem[] = [
{
EventType: EventType.GuildCreate,
ExecutionFunction: jest.fn(),
}
];
v3.0 (#145) * Change rules.txt to rules.json (#31) * Migrate to yarn * Add role configs to config template * Install packges and setup typescript * Migrate entry point * Migrate about command * Migrate ban command * Migrate clear command * Migrate kick command * Migrate mute command * Migrate poll command * Migrate bunny command * Update required roles checker * Migrate role command * Migrate unmute command * Migrate warn command * Migrate eval command * Migrate help command * Migrate rules command * Migrate events to typescript * Update about command to use the PublicEmbed class * Update ErrorMessage to ChannelNotFound * Update messageDelete event to ignore bots * Feature/74 merge vylbot core (#80) * Merge VylBot-Core * Update commands to new system * Fix issue where events would not load * Feature/12 create tests (#102) * Fix tests * Update coverage * Remove unrequired mock files * Add about command test * Update about tests * Ban command tests * eval command tests * Start help command tests * Add help command tests * Add kick command tests * Mute command tests * Poll command tests * Add role command tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add rules command tests * Add unmute command tests * Add warn command tests * Add MemberEvents tests * Add GuildMemberUpdate tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add MessageEvents tests * Add StringTools test Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add embed tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add GitHub Actions Signed-off-by: Ethan Lane <ethan@vylpes.com> * Move to tslint Signed-off-by: Ethan Lane <ethan@vylpes.com> * Remove tslint Signed-off-by: Ethan Lane <ethan@vylpes.com> * Remove linting script Signed-off-by: Ethan Lane <ethan@vylpes.com> * Update rules with blog website and event spoilers rule" (#106) Signed-off-by: Ethan Lane <ethan@vylpes.com> * Containerise bot (#107) * Add moderator names to audit reason (#108) * Feature/48 database (#114) * Add database and default values * Add ability to save a setting to the database * Get commands and events to use database * Setup and config command * Update commands to check roles per server * Different rules per server Signed-off-by: Ethan Lane <ethan@vylpes.com> * Different prefix per server Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add verification system Signed-off-by: Ethan Lane <ethan@vylpes.com> * Disabled commands per server * Add devmode for default prefix * Update embeds * Fix broken tests * Feature/66 add different commands per server (#122) * Add ability for server exclusive commands * Add MankBot server-exclusive commands * Add lobby entity to database * Add documentation * Add setup command for lobby (#123) * Update bot to discord.js v13 (#125) * Update bot to discord.js v13 * Remove debug code * 110 commandshelp about command errors which causes command to not run (#126) * Change onMessage to onMessageCreate * Fix help command * Add override for bot owner and server owner (#135) * Change help command so exclusive commands can only be seen for the server they're assigned to (#136) * Change parsing to not crash if invalid (#142) * 137 role command cannot read properties of undefined (#141) * Fix issue with bot crashing * Fix server prefix not showing * Add easy way to configure role command * Move help text to its own directory * Make role config command to use role id * Get lobby command to use IDs instead of names (#144) Co-authored-by: Vylpes <getgravitysoftware@gmail.com>
2022-04-24 14:46:37 +01:00
2024-03-25 17:59:34 +00:00
const util = new Util();
util.loadEvents(client, events);
v3.0 (#145) * Change rules.txt to rules.json (#31) * Migrate to yarn * Add role configs to config template * Install packges and setup typescript * Migrate entry point * Migrate about command * Migrate ban command * Migrate clear command * Migrate kick command * Migrate mute command * Migrate poll command * Migrate bunny command * Update required roles checker * Migrate role command * Migrate unmute command * Migrate warn command * Migrate eval command * Migrate help command * Migrate rules command * Migrate events to typescript * Update about command to use the PublicEmbed class * Update ErrorMessage to ChannelNotFound * Update messageDelete event to ignore bots * Feature/74 merge vylbot core (#80) * Merge VylBot-Core * Update commands to new system * Fix issue where events would not load * Feature/12 create tests (#102) * Fix tests * Update coverage * Remove unrequired mock files * Add about command test * Update about tests * Ban command tests * eval command tests * Start help command tests * Add help command tests * Add kick command tests * Mute command tests * Poll command tests * Add role command tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add rules command tests * Add unmute command tests * Add warn command tests * Add MemberEvents tests * Add GuildMemberUpdate tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add MessageEvents tests * Add StringTools test Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add embed tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add GitHub Actions Signed-off-by: Ethan Lane <ethan@vylpes.com> * Move to tslint Signed-off-by: Ethan Lane <ethan@vylpes.com> * Remove tslint Signed-off-by: Ethan Lane <ethan@vylpes.com> * Remove linting script Signed-off-by: Ethan Lane <ethan@vylpes.com> * Update rules with blog website and event spoilers rule" (#106) Signed-off-by: Ethan Lane <ethan@vylpes.com> * Containerise bot (#107) * Add moderator names to audit reason (#108) * Feature/48 database (#114) * Add database and default values * Add ability to save a setting to the database * Get commands and events to use database * Setup and config command * Update commands to check roles per server * Different rules per server Signed-off-by: Ethan Lane <ethan@vylpes.com> * Different prefix per server Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add verification system Signed-off-by: Ethan Lane <ethan@vylpes.com> * Disabled commands per server * Add devmode for default prefix * Update embeds * Fix broken tests * Feature/66 add different commands per server (#122) * Add ability for server exclusive commands * Add MankBot server-exclusive commands * Add lobby entity to database * Add documentation * Add setup command for lobby (#123) * Update bot to discord.js v13 (#125) * Update bot to discord.js v13 * Remove debug code * 110 commandshelp about command errors which causes command to not run (#126) * Change onMessage to onMessageCreate * Fix help command * Add override for bot owner and server owner (#135) * Change help command so exclusive commands can only be seen for the server they're assigned to (#136) * Change parsing to not crash if invalid (#142) * 137 role command cannot read properties of undefined (#141) * Fix issue with bot crashing * Fix server prefix not showing * Add easy way to configure role command * Move help text to its own directory * Make role config command to use role id * Get lobby command to use IDs instead of names (#144) Co-authored-by: Vylpes <getgravitysoftware@gmail.com>
2022-04-24 14:46:37 +01:00
2024-03-25 17:59:34 +00:00
expect(client.on).toHaveBeenCalledTimes(1);
expect(client.on).toHaveBeenCalledWith("guildCreate", expect.any(Function));
});
v3.0 (#145) * Change rules.txt to rules.json (#31) * Migrate to yarn * Add role configs to config template * Install packges and setup typescript * Migrate entry point * Migrate about command * Migrate ban command * Migrate clear command * Migrate kick command * Migrate mute command * Migrate poll command * Migrate bunny command * Update required roles checker * Migrate role command * Migrate unmute command * Migrate warn command * Migrate eval command * Migrate help command * Migrate rules command * Migrate events to typescript * Update about command to use the PublicEmbed class * Update ErrorMessage to ChannelNotFound * Update messageDelete event to ignore bots * Feature/74 merge vylbot core (#80) * Merge VylBot-Core * Update commands to new system * Fix issue where events would not load * Feature/12 create tests (#102) * Fix tests * Update coverage * Remove unrequired mock files * Add about command test * Update about tests * Ban command tests * eval command tests * Start help command tests * Add help command tests * Add kick command tests * Mute command tests * Poll command tests * Add role command tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add rules command tests * Add unmute command tests * Add warn command tests * Add MemberEvents tests * Add GuildMemberUpdate tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add MessageEvents tests * Add StringTools test Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add embed tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add GitHub Actions Signed-off-by: Ethan Lane <ethan@vylpes.com> * Move to tslint Signed-off-by: Ethan Lane <ethan@vylpes.com> * Remove tslint Signed-off-by: Ethan Lane <ethan@vylpes.com> * Remove linting script Signed-off-by: Ethan Lane <ethan@vylpes.com> * Update rules with blog website and event spoilers rule" (#106) Signed-off-by: Ethan Lane <ethan@vylpes.com> * Containerise bot (#107) * Add moderator names to audit reason (#108) * Feature/48 database (#114) * Add database and default values * Add ability to save a setting to the database * Get commands and events to use database * Setup and config command * Update commands to check roles per server * Different rules per server Signed-off-by: Ethan Lane <ethan@vylpes.com> * Different prefix per server Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add verification system Signed-off-by: Ethan Lane <ethan@vylpes.com> * Disabled commands per server * Add devmode for default prefix * Update embeds * Fix broken tests * Feature/66 add different commands per server (#122) * Add ability for server exclusive commands * Add MankBot server-exclusive commands * Add lobby entity to database * Add documentation * Add setup command for lobby (#123) * Update bot to discord.js v13 (#125) * Update bot to discord.js v13 * Remove debug code * 110 commandshelp about command errors which causes command to not run (#126) * Change onMessage to onMessageCreate * Fix help command * Add override for bot owner and server owner (#135) * Change help command so exclusive commands can only be seen for the server they're assigned to (#136) * Change parsing to not crash if invalid (#142) * 137 role command cannot read properties of undefined (#141) * Fix issue with bot crashing * Fix server prefix not showing * Add easy way to configure role command * Move help text to its own directory * Make role config command to use role id * Get lobby command to use IDs instead of names (#144) Co-authored-by: Vylpes <getgravitysoftware@gmail.com>
2022-04-24 14:46:37 +01:00
2024-03-25 17:59:34 +00:00
test("GIVEN event type is guildMemberAdd, EXPECT event function to be executed", () => {
const client = {
on: jest.fn(),
} as unknown as Client;
const events: IEventItem[] = [
{
EventType: EventType.GuildMemberAdd,
ExecutionFunction: jest.fn(),
}
];
v3.0 (#145) * Change rules.txt to rules.json (#31) * Migrate to yarn * Add role configs to config template * Install packges and setup typescript * Migrate entry point * Migrate about command * Migrate ban command * Migrate clear command * Migrate kick command * Migrate mute command * Migrate poll command * Migrate bunny command * Update required roles checker * Migrate role command * Migrate unmute command * Migrate warn command * Migrate eval command * Migrate help command * Migrate rules command * Migrate events to typescript * Update about command to use the PublicEmbed class * Update ErrorMessage to ChannelNotFound * Update messageDelete event to ignore bots * Feature/74 merge vylbot core (#80) * Merge VylBot-Core * Update commands to new system * Fix issue where events would not load * Feature/12 create tests (#102) * Fix tests * Update coverage * Remove unrequired mock files * Add about command test * Update about tests * Ban command tests * eval command tests * Start help command tests * Add help command tests * Add kick command tests * Mute command tests * Poll command tests * Add role command tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add rules command tests * Add unmute command tests * Add warn command tests * Add MemberEvents tests * Add GuildMemberUpdate tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add MessageEvents tests * Add StringTools test Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add embed tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add GitHub Actions Signed-off-by: Ethan Lane <ethan@vylpes.com> * Move to tslint Signed-off-by: Ethan Lane <ethan@vylpes.com> * Remove tslint Signed-off-by: Ethan Lane <ethan@vylpes.com> * Remove linting script Signed-off-by: Ethan Lane <ethan@vylpes.com> * Update rules with blog website and event spoilers rule" (#106) Signed-off-by: Ethan Lane <ethan@vylpes.com> * Containerise bot (#107) * Add moderator names to audit reason (#108) * Feature/48 database (#114) * Add database and default values * Add ability to save a setting to the database * Get commands and events to use database * Setup and config command * Update commands to check roles per server * Different rules per server Signed-off-by: Ethan Lane <ethan@vylpes.com> * Different prefix per server Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add verification system Signed-off-by: Ethan Lane <ethan@vylpes.com> * Disabled commands per server * Add devmode for default prefix * Update embeds * Fix broken tests * Feature/66 add different commands per server (#122) * Add ability for server exclusive commands * Add MankBot server-exclusive commands * Add lobby entity to database * Add documentation * Add setup command for lobby (#123) * Update bot to discord.js v13 (#125) * Update bot to discord.js v13 * Remove debug code * 110 commandshelp about command errors which causes command to not run (#126) * Change onMessage to onMessageCreate * Fix help command * Add override for bot owner and server owner (#135) * Change help command so exclusive commands can only be seen for the server they're assigned to (#136) * Change parsing to not crash if invalid (#142) * 137 role command cannot read properties of undefined (#141) * Fix issue with bot crashing * Fix server prefix not showing * Add easy way to configure role command * Move help text to its own directory * Make role config command to use role id * Get lobby command to use IDs instead of names (#144) Co-authored-by: Vylpes <getgravitysoftware@gmail.com>
2022-04-24 14:46:37 +01:00
2024-03-25 17:59:34 +00:00
const util = new Util();
util.loadEvents(client, events);
v3.0 (#145) * Change rules.txt to rules.json (#31) * Migrate to yarn * Add role configs to config template * Install packges and setup typescript * Migrate entry point * Migrate about command * Migrate ban command * Migrate clear command * Migrate kick command * Migrate mute command * Migrate poll command * Migrate bunny command * Update required roles checker * Migrate role command * Migrate unmute command * Migrate warn command * Migrate eval command * Migrate help command * Migrate rules command * Migrate events to typescript * Update about command to use the PublicEmbed class * Update ErrorMessage to ChannelNotFound * Update messageDelete event to ignore bots * Feature/74 merge vylbot core (#80) * Merge VylBot-Core * Update commands to new system * Fix issue where events would not load * Feature/12 create tests (#102) * Fix tests * Update coverage * Remove unrequired mock files * Add about command test * Update about tests * Ban command tests * eval command tests * Start help command tests * Add help command tests * Add kick command tests * Mute command tests * Poll command tests * Add role command tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add rules command tests * Add unmute command tests * Add warn command tests * Add MemberEvents tests * Add GuildMemberUpdate tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add MessageEvents tests * Add StringTools test Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add embed tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add GitHub Actions Signed-off-by: Ethan Lane <ethan@vylpes.com> * Move to tslint Signed-off-by: Ethan Lane <ethan@vylpes.com> * Remove tslint Signed-off-by: Ethan Lane <ethan@vylpes.com> * Remove linting script Signed-off-by: Ethan Lane <ethan@vylpes.com> * Update rules with blog website and event spoilers rule" (#106) Signed-off-by: Ethan Lane <ethan@vylpes.com> * Containerise bot (#107) * Add moderator names to audit reason (#108) * Feature/48 database (#114) * Add database and default values * Add ability to save a setting to the database * Get commands and events to use database * Setup and config command * Update commands to check roles per server * Different rules per server Signed-off-by: Ethan Lane <ethan@vylpes.com> * Different prefix per server Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add verification system Signed-off-by: Ethan Lane <ethan@vylpes.com> * Disabled commands per server * Add devmode for default prefix * Update embeds * Fix broken tests * Feature/66 add different commands per server (#122) * Add ability for server exclusive commands * Add MankBot server-exclusive commands * Add lobby entity to database * Add documentation * Add setup command for lobby (#123) * Update bot to discord.js v13 (#125) * Update bot to discord.js v13 * Remove debug code * 110 commandshelp about command errors which causes command to not run (#126) * Change onMessage to onMessageCreate * Fix help command * Add override for bot owner and server owner (#135) * Change help command so exclusive commands can only be seen for the server they're assigned to (#136) * Change parsing to not crash if invalid (#142) * 137 role command cannot read properties of undefined (#141) * Fix issue with bot crashing * Fix server prefix not showing * Add easy way to configure role command * Move help text to its own directory * Make role config command to use role id * Get lobby command to use IDs instead of names (#144) Co-authored-by: Vylpes <getgravitysoftware@gmail.com>
2022-04-24 14:46:37 +01:00
2024-03-25 17:59:34 +00:00
expect(client.on).toHaveBeenCalledTimes(1);
expect(client.on).toHaveBeenCalledWith("guildMemberAdd", expect.any(Function));
});
v3.0 (#145) * Change rules.txt to rules.json (#31) * Migrate to yarn * Add role configs to config template * Install packges and setup typescript * Migrate entry point * Migrate about command * Migrate ban command * Migrate clear command * Migrate kick command * Migrate mute command * Migrate poll command * Migrate bunny command * Update required roles checker * Migrate role command * Migrate unmute command * Migrate warn command * Migrate eval command * Migrate help command * Migrate rules command * Migrate events to typescript * Update about command to use the PublicEmbed class * Update ErrorMessage to ChannelNotFound * Update messageDelete event to ignore bots * Feature/74 merge vylbot core (#80) * Merge VylBot-Core * Update commands to new system * Fix issue where events would not load * Feature/12 create tests (#102) * Fix tests * Update coverage * Remove unrequired mock files * Add about command test * Update about tests * Ban command tests * eval command tests * Start help command tests * Add help command tests * Add kick command tests * Mute command tests * Poll command tests * Add role command tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add rules command tests * Add unmute command tests * Add warn command tests * Add MemberEvents tests * Add GuildMemberUpdate tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add MessageEvents tests * Add StringTools test Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add embed tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add GitHub Actions Signed-off-by: Ethan Lane <ethan@vylpes.com> * Move to tslint Signed-off-by: Ethan Lane <ethan@vylpes.com> * Remove tslint Signed-off-by: Ethan Lane <ethan@vylpes.com> * Remove linting script Signed-off-by: Ethan Lane <ethan@vylpes.com> * Update rules with blog website and event spoilers rule" (#106) Signed-off-by: Ethan Lane <ethan@vylpes.com> * Containerise bot (#107) * Add moderator names to audit reason (#108) * Feature/48 database (#114) * Add database and default values * Add ability to save a setting to the database * Get commands and events to use database * Setup and config command * Update commands to check roles per server * Different rules per server Signed-off-by: Ethan Lane <ethan@vylpes.com> * Different prefix per server Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add verification system Signed-off-by: Ethan Lane <ethan@vylpes.com> * Disabled commands per server * Add devmode for default prefix * Update embeds * Fix broken tests * Feature/66 add different commands per server (#122) * Add ability for server exclusive commands * Add MankBot server-exclusive commands * Add lobby entity to database * Add documentation * Add setup command for lobby (#123) * Update bot to discord.js v13 (#125) * Update bot to discord.js v13 * Remove debug code * 110 commandshelp about command errors which causes command to not run (#126) * Change onMessage to onMessageCreate * Fix help command * Add override for bot owner and server owner (#135) * Change help command so exclusive commands can only be seen for the server they're assigned to (#136) * Change parsing to not crash if invalid (#142) * 137 role command cannot read properties of undefined (#141) * Fix issue with bot crashing * Fix server prefix not showing * Add easy way to configure role command * Move help text to its own directory * Make role config command to use role id * Get lobby command to use IDs instead of names (#144) Co-authored-by: Vylpes <getgravitysoftware@gmail.com>
2022-04-24 14:46:37 +01:00
2024-03-25 17:59:34 +00:00
test("GIVEN event type is guildMemberRemove, EXPECT event function to be executed", () => {
const client = {
on: jest.fn(),
} as unknown as Client;
const events: IEventItem[] = [
{
EventType: EventType.GuildMemberRemove,
ExecutionFunction: jest.fn(),
}
];
v3.0 (#145) * Change rules.txt to rules.json (#31) * Migrate to yarn * Add role configs to config template * Install packges and setup typescript * Migrate entry point * Migrate about command * Migrate ban command * Migrate clear command * Migrate kick command * Migrate mute command * Migrate poll command * Migrate bunny command * Update required roles checker * Migrate role command * Migrate unmute command * Migrate warn command * Migrate eval command * Migrate help command * Migrate rules command * Migrate events to typescript * Update about command to use the PublicEmbed class * Update ErrorMessage to ChannelNotFound * Update messageDelete event to ignore bots * Feature/74 merge vylbot core (#80) * Merge VylBot-Core * Update commands to new system * Fix issue where events would not load * Feature/12 create tests (#102) * Fix tests * Update coverage * Remove unrequired mock files * Add about command test * Update about tests * Ban command tests * eval command tests * Start help command tests * Add help command tests * Add kick command tests * Mute command tests * Poll command tests * Add role command tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add rules command tests * Add unmute command tests * Add warn command tests * Add MemberEvents tests * Add GuildMemberUpdate tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add MessageEvents tests * Add StringTools test Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add embed tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add GitHub Actions Signed-off-by: Ethan Lane <ethan@vylpes.com> * Move to tslint Signed-off-by: Ethan Lane <ethan@vylpes.com> * Remove tslint Signed-off-by: Ethan Lane <ethan@vylpes.com> * Remove linting script Signed-off-by: Ethan Lane <ethan@vylpes.com> * Update rules with blog website and event spoilers rule" (#106) Signed-off-by: Ethan Lane <ethan@vylpes.com> * Containerise bot (#107) * Add moderator names to audit reason (#108) * Feature/48 database (#114) * Add database and default values * Add ability to save a setting to the database * Get commands and events to use database * Setup and config command * Update commands to check roles per server * Different rules per server Signed-off-by: Ethan Lane <ethan@vylpes.com> * Different prefix per server Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add verification system Signed-off-by: Ethan Lane <ethan@vylpes.com> * Disabled commands per server * Add devmode for default prefix * Update embeds * Fix broken tests * Feature/66 add different commands per server (#122) * Add ability for server exclusive commands * Add MankBot server-exclusive commands * Add lobby entity to database * Add documentation * Add setup command for lobby (#123) * Update bot to discord.js v13 (#125) * Update bot to discord.js v13 * Remove debug code * 110 commandshelp about command errors which causes command to not run (#126) * Change onMessage to onMessageCreate * Fix help command * Add override for bot owner and server owner (#135) * Change help command so exclusive commands can only be seen for the server they're assigned to (#136) * Change parsing to not crash if invalid (#142) * 137 role command cannot read properties of undefined (#141) * Fix issue with bot crashing * Fix server prefix not showing * Add easy way to configure role command * Move help text to its own directory * Make role config command to use role id * Get lobby command to use IDs instead of names (#144) Co-authored-by: Vylpes <getgravitysoftware@gmail.com>
2022-04-24 14:46:37 +01:00
2024-03-25 17:59:34 +00:00
const util = new Util();
util.loadEvents(client, events);
v3.0 (#145) * Change rules.txt to rules.json (#31) * Migrate to yarn * Add role configs to config template * Install packges and setup typescript * Migrate entry point * Migrate about command * Migrate ban command * Migrate clear command * Migrate kick command * Migrate mute command * Migrate poll command * Migrate bunny command * Update required roles checker * Migrate role command * Migrate unmute command * Migrate warn command * Migrate eval command * Migrate help command * Migrate rules command * Migrate events to typescript * Update about command to use the PublicEmbed class * Update ErrorMessage to ChannelNotFound * Update messageDelete event to ignore bots * Feature/74 merge vylbot core (#80) * Merge VylBot-Core * Update commands to new system * Fix issue where events would not load * Feature/12 create tests (#102) * Fix tests * Update coverage * Remove unrequired mock files * Add about command test * Update about tests * Ban command tests * eval command tests * Start help command tests * Add help command tests * Add kick command tests * Mute command tests * Poll command tests * Add role command tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add rules command tests * Add unmute command tests * Add warn command tests * Add MemberEvents tests * Add GuildMemberUpdate tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add MessageEvents tests * Add StringTools test Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add embed tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add GitHub Actions Signed-off-by: Ethan Lane <ethan@vylpes.com> * Move to tslint Signed-off-by: Ethan Lane <ethan@vylpes.com> * Remove tslint Signed-off-by: Ethan Lane <ethan@vylpes.com> * Remove linting script Signed-off-by: Ethan Lane <ethan@vylpes.com> * Update rules with blog website and event spoilers rule" (#106) Signed-off-by: Ethan Lane <ethan@vylpes.com> * Containerise bot (#107) * Add moderator names to audit reason (#108) * Feature/48 database (#114) * Add database and default values * Add ability to save a setting to the database * Get commands and events to use database * Setup and config command * Update commands to check roles per server * Different rules per server Signed-off-by: Ethan Lane <ethan@vylpes.com> * Different prefix per server Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add verification system Signed-off-by: Ethan Lane <ethan@vylpes.com> * Disabled commands per server * Add devmode for default prefix * Update embeds * Fix broken tests * Feature/66 add different commands per server (#122) * Add ability for server exclusive commands * Add MankBot server-exclusive commands * Add lobby entity to database * Add documentation * Add setup command for lobby (#123) * Update bot to discord.js v13 (#125) * Update bot to discord.js v13 * Remove debug code * 110 commandshelp about command errors which causes command to not run (#126) * Change onMessage to onMessageCreate * Fix help command * Add override for bot owner and server owner (#135) * Change help command so exclusive commands can only be seen for the server they're assigned to (#136) * Change parsing to not crash if invalid (#142) * 137 role command cannot read properties of undefined (#141) * Fix issue with bot crashing * Fix server prefix not showing * Add easy way to configure role command * Move help text to its own directory * Make role config command to use role id * Get lobby command to use IDs instead of names (#144) Co-authored-by: Vylpes <getgravitysoftware@gmail.com>
2022-04-24 14:46:37 +01:00
2024-03-25 17:59:34 +00:00
expect(client.on).toHaveBeenCalledTimes(1);
expect(client.on).toHaveBeenCalledWith("guildMemberRemove", expect.any(Function));
});
v3.0 (#145) * Change rules.txt to rules.json (#31) * Migrate to yarn * Add role configs to config template * Install packges and setup typescript * Migrate entry point * Migrate about command * Migrate ban command * Migrate clear command * Migrate kick command * Migrate mute command * Migrate poll command * Migrate bunny command * Update required roles checker * Migrate role command * Migrate unmute command * Migrate warn command * Migrate eval command * Migrate help command * Migrate rules command * Migrate events to typescript * Update about command to use the PublicEmbed class * Update ErrorMessage to ChannelNotFound * Update messageDelete event to ignore bots * Feature/74 merge vylbot core (#80) * Merge VylBot-Core * Update commands to new system * Fix issue where events would not load * Feature/12 create tests (#102) * Fix tests * Update coverage * Remove unrequired mock files * Add about command test * Update about tests * Ban command tests * eval command tests * Start help command tests * Add help command tests * Add kick command tests * Mute command tests * Poll command tests * Add role command tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add rules command tests * Add unmute command tests * Add warn command tests * Add MemberEvents tests * Add GuildMemberUpdate tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add MessageEvents tests * Add StringTools test Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add embed tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add GitHub Actions Signed-off-by: Ethan Lane <ethan@vylpes.com> * Move to tslint Signed-off-by: Ethan Lane <ethan@vylpes.com> * Remove tslint Signed-off-by: Ethan Lane <ethan@vylpes.com> * Remove linting script Signed-off-by: Ethan Lane <ethan@vylpes.com> * Update rules with blog website and event spoilers rule" (#106) Signed-off-by: Ethan Lane <ethan@vylpes.com> * Containerise bot (#107) * Add moderator names to audit reason (#108) * Feature/48 database (#114) * Add database and default values * Add ability to save a setting to the database * Get commands and events to use database * Setup and config command * Update commands to check roles per server * Different rules per server Signed-off-by: Ethan Lane <ethan@vylpes.com> * Different prefix per server Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add verification system Signed-off-by: Ethan Lane <ethan@vylpes.com> * Disabled commands per server * Add devmode for default prefix * Update embeds * Fix broken tests * Feature/66 add different commands per server (#122) * Add ability for server exclusive commands * Add MankBot server-exclusive commands * Add lobby entity to database * Add documentation * Add setup command for lobby (#123) * Update bot to discord.js v13 (#125) * Update bot to discord.js v13 * Remove debug code * 110 commandshelp about command errors which causes command to not run (#126) * Change onMessage to onMessageCreate * Fix help command * Add override for bot owner and server owner (#135) * Change help command so exclusive commands can only be seen for the server they're assigned to (#136) * Change parsing to not crash if invalid (#142) * 137 role command cannot read properties of undefined (#141) * Fix issue with bot crashing * Fix server prefix not showing * Add easy way to configure role command * Move help text to its own directory * Make role config command to use role id * Get lobby command to use IDs instead of names (#144) Co-authored-by: Vylpes <getgravitysoftware@gmail.com>
2022-04-24 14:46:37 +01:00
2024-03-25 17:59:34 +00:00
test("GIVEN event type is messageCreate, EXPECT event function to be executed", () => {
const client = {
on: jest.fn(),
} as unknown as Client;
const events: IEventItem[] = [
{
EventType: EventType.MessageCreate,
ExecutionFunction: jest.fn(),
}
];
const util = new Util();
util.loadEvents(client, events);
expect(client.on).toHaveBeenCalledTimes(1);
expect(client.on).toHaveBeenCalledWith("messageCreate", expect.any(Function));
});
test("GIVEN event type is messageDelete, EXPECT event function to be executed", () => {
const client = {
on: jest.fn(),
} as unknown as Client;
const events: IEventItem[] = [
{
EventType: EventType.MessageDelete,
ExecutionFunction: jest.fn(),
}
];
const util = new Util();
util.loadEvents(client, events);
expect(client.on).toHaveBeenCalledTimes(1);
expect(client.on).toHaveBeenCalledWith("messageDelete", expect.any(Function));
});
test("GIVEN event type is messageUpdate, EXPECT event function to be executed", () => {
const client = {
on: jest.fn(),
} as unknown as Client;
const events: IEventItem[] = [
{
EventType: EventType.MessageUpdate,
ExecutionFunction: jest.fn(),
}
];
const util = new Util();
util.loadEvents(client, events);
expect(client.on).toHaveBeenCalledTimes(1);
expect(client.on).toHaveBeenCalledWith("messageUpdate", expect.any(Function));
});
test("GIVEN event type is not implemented, EXPECT error", () => {
const client = {
on: jest.fn(),
} as unknown as Client;
const events: IEventItem[] = [
{
EventType: EventType.Ready,
ExecutionFunction: jest.fn(),
}
];
console.error = jest.fn();
const util = new Util();
util.loadEvents(client, events);
expect(console.error).toHaveBeenCalledWith("Event not implemented.");
});
2024-02-03 19:29:28 +00:00
});