This repository has been archived by the owner on Aug 28, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from Vylpes/feature/tests
Tests and CI
- Loading branch information
Showing
16 changed files
with
3,813 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
tests | ||
node_modules | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,19 @@ | ||
{ | ||
"parserOptions": { | ||
"ecmaVersion": 6 | ||
}, | ||
"root": true, | ||
"parser": "@typescript-eslint/parser", | ||
"plugins": [ | ||
"@typescript-eslint" | ||
], | ||
"extends": [ | ||
"eslint:recommended" | ||
"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", | ||
"require": "writable", | ||
"process": "writable", | ||
"console": "writable" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
/** @type {import('@ts-jest/dist/types').InitialOptionsTsJest} */ | ||
module.exports = { | ||
testEnvironment: 'node' | ||
} | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Command } from "../../../src/type/command"; | ||
|
||
export class noCategory extends Command { | ||
constructor() { | ||
super(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Command } from "../../../src/type/command"; | ||
|
||
export class normal extends Command { | ||
constructor() { | ||
super(); | ||
this._category = "General"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Command } from "../../../src/type/command"; | ||
|
||
export class roles extends Command { | ||
constructor() { | ||
super(); | ||
this._roles = [ "Moderator" ]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Event } from "../../../src/type/event"; | ||
|
||
export class normal extends Event { | ||
public override channelCreate() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
import { CoreClient } from "../../src/client/client"; | ||
|
||
import { Client } from "discord.js"; | ||
import * as dotenv from "dotenv"; | ||
import { Events } from "../../src/client/events"; | ||
import { Util } from "../../src/client/util"; | ||
|
||
jest.mock("discord.js"); | ||
jest.mock("dotenv"); | ||
jest.mock("../../src/client/events"); | ||
jest.mock("../../src/client/util"); | ||
|
||
describe('Constructor', () => { | ||
test('Constructor_ExpectSuccessfulInitialisation', () => { | ||
const coreClient = new CoreClient(); | ||
|
||
expect(coreClient).toBeInstanceOf(Client); | ||
expect(dotenv.config).toBeCalledTimes(1); | ||
expect(Events).toBeCalledTimes(1); | ||
expect(Util).toBeCalledTimes(1); | ||
}); | ||
}); | ||
|
||
describe('Start', () => { | ||
test('Given Env Is Valid, Expect Successful Start', () => { | ||
process.env = { | ||
BOT_TOKEN: 'TOKEN', | ||
BOT_PREFIX: '!', | ||
FOLDERS_COMMANDS: 'commands', | ||
FOLDERS_EVENTS: 'events', | ||
} | ||
|
||
const coreClient = new CoreClient(); | ||
|
||
expect(() => coreClient.start()).not.toThrow(); | ||
expect(coreClient.on).toBeCalledWith("message", expect.any(Function)); | ||
expect(coreClient.on).toBeCalledWith("ready", expect.any(Function)); | ||
}); | ||
|
||
test('Given BOT_TOKEN Is Null, Expect Failure', () => { | ||
process.env = { | ||
BOT_PREFIX: '!', | ||
FOLDERS_COMMANDS: 'commands', | ||
FOLDERS_EVENTS: 'events', | ||
} | ||
|
||
const coreClient = new CoreClient(); | ||
|
||
expect(() => coreClient.start()).toThrow("BOT_TOKEN is not defined in .env"); | ||
}); | ||
|
||
test('Given BOT_TOKEN Is Empty, Expect Failure', () => { | ||
process.env = { | ||
BOT_TOKEN: '', | ||
BOT_PREFIX: '!', | ||
FOLDERS_COMMANDS: 'commands', | ||
FOLDERS_EVENTS: 'events', | ||
} | ||
|
||
const coreClient = new CoreClient(); | ||
|
||
expect(() => coreClient.start()).toThrow("BOT_TOKEN is not defined in .env"); | ||
}); | ||
|
||
test('Given BOT_PREFIX Is Null, Expect Failure', () => { | ||
process.env = { | ||
BOT_TOKEN: 'TOKEN', | ||
FOLDERS_COMMANDS: 'commands', | ||
FOLDERS_EVENTS: 'events', | ||
} | ||
|
||
const coreClient = new CoreClient(); | ||
|
||
expect(() => coreClient.start()).toThrow("BOT_PREFIX is not defined in .env"); | ||
}); | ||
|
||
test('Given BOT_PREFIX Is Empty, Expect Failure', () => { | ||
process.env = { | ||
BOT_TOKEN: 'TOKEN', | ||
BOT_PREFIX: '', | ||
FOLDERS_COMMANDS: 'commands', | ||
FOLDERS_EVENTS: 'events', | ||
} | ||
|
||
const coreClient = new CoreClient(); | ||
|
||
expect(() => coreClient.start()).toThrow("BOT_PREFIX is not defined in .env"); | ||
}); | ||
|
||
test('Given FOLDERS_COMMANDS Is Null, Expect Failure', () => { | ||
process.env = { | ||
BOT_TOKEN: 'TOKEN', | ||
BOT_PREFIX: '!', | ||
FOLDERS_EVENTS: 'events', | ||
} | ||
|
||
const coreClient = new CoreClient(); | ||
|
||
expect(() => coreClient.start()).toThrow("FOLDERS_COMMANDS is not defined in .env"); | ||
}); | ||
|
||
test('Given FOLDERS_COMMANDS Is Empty, Expect Failure', () => { | ||
process.env = { | ||
BOT_TOKEN: 'TOKEN', | ||
BOT_PREFIX: '!', | ||
FOLDERS_COMMANDS: '', | ||
FOLDERS_EVENTS: 'events', | ||
} | ||
|
||
const coreClient = new CoreClient(); | ||
|
||
expect(() => coreClient.start()).toThrow("FOLDERS_COMMANDS is not defined in .env"); | ||
}); | ||
|
||
test('Given FOLDERS_EVENTS Is Null, Expect Failure', () => { | ||
process.env = { | ||
BOT_TOKEN: 'TOKEN', | ||
BOT_PREFIX: '!', | ||
FOLDERS_COMMANDS: 'commands', | ||
} | ||
|
||
const coreClient = new CoreClient(); | ||
|
||
expect(() => coreClient.start()).toThrow("FOLDERS_EVENTS is not defined in .env"); | ||
}); | ||
|
||
test('Given FOLDERS_EVENTS Is Empty, Expect Failure', () => { | ||
process.env = { | ||
BOT_TOKEN: 'TOKEN', | ||
BOT_PREFIX: '!', | ||
FOLDERS_COMMANDS: 'commands', | ||
FOLDERS_EVENTS: '', | ||
} | ||
|
||
const coreClient = new CoreClient(); | ||
|
||
expect(() => coreClient.start()).toThrow("FOLDERS_EVENTS is not defined in .env"); | ||
}); | ||
}); |
Oops, something went wrong.