Update command names, add describe categories
This commit is contained in:
parent
bb848dcec3
commit
7e623b4b64
3 changed files with 548 additions and 536 deletions
|
@ -10,6 +10,7 @@ jest.mock("dotenv");
|
||||||
jest.mock("../../src/client/events");
|
jest.mock("../../src/client/events");
|
||||||
jest.mock("../../src/client/util");
|
jest.mock("../../src/client/util");
|
||||||
|
|
||||||
|
describe('Constructor', () => {
|
||||||
test('Constructor_ExpectSuccessfulInitialisation', () => {
|
test('Constructor_ExpectSuccessfulInitialisation', () => {
|
||||||
const coreClient = new CoreClient();
|
const coreClient = new CoreClient();
|
||||||
|
|
||||||
|
@ -18,8 +19,10 @@ test('Constructor_ExpectSuccessfulInitialisation', () => {
|
||||||
expect(Events).toBeCalledTimes(1);
|
expect(Events).toBeCalledTimes(1);
|
||||||
expect(Util).toBeCalledTimes(1);
|
expect(Util).toBeCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test('Start_GivenEnvIsValid_ExpectSuccessfulStart', () => {
|
describe('Start', () => {
|
||||||
|
test('Given Env Is Valid, Expect Successful Start', () => {
|
||||||
process.env = {
|
process.env = {
|
||||||
BOT_TOKEN: 'TOKEN',
|
BOT_TOKEN: 'TOKEN',
|
||||||
BOT_PREFIX: '!',
|
BOT_PREFIX: '!',
|
||||||
|
@ -34,7 +37,7 @@ test('Start_GivenEnvIsValid_ExpectSuccessfulStart', () => {
|
||||||
expect(coreClient.on).toBeCalledWith("ready", expect.any(Function));
|
expect(coreClient.on).toBeCalledWith("ready", expect.any(Function));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Start_GivenBotTokenIsNull_ExpectFailure', () => {
|
test('Given BOT_TOKEN Is Null, Expect Failure', () => {
|
||||||
process.env = {
|
process.env = {
|
||||||
BOT_PREFIX: '!',
|
BOT_PREFIX: '!',
|
||||||
FOLDERS_COMMANDS: 'commands',
|
FOLDERS_COMMANDS: 'commands',
|
||||||
|
@ -46,7 +49,7 @@ test('Start_GivenBotTokenIsNull_ExpectFailure', () => {
|
||||||
expect(() => coreClient.start()).toThrow("BOT_TOKEN is not defined in .env");
|
expect(() => coreClient.start()).toThrow("BOT_TOKEN is not defined in .env");
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Start_GivenBotTokenIsEmpty_ExpectFailure', () => {
|
test('Given BOT_TOKEN Is Empty, Expect Failure', () => {
|
||||||
process.env = {
|
process.env = {
|
||||||
BOT_TOKEN: '',
|
BOT_TOKEN: '',
|
||||||
BOT_PREFIX: '!',
|
BOT_PREFIX: '!',
|
||||||
|
@ -59,7 +62,7 @@ test('Start_GivenBotTokenIsEmpty_ExpectFailure', () => {
|
||||||
expect(() => coreClient.start()).toThrow("BOT_TOKEN is not defined in .env");
|
expect(() => coreClient.start()).toThrow("BOT_TOKEN is not defined in .env");
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Start_GivenBotPrefixIsNull_ExpectFailure', () => {
|
test('Given BOT_PREFIX Is Null, Expect Failure', () => {
|
||||||
process.env = {
|
process.env = {
|
||||||
BOT_TOKEN: 'TOKEN',
|
BOT_TOKEN: 'TOKEN',
|
||||||
FOLDERS_COMMANDS: 'commands',
|
FOLDERS_COMMANDS: 'commands',
|
||||||
|
@ -71,7 +74,7 @@ test('Start_GivenBotPrefixIsNull_ExpectFailure', () => {
|
||||||
expect(() => coreClient.start()).toThrow("BOT_PREFIX is not defined in .env");
|
expect(() => coreClient.start()).toThrow("BOT_PREFIX is not defined in .env");
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Start_GivenBotPrefixIsEmpty_ExpectFailure', () => {
|
test('Given BOT_PREFIX Is Empty, Expect Failure', () => {
|
||||||
process.env = {
|
process.env = {
|
||||||
BOT_TOKEN: 'TOKEN',
|
BOT_TOKEN: 'TOKEN',
|
||||||
BOT_PREFIX: '',
|
BOT_PREFIX: '',
|
||||||
|
@ -84,7 +87,7 @@ test('Start_GivenBotPrefixIsEmpty_ExpectFailure', () => {
|
||||||
expect(() => coreClient.start()).toThrow("BOT_PREFIX is not defined in .env");
|
expect(() => coreClient.start()).toThrow("BOT_PREFIX is not defined in .env");
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Start_GivenFoldersCommandsIsNull_ExpectFailure', () => {
|
test('Given FOLDERS_COMMANDS Is Null, Expect Failure', () => {
|
||||||
process.env = {
|
process.env = {
|
||||||
BOT_TOKEN: 'TOKEN',
|
BOT_TOKEN: 'TOKEN',
|
||||||
BOT_PREFIX: '!',
|
BOT_PREFIX: '!',
|
||||||
|
@ -96,7 +99,7 @@ test('Start_GivenFoldersCommandsIsNull_ExpectFailure', () => {
|
||||||
expect(() => coreClient.start()).toThrow("FOLDERS_COMMANDS is not defined in .env");
|
expect(() => coreClient.start()).toThrow("FOLDERS_COMMANDS is not defined in .env");
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Start_GivenFoldersCommandsIsEmpty_ExpectFailure', () => {
|
test('Given FOLDERS_COMMANDS Is Empty, Expect Failure', () => {
|
||||||
process.env = {
|
process.env = {
|
||||||
BOT_TOKEN: 'TOKEN',
|
BOT_TOKEN: 'TOKEN',
|
||||||
BOT_PREFIX: '!',
|
BOT_PREFIX: '!',
|
||||||
|
@ -109,7 +112,7 @@ test('Start_GivenFoldersCommandsIsEmpty_ExpectFailure', () => {
|
||||||
expect(() => coreClient.start()).toThrow("FOLDERS_COMMANDS is not defined in .env");
|
expect(() => coreClient.start()).toThrow("FOLDERS_COMMANDS is not defined in .env");
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Start_GivenFoldersEventsIsNull_ExpectFailure', () => {
|
test('Given FOLDERS_EVENTS Is Null, Expect Failure', () => {
|
||||||
process.env = {
|
process.env = {
|
||||||
BOT_TOKEN: 'TOKEN',
|
BOT_TOKEN: 'TOKEN',
|
||||||
BOT_PREFIX: '!',
|
BOT_PREFIX: '!',
|
||||||
|
@ -121,7 +124,7 @@ test('Start_GivenFoldersEventsIsNull_ExpectFailure', () => {
|
||||||
expect(() => coreClient.start()).toThrow("FOLDERS_EVENTS is not defined in .env");
|
expect(() => coreClient.start()).toThrow("FOLDERS_EVENTS is not defined in .env");
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Start_GivenFoldersCommandsIsEmpty_ExpectFailure', () => {
|
test('Given FOLDERS_EVENTS Is Empty, Expect Failure', () => {
|
||||||
process.env = {
|
process.env = {
|
||||||
BOT_TOKEN: 'TOKEN',
|
BOT_TOKEN: 'TOKEN',
|
||||||
BOT_PREFIX: '!',
|
BOT_PREFIX: '!',
|
||||||
|
@ -133,3 +136,4 @@ test('Start_GivenFoldersCommandsIsEmpty_ExpectFailure', () => {
|
||||||
|
|
||||||
expect(() => coreClient.start()).toThrow("FOLDERS_EVENTS is not defined in .env");
|
expect(() => coreClient.start()).toThrow("FOLDERS_EVENTS is not defined in .env");
|
||||||
});
|
});
|
||||||
|
});
|
|
@ -9,7 +9,8 @@ beforeEach(() => {
|
||||||
Util.prototype.loadCommand = jest.fn();
|
Util.prototype.loadCommand = jest.fn();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('OnMessage_GivenMessageIsValid_ExpectMessageSent', () => {
|
describe('OnMessage', () => {
|
||||||
|
test('Given Message Is Valid Expect Message Sent', () => {
|
||||||
process.env = {
|
process.env = {
|
||||||
BOT_TOKEN: 'TOKEN',
|
BOT_TOKEN: 'TOKEN',
|
||||||
BOT_PREFIX: '!',
|
BOT_PREFIX: '!',
|
||||||
|
@ -40,7 +41,7 @@ test('OnMessage_GivenMessageIsValid_ExpectMessageSent', () => {
|
||||||
expect(result.context?.message).toBe(message);
|
expect(result.context?.message).toBe(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('OnMessage_GivenGuildIsNull_ExpectFailedResult', () => {
|
test('Given Guild Is Null, Expect Failed Result', () => {
|
||||||
process.env = {
|
process.env = {
|
||||||
BOT_TOKEN: 'TOKEN',
|
BOT_TOKEN: 'TOKEN',
|
||||||
BOT_PREFIX: '!',
|
BOT_PREFIX: '!',
|
||||||
|
@ -66,7 +67,7 @@ test('OnMessage_GivenGuildIsNull_ExpectFailedResult', () => {
|
||||||
expect(result.message).toBe("Message was not sent in a guild, ignoring.");
|
expect(result.message).toBe("Message was not sent in a guild, ignoring.");
|
||||||
});
|
});
|
||||||
|
|
||||||
test('OnMessage_GivenAuthorIsBot_ExpectFailedResult', () => {
|
test('Given Author Is A Bot, Expect Failed Result', () => {
|
||||||
process.env = {
|
process.env = {
|
||||||
BOT_TOKEN: 'TOKEN',
|
BOT_TOKEN: 'TOKEN',
|
||||||
BOT_PREFIX: '!',
|
BOT_PREFIX: '!',
|
||||||
|
@ -92,7 +93,7 @@ test('OnMessage_GivenAuthorIsBot_ExpectFailedResult', () => {
|
||||||
expect(result.message).toBe("Message was sent by a bot, ignoring.");
|
expect(result.message).toBe("Message was sent by a bot, ignoring.");
|
||||||
});
|
});
|
||||||
|
|
||||||
test('OnMessage_GivenMessageContentsWasNotACommand_ExpectFailedResult', () => {
|
test('Given Message Content Was Not A Command, Expect Failed Result', () => {
|
||||||
process.env = {
|
process.env = {
|
||||||
BOT_TOKEN: 'TOKEN',
|
BOT_TOKEN: 'TOKEN',
|
||||||
BOT_PREFIX: '!',
|
BOT_PREFIX: '!',
|
||||||
|
@ -118,7 +119,7 @@ test('OnMessage_GivenMessageContentsWasNotACommand_ExpectFailedResult', () => {
|
||||||
expect(result.message).toBe("Message was not a command, ignoring.");
|
expect(result.message).toBe("Message was not a command, ignoring.");
|
||||||
});
|
});
|
||||||
|
|
||||||
test('OnMessage_GivenMessageHadNoCommandName_ExpectFailedResult', () => {
|
test('Given Message Had No Command Name, Expect Failed Result', () => {
|
||||||
process.env = {
|
process.env = {
|
||||||
BOT_TOKEN: 'TOKEN',
|
BOT_TOKEN: 'TOKEN',
|
||||||
BOT_PREFIX: '!',
|
BOT_PREFIX: '!',
|
||||||
|
@ -144,7 +145,7 @@ test('OnMessage_GivenMessageHadNoCommandName_ExpectFailedResult', () => {
|
||||||
expect(result.message).toBe("Command name was not found");
|
expect(result.message).toBe("Command name was not found");
|
||||||
});
|
});
|
||||||
|
|
||||||
test('OnMessage_GivenCommandFailedToExecute_ExpectFailedResult', () => {
|
test('Given Command Failed To Execute, Expect Failed Result', () => {
|
||||||
process.env = {
|
process.env = {
|
||||||
BOT_TOKEN: 'TOKEN',
|
BOT_TOKEN: 'TOKEN',
|
||||||
BOT_PREFIX: '!',
|
BOT_PREFIX: '!',
|
||||||
|
@ -169,8 +170,10 @@ test('OnMessage_GivenCommandFailedToExecute_ExpectFailedResult', () => {
|
||||||
expect(result.valid).toBeFalsy();
|
expect(result.valid).toBeFalsy();
|
||||||
expect(result.message).toBe("Command failed");
|
expect(result.message).toBe("Command failed");
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test('OnReady_ExpectConsoleLog', () => {
|
describe('OnReady', () => {
|
||||||
|
test('Expect Console Log', () => {
|
||||||
console.log = jest.fn();
|
console.log = jest.fn();
|
||||||
|
|
||||||
const events = new Events();
|
const events = new Events();
|
||||||
|
@ -179,3 +182,4 @@ test('OnReady_ExpectConsoleLog', () => {
|
||||||
|
|
||||||
expect(console.log).toBeCalledWith("Ready");
|
expect(console.log).toBeCalledWith("Ready");
|
||||||
});
|
});
|
||||||
|
});
|
|
@ -9,7 +9,8 @@ beforeEach(() => {
|
||||||
fs.existsSync = jest.fn();
|
fs.existsSync = jest.fn();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('LoadCommand_GivenSuccessfulExection_ExpectSuccessfulResult', () => {
|
describe('LoadCommand', () => {
|
||||||
|
test('Given Successful Exection, Expect Successful Result', () => {
|
||||||
process.env = {
|
process.env = {
|
||||||
BOT_TOKEN: 'TOKEN',
|
BOT_TOKEN: 'TOKEN',
|
||||||
BOT_PREFIX: '!',
|
BOT_PREFIX: '!',
|
||||||
|
@ -38,7 +39,7 @@ test('LoadCommand_GivenSuccessfulExection_ExpectSuccessfulResult', () => {
|
||||||
expect(result.valid).toBeTruthy();
|
expect(result.valid).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('LoadCommand_GivenMemberIsNull_ExpectFailedResult', () => {
|
test('Given Member Is Null, Expect Failed Result', () => {
|
||||||
process.env = {
|
process.env = {
|
||||||
BOT_TOKEN: 'TOKEN',
|
BOT_TOKEN: 'TOKEN',
|
||||||
BOT_PREFIX: '!',
|
BOT_PREFIX: '!',
|
||||||
|
@ -61,7 +62,7 @@ test('LoadCommand_GivenMemberIsNull_ExpectFailedResult', () => {
|
||||||
expect(result.message).toBe("Member is not part of message");
|
expect(result.message).toBe("Member is not part of message");
|
||||||
});
|
});
|
||||||
|
|
||||||
test('LoadCommand_GivenFolderDoesNotExist_ExpectFailedResult', () => {
|
test('Given Folder Does Not Exist, Expect Failed Result', () => {
|
||||||
process.env = {
|
process.env = {
|
||||||
BOT_TOKEN: 'TOKEN',
|
BOT_TOKEN: 'TOKEN',
|
||||||
BOT_PREFIX: '!',
|
BOT_PREFIX: '!',
|
||||||
|
@ -91,7 +92,7 @@ test('LoadCommand_GivenFolderDoesNotExist_ExpectFailedResult', () => {
|
||||||
expect(result.message).toBe("Command folder does not exist");
|
expect(result.message).toBe("Command folder does not exist");
|
||||||
});
|
});
|
||||||
|
|
||||||
test('LoadCommand_GivenFileDoesNotExist_ExpectFailedResult', () => {
|
test('Given File Does Not Exist, Expect Failed Result', () => {
|
||||||
process.env = {
|
process.env = {
|
||||||
BOT_TOKEN: 'TOKEN',
|
BOT_TOKEN: 'TOKEN',
|
||||||
BOT_PREFIX: '!',
|
BOT_PREFIX: '!',
|
||||||
|
@ -122,7 +123,7 @@ test('LoadCommand_GivenFileDoesNotExist_ExpectFailedResult', () => {
|
||||||
expect(result.message).toBe("File does not exist");
|
expect(result.message).toBe("File does not exist");
|
||||||
});
|
});
|
||||||
|
|
||||||
test('LoadCommand_GivenUserDoesHaveRole_ExpectSuccessfulResult', () => {
|
test('Given User Does Have Role, Expect Successful Result', () => {
|
||||||
process.env = {
|
process.env = {
|
||||||
BOT_TOKEN: 'TOKEN',
|
BOT_TOKEN: 'TOKEN',
|
||||||
BOT_PREFIX: '!',
|
BOT_PREFIX: '!',
|
||||||
|
@ -151,7 +152,7 @@ test('LoadCommand_GivenUserDoesHaveRole_ExpectSuccessfulResult', () => {
|
||||||
expect(result.valid).toBeTruthy();
|
expect(result.valid).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('LoadCommand_GivenUserDoesNotHaveRole_ExpectFailedResult', () => {
|
test('Given User Does Not Have Role, Expect Failed Result', () => {
|
||||||
process.env = {
|
process.env = {
|
||||||
BOT_TOKEN: 'TOKEN',
|
BOT_TOKEN: 'TOKEN',
|
||||||
BOT_PREFIX: '!',
|
BOT_PREFIX: '!',
|
||||||
|
@ -181,7 +182,7 @@ test('LoadCommand_GivenUserDoesNotHaveRole_ExpectFailedResult', () => {
|
||||||
expect(result.message).toBe("You require the `Moderator` role to run this command");
|
expect(result.message).toBe("You require the `Moderator` role to run this command");
|
||||||
});
|
});
|
||||||
|
|
||||||
test('LoadCommand_GivenCommandCategoryIsNull_ExpectSuccessfulResultStill', () => {
|
test('Given Command Category Is Null, Expect Successful Result', () => {
|
||||||
process.env = {
|
process.env = {
|
||||||
BOT_TOKEN: 'TOKEN',
|
BOT_TOKEN: 'TOKEN',
|
||||||
BOT_PREFIX: '!',
|
BOT_PREFIX: '!',
|
||||||
|
@ -209,8 +210,10 @@ test('LoadCommand_GivenCommandCategoryIsNull_ExpectSuccessfulResultStill', () =>
|
||||||
|
|
||||||
expect(result.valid).toBeTruthy();
|
expect(result.valid).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test('LoadEvents_GivenEventsAreLoaded_ExpectSuccessfulResult', () => {
|
describe('LoadEvents', () => {
|
||||||
|
test('Given Events Are Loaded, Expect Successful Result', () => {
|
||||||
process.env = {
|
process.env = {
|
||||||
BOT_TOKEN: 'TOKEN',
|
BOT_TOKEN: 'TOKEN',
|
||||||
BOT_PREFIX: '!',
|
BOT_PREFIX: '!',
|
||||||
|
@ -236,7 +239,7 @@ test('LoadEvents_GivenEventsAreLoaded_ExpectSuccessfulResult', () => {
|
||||||
expect(clientOn).toBeCalledTimes(13);
|
expect(clientOn).toBeCalledTimes(13);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('LoadEvents_GivenNoEventsFound_ExpectSuccessfulResultStill', () => {
|
test('Given No Events Found, Expect Successful Result', () => {
|
||||||
process.env = {
|
process.env = {
|
||||||
BOT_TOKEN: 'TOKEN',
|
BOT_TOKEN: 'TOKEN',
|
||||||
BOT_PREFIX: '!',
|
BOT_PREFIX: '!',
|
||||||
|
@ -262,7 +265,7 @@ test('LoadEvents_GivenNoEventsFound_ExpectSuccessfulResultStill', () => {
|
||||||
expect(clientOn).toBeCalledTimes(0);
|
expect(clientOn).toBeCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('LoadEvents_GivenEventFolderDoesNotExist_FailedResult', () => {
|
test('Given Event Folder Does Not Exist, Expect Failed Result', () => {
|
||||||
process.env = {
|
process.env = {
|
||||||
BOT_TOKEN: 'TOKEN',
|
BOT_TOKEN: 'TOKEN',
|
||||||
BOT_PREFIX: '!',
|
BOT_PREFIX: '!',
|
||||||
|
@ -285,3 +288,4 @@ test('LoadEvents_GivenEventFolderDoesNotExist_FailedResult', () => {
|
||||||
expect(result.valid).toBeFalsy();
|
expect(result.valid).toBeFalsy();
|
||||||
expect(result.message).toBe("Event folder does not exist");
|
expect(result.message).toBe("Event folder does not exist");
|
||||||
});
|
});
|
||||||
|
});
|
Reference in a new issue