Feature/12 create tests #102

Merged
Vylpes merged 25 commits from feature/12-create-tests into develop 2022-01-30 17:03:37 +00:00
4 changed files with 136 additions and 88 deletions
Showing only changes of commit 12168b52c4 - Show all commits

View file

@ -6,7 +6,7 @@
"typings": "./dist",
"scripts": {
"build": "tsc",
"start": "ts-node ./src/vylbot",
"start": "node ./dist/vylbot",
"test": "jest"
},
"repository": {
@ -30,7 +30,6 @@
"devDependencies": {
"@types/node": "^16.11.10",
"eslint": "^7.17.0",
"ts-node": "^10.4.0",
"typescript": "^4.5.2"
}
}

View file

@ -1,4 +1,5 @@
import { ICommandContext } from "../contracts/ICommandContext";
import ICommandReturnContext from "../contracts/ICommandReturnContext";
import PublicEmbed from "../helpers/embeds/PublicEmbed";
import { Command } from "../type/command";
@ -8,12 +9,17 @@ export default class About extends Command {
super._category = "General";
}
public override execute(context: ICommandContext) {
public override execute(context: ICommandContext): ICommandReturnContext {
const embed = new PublicEmbed(context, "About", "")
.addField("Version", process.env.BOT_VER)
.addField("Author", process.env.BOT_AUTHOR)
.addField("Date", process.env.BOT_DATE);
embed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [embed]
};
}
}

View file

