First util.ts test
This commit is contained in:
parent
a0a93a4737
commit
1044c57e66
6 changed files with 116 additions and 4 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -108,8 +108,7 @@ commands/
|
|||
events/
|
||||
/bot.ts
|
||||
|
||||
!tests/commands/
|
||||
!tests/events/
|
||||
!tests/__mocks/commands
|
||||
|
||||
# Linux Environment Files
|
||||
*.swp
|
||||
|
|
|
@ -27,7 +27,9 @@
|
|||
"devDependencies": {
|
||||
"@types/jest": "^26.0.24",
|
||||
"@types/node": "^16.3.2",
|
||||
"@types/proxyquire": "^1.3.28",
|
||||
"jest": "^27.0.6",
|
||||
"proxyquire": "^2.1.3",
|
||||
"ts-jest": "^27.0.4",
|
||||
"typescript": "^4.3.5"
|
||||
}
|
||||
|
|
5
tests/__mocks/commands/name.ts
Normal file
5
tests/__mocks/commands/name.ts
Normal file
|
@ -0,0 +1,5 @@
|
|||
import { Command } from "../../../src/type/command";
|
||||
|
||||
export class name extends Command {
|
||||
|
||||
}
|
|
@ -3,7 +3,6 @@ import { Events } from "../../src/client/events";
|
|||
import { Message, Client, TextChannel, Guild, SnowflakeUtil, DMChannel } from "discord.js";
|
||||
import { Util } from "../../src/client/util";
|
||||
|
||||
jest.mock("dotenv");
|
||||
jest.mock("../../src/client/util");
|
||||
|
||||
beforeEach(() => {
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
import { Util } from "../../src/client/util";
|
||||
|
||||
import { Client, Guild, Message, SnowflakeUtil, TextChannel, User } from "discord.js";
|
||||
import fs from "fs";
|
||||
|
||||
jest.mock("fs");
|
||||
|
||||
beforeEach(() => {
|
||||
fs.existsSync = jest.fn();
|
||||
});
|
||||
|
||||
test('LoadCommand_GivenSuccessfulExection_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 util = new Util();
|
||||
|
||||
let client = new Client();
|
||||
let user = new User(client, {
|
||||
id: SnowflakeUtil.generate(),
|
||||
username: "test-user",
|
||||
discriminator: 1234,
|
||||
});
|
||||
let guild = new Guild(client, {
|
||||
id: SnowflakeUtil.generate(),
|
||||
members: [{
|
||||
user: user,
|
||||
nick: "Test User",
|
||||
roles: [],
|
||||
joined_at: "2015-04-26T06:26:56.936000+00:00",
|
||||
deaf: false,
|
||||
mute: false
|
||||
}]
|
||||
});
|
||||
let message = new Message(
|
||||
client,
|
||||
{
|
||||
content: "!test first",
|
||||
id: "test",
|
||||
member: {
|
||||
user: user,
|
||||
nick: "NOT API SUPPORT",
|
||||
roles: [],
|
||||
joined_at: "2015-04-26T06:26:56.936000+00:00",
|
||||
deaf: false,
|
||||
mute: false
|
||||
},
|
||||
type: 0,
|
||||
author: user,
|
||||
},
|
||||
new TextChannel(guild, {
|
||||
client: client,
|
||||
guild: guild,
|
||||
id: "channel-id",
|
||||
}),
|
||||
);
|
||||
|
||||
const result = util.loadCommand("name", [ "first" ], message);
|
||||
|
||||
expect(result.valid).toBeTruthy();
|
||||
|
||||
client.destroy();
|
||||
});
|
39
yarn.lock
39
yarn.lock
|
@ -613,6 +613,11 @@
|
|||
resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.3.2.tgz#fc8c2825e4ed2142473b4a81064e6e081463d1b3"
|
||||
integrity sha512-eI5Yrz3Qv4KPUa/nSIAi0h+qX0XyewOliug5F2QAtuRg6Kjg6jfmxe1GIwoIRhZspD1A0RP8ANrPwvEXXtRFog==
|
||||
|
||||
"@types/proxyquire@^1.3.28":
|
||||
version "1.3.28"
|
||||
resolved "https://registry.yarnpkg.com/@types/proxyquire/-/proxyquire-1.3.28.tgz#05a647bb0d8fe48fc8edcc193e43cc79310faa7d"
|
||||
integrity sha512-SQaNzWQ2YZSr7FqAyPPiA3FYpux2Lqh3HWMZQk47x3xbMCqgC/w0dY3dw9rGqlweDDkrySQBcaScXWeR+Yb11Q==
|
||||
|
||||
"@types/stack-utils@^2.0.0":
|
||||
version "2.0.1"
|
||||
resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-2.0.1.tgz#20f18294f797f2209b5f65c8e3b5c8e8261d127c"
|
||||
|
@ -1184,6 +1189,14 @@ fb-watchman@^2.0.0:
|
|||
dependencies:
|
||||
bser "2.1.1"
|
||||
|
||||
fill-keys@^1.0.2:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/fill-keys/-/fill-keys-1.0.2.tgz#9a8fa36f4e8ad634e3bf6b4f3c8882551452eb20"
|
||||
integrity sha1-mo+jb06K1jTjv2tPPIiCVRRS6yA=
|
||||
dependencies:
|
||||
is-object "~1.0.1"
|
||||
merge-descriptors "~1.0.0"
|
||||
|
||||
fill-range@^7.0.1:
|
||||
version "7.0.1"
|
||||
resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.0.1.tgz#1919a6a7c75fe38b2c7c77e5198535da9acdda40"
|
||||
|
@ -1378,6 +1391,11 @@ is-number@^7.0.0:
|
|||
resolved "https://registry.yarnpkg.com/is-number/-/is-number-7.0.0.tgz#7535345b896734d5f80c4d06c50955527a14f12b"
|
||||
integrity sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==
|
||||
|
||||
is-object@~1.0.1:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/is-object/-/is-object-1.0.2.tgz#a56552e1c665c9e950b4a025461da87e72f86fcf"
|
||||
integrity sha512-2rRIahhZr2UWb45fIOuvZGpFtz0TyOZLf32KxBbSoUCeZR495zCKlWUKKUByk3geS2eAs7ZAABt0Y/Rx0GiQGA==
|
||||
|
||||
is-potential-custom-element-name@^1.0.1:
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/is-potential-custom-element-name/-/is-potential-custom-element-name-1.0.1.tgz#171ed6f19e3ac554394edf78caa05784a45bebb5"
|
||||
|
@ -1977,6 +1995,11 @@ makeerror@1.0.x:
|
|||
dependencies:
|
||||
tmpl "1.0.x"
|
||||
|
||||
merge-descriptors@~1.0.0:
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/merge-descriptors/-/merge-descriptors-1.0.1.tgz#b00aaa556dd8b44568150ec9d1b953f3f90cbb61"
|
||||
integrity sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E=
|
||||
|
||||
merge-stream@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/merge-stream/-/merge-stream-2.0.0.tgz#52823629a14dd00c9770fb6ad47dc6310f2c1f60"
|
||||
|
@ -2024,6 +2047,11 @@ mkdirp@1.x:
|
|||
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e"
|
||||
integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==
|
||||
|
||||
module-not-found-error@^1.0.1:
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/module-not-found-error/-/module-not-found-error-1.0.1.tgz#cf8b4ff4f29640674d6cdd02b0e3bc523c2bbdc0"
|
||||
integrity sha1-z4tP9PKWQGdNbN0CsOO8UjwrvcA=
|
||||
|
||||
ms@2.1.2:
|
||||
version "2.1.2"
|
||||
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
|
||||
|
@ -2203,6 +2231,15 @@ prompts@^2.0.1:
|
|||
kleur "^3.0.3"
|
||||
sisteransi "^1.0.5"
|
||||
|
||||
proxyquire@^2.1.3:
|
||||
version "2.1.3"
|
||||
resolved "https://registry.yarnpkg.com/proxyquire/-/proxyquire-2.1.3.tgz#2049a7eefa10a9a953346a18e54aab2b4268df39"
|
||||
integrity sha512-BQWfCqYM+QINd+yawJz23tbBM40VIGXOdDw3X344KcclI/gtBbdWF6SlQ4nK/bYhF9d27KYug9WzljHC6B9Ysg==
|
||||
dependencies:
|
||||
fill-keys "^1.0.2"
|
||||
module-not-found-error "^1.0.1"
|
||||
resolve "^1.11.1"
|
||||
|
||||
psl@^1.1.33:
|
||||
version "1.8.0"
|
||||
resolved "https://registry.yarnpkg.com/psl/-/psl-1.8.0.tgz#9326f8bcfb013adcc005fdff056acce020e51c24"
|
||||
|
@ -2235,7 +2272,7 @@ resolve-from@^5.0.0:
|
|||
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-5.0.0.tgz#c35225843df8f776df21c57557bc087e9dfdfc69"
|
||||
integrity sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==
|
||||
|
||||
resolve@^1.20.0:
|
||||
resolve@^1.11.1, resolve@^1.20.0:
|
||||
version "1.20.0"
|
||||
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.20.0.tgz#629a013fb3f70755d6f0b7935cc1c2c5378b1975"
|
||||
integrity sha512-wENBPt4ySzg4ybFQW2TT1zMQucPK95HSh/nq2CFTZVOGut2+pQvSsgtda4d26YrYcr067wjbmzOG8byDPBX63A==
|
||||
|
|
Reference in a new issue