Tests and CI #44

Merged
Vylpes merged 17 commits from feature/tests into develop 2021-08-21 16:00:28 +01:00
3 changed files with 96 additions and 1 deletions
Showing only changes of commit f11f3954a1 - Show all commits

View file

@ -1,5 +1,8 @@
VylpesTester commented 2021-08-21 15:07:46 +01:00 (Migrated from github.com)
Review

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
VylpesTester commented 2021-08-21 15:07:46 +01:00 (Migrated from github.com)
Review

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 {
VylpesTester commented 2021-08-21 15:07:46 +01:00 (Migrated from github.com)
Review

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() {
VylpesTester commented 2021-08-21 15:07:46 +01:00 (Migrated from github.com)
Review

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();
VylpesTester commented 2021-08-21 15:07:46 +01:00 (Migrated from github.com)
Review

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";
VylpesTester commented 2021-08-21 15:07:46 +01:00 (Migrated from github.com)
Review

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
}
VylpesTester commented 2021-08-21 15:07:46 +01:00 (Migrated from github.com)
Review

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
}

View file

@ -0,0 +1,8 @@
VylpesTester commented 2021-08-21 15:06:40 +01:00 (Migrated from github.com)
Review

Empty line

Empty line
VylpesTester commented 2021-08-21 15:06:40 +01:00 (Migrated from github.com)
Review

Empty line

Empty line
import { Command } from "../../../src/type/command";
VylpesTester commented 2021-08-21 15:06:40 +01:00 (Migrated from github.com)
Review

Empty line

Empty line
VylpesTester commented 2021-08-21 15:06:40 +01:00 (Migrated from github.com)
Review

Empty line

Empty line
export class noCategory extends Command {
VylpesTester commented 2021-08-21 15:06:40 +01:00 (Migrated from github.com)
Review

Empty line

Empty line
constructor() {
VylpesTester commented 2021-08-21 15:06:40 +01:00 (Migrated from github.com)
Review

Empty line

Empty line
super();
VylpesTester commented 2021-08-21 15:06:40 +01:00 (Migrated from github.com)
Review

Empty line

Empty line
VylpesTester commented 2021-08-21 15:06:40 +01:00 (Migrated from github.com)
Review

Empty line

Empty line
}
VylpesTester commented 2021-08-21 15:06:40 +01:00 (Migrated from github.com)
Review

Empty line

Empty line
}
VylpesTester commented 2021-08-21 15:06:40 +01:00 (Migrated from github.com)
Review

Empty line

Empty line

View file

@ -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',