Update tests

This commit is contained in:
Ethan Lane 2021-09-26 14:32:56 +01:00
parent 3a9f1965ae
commit 799b04e936
Signed by: Vylpes
GPG key ID: EED233CC06D12504
5 changed files with 42 additions and 42 deletions

View file

@ -1,7 +1,7 @@
import { Command } from "../../../src/type/command"; import { Command } from "../../../src/type/command";
export class noCategory extends Command { export default class noCategory extends Command {
constructor() { constructor() {
super(); super();
} }
} }

View file

@ -1,8 +1,8 @@
import { Command } from "../../../src/type/command"; import { Command } from "../../../src/type/command";
export class normal extends Command { export default class normal extends Command {
constructor() { constructor() {
super(); super();
this._category = "General"; this._category = "General";
} }
} }

View file

@ -1,8 +1,8 @@
import { Command } from "../../../src/type/command"; import { Command } from "../../../src/type/command";
export class roles extends Command { export default class roles extends Command {
constructor() { constructor() {
super(); super();
this._roles = [ "Moderator" ]; this._roles = [ "Moderator" ];
} }
} }

View file

@ -10,7 +10,7 @@ beforeEach(() => {
}); });
describe('OnMessage', () => { describe('OnMessage', () => {
test('Given Message Is Valid Expect Message Sent', () => { test('Given Message Is Valid Expect Message Sent', async () => {
process.env = { process.env = {
BOT_TOKEN: 'TOKEN', BOT_TOKEN: 'TOKEN',
BOT_PREFIX: '!', BOT_PREFIX: '!',
@ -30,7 +30,7 @@ describe('OnMessage', () => {
const events = new Events(); const events = new Events();
const result = events.onMessage(message); const result = await events.onMessage(message);
expect(result.valid).toBeTruthy(); expect(result.valid).toBeTruthy();
@ -41,7 +41,7 @@ describe('OnMessage', () => {
expect(result.context?.message).toBe(message); expect(result.context?.message).toBe(message);
}); });
test('Given Guild Is Null, Expect Failed Result', () => { test('Given Guild Is Null, Expect Failed Result', async () => {
process.env = { process.env = {
BOT_TOKEN: 'TOKEN', BOT_TOKEN: 'TOKEN',
BOT_PREFIX: '!', BOT_PREFIX: '!',
@ -61,13 +61,13 @@ describe('OnMessage', () => {
const events = new Events(); const events = new Events();
const result = events.onMessage(message); const result = await events.onMessage(message);
expect(result.valid).toBeFalsy(); expect(result.valid).toBeFalsy();
expect(result.message).toBe("Message was not sent in a guild, ignoring."); expect(result.message).toBe("Message was not sent in a guild, ignoring.");
}); });
test('Given Author Is A Bot, Expect Failed Result', () => { test('Given Author Is A Bot, Expect Failed Result', async () => {
process.env = { process.env = {
BOT_TOKEN: 'TOKEN', BOT_TOKEN: 'TOKEN',
BOT_PREFIX: '!', BOT_PREFIX: '!',
@ -87,13 +87,13 @@ describe('OnMessage', () => {
const events = new Events(); const events = new Events();
const result = events.onMessage(message); const result = await events.onMessage(message);
expect(result.valid).toBeFalsy(); expect(result.valid).toBeFalsy();
expect(result.message).toBe("Message was sent by a bot, ignoring."); expect(result.message).toBe("Message was sent by a bot, ignoring.");
}); });
test('Given Message Content Was Not A Command, Expect Failed Result', () => { test('Given Message Content Was Not A Command, Expect Failed Result', async () => {
process.env = { process.env = {
BOT_TOKEN: 'TOKEN', BOT_TOKEN: 'TOKEN',
BOT_PREFIX: '!', BOT_PREFIX: '!',
@ -113,13 +113,13 @@ describe('OnMessage', () => {
const events = new Events(); const events = new Events();
const result = events.onMessage(message); const result = await events.onMessage(message);
expect(result.valid).toBeFalsy(); expect(result.valid).toBeFalsy();
expect(result.message).toBe("Message was not a command, ignoring."); expect(result.message).toBe("Message was not a command, ignoring.");
}); });
test('Given Message Had No Command Name, Expect Failed Result', () => { test('Given Message Had No Command Name, Expect Failed Result', async () => {
process.env = { process.env = {
BOT_TOKEN: 'TOKEN', BOT_TOKEN: 'TOKEN',
BOT_PREFIX: '!', BOT_PREFIX: '!',
@ -139,13 +139,13 @@ describe('OnMessage', () => {
const events = new Events(); const events = new Events();
const result = events.onMessage(message); const result = await events.onMessage(message);
expect(result.valid).toBeFalsy(); expect(result.valid).toBeFalsy();
expect(result.message).toBe("Command name was not found"); expect(result.message).toBe("Command name was not found");
}); });
test('Given Command Failed To Execute, Expect Failed Result', () => { test('Given Command Failed To Execute, Expect Failed Result', async () => {
process.env = { process.env = {
BOT_TOKEN: 'TOKEN', BOT_TOKEN: 'TOKEN',
BOT_PREFIX: '!', BOT_PREFIX: '!',
@ -165,7 +165,7 @@ describe('OnMessage', () => {
const events = new Events(); const events = new Events();
const result = events.onMessage(message); const result = await events.onMessage(message);
expect(result.valid).toBeFalsy(); expect(result.valid).toBeFalsy();
expect(result.message).toBe("Command failed"); expect(result.message).toBe("Command failed");
@ -182,4 +182,4 @@ describe('OnReady', () => {
expect(console.log).toBeCalledWith("Ready"); expect(console.log).toBeCalledWith("Ready");
}); });
}); });

View file

@ -10,7 +10,7 @@ beforeEach(() => {
}); });
describe('LoadCommand', () => { describe('LoadCommand', () => {
test('Given Successful Exection, Expect Successful Result', () => { test('Given Successful Exection, Expect Successful Result', async () => {
process.env = { process.env = {
BOT_TOKEN: 'TOKEN', BOT_TOKEN: 'TOKEN',
BOT_PREFIX: '!', BOT_PREFIX: '!',
@ -34,12 +34,12 @@ describe('LoadCommand', () => {
const util = new Util(); const util = new Util();
const result = util.loadCommand("normal", [ "first" ], message); const result = await util.loadCommand("normal", [ "first" ], message);
expect(result.valid).toBeTruthy(); expect(result.valid).toBeTruthy();
}); });
test('Given Member Is Null, Expect Failed Result', () => { test('Given Member Is Null, Expect Failed Result', async () => {
process.env = { process.env = {
BOT_TOKEN: 'TOKEN', BOT_TOKEN: 'TOKEN',
BOT_PREFIX: '!', BOT_PREFIX: '!',
@ -56,13 +56,13 @@ describe('LoadCommand', () => {
const util = new Util(); const util = new Util();
const result = util.loadCommand("normal", [ "first" ], message); const result = await util.loadCommand("normal", [ "first" ], message);
expect(result.valid).toBeFalsy(); expect(result.valid).toBeFalsy();
expect(result.message).toBe("Member is not part of message"); expect(result.message).toBe("Member is not part of message");
}); });
test('Given Folder Does Not Exist, Expect Failed Result', () => { test('Given Folder Does Not Exist, Expect Failed Result', async () => {
process.env = { process.env = {
BOT_TOKEN: 'TOKEN', BOT_TOKEN: 'TOKEN',
BOT_PREFIX: '!', BOT_PREFIX: '!',
@ -86,13 +86,13 @@ describe('LoadCommand', () => {
const util = new Util(); const util = new Util();
const result = util.loadCommand("normal", [ "first" ], message); const result = await util.loadCommand("normal", [ "first" ], message);
expect(result.valid).toBeFalsy(); expect(result.valid).toBeFalsy();
expect(result.message).toBe("Command folder does not exist"); expect(result.message).toBe("Command folder does not exist");
}); });
test('Given File Does Not Exist, Expect Failed Result', () => { test('Given File Does Not Exist, Expect Failed Result', async () => {
process.env = { process.env = {
BOT_TOKEN: 'TOKEN', BOT_TOKEN: 'TOKEN',
BOT_PREFIX: '!', BOT_PREFIX: '!',
@ -117,13 +117,13 @@ describe('LoadCommand', () => {
const util = new Util(); const util = new Util();
const result = util.loadCommand("normal", [ "first" ], message); const result = await util.loadCommand("normal", [ "first" ], message);
expect(result.valid).toBeFalsy(); expect(result.valid).toBeFalsy();
expect(result.message).toBe("File does not exist"); expect(result.message).toBe("File does not exist");
}); });
test('Given User Does Have Role, Expect Successful Result', () => { test('Given User Does Have Role, Expect Successful Result', async () => {
process.env = { process.env = {
BOT_TOKEN: 'TOKEN', BOT_TOKEN: 'TOKEN',
BOT_PREFIX: '!', BOT_PREFIX: '!',
@ -147,12 +147,12 @@ describe('LoadCommand', () => {
const util = new Util(); const util = new Util();
const result = util.loadCommand("roles", [ "first" ], message); const result = await util.loadCommand("roles", [ "first" ], message);
expect(result.valid).toBeTruthy(); expect(result.valid).toBeTruthy();
}); });
test('Given User Does Not Have Role, Expect Failed Result', () => { test('Given User Does Not Have Role, Expect Failed Result', async () => {
process.env = { process.env = {
BOT_TOKEN: 'TOKEN', BOT_TOKEN: 'TOKEN',
BOT_PREFIX: '!', BOT_PREFIX: '!',
@ -176,13 +176,13 @@ describe('LoadCommand', () => {
const util = new Util(); const util = new Util();
const result = util.loadCommand("roles", [ "first" ], message); const result = await util.loadCommand("roles", [ "first" ], message);
expect(result.valid).toBeFalsy(); expect(result.valid).toBeFalsy();
expect(result.message).toBe("You require the `Moderator` role to run this command"); expect(result.message).toBe("You require the `Moderator` role to run this command");
}); });
test('Given Command Category Is Null, Expect Successful Result', () => { test('Given Command Category Is Null, Expect Successful Result', async () => {
process.env = { process.env = {
BOT_TOKEN: 'TOKEN', BOT_TOKEN: 'TOKEN',
BOT_PREFIX: '!', BOT_PREFIX: '!',
@ -206,12 +206,12 @@ describe('LoadCommand', () => {
const util = new Util(); const util = new Util();
const result = util.loadCommand("noCategory", [ "first" ], message); const result = await util.loadCommand("noCategory", [ "first" ], message);
expect(result.valid).toBeTruthy(); expect(result.valid).toBeTruthy();
}); });
test('Given command is set to disabled, Expect command to not fire', () => { test('Given command is set to disabled, Expect command to not fire', async () => {
process.env = { process.env = {
BOT_TOKEN: 'TOKEN', BOT_TOKEN: 'TOKEN',
BOT_PREFIX: '!', BOT_PREFIX: '!',
@ -239,14 +239,14 @@ describe('LoadCommand', () => {
const util = new Util(); const util = new Util();
const result = util.loadCommand("normal", [ "first" ], message); const result = await util.loadCommand("normal", [ "first" ], message);
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"); expect(messageReply).toBeCalledWith("disabled");
}); });
test('Given command COMMANDS_DISABLED_MESSAGE is empty, Expect default message sent', () => { test('Given command COMMANDS_DISABLED_MESSAGE is empty, Expect default message sent', async () => {
process.env = { process.env = {
BOT_TOKEN: 'TOKEN', BOT_TOKEN: 'TOKEN',
BOT_PREFIX: '!', BOT_PREFIX: '!',
@ -273,14 +273,14 @@ describe('LoadCommand', () => {
const util = new Util(); const util = new Util();
const result = util.loadCommand("normal", [ "first" ], message); const result = await util.loadCommand("normal", [ "first" ], message);
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("This 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', async () => {
process.env = { process.env = {
BOT_TOKEN: 'TOKEN', BOT_TOKEN: 'TOKEN',
BOT_PREFIX: '!', BOT_PREFIX: '!',
@ -305,12 +305,12 @@ describe('LoadCommand', () => {
const util = new Util(); const util = new Util();
const result = util.loadCommand("normal", [ "first" ], message); const result = await util.loadCommand("normal", [ "first" ], message);
expect(result.valid).toBeTruthy(); expect(result.valid).toBeTruthy();
}); });
test('Given a different command is disabled with this one, Expect command to not fire', () => { test('Given a different command is disabled with this one, Expect command to not fire', async () => {
process.env = { process.env = {
BOT_TOKEN: 'TOKEN', BOT_TOKEN: 'TOKEN',
BOT_PREFIX: '!', BOT_PREFIX: '!',
@ -335,7 +335,7 @@ describe('LoadCommand', () => {
const util = new Util(); const util = new Util();
const result = util.loadCommand("normal", [ "first" ], message); const result = await util.loadCommand("normal", [ "first" ], message);
expect(result.valid).toBeFalsy(); expect(result.valid).toBeFalsy();
expect(result.message).toBe("Command is disabled"); expect(result.message).toBe("Command is disabled");
@ -418,4 +418,4 @@ describe('LoadEvents', () => {
expect(result.valid).toBeFalsy(); expect(result.valid).toBeFalsy();
expect(result.message).toBe("Event folder does not exist"); expect(result.message).toBe("Event folder does not exist");
}); });
}); });