From b10ac370079f8d75ba1adca008f727c988a94987 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Fri, 24 Sep 2021 18:52:12 +0100 Subject: [PATCH] Update tests --- src/client/client.ts | 1 - tests/client/util.test.ts | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/client/client.ts b/src/client/client.ts index 2eb5a37..9337496 100644 --- a/src/client/client.ts +++ b/src/client/client.ts @@ -21,7 +21,6 @@ export class CoreClient extends Client { if (!process.env.BOT_PREFIX) throw "BOT_PREFIX is not defined in .env"; if (!process.env.FOLDERS_COMMANDS) throw "FOLDERS_COMMANDS is not defined in .env"; if (!process.env.FOLDERS_EVENTS) throw "FOLDERS_EVENTS is not defined in .env"; - if (!process.env.COMMANDS_DISABLED_MESSAGE) throw "COMMANDS_DISABLED_MESSAGE is not defined in .env"; super.on("message", this._events.onMessage); super.on("ready", this._events.onReady); diff --git a/tests/client/util.test.ts b/tests/client/util.test.ts index 759490f..9787ed4 100644 --- a/tests/client/util.test.ts +++ b/tests/client/util.test.ts @@ -218,6 +218,7 @@ describe('LoadCommand', () => { FOLDERS_COMMANDS: 'commands', FOLDERS_EVENTS: 'events', COMMANDS_DISABLED: 'normal', + COMMANDS_DISABLED_MESSAGE: 'disabled', } process.cwd = jest.fn().mockReturnValue("../../tests/__mocks"); @@ -233,6 +234,8 @@ describe('LoadCommand', () => { }, reply: jest.fn(), } as unknown as Message; + + const messageReply = jest.spyOn(message, 'reply'); const util = new Util(); @@ -240,6 +243,41 @@ describe('LoadCommand', () => { expect(result.valid).toBeFalsy(); expect(result.message).toBe("Command is disabled"); + expect(messageReply).toBeCalledWith("disabled"); + }); + + test('Given command COMMANDS_DISABLED_MESSAGE is empty, Expect default message sent', () => { + process.env = { + BOT_TOKEN: 'TOKEN', + BOT_PREFIX: '!', + FOLDERS_COMMANDS: 'commands', + FOLDERS_EVENTS: 'events', + COMMANDS_DISABLED: 'normal', + } + + 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 messageReply = jest.spyOn(message, 'reply'); + + const util = new Util(); + + const result = util.loadCommand("normal", [ "first" ], message); + + expect(result.valid).toBeFalsy(); + expect(result.message).toBe("Command is disabled"); + expect(messageReply).toBeCalledWith("This command is disabled."); }); test('Given a different command is disabled, Expect command to still fire', () => {