Update coverage

This commit is contained in:
Ethan Lane 2021-12-24 16:20:58 +00:00
parent 1223e35bde
commit aa81b125ac
3 changed files with 71 additions and 0 deletions

View file

@ -15,6 +15,14 @@ export class CoreClient extends Client {
private _events: Events; private _events: Events;
private _util: Util; private _util: Util;
public get commandItems(): ICommandItem[] {
return this._commandItems;
}
public get eventItems(): IEventItem[] {
return this._eventItems;
}
constructor() { constructor() {
super(); super();
dotenv.config(); dotenv.config();

View file

@ -4,6 +4,11 @@ import { Client } from "discord.js";
import * as dotenv from "dotenv"; import * as dotenv from "dotenv";
import { Events } from "../../src/client/events"; import { Events } from "../../src/client/events";
import { Util } from "../../src/client/util"; import { Util } from "../../src/client/util";
import { Command } from "../../src/type/command";
import ICommandItem from "../../src/contracts/ICommandItem";
import { mock } from "jest-mock-extended";
import IEventItem from "../../src/contracts/IEventItem";
import { Event } from "../../src/type/event";
jest.mock("discord.js"); jest.mock("discord.js");
jest.mock("dotenv"); jest.mock("dotenv");
@ -137,3 +142,28 @@ describe('Start', () => {
expect(() => coreClient.start()).toThrow("FOLDERS_EVENTS is not defined in .env"); expect(() => coreClient.start()).toThrow("FOLDERS_EVENTS is not defined in .env");
}); });
}); });
describe('RegisterCommand', () => {
test('Expect command added to register', () => {
const cmd = mock<Command>();
const client = new CoreClient();
client.RegisterCommand("test", cmd);
expect(client.commandItems.length).toBe(1);
expect(client.commandItems[0].Name).toBe("test");
expect(client.commandItems[0].Command).toBe(cmd);
});
});
describe('RegisterEvent', () => {
test('Expect event added to register', () => {
const evt = mock<Event>();
const client = new CoreClient();
client.RegisterEvent(evt);
expect(client.eventItems.length).toBe(1);
expect(client.eventItems[0].Event).toBe(evt);
});
});

View file

@ -302,6 +302,39 @@ describe('LoadCommand', () => {
expect(cmd.execute).toBeCalled(); expect(cmd.execute).toBeCalled();
expect(otherCmd.execute).not.toBeCalled(); expect(otherCmd.execute).not.toBeCalled();
}); });
test('Given command is not found in register, expect command not found error', () => {
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 commands: ICommandItem[] = [];
const util = new Util();
const result = util.loadCommand("test", [ "first" ], message, commands);
expect(result.valid).toBeFalsy();
expect(result.message).toBe('Command not found');
expect(message.reply).toBeCalledWith('Command not found');
});
}); });
describe('LoadEvents', () => { describe('LoadEvents', () => {