From a3230cad201b9c60be13eee3815ece49bb548d60 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Wed, 22 Sep 2021 19:59:40 +0100 Subject: [PATCH] Add tests --- tests/client/util.test.ts | 92 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/tests/client/util.test.ts b/tests/client/util.test.ts index f99668d..759490f 100644 --- a/tests/client/util.test.ts +++ b/tests/client/util.test.ts @@ -210,6 +210,98 @@ describe('LoadCommand', () => { expect(result.valid).toBeTruthy(); }); + + test('Given command is set to disabled, Expect command to not fire', () => { + 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 util = new Util(); + + const result = util.loadCommand("normal", [ "first" ], message); + + expect(result.valid).toBeFalsy(); + expect(result.message).toBe("Command is disabled"); + }); + + test('Given a different command is disabled, Expect command to still fire', () => { + process.env = { + BOT_TOKEN: 'TOKEN', + BOT_PREFIX: '!', + FOLDERS_COMMANDS: 'commands', + FOLDERS_EVENTS: 'events', + COMMANDS_DISABLED: 'anything', + } + + 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("normal", [ "first" ], message); + + expect(result.valid).toBeTruthy(); + }); + + test('Given a different command is disabled with this one, Expect command to not fire', () => { + process.env = { + BOT_TOKEN: 'TOKEN', + BOT_PREFIX: '!', + FOLDERS_COMMANDS: 'commands', + FOLDERS_EVENTS: 'events', + COMMANDS_DISABLED: 'normal,anything,', + } + + 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("normal", [ "first" ], message); + + expect(result.valid).toBeFalsy(); + expect(result.message).toBe("Command is disabled"); + }); }); describe('LoadEvents', () => {