Update tests
This commit is contained in:
parent
3392e6f031
commit
b10ac37007
2 changed files with 38 additions and 1 deletions
|
@ -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.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_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.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("message", this._events.onMessage);
|
||||||
super.on("ready", this._events.onReady);
|
super.on("ready", this._events.onReady);
|
||||||
|
|
|
@ -218,6 +218,7 @@ describe('LoadCommand', () => {
|
||||||
FOLDERS_COMMANDS: 'commands',
|
FOLDERS_COMMANDS: 'commands',
|
||||||
FOLDERS_EVENTS: 'events',
|
FOLDERS_EVENTS: 'events',
|
||||||
COMMANDS_DISABLED: 'normal',
|
COMMANDS_DISABLED: 'normal',
|
||||||
|
COMMANDS_DISABLED_MESSAGE: 'disabled',
|
||||||
}
|
}
|
||||||
|
|
||||||
process.cwd = jest.fn().mockReturnValue("../../tests/__mocks");
|
process.cwd = jest.fn().mockReturnValue("../../tests/__mocks");
|
||||||
|
@ -233,6 +234,8 @@ describe('LoadCommand', () => {
|
||||||
},
|
},
|
||||||
reply: jest.fn(),
|
reply: jest.fn(),
|
||||||
} as unknown as Message;
|
} as unknown as Message;
|
||||||
|
|
||||||
|
const messageReply = jest.spyOn(message, 'reply');
|
||||||
|
|
||||||
const util = new Util();
|
const util = new Util();
|
||||||
|
|
||||||
|
@ -240,6 +243,41 @@ describe('LoadCommand', () => {
|
||||||
|
|
||||||
expect(result.valid).toBeFalsy();
|
expect(result.valid).toBeFalsy();
|
||||||
expect(result.message).toBe("Command is disabled");
|
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', () => {
|
test('Given a different command is disabled, Expect command to still fire', () => {
|
||||||
|
|
Reference in a new issue