Tests and CI #44
|
@ -1 +1,2 @@
|
|||
tests
|
||||
node_modules
|
||||
dist
|
50
.eslintrc
|
@ -1,44 +1,14 @@
|
|||
{
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 6
|
||||
},
|
||||
"extends": [
|
||||
"eslint:recommended"
|
||||
"root": true,
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"plugins": [
|
||||
"@typescript-eslint"
|
||||
],
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/eslint-recommended",
|
||||
"plugin:@typescript-eslint/recommended"
|
||||
],
|
||||
"rules": {
|
||||
"camelcase": "error",
|
||||
"brace-style": [
|
||||
"error",
|
||||
"1tbs"
|
||||
],
|
||||
"comma-dangle": [
|
||||
"error",
|
||||
"never"
|
||||
],
|
||||
"comma-spacing": [
|
||||
"error",
|
||||
{
|
||||
"before": false,
|
||||
"after": true
|
||||
}
|
||||
],
|
||||
"comma-style": [
|
||||
"error",
|
||||
"last"
|
||||
],
|
||||
"arrow-body-style": [
|
||||
"error",
|
||||
"as-needed"
|
||||
],
|
||||
"arrow-parens": [
|
||||
"error",
|
||||
"as-needed"
|
||||
],
|
||||
"arrow-spacing": "error",
|
||||
"no-var": "error",
|
||||
"prefer-template": "error",
|
||||
"prefer-const": "error"
|
||||
},
|
||||
"globals": {
|
||||
"exports": "writable",
|
||||
"module": "writable",
|
||||
|
@ -46,4 +16,4 @@
|
|||
"process": "writable",
|
||||
"console": "writable"
|
||||
}
|
||||
}
|
||||
}
|
4
.gitignore
vendored
|
@ -108,8 +108,8 @@ commands/
|
|||
events/
|
||||
/bot.ts
|
||||
|
||||
!tests/commands/
|
||||
!tests/events/
|
||||
!tests/__mocks/commands
|
||||
!tests/__mocks/events
|
||||
|
||||
# Linux Environment Files
|
||||
*.swp
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
/** @type {import('@ts-jest/dist/types').InitialOptionsTsJest} */
|
||||
module.exports = {
|
||||
testEnvironment: 'node'
|
||||
}
|
||||
preset: 'ts-jest',
|
||||
testEnvironment: 'node',
|
||||
};
|
|
@ -6,8 +6,7 @@
|
|||
"scripts": {
|
||||
"build": "tsc",
|
||||
"test": "jest --coverage",
|
||||
"lint": "eslint .",
|
||||
"lint:fix": "eslint . --fix"
|
||||
"lint": "eslint ."
|
||||
},
|
||||
"author": "Vylpes",
|
||||
"license": "MIT",
|
||||
|
@ -25,7 +24,13 @@
|
|||
],
|
||||
"repository": "github:vylpes/vylbot-core",
|
||||
"devDependencies": {
|
||||
"@types/jest": "^26.0.24",
|
||||
"@types/node": "^16.3.2",
|
||||
"@typescript-eslint/eslint-plugin": "^4.29.2",
|
||||
"@typescript-eslint/parser": "^4.29.2",
|
||||
"eslint": "^7.32.0",
|
||||
"jest": "^27.0.6",
|
||||
"ts-jest": "^27.0.4",
|
||||
"typescript": "^4.3.5"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,11 +21,6 @@ export class Events {
|
|||
// Emit when a message is sent
|
||||
// Used to check for commands
|
||||
public onMessage(message: Message): IEventResponse {
|
||||
if (!message) return {
|
||||
valid: false,
|
||||
message: "Message was not supplied.",
|
||||
};
|
||||
|
||||
if (!message.guild) return {
|
||||
valid: false,
|
||||
message: "Message was not sent in a guild, ignoring.",
|
||||
|
@ -50,7 +45,7 @@ export class Events {
|
|||
const res = this._util.loadCommand(name, args, message);
|
||||
|
||||
if (!res.valid) {
|
||||
if (res.message != 'File does not exist') return {
|
||||
return {
|
||||
valid: false,
|
||||
message: res.message,
|
||||
};
|
||||
|
|
|
@ -70,7 +70,7 @@ export class Util {
|
|||
} else {
|
||||
return {
|
||||
valid: false,
|
||||
message: "Comamnd folder does not exist",
|
||||
message: "Command folder does not exist",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
7
tests/__mocks/commands/noCategory.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
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
|
8
tests/__mocks/commands/normal.ts
Normal file
|
@ -0,0 +1,8 @@
|
|||
import { Command } from "../../../src/type/command";
|
||||
|
||||
export class normal extends Command {
|
||||
constructor() {
|
||||
super();
|
||||
this._category = "General";
|
||||
}
|
||||
}
|
8
tests/__mocks/commands/roles.ts
Normal file
|
@ -0,0 +1,8 @@
|
|||
import { Command } from "../../../src/type/command";
|
||||
|
||||
export class roles extends Command {
|
||||
constructor() {
|
||||
super();
|
||||
this._roles = [ "Moderator" ];
|
||||
}
|
||||
}
|
5
tests/__mocks/events/normal.ts
Normal file
|
@ -0,0 +1,5 @@
|
|||
import { Event } from "../../../src/type/event";
|
||||
|
||||
export class normal extends Event {
|
||||
public override channelCreate() {}
|
||||
}
|
139
tests/client/client.test.ts
Normal file
|
@ -0,0 +1,139 @@
|
|||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
import { CoreClient } from "../../src/client/client";
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
import { Client } from "discord.js";
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
import * as dotenv from "dotenv";
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
import { Events } from "../../src/client/events";
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
import { Util } from "../../src/client/util";
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
jest.mock("discord.js");
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
jest.mock("dotenv");
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
jest.mock("../../src/client/events");
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
jest.mock("../../src/client/util");
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
describe('Constructor', () => {
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
test('Constructor_ExpectSuccessfulInitialisation', () => {
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
const coreClient = new CoreClient();
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
expect(coreClient).toBeInstanceOf(Client);
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
expect(dotenv.config).toBeCalledTimes(1);
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
expect(Events).toBeCalledTimes(1);
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
expect(Util).toBeCalledTimes(1);
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
});
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
});
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
describe('Start', () => {
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
test('Given Env Is Valid, Expect Successful Start', () => {
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
process.env = {
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
BOT_TOKEN: 'TOKEN',
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
BOT_PREFIX: '!',
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
FOLDERS_COMMANDS: 'commands',
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
FOLDERS_EVENTS: 'events',
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
}
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
const coreClient = new CoreClient();
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
expect(() => coreClient.start()).not.toThrow();
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
expect(coreClient.on).toBeCalledWith("message", expect.any(Function));
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
expect(coreClient.on).toBeCalledWith("ready", expect.any(Function));
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
});
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
test('Given BOT_TOKEN Is Null, Expect Failure', () => {
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
process.env = {
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
BOT_PREFIX: '!',
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
FOLDERS_COMMANDS: 'commands',
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
FOLDERS_EVENTS: 'events',
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
}
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
const coreClient = new CoreClient();
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
expect(() => coreClient.start()).toThrow("BOT_TOKEN is not defined in .env");
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
});
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
test('Given BOT_TOKEN Is Empty, Expect Failure', () => {
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
process.env = {
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
BOT_TOKEN: '',
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
BOT_PREFIX: '!',
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
FOLDERS_COMMANDS: 'commands',
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
FOLDERS_EVENTS: 'events',
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
}
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
const coreClient = new CoreClient();
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
expect(() => coreClient.start()).toThrow("BOT_TOKEN is not defined in .env");
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
});
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
test('Given BOT_PREFIX Is Null, Expect Failure', () => {
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
process.env = {
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
BOT_TOKEN: 'TOKEN',
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
FOLDERS_COMMANDS: 'commands',
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
FOLDERS_EVENTS: 'events',
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
}
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
const coreClient = new CoreClient();
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
expect(() => coreClient.start()).toThrow("BOT_PREFIX is not defined in .env");
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
});
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
test('Given BOT_PREFIX Is Empty, Expect Failure', () => {
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
process.env = {
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
BOT_TOKEN: 'TOKEN',
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
BOT_PREFIX: '',
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
FOLDERS_COMMANDS: 'commands',
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
FOLDERS_EVENTS: 'events',
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
}
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
const coreClient = new CoreClient();
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
expect(() => coreClient.start()).toThrow("BOT_PREFIX is not defined in .env");
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
});
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
test('Given FOLDERS_COMMANDS Is Null, Expect Failure', () => {
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
process.env = {
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
BOT_TOKEN: 'TOKEN',
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
BOT_PREFIX: '!',
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
FOLDERS_EVENTS: 'events',
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
}
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
const coreClient = new CoreClient();
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
expect(() => coreClient.start()).toThrow("FOLDERS_COMMANDS is not defined in .env");
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
});
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
test('Given FOLDERS_COMMANDS Is Empty, Expect Failure', () => {
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
process.env = {
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
BOT_TOKEN: 'TOKEN',
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
BOT_PREFIX: '!',
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
FOLDERS_COMMANDS: '',
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
FOLDERS_EVENTS: 'events',
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
}
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
const coreClient = new CoreClient();
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
expect(() => coreClient.start()).toThrow("FOLDERS_COMMANDS is not defined in .env");
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
});
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
test('Given FOLDERS_EVENTS Is Null, Expect Failure', () => {
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
process.env = {
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
BOT_TOKEN: 'TOKEN',
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
BOT_PREFIX: '!',
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
FOLDERS_COMMANDS: 'commands',
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
}
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
const coreClient = new CoreClient();
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
expect(() => coreClient.start()).toThrow("FOLDERS_EVENTS is not defined in .env");
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
});
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
test('Given FOLDERS_EVENTS Is Empty, Expect Failure', () => {
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
process.env = {
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
BOT_TOKEN: 'TOKEN',
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
BOT_PREFIX: '!',
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
FOLDERS_COMMANDS: 'commands',
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
FOLDERS_EVENTS: '',
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
}
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
const coreClient = new CoreClient();
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
expect(() => coreClient.start()).toThrow("FOLDERS_EVENTS is not defined in .env");
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
});
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
||||
});
|
||||
Should these be put into a describe group? Should these be put into a describe group?
This would apply to all other tests also This would apply to all other tests also
|
185
tests/client/events.test.ts
Normal file
|
@ -0,0 +1,185 @@
|
|||
import { Events } from "../../src/client/events";
|
||||
|
||||
import { Message, Client, TextChannel, Guild, SnowflakeUtil, DMChannel } from "discord.js";
|
||||
import { Util } from "../../src/client/util";
|
||||
|
||||
jest.mock("../../src/client/util");
|
||||
|
||||
beforeEach(() => {
|
||||
Util.prototype.loadCommand = jest.fn();
|
||||
});
|
||||
|
||||
describe('OnMessage', () => {
|
||||
test('Given Message Is Valid Expect Message Sent', () => {
|
||||
process.env = {
|
||||
BOT_TOKEN: 'TOKEN',
|
||||
BOT_PREFIX: '!',
|
||||
FOLDERS_COMMANDS: 'commands',
|
||||
FOLDERS_EVENTS: 'events',
|
||||
};
|
||||
|
||||
Util.prototype.loadCommand = jest.fn().mockReturnValue({ valid: true });
|
||||
|
||||
const message = {
|
||||
guild: {},
|
||||
author: {
|
||||
bot: false,
|
||||
},
|
||||
content: "!test first",
|
||||
} as unknown as Message;
|
||||
|
||||
const events = new Events();
|
||||
|
||||
const result = events.onMessage(message);
|
||||
|
||||
expect(result.valid).toBeTruthy();
|
||||
|
||||
expect(result.context?.prefix).toBe('!');
|
||||
expect(result.context?.name).toBe('test');
|
||||
expect(result.context?.args.length).toBe(1);
|
||||
expect(result.context?.args[0]).toBe('first');
|
||||
expect(result.context?.message).toBe(message);
|
||||
});
|
||||
|
||||
test('Given Guild Is Null, Expect Failed Result', () => {
|
||||
process.env = {
|
||||
BOT_TOKEN: 'TOKEN',
|
||||
BOT_PREFIX: '!',
|
||||
FOLDERS_COMMANDS: 'commands',
|
||||
FOLDERS_EVENTS: 'events',
|
||||
}
|
||||
|
||||
Util.prototype.loadCommand = jest.fn().mockReturnValue({ valid: true });
|
||||
|
||||
const message = {
|
||||
guild: null,
|
||||
author: {
|
||||
bot: false,
|
||||
},
|
||||
content: "!test first",
|
||||
} as unknown as Message;
|
||||
|
||||
const events = new Events();
|
||||
|
||||
const result = events.onMessage(message);
|
||||
|
||||
expect(result.valid).toBeFalsy();
|
||||
expect(result.message).toBe("Message was not sent in a guild, ignoring.");
|
||||
});
|
||||
|
||||
test('Given Author Is A Bot, Expect Failed Result', () => {
|
||||
process.env = {
|
||||
BOT_TOKEN: 'TOKEN',
|
||||
BOT_PREFIX: '!',
|
||||
FOLDERS_COMMANDS: 'commands',
|
||||
FOLDERS_EVENTS: 'events',
|
||||
}
|
||||
|
||||
Util.prototype.loadCommand = jest.fn().mockReturnValue({ valid: true });
|
||||
|
||||
const message = {
|
||||
guild: {},
|
||||
author: {
|
||||
bot: true,
|
||||
},
|
||||
content: "!test first",
|
||||
} as unknown as Message;
|
||||
|
||||
const events = new Events();
|
||||
|
||||
const result = events.onMessage(message);
|
||||
|
||||
expect(result.valid).toBeFalsy();
|
||||
expect(result.message).toBe("Message was sent by a bot, ignoring.");
|
||||
});
|
||||
|
||||
test('Given Message Content Was Not A Command, Expect Failed Result', () => {
|
||||
process.env = {
|
||||
BOT_TOKEN: 'TOKEN',
|
||||
BOT_PREFIX: '!',
|
||||
FOLDERS_COMMANDS: 'commands',
|
||||
FOLDERS_EVENTS: 'events',
|
||||
}
|
||||
|
||||
Util.prototype.loadCommand = jest.fn().mockReturnValue({ valid: true });
|
||||
|
||||
const message = {
|
||||
guild: {},
|
||||
author: {
|
||||
bot: false,
|
||||
},
|
||||
content: "This is a standard message",
|
||||
} as unknown as Message;
|
||||
|
||||
const events = new Events();
|
||||
|
||||
const result = events.onMessage(message);
|
||||
|
||||
expect(result.valid).toBeFalsy();
|
||||
expect(result.message).toBe("Message was not a command, ignoring.");
|
||||
});
|
||||
|
||||
test('Given Message Had No Command Name, Expect Failed Result', () => {
|
||||
process.env = {
|
||||
BOT_TOKEN: 'TOKEN',
|
||||
BOT_PREFIX: '!',
|
||||
FOLDERS_COMMANDS: 'commands',
|
||||
FOLDERS_EVENTS: 'events',
|
||||
}
|
||||
|
||||
Util.prototype.loadCommand = jest.fn().mockReturnValue({ valid: true });
|
||||
|
||||
const message = {
|
||||
guild: {},
|
||||
author: {
|
||||
bot: false,
|
||||
},
|
||||
content: "!",
|
||||
} as unknown as Message;
|
||||
|
||||
const events = new Events();
|
||||
|
||||
const result = events.onMessage(message);
|
||||
|
||||
expect(result.valid).toBeFalsy();
|
||||
expect(result.message).toBe("Command name was not found");
|
||||
});
|
||||
|
||||
test('Given Command Failed To Execute, Expect Failed Result', () => {
|
||||
process.env = {
|
||||
BOT_TOKEN: 'TOKEN',
|
||||
BOT_PREFIX: '!',
|
||||
FOLDERS_COMMANDS: 'commands',
|
||||
FOLDERS_EVENTS: 'events',
|
||||
}
|
||||
|
||||
Util.prototype.loadCommand = jest.fn().mockReturnValue({ valid: false, message: "Command failed" });
|
||||
|
||||
const message = {
|
||||
guild: {},
|
||||
author: {
|
||||
bot: false,
|
||||
},
|
||||
content: "!test first",
|
||||
} as unknown as Message;
|
||||
|
||||
const events = new Events();
|
||||
|
||||
const result = events.onMessage(message);
|
||||
|
||||
expect(result.valid).toBeFalsy();
|
||||
expect(result.message).toBe("Command failed");
|
||||
});
|
||||
});
|
||||
|
||||
describe('OnReady', () => {
|
||||
test('Expect Console Log', () => {
|
||||
console.log = jest.fn();
|
||||
|
||||
const events = new Events();
|
||||
|
||||
events.onReady();
|
||||
|
||||
expect(console.log).toBeCalledWith("Ready");
|
||||
});
|
||||
});
|
291
tests/client/util.test.ts
Normal file
|
@ -0,0 +1,291 @@
|
|||
import { Util } from "../../src/client/util";
|
||||
|
||||
import { Client, Guild, Message, Role, SnowflakeUtil, TextChannel, User } from "discord.js";
|
||||
import fs from "fs";
|
||||
|
||||
jest.mock("fs");
|
||||
|
||||
beforeEach(() => {
|
||||
fs.existsSync = jest.fn();
|
||||
});
|
||||
|
||||
describe('LoadCommand', () => {
|
||||
test('Given Successful Exection, Expect Successful Result', () => {
|
||||
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("normal", [ "first" ], message);
|
||||
|
||||
expect(result.valid).toBeTruthy();
|
||||
});
|
||||
|
||||
test('Given Member Is Null, Expect Failed Result', () => {
|
||||
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: null
|
||||
} as unknown as Message;
|
||||
|
||||
const util = new Util();
|
||||
|
||||
const result = util.loadCommand("normal", [ "first" ], message);
|
||||
|
||||
expect(result.valid).toBeFalsy();
|
||||
expect(result.message).toBe("Member is not part of message");
|
||||
});
|
||||
|
||||
test('Given Folder Does Not Exist, Expect Failed Result', () => {
|
||||
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(false);
|
||||
|
||||
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("normal", [ "first" ], message);
|
||||
|
||||
expect(result.valid).toBeFalsy();
|
||||
expect(result.message).toBe("Command folder does not exist");
|
||||
});
|
||||
|
||||
test('Given File Does Not Exist, Expect Failed Result', () => {
|
||||
process.env = {
|
||||
BOT_TOKEN: 'TOKEN',
|
||||
BOT_PREFIX: '!',
|
||||
FOLDERS_COMMANDS: 'commands',
|
||||
FOLDERS_EVENTS: 'events',
|
||||
}
|
||||
|
||||
process.cwd = jest.fn().mockReturnValue("../../tests/__mocks");
|
||||
fs.existsSync = jest.fn().mockReturnValueOnce(true)
|
||||
.mockReturnValue(false);
|
||||
|
||||
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("normal", [ "first" ], message);
|
||||
|
||||
expect(result.valid).toBeFalsy();
|
||||
expect(result.message).toBe("File does not exist");
|
||||
});
|
||||
|
||||
test('Given User Does Have Role, Expect Successful Result', () => {
|
||||
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('Given User Does Not Have Role, Expect Failed Result', () => {
|
||||
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(false),
|
||||
}
|
||||
},
|
||||
},
|
||||
reply: jest.fn(),
|
||||
} as unknown as Message;
|
||||
|
||||
const util = new Util();
|
||||
|
||||
const result = util.loadCommand("roles", [ "first" ], message);
|
||||
|
||||
expect(result.valid).toBeFalsy();
|
||||
expect(result.message).toBe("You require the `Moderator` role to run this command");
|
||||
});
|
||||
|
||||
test('Given Command Category Is Null, Expect Successful Result', () => {
|
||||
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();
|
||||
});
|
||||
});
|
||||
|
||||
describe('LoadEvents', () => {
|
||||
test('Given Events Are Loaded, Expect Successful Result', () => {
|
||||
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(["normal.ts"]);
|
||||
|
||||
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(13);
|
||||
});
|
||||
|
||||
test('Given No Events Found, Expect Successful Result', () => {
|
||||
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(["normal"]);
|
||||
|
||||
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('Given Event Folder Does Not Exist, Expect Failed Result', () => {
|
||||
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(false);
|
||||
fs.readdirSync = jest.fn().mockReturnValue(["normal.ts"]);
|
||||
|
||||
const client = {
|
||||
on: jest.fn(),
|
||||
} as unknown as Client;
|
||||
|
||||
const util = new Util();
|
||||
|
||||
const result = util.loadEvents(client);
|
||||
|
||||
expect(result.valid).toBeFalsy();
|
||||
expect(result.message).toBe("Event folder does not exist");
|
||||
});
|
||||
});
|
|
@ -71,5 +71,8 @@
|
|||
},
|
||||
"include": [
|
||||
"./src",
|
||||
],
|
||||
"exclude": [
|
||||
"./tests"
|
||||
]
|
||||
}
|
||||
|
|
Empty line