@ -4,6 +4,10 @@ import About from "../../src/commands/about";
import { ICommandContext } from "../../src/contracts/ICommandContext";
import PublicEmbed from "../../src/helpers/embeds/PublicEmbed";
beforeEach(() => {
process.env = {};
});
describe('Constructor', () => {
test('Expect values set', () => {
const about = new About();
@ -13,14 +17,15 @@ describe('Constructor', () => {
});
describe('Execute', () => {
test('Expect embed to be made and sent to the current channel', (done) => {
const message = mock<Message>();
message.channel.send = jest.fn().mockImplementation((embed: PublicEmbed) => {
expect(embed.title).toBe('About');
expect(embed.description).toBe('');
test('Expect embed to be made and sent to the current channel', async () => {
process.env = {
BOT_VER: "BOT_VER",
BOT_AUTHOR: "BOT_AUTHOR",
BOT_DATE: "BOT_DATE"
};
done();
});
const message = mock<Message>();
message.channel.send = jest.fn();
const context: ICommandContext = {
name: "about",
@ -29,6 +34,119 @@ describe('Execute', () => {
};
const about = new About();
about.execute(context);
const result = await about.execute(context);
expect(message.channel.send).toBeCalledTimes(1);
});
test('Expect embed send to have values', async () => {
process.env = {
BOT_VER: "BOT_VER",
BOT_AUTHOR: "BOT_AUTHOR",
BOT_DATE: "BOT_DATE"
};
const message = mock<Message>();
message.channel.send = jest.fn();
const context: ICommandContext = {
name: "about",
args: [],
message: message
};
const about = new About();
const result = await about.execute(context);
expect(result.embeds.length).toBe(1);
const embed = result.embeds[0];
expect(embed.title).toBe('About');
expect(embed.description).toBe('');
expect(embed.fields.length).toBe(3);
});
test('Expect version field to have values', async () => {
process.env = {
BOT_VER: "BOT_VER",
BOT_AUTHOR: "BOT_AUTHOR",
BOT_DATE: "BOT_DATE"
};
const message = mock<Message>();
message.channel.send = jest.fn();
const context: ICommandContext = {
name: "about",
args: [],
message: message
};
const about = new About();
const result = await about.execute(context);
const embed = result.embeds[0];
const field = embed.fields[0];
expect(field.name).toBe('Version');
expect(field.value).toBe('BOT_VER');
});
test('Expect author field to have values', async () => {
process.env = {
BOT_VER: "BOT_VER",
BOT_AUTHOR: "BOT_AUTHOR",
BOT_DATE: "BOT_DATE"
};
const message = mock<Message>();
message.channel.send = jest.fn();
const context: ICommandContext = {
name: "about",
args: [],
message: message
};
const about = new About();
const result = await about.execute(context);
const embed = result.embeds[0];
const field = embed.fields[1];
expect(field.name).toBe('Author');
expect(field.value).toBe('BOT_AUTHOR');
});
test('Expect version field to have values', async () => {
process.env = {
BOT_VER: "BOT_VER",
BOT_AUTHOR: "BOT_AUTHOR",
BOT_DATE: "BOT_DATE"
};
const message = mock<Message>();
message.channel.send = jest.fn();
const context: ICommandContext = {
name: "about",
args: [],
message: message
};
const about = new About();
const result = await about.execute(context);
const embed = result.embeds[0];
const field = embed.fields[2];
expect(field.name).toBe('Date');
expect(field.value).toBe('BOT_DATE');
});
});

View file

@ -293,18 +293,6 @@
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
"@cspotcode/source-map-consumer@0.8.0":
version "0.8.0"
resolved "https://registry.yarnpkg.com/@cspotcode/source-map-consumer/-/source-map-consumer-0.8.0.tgz#33bf4b7b39c178821606f669bbc447a6a629786b"
integrity sha512-41qniHzTU8yAGbCp04ohlmSrZf8bkf/iJsl3V0dRGsQN/5GFfx+LbCSsCpp2gqrqjTVg/K6O8ycoV35JIwAzAg==
"@cspotcode/source-map-support@0.7.0":
version "0.7.0"
resolved "https://registry.yarnpkg.com/@cspotcode/source-map-support/-/source-map-support-0.7.0.tgz#4789840aa859e46d2f3173727ab707c66bf344f5"
integrity sha512-X4xqRHqN8ACt2aHVe51OxeA2HjbcL4MqFqXkrmQszJ1NOUuUu5u6Vqx/0lZSVNku7velL5FC/s5uEAj1lsBMhA==
dependencies:
"@cspotcode/source-map-consumer" "0.8.0"
"@discordjs/collection@^0.1.6":
version "0.1.6"
resolved "https://registry.yarnpkg.com/@discordjs/collection/-/collection-0.1.6.tgz#9e9a7637f4e4e0688fd8b2b5c63133c91607682c"
@ -564,26 +552,6 @@
resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-1.1.2.tgz#ccb91445360179a04e7fe6aff78c00ffc1eeaf82"
integrity sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw==
"@tsconfig/node10@^1.0.7":
version "1.0.8"
resolved "https://registry.yarnpkg.com/@tsconfig/node10/-/node10-1.0.8.tgz#c1e4e80d6f964fbecb3359c43bd48b40f7cadad9"
integrity sha512-6XFfSQmMgq0CFLY1MslA/CPUfhIL919M1rMsa5lP2P097N2Wd1sSX0tx1u4olM16fLNhtHZpRhedZJphNJqmZg==
"@tsconfig/node12@^1.0.7":
version "1.0.9"
resolved "https://registry.yarnpkg.com/@tsconfig/node12/-/node12-1.0.9.tgz#62c1f6dee2ebd9aead80dc3afa56810e58e1a04c"
integrity sha512-/yBMcem+fbvhSREH+s14YJi18sp7J9jpuhYByADT2rypfajMZZN4WQ6zBGgBKp53NKmqI36wFYDb3yaMPurITw==
"@tsconfig/node14@^1.0.0":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@tsconfig/node14/-/node14-1.0.1.tgz#95f2d167ffb9b8d2068b0b235302fafd4df711f2"
integrity sha512-509r2+yARFfHHE7T6Puu2jjkoycftovhXRqW328PDXTVGKihlb1P8Z9mMZH04ebyajfRY7dedfGynlrFHJUQCg==
"@tsconfig/node16@^1.0.2":
version "1.0.2"
resolved "https://registry.yarnpkg.com/@tsconfig/node16/-/node16-1.0.2.tgz#423c77877d0569db20e1fc80885ac4118314010e"
integrity sha512-eZxlbI8GZscaGS7kkc/trHTT5xgrjH3/1n2JDwusC9iahPKWMRvRjJSAN5mCXviuTGQ/lHnhvv8Q1YTpnfz9gA==
"@types/babel__core@^7.0.0", "@types/babel__core@^7.1.14":
version "7.1.17"
resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.17.tgz#f50ac9d20d64153b510578d84f9643f9a3afbe64"
@ -742,17 +710,12 @@ acorn-walk@^7.1.1:
resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-7.2.0.tgz#0de889a601203909b0fbe07b8938dc21d2e967bc"
integrity sha512-OPdCF6GsMIP+Az+aWfAAOEt2/+iVDKE7oy6lJ098aoe59oAmK76qV6Gw60SbZ8jHuG2wH058GF4pLFbYamYrVA==
acorn-walk@^8.1.1:
version "8.2.0"
resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-8.2.0.tgz#741210f2e2426454508853a2f44d0ab83b7f69c1"
integrity sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==
acorn@^7.1.1, acorn@^7.4.0:
version "7.4.1"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.4.1.tgz#feaed255973d2e77555b83dbc08851a6c63520fa"
integrity sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==
acorn@^8.2.4, acorn@^8.4.1:
acorn@^8.2.4:
version "8.6.0"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.6.0.tgz#e3692ba0eb1a0c83eaa4f37f5fa7368dd7142895"
integrity sha512-U1riIR+lBSNi3IbxtaHOIKdH8sLFv3NYfNv8sg7ZsNhcfl4HF2++BfqqrNAxoCLQW1iiylOj76ecnaUxz+z9yw==
@ -828,11 +791,6 @@ anymatch@^3.0.3:
normalize-path "^3.0.0"
picomatch "^2.0.4"
arg@^4.1.0:
version "4.1.3"
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089"
integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==
argparse@^1.0.7:
version "1.0.10"
resolved "https://registry.yarnpkg.com/argparse/-/argparse-1.0.10.tgz#bcd6791ea5ae09725e17e5ad988134cd40b3d911"
@ -1105,11 +1063,6 @@ convert-source-map@^1.4.0, convert-source-map@^1.6.0, convert-source-map@^1.7.0:
dependencies:
safe-buffer "~5.1.1"
create-require@^1.1.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/create-require/-/create-require-1.1.1.tgz#c1d7e8f1e5f6cfc9ff65f9cd352d37348756c333"
integrity sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==
cross-spawn@^7.0.2, cross-spawn@^7.0.3:
version "7.0.3"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6"
@ -1206,11 +1159,6 @@ diff-sequences@^27.4.0:
resolved "https://registry.yarnpkg.com/diff-sequences/-/diff-sequences-27.4.0.tgz#d783920ad8d06ec718a060d00196dfef25b132a5"
integrity sha512-YqiQzkrsmHMH5uuh8OdQFU9/ZpADnwzml8z0O5HvRNda+5UZsaX/xN+AAxfR2hWq1Y7HZnAzO9J5lJXOuDz2Ww==
diff@^4.0.1:
version "4.0.2"
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==
discord.js@12.5.3:
version "12.5.3"
resolved "https://registry.yarnpkg.com/discord.js/-/discord.js-12.5.3.tgz#56820d473c24320871df9ea0bbc6b462f21cf85c"
@ -2425,7 +2373,7 @@ make-dir@^3.0.0:
dependencies:
semver "^6.0.0"
make-error@1.x, make-error@^1.1.1:
make-error@1.x:
version "1.3.6"
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2"
integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==
@ -3065,24 +3013,6 @@ ts-jest@^27.1.2:
semver "7.x"
yargs-parser "20.x"
ts-node@^10.4.0:
version "10.4.0"
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.4.0.tgz#680f88945885f4e6cf450e7f0d6223dd404895f7"
integrity sha512-g0FlPvvCXSIO1JDF6S232P5jPYqBkRL9qly81ZgAOSU7rwI0stphCgd2kLiCrU9DjQCrJMWEqcNSjQL02s6d8A==
dependencies:
"@cspotcode/source-map-support" "0.7.0"
"@tsconfig/node10" "^1.0.7"
"@tsconfig/node12" "^1.0.7"
"@tsconfig/node14" "^1.0.0"
"@tsconfig/node16" "^1.0.2"
acorn "^8.4.1"
acorn-walk "^8.1.1"
arg "^4.1.0"
create-require "^1.1.0"
diff "^4.0.1"
make-error "^1.1.1"
yn "3.1.1"
tweetnacl@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-1.0.3.tgz#ac0af71680458d8a6378d0d0d050ab1407d35596"
@ -3298,8 +3228,3 @@ yargs@^16.2.0:
string-width "^4.2.0"
y18n "^5.0.5"
yargs-parser "^20.2.2"
yn@3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50"
integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==