v2.0 #55
3 changed files with 96 additions and 1 deletions
|
@ -1,5 +1,8 @@
|
|||
import { Command } from "../../../src/type/command";
|
||||
|
||||
export class name extends Command {
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this._category = "General";
|
||||
}
|
||||
}
|
8
tests/__mocks/commands/noCategory.ts
Normal file
8
tests/__mocks/commands/noCategory.ts
Normal file
|
@ -0,0 +1,8 @@
|
|||
import { Command } from "../../../src/type/command";
|
||||
|
||||
export class noCategory extends Command {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
}
|
||||
}
|
|
@ -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',
|
||||
|
|
Reference in a new issue