diff --git a/tests/__mocks/commands/name.ts b/tests/__mocks/commands/name.ts index ab5fcd2..155ee8a 100644 --- a/tests/__mocks/commands/name.ts +++ b/tests/__mocks/commands/name.ts @@ -1,5 +1,8 @@ import { Command } from "../../../src/type/command"; export class name extends Command { - + constructor() { + super(); + this._category = "General"; + } } \ No newline at end of file diff --git a/tests/__mocks/commands/noCategory.ts b/tests/__mocks/commands/noCategory.ts new file mode 100644 index 0000000..929ee99 --- /dev/null +++ b/tests/__mocks/commands/noCategory.ts @@ -0,0 +1,8 @@ +import { Command } from "../../../src/type/command"; + +export class noCategory extends Command { + constructor() { + super(); + + } +} \ No newline at end of file diff --git a/tests/client/util.test.ts b/tests/client/util.test.ts index 3dd61d1..36b0267 100644 --- a/tests/client/util.test.ts +++ b/tests/client/util.test.ts @@ -122,6 +122,35 @@ test('LoadCommand_GivenFileDoesNotExist_ExpectFailedResult', () => { expect(result.message).toBe("File does not exist"); }); +test('LoadCommand_GivenUserDoesHaveRole_ExpectSuccessfulResult', () => { + process.env = { + BOT_TOKEN: 'TOKEN', + BOT_PREFIX: '!', + FOLDERS_COMMANDS: 'commands', + FOLDERS_EVENTS: 'events', + } + + process.cwd = jest.fn().mockReturnValue("../../tests/__mocks"); + fs.existsSync = jest.fn().mockReturnValue(true); + + const message = { + member: { + roles: { + cache: { + find: jest.fn().mockReturnValue(true), + } + }, + }, + reply: jest.fn(), + } as unknown as Message; + + const util = new Util(); + + const result = util.loadCommand("roles", [ "first" ], message); + + expect(result.valid).toBeTruthy(); +}); + test('LoadCommand_GivenUserDoesNotHaveRole_ExpectFailedResult', () => { process.env = { BOT_TOKEN: 'TOKEN', @@ -152,6 +181,35 @@ test('LoadCommand_GivenUserDoesNotHaveRole_ExpectFailedResult', () => { expect(result.message).toBe("You require the `Moderator` role to run this command"); }); +test('LoadCommand_GivenCommandCategoryIsNull_ExpectSuccessfulResultStill', () => { + process.env = { + BOT_TOKEN: 'TOKEN', + BOT_PREFIX: '!', + FOLDERS_COMMANDS: 'commands', + FOLDERS_EVENTS: 'events', + } + + process.cwd = jest.fn().mockReturnValue("../../tests/__mocks"); + fs.existsSync = jest.fn().mockReturnValue(true); + + const message = { + member: { + roles: { + cache: { + find: jest.fn().mockReturnValue(true), + } + }, + }, + reply: jest.fn(), + } as unknown as Message; + + const util = new Util(); + + const result = util.loadCommand("noCategory", [ "first" ], message); + + expect(result.valid).toBeTruthy(); +}); + test('LoadEvents_GivenEventsAreLoaded_ExpectSuccessfulResult', () => { process.env = { BOT_TOKEN: 'TOKEN', @@ -178,6 +236,32 @@ test('LoadEvents_GivenEventsAreLoaded_ExpectSuccessfulResult', () => { expect(clientOn).toBeCalledTimes(13); }); +test('LoadEvents_GivenNoEventsFound_ExpectSuccessfulResultStill', () => { + process.env = { + BOT_TOKEN: 'TOKEN', + BOT_PREFIX: '!', + FOLDERS_COMMANDS: 'commands', + FOLDERS_EVENTS: 'events', + } + + process.cwd = jest.fn().mockReturnValue("../../tests/__mocks"); + fs.existsSync = jest.fn().mockReturnValue(true); + fs.readdirSync = jest.fn().mockReturnValue(["name"]); + + const client = { + on: jest.fn(), + } as unknown as Client; + + const util = new Util(); + + const result = util.loadEvents(client); + + const clientOn = jest.spyOn(client, 'on'); + + expect(result.valid).toBeTruthy(); + expect(clientOn).toBeCalledTimes(0); +}); + test('LoadEvents_GivenEventFolderDoesNotExist_FailedResult', () => { process.env = { BOT_TOKEN: 'TOKEN',