Tests and CI #44
|
@ -1,5 +1,8 @@
|
|||
This should probably be renamed, such as "normal", to indicate its the normal command mock, without anything changed This should probably be renamed, such as "normal", to indicate its the normal command mock, without anything changed
|
||||
import { Command } from "../../../src/type/command";
|
||||
|
||||
export class name extends Command {
|
||||
|
||||
This should probably be renamed, such as "normal", to indicate its the normal command mock, without anything changed This should probably be renamed, such as "normal", to indicate its the normal command mock, without anything changed
|
||||
constructor() {
|
||||
This should probably be renamed, such as "normal", to indicate its the normal command mock, without anything changed This should probably be renamed, such as "normal", to indicate its the normal command mock, without anything changed
|
||||
super();
|
||||
This should probably be renamed, such as "normal", to indicate its the normal command mock, without anything changed This should probably be renamed, such as "normal", to indicate its the normal command mock, without anything changed
|
||||
this._category = "General";
|
||||
This should probably be renamed, such as "normal", to indicate its the normal command mock, without anything changed This should probably be renamed, such as "normal", to indicate its the normal command mock, without anything changed
|
||||
}
|
||||
This should probably be renamed, such as "normal", to indicate its the normal command mock, without anything changed This should probably be renamed, such as "normal", to indicate its the normal command mock, without anything changed
|
||||
}
|
8
tests/__mocks/commands/noCategory.ts
Normal file
|
@ -0,0 +1,8 @@
|
|||
Empty line Empty line
Empty line Empty line
|
||||
import { Command } from "../../../src/type/command";
|
||||
Empty line Empty line
|
||||
|
||||
Empty line Empty line
|
||||
export class noCategory extends Command {
|
||||
Empty line Empty line
|
||||
constructor() {
|
||||
Empty line Empty line
|
||||
super();
|
||||
Empty line Empty line
|
||||
|
||||
Empty line Empty line
|
||||
}
|
||||
Empty line Empty line
|
||||
}
|
||||
Empty line Empty line
|
|
@ -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',
|
||||
|
|
This should probably be renamed, such as "normal", to indicate its the normal command mock, without anything changed