* 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>
268 lines
5.9 KiB
TypeScript
268 lines
5.9 KiB
TypeScript
import Help, { ICommandData } from "../../src/commands/help";
|
|
import { Message } from "discord.js";
|
|
import { ICommandContext } from "../../src/contracts/ICommandContext";
|
|
|
|
const oldCwd = process.cwd();
|
|
|
|
describe('Constructor', () => {
|
|
test('Expect properties to be set', () => {
|
|
const help = new Help();
|
|
|
|
expect(help._category).toBe('General');
|
|
});
|
|
});
|
|
|
|
describe('Execute', () => {
|
|
test('Given no arguments were given, expect SendAll to be executed', () => {
|
|
const message = {} as unknown as Message;
|
|
|
|
const context: ICommandContext = {
|
|
name: 'help',
|
|
args: [],
|
|
message: message
|
|
};
|
|
|
|
const help = new Help();
|
|
|
|
help.SendAll = jest.fn();
|
|
help.SendSingle = jest.fn();
|
|
|
|
help.execute(context);
|
|
|
|
expect(help.SendAll).toBeCalled();
|
|
expect(help.SendSingle).not.toBeCalled();
|
|
});
|
|
|
|
test('Given an argument was given, expect SendSingle to be executed', () => {
|
|
const message = {} as unknown as Message;
|
|
|
|
const context: ICommandContext = {
|
|
name: 'help',
|
|
args: ['about'],
|
|
message: message
|
|
};
|
|
|
|
const help = new Help();
|
|
|
|
help.SendAll = jest.fn();
|
|
help.SendSingle = jest.fn();
|
|
|
|
help.execute(context);
|
|
|
|
expect(help.SendAll).not.toBeCalled();
|
|
expect(help.SendSingle).toBeCalled();
|
|
});
|
|
});
|
|
|
|
describe('SendAll', () => {
|
|
test('Expect embed with all commands to be sent', () => {
|
|
const messageChannelSend = jest.fn();
|
|
|
|
const message = {
|
|
channel: {
|
|
send: messageChannelSend
|
|
}
|
|
} as unknown as Message;
|
|
|
|
const context: ICommandContext = {
|
|
name: 'help',
|
|
args: [],
|
|
message: message
|
|
};
|
|
|
|
const help = new Help();
|
|
|
|
const commandData0: ICommandData = {
|
|
Exists: true,
|
|
Name: 'about',
|
|
Category: 'general',
|
|
Roles: []
|
|
};
|
|
|
|
const commandData1: ICommandData = {
|
|
Exists: true,
|
|
Name: 'role',
|
|
Category: 'general',
|
|
Roles: []
|
|
};
|
|
|
|
help.GetAllCommandData = jest.fn()
|
|
.mockReturnValue([commandData0, commandData1]);
|
|
|
|
const result = help.SendAll(context);
|
|
|
|
expect(help.GetAllCommandData).toBeCalled();
|
|
expect(messageChannelSend).toBeCalled();
|
|
|
|
expect(result.embeds.length).toBe(1);
|
|
|
|
// PublicEmbed
|
|
const publicEmbed = result.embeds[0];
|
|
|
|
expect(publicEmbed.fields.length).toBe(1);
|
|
|
|
// PublicEmbed -> GeneralCategory Field
|
|
const publicEmbedFieldGeneral = publicEmbed.fields[0];
|
|
|
|
expect(publicEmbedFieldGeneral.name).toBe('General');
|
|
expect(publicEmbedFieldGeneral.value).toBe('about, role');
|
|
});
|
|
});
|
|
|
|
describe('SendSingle', () => {
|
|
test('Given command exists, expect embed to be sent with command fields', () => {
|
|
const messageChannelSend = jest.fn();
|
|
|
|
const message = {
|
|
channel: {
|
|
send: messageChannelSend
|
|
}
|
|
} as unknown as Message;
|
|
|
|
const context: ICommandContext = {
|
|
name: 'help',
|
|
args: ['about'],
|
|
message: message
|
|
};
|
|
|
|
const commandData: ICommandData = {
|
|
Exists: true,
|
|
Name: 'about',
|
|
Category: 'general',
|
|
Roles: ['role1', 'role2']
|
|
};
|
|
|
|
const help = new Help();
|
|
|
|
help.GetCommandData = jest.fn()
|
|
.mockReturnValue(commandData);
|
|
|
|
const result = help.SendSingle(context);
|
|
|
|
expect(help.GetCommandData).toBeCalledWith('about');
|
|
expect(messageChannelSend).toBeCalled();
|
|
expect(result.embeds.length).toBe(1);
|
|
|
|
// PublicEmbed
|
|
const publicEmbed = result.embeds[0];
|
|
|
|
expect(publicEmbed.title).toBe('About');
|
|
expect(publicEmbed.description).toBe('');
|
|
expect(publicEmbed.fields.length).toBe(2);
|
|
|
|
// PublicEmbed -> Category Field
|
|
const fieldCategory = publicEmbed.fields[0];
|
|
|
|
expect(fieldCategory.name).toBe('Category');
|
|
expect(fieldCategory.value).toBe('General');
|
|
|
|
// PublicEmbed -> RequiredRoles Field
|
|
const fieldRoles = publicEmbed.fields[1];
|
|
|
|
expect(fieldRoles.name).toBe('Required Roles');
|
|
expect(fieldRoles.value).toBe('Role1, Role2');
|
|
});
|
|
|
|
test('Given command does not exist, expect error embed to be sent', () => {
|
|
const messageChannelSend = jest.fn();
|
|
|
|
const message = {
|
|
channel: {
|
|
send: messageChannelSend
|
|
}
|
|
} as unknown as Message;
|
|
|
|
const context: ICommandContext = {
|
|
name: 'help',
|
|
args: ['about'],
|
|
message: message
|
|
};
|
|
|
|
const commandData: ICommandData = {
|
|
Exists: false
|
|
};
|
|
|
|
const help = new Help();
|
|
|
|
help.GetCommandData = jest.fn()
|
|
.mockReturnValue(commandData);
|
|
|
|
const result = help.SendSingle(context);
|
|
|
|
expect(help.GetCommandData).toBeCalledWith('about');
|
|
expect(messageChannelSend).toBeCalled();
|
|
expect(result.embeds.length).toBe(1);
|
|
|
|
// ErrorEmbed
|
|
const errorEmbed = result.embeds[0];
|
|
|
|
expect(errorEmbed.description).toBe('Command does not exist');
|
|
});
|
|
});
|
|
|
|
describe('GetAllCommandData', () => {
|
|
test('Expect array of command data to be returned', () => {
|
|
process.env = {
|
|
FOLDERS_COMMANDS: "commands"
|
|
};
|
|
|
|
process.cwd = jest.fn()
|
|
.mockReturnValue(`${oldCwd}/tests/_mocks`);
|
|
|
|
const help = new Help();
|
|
|
|
const result = help.GetAllCommandData();
|
|
|
|
expect(result.length).toBe(1);
|
|
|
|
// Mock Command
|
|
const mockCommand = result[0];
|
|
|
|
expect(mockCommand.Exists).toBeTruthy();
|
|
expect(mockCommand.Name).toBe("mockCmd");
|
|
expect(mockCommand.Category).toBe("General");
|
|
|
|
expect(mockCommand.Roles!.length).toBe(1);
|
|
expect(mockCommand.Roles![0]).toBe("Moderator");
|
|
});
|
|
});
|
|
|
|
describe('GetCommandData', () => {
|
|
test('Given command exists, expect data to be returned', () => {
|
|
process.env = {
|
|
FOLDERS_COMMANDS: "commands"
|
|
};
|
|
|
|
process.cwd = jest.fn()
|
|
.mockReturnValue(`${oldCwd}/tests/_mocks`);
|
|
|
|
const help = new Help();
|
|
|
|
const result = help.GetCommandData('mockCmd');
|
|
|
|
expect(result.Exists).toBeTruthy();
|
|
expect(result.Name).toBe("mockCmd");
|
|
expect(result.Category).toBe("General");
|
|
|
|
expect(result.Roles!.length).toBe(1);
|
|
expect(result.Roles![0]).toBe("Moderator");
|
|
});
|
|
|
|
test('Given command does not exist, expect exists false to be returned', () => {
|
|
process.env = {
|
|
FOLDERS_COMMANDS: "commands"
|
|
};
|
|
|
|
const oldCwd = process.cwd();
|
|
|
|
process.cwd = jest.fn()
|
|
.mockReturnValue(`${oldCwd}/tests/_mocks`);
|
|
|
|
const help = new Help();
|
|
|
|
const result = help.GetCommandData('none');
|
|
|
|
expect(result.Exists).toBeFalsy();
|
|
});
|
|
});
|