Compare commits
2 commits
68f29c814a
...
69ef94dbb5
Author | SHA1 | Date | |
---|---|---|---|
69ef94dbb5 | |||
ea6bac2af1 |
88 changed files with 1000 additions and 7402 deletions
2
.dev.env
2
.dev.env
|
@ -7,7 +7,7 @@
|
||||||
# any secret values.
|
# any secret values.
|
||||||
|
|
||||||
BOT_TOKEN=
|
BOT_TOKEN=
|
||||||
BOT_VER=3.2 DEV
|
BOT_VER=3.3.0
|
||||||
BOT_AUTHOR=Vylpes
|
BOT_AUTHOR=Vylpes
|
||||||
BOT_OWNERID=147392775707426816
|
BOT_OWNERID=147392775707426816
|
||||||
BOT_CLIENTID=682942374040961060
|
BOT_CLIENTID=682942374040961060
|
||||||
|
|
|
@ -54,11 +54,10 @@ steps:
|
||||||
- yarn install --frozen-lockfile
|
- yarn install --frozen-lockfile
|
||||||
- yarn build
|
- yarn build
|
||||||
|
|
||||||
# - name: test
|
- name: test
|
||||||
# image: node
|
image: node
|
||||||
# commands:
|
commands:
|
||||||
# - yarn install --frozen-lockfile
|
- yarn test
|
||||||
# - yarn test
|
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
branch:
|
branch:
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
# any secret values.
|
# any secret values.
|
||||||
|
|
||||||
BOT_TOKEN=
|
BOT_TOKEN=
|
||||||
BOT_VER=3.2
|
BOT_VER=3.3.0
|
||||||
BOT_AUTHOR=Vylpes
|
BOT_AUTHOR=Vylpes
|
||||||
BOT_OWNERID=147392775707426816
|
BOT_OWNERID=147392775707426816
|
||||||
BOT_CLIENTID=680083120896081954
|
BOT_CLIENTID=680083120896081954
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
# any secret values.
|
# any secret values.
|
||||||
|
|
||||||
BOT_TOKEN=
|
BOT_TOKEN=
|
||||||
BOT_VER=3.2 BETA
|
BOT_VER=3.3.0
|
||||||
BOT_AUTHOR=Vylpes
|
BOT_AUTHOR=Vylpes
|
||||||
BOT_OWNERID=147392775707426816
|
BOT_OWNERID=147392775707426816
|
||||||
BOT_CLIENTID=1016767908740857949
|
BOT_CLIENTID=1016767908740857949
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
"clean": "rm -rf node_modules/ dist/",
|
"clean": "rm -rf node_modules/ dist/",
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"start": "node ./dist/vylbot",
|
"start": "node ./dist/vylbot",
|
||||||
"test": "echo true",
|
"test": "jest",
|
||||||
"db:up": "typeorm migration:run -d dist/database/dataSources/appDataSource.js",
|
"db:up": "typeorm migration:run -d dist/database/dataSources/appDataSource.js",
|
||||||
"db:down": "typeorm migration:revert -d dist/database/dataSources/appDataSource.js",
|
"db:down": "typeorm migration:revert -d dist/database/dataSources/appDataSource.js",
|
||||||
"release": "np --no-publish"
|
"release": "np --no-publish"
|
||||||
|
|
|
@ -6,7 +6,7 @@ export default class AddRole extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
super.CommandBuilder = new SlashCommandBuilder()
|
this.CommandBuilder = new SlashCommandBuilder()
|
||||||
.setName('addlobby')
|
.setName('addlobby')
|
||||||
.setDescription('Add lobby channel')
|
.setDescription('Add lobby channel')
|
||||||
.setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers)
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { CacheType, CommandInteraction, EmbedBuilder, GuildBasedChannel, PermissionsBitField, SlashCommandBuilder } from "discord.js";
|
import { CacheType, CommandInteraction, EmbedBuilder, PermissionsBitField, SlashCommandBuilder } from "discord.js";
|
||||||
import { Command } from "../../../type/command";
|
import { Command } from "../../../type/command";
|
||||||
import { default as eLobby } from "../../../database/entities/501231711271780357/Lobby";
|
import { default as eLobby } from "../../../database/entities/501231711271780357/Lobby";
|
||||||
import EmbedColours from "../../../constants/EmbedColours";
|
import EmbedColours from "../../../constants/EmbedColours";
|
||||||
|
@ -7,7 +7,7 @@ export default class ListLobby extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
super.CommandBuilder = new SlashCommandBuilder()
|
this.CommandBuilder = new SlashCommandBuilder()
|
||||||
.setName('listlobby')
|
.setName('listlobby')
|
||||||
.setDescription('Lists all channels set up as lobbies')
|
.setDescription('Lists all channels set up as lobbies')
|
||||||
.setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers);
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers);
|
||||||
|
|
|
@ -6,7 +6,7 @@ export default class Lobby extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
super.CommandBuilder = new SlashCommandBuilder()
|
this.CommandBuilder = new SlashCommandBuilder()
|
||||||
.setName('lobby')
|
.setName('lobby')
|
||||||
.setDescription('Attempt to organise a lobby');
|
.setDescription('Attempt to organise a lobby');
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ export default class RemoveLobby extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
super.CommandBuilder = new SlashCommandBuilder()
|
this.CommandBuilder = new SlashCommandBuilder()
|
||||||
.setName('removelobby')
|
.setName('removelobby')
|
||||||
.setDescription('Remove a lobby channel')
|
.setDescription('Remove a lobby channel')
|
||||||
.setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers)
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers)
|
||||||
|
|
|
@ -7,7 +7,7 @@ export default class Entry extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
super.CommandBuilder = new SlashCommandBuilder()
|
this.CommandBuilder = new SlashCommandBuilder()
|
||||||
.setName('entry')
|
.setName('entry')
|
||||||
.setDescription('Sends the entry embed')
|
.setDescription('Sends the entry embed')
|
||||||
.setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers);
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers);
|
||||||
|
|
|
@ -7,7 +7,7 @@ export default class ConfigRole extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
super.CommandBuilder = new SlashCommandBuilder()
|
this.CommandBuilder = new SlashCommandBuilder()
|
||||||
.setName('configrole')
|
.setName('configrole')
|
||||||
.setDescription('Toggle your roles')
|
.setDescription('Toggle your roles')
|
||||||
.setDefaultMemberPermissions(PermissionsBitField.Flags.ManageRoles)
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.ManageRoles)
|
||||||
|
|
|
@ -7,7 +7,7 @@ export default class Role extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
super.CommandBuilder = new SlashCommandBuilder()
|
this.CommandBuilder = new SlashCommandBuilder()
|
||||||
.setName('role')
|
.setName('role')
|
||||||
.setDescription('Toggle your roles')
|
.setDescription('Toggle your roles')
|
||||||
.addSubcommand(subcommand =>
|
.addSubcommand(subcommand =>
|
||||||
|
|
|
@ -6,7 +6,7 @@ export default class About extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
super.CommandBuilder = new SlashCommandBuilder()
|
this.CommandBuilder = new SlashCommandBuilder()
|
||||||
.setName('about')
|
.setName('about')
|
||||||
.setDescription('About VylBot');
|
.setDescription('About VylBot');
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ export default class Audits extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
super.CommandBuilder = new SlashCommandBuilder()
|
this.CommandBuilder = new SlashCommandBuilder()
|
||||||
.setName("audits")
|
.setName("audits")
|
||||||
.setDescription("View audits of a particular user in the server")
|
.setDescription("View audits of a particular user in the server")
|
||||||
.setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers)
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers)
|
||||||
|
|
|
@ -9,7 +9,7 @@ export default class Ban extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
super.CommandBuilder = new SlashCommandBuilder()
|
this.CommandBuilder = new SlashCommandBuilder()
|
||||||
.setName("ban")
|
.setName("ban")
|
||||||
.setDescription("Ban a member from the server with an optional reason")
|
.setDescription("Ban a member from the server with an optional reason")
|
||||||
.setDefaultMemberPermissions(PermissionsBitField.Flags.BanMembers)
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.BanMembers)
|
||||||
|
|
|
@ -7,7 +7,7 @@ export default class Bunny extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
super.CommandBuilder = new SlashCommandBuilder()
|
this.CommandBuilder = new SlashCommandBuilder()
|
||||||
.setName("bunny")
|
.setName("bunny")
|
||||||
.setDescription("Get a random picture of a rabbit.");
|
.setDescription("Get a random picture of a rabbit.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ export default class Clear extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
super.CommandBuilder = new SlashCommandBuilder()
|
this.CommandBuilder = new SlashCommandBuilder()
|
||||||
.setName("clear")
|
.setName("clear")
|
||||||
.setDescription("Clears the channel of messages")
|
.setDescription("Clears the channel of messages")
|
||||||
.setDefaultMemberPermissions(PermissionsBitField.Flags.ManageMessages)
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.ManageMessages)
|
||||||
|
|
|
@ -7,7 +7,7 @@ export default class Code extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
super.CommandBuilder = new SlashCommandBuilder()
|
this.CommandBuilder = new SlashCommandBuilder()
|
||||||
.setName('code')
|
.setName('code')
|
||||||
.setDescription('Manage the verification code of the server')
|
.setDescription('Manage the verification code of the server')
|
||||||
.setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers)
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers)
|
||||||
|
|
|
@ -10,7 +10,7 @@ export default class Config extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
super.CommandBuilder = new SlashCommandBuilder()
|
this.CommandBuilder = new SlashCommandBuilder()
|
||||||
.setName('config')
|
.setName('config')
|
||||||
.setDescription('Configure the current server')
|
.setDescription('Configure the current server')
|
||||||
.setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator)
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator)
|
||||||
|
|
|
@ -6,7 +6,7 @@ export default class Disable extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
super.CommandBuilder = new SlashCommandBuilder()
|
this.CommandBuilder = new SlashCommandBuilder()
|
||||||
.setName('disable')
|
.setName('disable')
|
||||||
.setDescription('Disables a command')
|
.setDescription('Disables a command')
|
||||||
.setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator)
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator)
|
||||||
|
|
|
@ -6,7 +6,7 @@ export default class Ignore extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
super.CommandBuilder = new SlashCommandBuilder()
|
this.CommandBuilder = new SlashCommandBuilder()
|
||||||
.setName('ignore')
|
.setName('ignore')
|
||||||
.setDescription('Ignore events in this channel')
|
.setDescription('Ignore events in this channel')
|
||||||
.setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator);
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator);
|
||||||
|
|
|
@ -9,7 +9,7 @@ export default class Kick extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
super.CommandBuilder = new SlashCommandBuilder()
|
this.CommandBuilder = new SlashCommandBuilder()
|
||||||
.setName("kick")
|
.setName("kick")
|
||||||
.setDescription("Kick a member from the server with an optional reason")
|
.setDescription("Kick a member from the server with an optional reason")
|
||||||
.setDefaultMemberPermissions(PermissionsBitField.Flags.KickMembers)
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.KickMembers)
|
||||||
|
|
|
@ -9,7 +9,7 @@ export default class Mute extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
super.CommandBuilder = new SlashCommandBuilder()
|
this.CommandBuilder = new SlashCommandBuilder()
|
||||||
.setName("mute")
|
.setName("mute")
|
||||||
.setDescription("(DEPRECATED) Mute a member in the server with an optional reason")
|
.setDescription("(DEPRECATED) Mute a member in the server with an optional reason")
|
||||||
.setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers)
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers)
|
||||||
|
|
|
@ -7,7 +7,7 @@ export default class Poll extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
super.CommandBuilder = new SlashCommandBuilder()
|
this.CommandBuilder = new SlashCommandBuilder()
|
||||||
.setName('poll')
|
.setName('poll')
|
||||||
.setDescription('Run a poll, automatically adding reaction emojis as options')
|
.setDescription('Run a poll, automatically adding reaction emojis as options')
|
||||||
.addStringOption(option =>
|
.addStringOption(option =>
|
||||||
|
|
|
@ -6,7 +6,7 @@ export default class Setup extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
super.CommandBuilder = new SlashCommandBuilder()
|
this.CommandBuilder = new SlashCommandBuilder()
|
||||||
.setName('setup')
|
.setName('setup')
|
||||||
.setDescription('Makes the server ready to be configured')
|
.setDescription('Makes the server ready to be configured')
|
||||||
.setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator);
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator);
|
||||||
|
|
|
@ -10,7 +10,7 @@ export default class Timeout extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
super.CommandBuilder = new SlashCommandBuilder()
|
this.CommandBuilder = new SlashCommandBuilder()
|
||||||
.setName("timeout")
|
.setName("timeout")
|
||||||
.setDescription("Timeouts a user out, sending them a DM with the reason if possible")
|
.setDescription("Timeouts a user out, sending them a DM with the reason if possible")
|
||||||
.setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers)
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers)
|
||||||
|
|
|
@ -9,7 +9,7 @@ export default class Warn extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
super.CommandBuilder = new SlashCommandBuilder()
|
this.CommandBuilder = new SlashCommandBuilder()
|
||||||
.setName("warn")
|
.setName("warn")
|
||||||
.setDescription("Warns a member in the server with an optional reason")
|
.setDescription("Warns a member in the server with an optional reason")
|
||||||
.setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers)
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers)
|
||||||
|
|
|
@ -46,14 +46,4 @@ export default class SettingsHelper {
|
||||||
await server.Save(Server, server);
|
await server.Save(Server, server);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async GetServerPrefix(serverId: string): Promise<string> {
|
|
||||||
const setting = await this.GetSetting("bot.prefix", serverId);
|
|
||||||
|
|
||||||
if (!setting) {
|
|
||||||
return "v!";
|
|
||||||
}
|
|
||||||
|
|
||||||
return setting;
|
|
||||||
}
|
|
||||||
}
|
}
|
15
tests/buttonEvents/verify.test.ts
Normal file
15
tests/buttonEvents/verify.test.ts
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
describe("execute", () => {
|
||||||
|
test.todo("EXPECT verification role to be given");
|
||||||
|
|
||||||
|
test.todo("GIVEN interaction.guildId is null, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN interaction.guild is null, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN verification.role setting is not found, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN role can not be found, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN member can not be found, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN member is not manageable, EXPECT error");
|
||||||
|
});
|
|
@ -1,153 +1,23 @@
|
||||||
import { mock } from "jest-mock-extended";
|
describe('constructor', () => {
|
||||||
|
test.todo("EXPECT properties to be set");
|
||||||
const connectionMock = mock<Connection>();
|
|
||||||
const qbuilderMock = mock<SelectQueryBuilder<any>>();
|
|
||||||
|
|
||||||
let repositoryMock = mock<Repository<any>>();
|
|
||||||
let settingMock = mock<Setting>();
|
|
||||||
|
|
||||||
jest.mock('typeorm', () => {
|
|
||||||
qbuilderMock.where.mockReturnThis();
|
|
||||||
qbuilderMock.select.mockReturnThis();
|
|
||||||
repositoryMock.createQueryBuilder.mockReturnValue(qbuilderMock);
|
|
||||||
repositoryMock.findOne.mockImplementation(async () => {
|
|
||||||
return settingMock;
|
|
||||||
});
|
|
||||||
connectionMock.getRepository.mockReturnValue(repositoryMock);
|
|
||||||
|
|
||||||
return {
|
|
||||||
getConnection: () => connectionMock,
|
|
||||||
createConnection: () => connectionMock,
|
|
||||||
|
|
||||||
BaseEntity: class Mock {},
|
|
||||||
ObjectType: () => {},
|
|
||||||
Entity: () => {},
|
|
||||||
InputType: () => {},
|
|
||||||
Index: () => {},
|
|
||||||
PrimaryColumn: () => {},
|
|
||||||
Column: () => {},
|
|
||||||
CreateDateColumn: () => {},
|
|
||||||
UpdateDateColumn: () => {},
|
|
||||||
OneToMany: () => {},
|
|
||||||
ManyToOne: () => {},
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
jest.mock("discord.js");
|
describe('start', () => {
|
||||||
jest.mock("dotenv");
|
test.todo("EXPECT bot to start");
|
||||||
jest.mock("../../src/client/events");
|
|
||||||
jest.mock("../../src/client/util");
|
|
||||||
jest.mock("../../src/constants/DefaultValues");
|
|
||||||
|
|
||||||
import { CoreClient } from "../../src/client/client";
|
test.todo("GIVEN BOT_TOKEN is not in env var, EXPECT error");
|
||||||
|
|
||||||
import { Client } from "discord.js";
|
test.todo("GIVEN database connection can not be initialised, EXPECT error");
|
||||||
import * as dotenv from "dotenv";
|
|
||||||
import { Events } from "../../src/client/events";
|
|
||||||
import { Util } from "../../src/client/util";
|
|
||||||
import { Command } from "../../src/type/command";
|
|
||||||
import { Event } from "../../src/type/event";
|
|
||||||
import DefaultValues from "../../src/constants/DefaultValues";
|
|
||||||
import { Connection, Repository, SelectQueryBuilder } from "typeorm";
|
|
||||||
import Setting from "../../src/entity/Setting";
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
jest.resetAllMocks();
|
|
||||||
jest.resetModules();
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('Constructor', () => {
|
|
||||||
test('Expect Successful Initialisation', () => {
|
|
||||||
const coreClient = new CoreClient();
|
|
||||||
|
|
||||||
expect(coreClient).toBeInstanceOf(Client);
|
|
||||||
expect(dotenv.config).toBeCalledTimes(1);
|
|
||||||
expect(Events).toBeCalledTimes(1);
|
|
||||||
expect(Util).toBeCalledTimes(1);
|
|
||||||
expect(DefaultValues.useDevPrefix).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given devmode parameter is true, Expect devmode prefix to be true', () => {
|
|
||||||
const coreClient = new CoreClient(true);
|
|
||||||
|
|
||||||
expect(coreClient).toBeInstanceOf(Client);
|
|
||||||
expect(dotenv.config).toBeCalledTimes(1);
|
|
||||||
expect(Events).toBeCalledTimes(1);
|
|
||||||
expect(Util).toBeCalledTimes(1);
|
|
||||||
expect(DefaultValues.useDevPrefix).toBe(true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Start', () => {
|
|
||||||
test('Given Env Is Valid, Expect Successful Start', async () => {
|
|
||||||
process.env = {
|
|
||||||
BOT_TOKEN: "TOKEN",
|
|
||||||
};
|
|
||||||
|
|
||||||
const coreClient = new CoreClient();
|
|
||||||
|
|
||||||
await coreClient.start();
|
|
||||||
|
|
||||||
expect(coreClient.on).toBeCalledWith("message", expect.any(Function));
|
|
||||||
expect(coreClient.on).toBeCalledWith("ready", expect.any(Function));
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given BOT_TOKEN Is Null, Expect Failure', async () => {
|
|
||||||
process.env = {};
|
|
||||||
|
|
||||||
const consoleError = jest.fn();
|
|
||||||
|
|
||||||
console.error = consoleError;
|
|
||||||
|
|
||||||
const coreClient = new CoreClient();
|
|
||||||
|
|
||||||
await coreClient.start();
|
|
||||||
|
|
||||||
expect(consoleError).toBeCalledWith("BOT_TOKEN is not defined in .env");
|
|
||||||
expect(coreClient.on).not.toBeCalled();
|
|
||||||
expect(coreClient.login).not.toBeCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given BOT_TOKEN Is Empty, Expect Failure', async () => {
|
|
||||||
process.env = {
|
|
||||||
BOT_TOKEN: '',
|
|
||||||
}
|
|
||||||
|
|
||||||
const consoleError = jest.fn();
|
|
||||||
|
|
||||||
console.error = consoleError;
|
|
||||||
|
|
||||||
const coreClient = new CoreClient();
|
|
||||||
|
|
||||||
await coreClient.start();
|
|
||||||
|
|
||||||
expect(consoleError).toBeCalledWith("BOT_TOKEN is not defined in .env");
|
|
||||||
expect(coreClient.on).not.toBeCalled();
|
|
||||||
expect(coreClient.login).not.toBeCalled();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('RegisterCommand', () => {
|
describe('RegisterCommand', () => {
|
||||||
test('Expect command added to register', () => {
|
test.todo("EXPECT command to be added to list");
|
||||||
const cmd = mock<Command>();
|
|
||||||
|
|
||||||
const client = new CoreClient();
|
|
||||||
client.RegisterCommand("test", cmd);
|
|
||||||
|
|
||||||
expect(client.commandItems.length).toBe(1);
|
|
||||||
expect(client.commandItems[0].Name).toBe("test");
|
|
||||||
expect(client.commandItems[0].Command).toBe(cmd);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('RegisterEvent', () => {
|
describe("RegisterEvent", () => {
|
||||||
test('Expect event added to register', () => {
|
test.todo("EXPECT event to be added to list");
|
||||||
const evt = mock<Event>();
|
});
|
||||||
|
|
||||||
const client = new CoreClient();
|
|
||||||
client.RegisterEvent(evt);
|
|
||||||
|
|
||||||
expect(client.eventItems.length).toBe(1);
|
describe("RegisterButtonEvent", () => {
|
||||||
expect(client.eventItems[0].Event).toBe(evt);
|
test.todo("EXPECT button event to be added to list");
|
||||||
});
|
|
||||||
});
|
});
|
|
@ -1,241 +1,11 @@
|
||||||
import { Events } from "../../src/client/events";
|
describe('onInteractionCreate', () => {
|
||||||
import { Message } from "discord.js";
|
test.todo("GIVEN the interaction is a chat input command, EXPECT chat input command handler to be executed");
|
||||||
import { Util } from "../../src/client/util";
|
|
||||||
import ICommandItem from "../../src/contracts/ICommandItem";
|
|
||||||
import { Command } from "../../src/type/command";
|
|
||||||
import { mock } from "jest-mock-extended";
|
|
||||||
|
|
||||||
jest.mock("../../src/client/util");
|
test.todo("GIVEN the interaction is a button, EXPECT button handler to be executed");
|
||||||
|
|
||||||
beforeEach(() => {
|
test.todo("GIVEN interaction.guildId is null, EXPECT nothing to happen");
|
||||||
Util.prototype.loadCommand = jest.fn();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('OnMessage', () => {
|
describe("onReady", () => {
|
||||||
test('Given Message Is Valid Expect Message Sent', async () => {
|
test.todo("EXPECT console to be logged");
|
||||||
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 cmd = mock<Command>();
|
|
||||||
|
|
||||||
const commandItem: ICommandItem = {
|
|
||||||
Name: "test",
|
|
||||||
Command: cmd
|
|
||||||
};
|
|
||||||
|
|
||||||
const commands: ICommandItem[] = [ commandItem ];
|
|
||||||
|
|
||||||
const events = new Events();
|
|
||||||
|
|
||||||
const result = await events.onMessage(message, commands);
|
|
||||||
|
|
||||||
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', async () => {
|
|
||||||
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 cmd = mock<Command>();
|
|
||||||
|
|
||||||
const commandItem: ICommandItem = {
|
|
||||||
Name: "test",
|
|
||||||
Command: cmd
|
|
||||||
};
|
|
||||||
|
|
||||||
const commands: ICommandItem[] = [ commandItem ];
|
|
||||||
|
|
||||||
const events = new Events();
|
|
||||||
|
|
||||||
const result = await events.onMessage(message, commands);
|
|
||||||
|
|
||||||
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', async () => {
|
|
||||||
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 cmd = mock<Command>();
|
|
||||||
|
|
||||||
const commandItem: ICommandItem = {
|
|
||||||
Name: "test",
|
|
||||||
Command: cmd
|
|
||||||
};
|
|
||||||
|
|
||||||
const commands: ICommandItem[] = [ commandItem ];
|
|
||||||
|
|
||||||
const events = new Events();
|
|
||||||
|
|
||||||
const result = await events.onMessage(message, commands);
|
|
||||||
|
|
||||||
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', async () => {
|
|
||||||
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 cmd = mock<Command>();
|
|
||||||
|
|
||||||
const commandItem: ICommandItem = {
|
|
||||||
Name: "test",
|
|
||||||
Command: cmd
|
|
||||||
};
|
|
||||||
|
|
||||||
const commands: ICommandItem[] = [ commandItem ];
|
|
||||||
|
|
||||||
const events = new Events();
|
|
||||||
|
|
||||||
const result = await events.onMessage(message, commands);
|
|
||||||
|
|
||||||
expect(result.valid).toBeFalsy();
|
|
||||||
expect(result.message).toBe("Message was not a command, ignoring.");
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given Message Had No Command Name, Expect Failed Result', async () => {
|
|
||||||
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 cmd = mock<Command>();
|
|
||||||
|
|
||||||
const commandItem: ICommandItem = {
|
|
||||||
Name: "test",
|
|
||||||
Command: cmd
|
|
||||||
};
|
|
||||||
|
|
||||||
const commands: ICommandItem[] = [ commandItem ];
|
|
||||||
|
|
||||||
const events = new Events();
|
|
||||||
|
|
||||||
const result = await events.onMessage(message, commands);
|
|
||||||
|
|
||||||
expect(result.valid).toBeFalsy();
|
|
||||||
expect(result.message).toBe("Command name was not found");
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given Command Failed To Execute, Expect Failed Result', async () => {
|
|
||||||
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 cmd = mock<Command>();
|
|
||||||
|
|
||||||
const commandItem: ICommandItem = {
|
|
||||||
Name: "test",
|
|
||||||
Command: cmd
|
|
||||||
};
|
|
||||||
|
|
||||||
const commands: ICommandItem[] = [ commandItem ];
|
|
||||||
|
|
||||||
const events = new Events();
|
|
||||||
|
|
||||||
const result = await events.onMessage(message, commands);
|
|
||||||
|
|
||||||
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");
|
|
||||||
});
|
|
||||||
});
|
|
7
tests/client/interactionCreate/button.test.ts
Normal file
7
tests/client/interactionCreate/button.test.ts
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
describe('onButtonClicked', () => {
|
||||||
|
test.todo("EXPECT button event to be executed");
|
||||||
|
|
||||||
|
test.todo("GIVEN interaction is not a button, EXEPCT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN button event is not registered, EXPECT error");
|
||||||
|
});
|
9
tests/client/interactionCreate/chatInputCommand.test.ts
Normal file
9
tests/client/interactionCreate/chatInputCommand.test.ts
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
describe('onChatInput', () => {
|
||||||
|
test.todo("GIVEN command is registered globally AND command is found, execute the global command");
|
||||||
|
|
||||||
|
test.todo("GIVEN command is registered to a single server, execute the server command");
|
||||||
|
|
||||||
|
test.todo("GIVEN interaction is not a chat input command, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN command is registered globally AND command is not found, EXPECT error");
|
||||||
|
});
|
|
@ -1,370 +1,31 @@
|
||||||
import { Util } from "../../src/client/util";
|
describe("loadSlashCommands", () => {
|
||||||
|
test.todo("EXPECT slash commands to be loaded to the discord API");
|
||||||
|
|
||||||
import { Client, Message } from "discord.js";
|
test.todo("GIVEN bot is not in a guild for a server command, EXPECT this to be ignored");
|
||||||
import fs from "fs";
|
|
||||||
import { mock } from "jest-mock-extended";
|
|
||||||
import { Command } from "../../src/type/command";
|
|
||||||
import ICommandItem from "../../src/contracts/ICommandItem";
|
|
||||||
import IEventItem from "../../src/contracts/IEventItem";
|
|
||||||
import { Event } from "../../src/type/event";
|
|
||||||
|
|
||||||
jest.mock("fs");
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
fs.existsSync = jest.fn();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('LoadCommand', () => {
|
describe("loadEvents", () => {
|
||||||
test('Given Successful Exection, Expect Successful Result', async () => {
|
test.todo("GIVEN event type is channelCreate, EXPECT event function to be executed");
|
||||||
process.env = {
|
|
||||||
BOT_TOKEN: 'TOKEN',
|
|
||||||
BOT_PREFIX: '!',
|
|
||||||
FOLDERS_COMMANDS: 'commands',
|
|
||||||
FOLDERS_EVENTS: 'events',
|
|
||||||
}
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
member: {
|
|
||||||
roles: {
|
|
||||||
cache: {
|
|
||||||
find: jest.fn().mockReturnValue(true),
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
reply: jest.fn(),
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const cmd = mock<Command>();
|
test.todo("GIVEN event type is channelDelete, EXPECT event function to be executed");
|
||||||
|
|
||||||
const commandItem: ICommandItem = {
|
test.todo("GIVEN event type is channelUpdate, EXPECT event function to be executed");
|
||||||
Name: "test",
|
|
||||||
Command: cmd
|
|
||||||
};
|
|
||||||
|
|
||||||
const commands: ICommandItem[] = [ commandItem ];
|
test.todo("GIVEN event type is guildBanAdd, EXPECT event function to be executed");
|
||||||
|
|
||||||
const util = new Util();
|
|
||||||
|
|
||||||
const result = await util.loadCommand("test", [ "first" ], message, commands);
|
|
||||||
|
|
||||||
expect(result.valid).toBeTruthy();
|
|
||||||
expect(cmd.execute).toBeCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given Member Is Null, Expect Failed Result', async () => {
|
|
||||||
process.env = {
|
|
||||||
BOT_TOKEN: 'TOKEN',
|
|
||||||
BOT_PREFIX: '!',
|
|
||||||
FOLDERS_COMMANDS: 'commands',
|
|
||||||
FOLDERS_EVENTS: 'events',
|
|
||||||
}
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
member: null
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const cmd = mock<Command>();
|
test.todo("GIVEN event type is guildBanRemove, EXPECT event function to be executed");
|
||||||
|
|
||||||
const commandItem: ICommandItem = {
|
test.todo("GIVEN event type is guildCreate, EXPECT event function to be executed");
|
||||||
Name: "test",
|
|
||||||
Command: cmd
|
|
||||||
};
|
|
||||||
|
|
||||||
const commands: ICommandItem[] = [ commandItem ];
|
test.todo("GIVEN event type is guildMemberAdd, EXPECT event function to be executed");
|
||||||
|
|
||||||
const util = new Util();
|
|
||||||
|
|
||||||
const result = await util.loadCommand("test", [ "first" ], message, commands);
|
|
||||||
|
|
||||||
expect(result.valid).toBeFalsy();
|
|
||||||
expect(result.message).toBe("Member is not part of message");
|
|
||||||
expect(cmd.execute).not.toBeCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given User Does Have Role, Expect Successful Result', async () => {
|
|
||||||
process.env = {
|
|
||||||
BOT_TOKEN: 'TOKEN',
|
|
||||||
BOT_PREFIX: '!',
|
|
||||||
FOLDERS_COMMANDS: 'commands',
|
|
||||||
FOLDERS_EVENTS: 'events',
|
|
||||||
}
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
member: {
|
|
||||||
roles: {
|
|
||||||
cache: {
|
|
||||||
find: jest.fn().mockReturnValue(true),
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
reply: jest.fn(),
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const cmd = mock<Command>();
|
test.todo("GIVEN event type is guildMemberRemove, EXPECT event function to be executed");
|
||||||
|
|
||||||
const commandItem: ICommandItem = {
|
test.todo("GIVEN event type is messageCreate, EXPECT event function to be executed");
|
||||||
Name: "test",
|
|
||||||
Command: cmd
|
|
||||||
};
|
|
||||||
|
|
||||||
const commands: ICommandItem[] = [ commandItem ];
|
test.todo("GIVEN event type is messageDelete, EXPECT event function to be executed");
|
||||||
|
|
||||||
const util = new Util();
|
|
||||||
|
|
||||||
const result = await util.loadCommand("test", [ "first" ], message, commands);
|
|
||||||
|
|
||||||
expect(result.valid).toBeTruthy();
|
|
||||||
expect(cmd.execute).toBeCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given User Does Not Have Role, Expect Failed Result', async () => {
|
|
||||||
process.env = {
|
|
||||||
BOT_TOKEN: 'TOKEN',
|
|
||||||
BOT_PREFIX: '!',
|
|
||||||
FOLDERS_COMMANDS: 'commands',
|
|
||||||
FOLDERS_EVENTS: 'events',
|
|
||||||
}
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
member: {
|
|
||||||
roles: {
|
|
||||||
cache: {
|
|
||||||
find: jest.fn().mockReturnValue(false),
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
reply: jest.fn(),
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const cmd = mock<Command>();
|
test.todo("GIVEN event type is messageUpdate, EXPECT event function to be executed");
|
||||||
cmd._roles = [ "Moderator" ];
|
|
||||||
|
|
||||||
const commandItem: ICommandItem = {
|
test.todo("GIVEN event type is not implemented, EXPECT error");
|
||||||
Name: "test",
|
});
|
||||||
Command: cmd
|
|
||||||
};
|
|
||||||
|
|
||||||
const commands: ICommandItem[] = [ commandItem ];
|
|
||||||
|
|
||||||
const util = new Util();
|
|
||||||
|
|
||||||
const result = await util.loadCommand("test", [ "first" ], message, commands);
|
|
||||||
|
|
||||||
expect(result.valid).toBeFalsy();
|
|
||||||
expect(result.message).toBe("You require the `Moderator` role to run this command");
|
|
||||||
expect(cmd.execute).not.toBeCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given command is set to disabled, Expect command to not fire', async () => {
|
|
||||||
process.env = {
|
|
||||||
BOT_TOKEN: 'TOKEN',
|
|
||||||
BOT_PREFIX: '!',
|
|
||||||
FOLDERS_COMMANDS: 'commands',
|
|
||||||
FOLDERS_EVENTS: 'events',
|
|
||||||
COMMANDS_DISABLED: 'test',
|
|
||||||
COMMANDS_DISABLED_MESSAGE: 'disabled',
|
|
||||||
}
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
member: {
|
|
||||||
roles: {
|
|
||||||
cache: {
|
|
||||||
find: jest.fn().mockReturnValue(true),
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
reply: jest.fn(),
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const messageReply = jest.spyOn(message, 'reply');
|
|
||||||
|
|
||||||
const cmd = mock<Command>();
|
|
||||||
|
|
||||||
const commandItem: ICommandItem = {
|
|
||||||
Name: "test",
|
|
||||||
Command: cmd
|
|
||||||
};
|
|
||||||
|
|
||||||
const commands: ICommandItem[] = [ commandItem ];
|
|
||||||
|
|
||||||
const util = new Util();
|
|
||||||
|
|
||||||
const result = await util.loadCommand("test", [ "first" ], message, commands);
|
|
||||||
|
|
||||||
expect(result.valid).toBeFalsy();
|
|
||||||
expect(result.message).toBe("Command is disabled");
|
|
||||||
expect(messageReply).toBeCalledWith("disabled");
|
|
||||||
expect(cmd.execute).not.toBeCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given command COMMANDS_DISABLED_MESSAGE is empty, Expect default message sent', async () => {
|
|
||||||
process.env = {
|
|
||||||
BOT_TOKEN: 'TOKEN',
|
|
||||||
BOT_PREFIX: '!',
|
|
||||||
FOLDERS_COMMANDS: 'commands',
|
|
||||||
FOLDERS_EVENTS: 'events',
|
|
||||||
COMMANDS_DISABLED: 'test',
|
|
||||||
}
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
member: {
|
|
||||||
roles: {
|
|
||||||
cache: {
|
|
||||||
find: jest.fn().mockReturnValue(true),
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
reply: jest.fn(),
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const messageReply = jest.spyOn(message, 'reply');
|
|
||||||
|
|
||||||
const cmd = mock<Command>();
|
|
||||||
|
|
||||||
const commandItem: ICommandItem = {
|
|
||||||
Name: "test",
|
|
||||||
Command: cmd
|
|
||||||
};
|
|
||||||
|
|
||||||
const commands: ICommandItem[] = [ commandItem ];
|
|
||||||
|
|
||||||
const util = new Util();
|
|
||||||
|
|
||||||
const result = await util.loadCommand("test", [ "first" ], message, commands);
|
|
||||||
|
|
||||||
expect(result.valid).toBeFalsy();
|
|
||||||
expect(result.message).toBe("Command is disabled");
|
|
||||||
expect(messageReply).toBeCalledWith("This command is disabled.");
|
|
||||||
expect(cmd.execute).not.toBeCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given a different command is disabled, Expect command to still fire', async () => {
|
|
||||||
process.env = {
|
|
||||||
BOT_TOKEN: 'TOKEN',
|
|
||||||
BOT_PREFIX: '!',
|
|
||||||
FOLDERS_COMMANDS: 'commands',
|
|
||||||
FOLDERS_EVENTS: 'events',
|
|
||||||
COMMANDS_DISABLED: 'other',
|
|
||||||
}
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
member: {
|
|
||||||
roles: {
|
|
||||||
cache: {
|
|
||||||
find: jest.fn().mockReturnValue(true),
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
reply: jest.fn(),
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const cmd = mock<Command>();
|
|
||||||
const otherCmd = mock<Command>();
|
|
||||||
|
|
||||||
const commandItem: ICommandItem = {
|
|
||||||
Name: "test",
|
|
||||||
Command: cmd
|
|
||||||
};
|
|
||||||
|
|
||||||
const otherCommandItem: ICommandItem = {
|
|
||||||
Name: "other",
|
|
||||||
Command: otherCmd,
|
|
||||||
}
|
|
||||||
|
|
||||||
const commands: ICommandItem[] = [ commandItem, otherCommandItem ];
|
|
||||||
|
|
||||||
const util = new Util();
|
|
||||||
|
|
||||||
const result = await util.loadCommand("test", [ "first" ], message, commands);
|
|
||||||
|
|
||||||
expect(result.valid).toBeTruthy();
|
|
||||||
expect(cmd.execute).toBeCalled();
|
|
||||||
expect(otherCmd.execute).not.toBeCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given command is not found in register, expect command not found error', async () => {
|
|
||||||
process.env = {
|
|
||||||
BOT_TOKEN: 'TOKEN',
|
|
||||||
BOT_PREFIX: '!',
|
|
||||||
FOLDERS_COMMANDS: 'commands',
|
|
||||||
FOLDERS_EVENTS: 'events',
|
|
||||||
}
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
member: {
|
|
||||||
roles: {
|
|
||||||
cache: {
|
|
||||||
find: jest.fn().mockReturnValue(true),
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
reply: jest.fn(),
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const commands: ICommandItem[] = [];
|
|
||||||
|
|
||||||
const util = new Util();
|
|
||||||
|
|
||||||
const result = await util.loadCommand("test", [ "first" ], message, commands);
|
|
||||||
|
|
||||||
expect(result.valid).toBeFalsy();
|
|
||||||
expect(result.message).toBe('Command not found');
|
|
||||||
expect(message.reply).toBeCalledWith('Command not found');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('LoadEvents', () => {
|
|
||||||
test('Given Events Are Loaded, Expect Successful Result', () => {
|
|
||||||
process.env = {
|
|
||||||
BOT_TOKEN: 'TOKEN',
|
|
||||||
BOT_PREFIX: '!',
|
|
||||||
FOLDERS_COMMANDS: 'commands',
|
|
||||||
FOLDERS_EVENTS: 'events',
|
|
||||||
}
|
|
||||||
|
|
||||||
const client = {
|
|
||||||
on: jest.fn(),
|
|
||||||
} as unknown as Client;
|
|
||||||
|
|
||||||
const evt = mock<Event>();
|
|
||||||
|
|
||||||
const eventItem: IEventItem = {
|
|
||||||
Event: evt
|
|
||||||
};
|
|
||||||
|
|
||||||
const eventItems: IEventItem[] = [ eventItem ];
|
|
||||||
|
|
||||||
const util = new Util();
|
|
||||||
|
|
||||||
const result = util.loadEvents(client, eventItems);
|
|
||||||
|
|
||||||
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',
|
|
||||||
}
|
|
||||||
|
|
||||||
const client = {
|
|
||||||
on: jest.fn(),
|
|
||||||
} as unknown as Client;
|
|
||||||
|
|
||||||
const eventItems: IEventItem[] = [];
|
|
||||||
|
|
||||||
const util = new Util();
|
|
||||||
|
|
||||||
const result = util.loadEvents(client, eventItems);
|
|
||||||
|
|
||||||
const clientOn = jest.spyOn(client, 'on');
|
|
||||||
|
|
||||||
expect(result.valid).toBeTruthy();
|
|
||||||
expect(clientOn).toBeCalledTimes(0);
|
|
||||||
});
|
|
||||||
});
|
|
25
tests/commands/501231711271780357/Lobby/add.test.ts
Normal file
25
tests/commands/501231711271780357/Lobby/add.test.ts
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
describe('constuctor', () => {
|
||||||
|
test.todo("EXPECT properties to be set");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('execute', () => {
|
||||||
|
test.todo("EXPECT channel to be added to the lobby database table");
|
||||||
|
|
||||||
|
test.todo("GIVEN channel is null, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN channel.channel is undefined, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN role is null, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN role.role is undefined, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN cooldown is null, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN cooldown.value is undefined, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN gameName is null, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN gameName.value is undefined, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN channel has already been set up in the database, EXPECT error");
|
||||||
|
});
|
9
tests/commands/501231711271780357/Lobby/list.test.ts
Normal file
9
tests/commands/501231711271780357/Lobby/list.test.ts
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
describe('constructor', () => {
|
||||||
|
test.todo("EXPECT properties to be set");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("execute", () => {
|
||||||
|
test.todo('EXPECT list of lobby channels to be sent');
|
||||||
|
|
||||||
|
test.todo("GIVEN interaction.guild is null, EXPECT error");
|
||||||
|
});
|
13
tests/commands/501231711271780357/Lobby/lobby.test.ts
Normal file
13
tests/commands/501231711271780357/Lobby/lobby.test.ts
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
describe('constructor', () => {
|
||||||
|
test.todo("EXPECT properties to be set");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("execute", () => {
|
||||||
|
test.todo("EXPECT lobby command to announce a lobby setup");
|
||||||
|
|
||||||
|
test.todo("GIVEN interaction.channelId is null, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN channel is not setup in the database as a lobby, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN lobby command was last used within the cooldown, EXPECT error");
|
||||||
|
});
|
13
tests/commands/501231711271780357/Lobby/remove.test.ts
Normal file
13
tests/commands/501231711271780357/Lobby/remove.test.ts
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
describe('constructor', () => {
|
||||||
|
test.todo("EXPECT properties to be set");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("execute", () => {
|
||||||
|
test.todo("EXPECT channel to be removed from database");
|
||||||
|
|
||||||
|
test.todo("GIVEN channel is null, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN channel.channel is undefined, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN channel is not set up as a lobby, EXPECT error");
|
||||||
|
});
|
13
tests/commands/501231711271780357/entry.test.ts
Normal file
13
tests/commands/501231711271780357/entry.test.ts
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
describe('constructor', () => {
|
||||||
|
test.todo("EXPECT properties to be set");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("execute", () => {
|
||||||
|
test.todo("EXPECT entry embed to be sent");
|
||||||
|
|
||||||
|
test.todo("GIVEN interaction.guildId is null, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN interaction.channel is null, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN channels.rules setting is not set, EXPECT channel id to be defaulted");
|
||||||
|
});
|
21
tests/commands/Role/config.test.ts
Normal file
21
tests/commands/Role/config.test.ts
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
describe('constructor', () => {
|
||||||
|
test.todo('EXPECT properties to be set');
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("execute", () => {
|
||||||
|
test.todo("GIVEN role is marked as assignable, EXPECT role to be removed");
|
||||||
|
|
||||||
|
test.todo("GIVEN role is not marked as assignable, EXPECT role to be added");
|
||||||
|
|
||||||
|
test.todo("GIVEN interaction.guildId is null, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN interaction.guild is null, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN interaction.member is null, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN role is null, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN role.role is undefined, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN server is not configured in the database, EXPECT error");
|
||||||
|
});
|
37
tests/commands/Role/role.test.ts
Normal file
37
tests/commands/Role/role.test.ts
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
beforeEach(() => {
|
||||||
|
process.env = {};
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Constructor', () => {
|
||||||
|
test.todo('EXPECT properties are set');
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Execute', () => {
|
||||||
|
test.todo("GIVEN interaction is not a chat input command, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN an invalid subcommand is given, EXPECT not found error");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("toggle", () => {
|
||||||
|
test.todo("GIVEN user has the role, EXPECT role to be removed");
|
||||||
|
|
||||||
|
test.todo("GIVEN user does not have the role, EXPECT role to be added")
|
||||||
|
|
||||||
|
test.todo("GIVEN interaction.guild is null, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN interaction.member is null, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN requestedRole is null, EXPECT invalid error");
|
||||||
|
|
||||||
|
test.todo("GIVEN requestedRole.role is undefined, EXPECT invalid error");
|
||||||
|
|
||||||
|
test.todo("GIVEN role is not assignable, EXPECT unassignable error");
|
||||||
|
|
||||||
|
test.todo("GIVEN assignRole is not foundm, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN assignRole is not editable, EXPECT insufficient permissions error");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("list", () => {
|
||||||
|
test.todo("EXPECT role list to be sent");
|
||||||
|
});
|
|
@ -1,8 +1,6 @@
|
||||||
import { Message } from "discord.js";
|
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, CommandInteraction, EmbedBuilder, InteractionReplyOptions,SlashCommandBuilder } from "discord.js";
|
||||||
import { mock } from "jest-mock-extended";
|
|
||||||
import About from "../../src/commands/about";
|
import About from "../../src/commands/about";
|
||||||
import { ICommandContext } from "../../src/contracts/ICommandContext";
|
import EmbedColours from "../../src/constants/EmbedColours";
|
||||||
import PublicEmbed from "../../src/helpers/embeds/PublicEmbed";
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
process.env = {};
|
process.env = {};
|
||||||
|
@ -10,143 +8,169 @@ beforeEach(() => {
|
||||||
|
|
||||||
describe('Constructor', () => {
|
describe('Constructor', () => {
|
||||||
test('Expect values set', () => {
|
test('Expect values set', () => {
|
||||||
const about = new About();
|
const command = new About();
|
||||||
|
|
||||||
expect(about._category).toBe("General");
|
expect(command.CommandBuilder).toBeDefined();
|
||||||
|
|
||||||
|
const commandBuilder = command.CommandBuilder as SlashCommandBuilder;
|
||||||
|
|
||||||
|
expect(commandBuilder.name).toBe("about");
|
||||||
|
expect(commandBuilder.description).toBe("About VylBot");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Execute', () => {
|
describe('Execute', () => {
|
||||||
test('Expect embed to be made and sent to the current channel', async () => {
|
test('GIVEN ABOUT_FUNDING and ABOUT_REPO are NOT present in env var, EXPECT embed to be sent without buttons', async () => {
|
||||||
process.env = {
|
// Setup
|
||||||
BOT_VER: "BOT_VER",
|
let replyOptions: InteractionReplyOptions | undefined;
|
||||||
BOT_AUTHOR: "BOT_AUTHOR",
|
|
||||||
BOT_DATE: "BOT_DATE"
|
|
||||||
};
|
|
||||||
|
|
||||||
const message = mock<Message>();
|
const interaction = {
|
||||||
message.channel.send = jest.fn();
|
reply: jest.fn((options: InteractionReplyOptions) => {
|
||||||
|
replyOptions = options;
|
||||||
|
}),
|
||||||
|
} as unknown as CommandInteraction;
|
||||||
|
|
||||||
const context: ICommandContext = {
|
// Execution
|
||||||
name: "about",
|
process.env.BOT_VER = "VERSION";
|
||||||
args: [],
|
process.env.BOT_AUTHOR = "AUTHOR";
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const about = new About();
|
const command = new About();
|
||||||
|
|
||||||
const result = await about.execute(context);
|
await command.execute(interaction);
|
||||||
|
|
||||||
expect(message.channel.send).toBeCalledTimes(1);
|
// Assertion
|
||||||
|
expect(interaction.reply).toHaveBeenCalledTimes(1);
|
||||||
|
expect(replyOptions).toBeDefined();
|
||||||
|
|
||||||
|
expect(replyOptions?.embeds).toBeDefined();
|
||||||
|
expect(replyOptions?.embeds?.length).toBe(1);
|
||||||
|
|
||||||
|
expect(replyOptions?.components).toBeDefined();
|
||||||
|
expect(replyOptions?.components?.length).toBe(0);
|
||||||
|
|
||||||
|
const repliedEmbed = replyOptions?.embeds![0] as EmbedBuilder;
|
||||||
|
|
||||||
|
expect(repliedEmbed.data.color).toBe(EmbedColours.Ok);
|
||||||
|
expect(repliedEmbed.data.title).toBe("About");
|
||||||
|
expect(repliedEmbed.data.description).toBe("Discord Bot made by Vylpes");
|
||||||
|
expect(repliedEmbed.data.fields?.length).toBe(2);
|
||||||
|
|
||||||
|
const repliedEmbedVersionField = repliedEmbed.data.fields![0];
|
||||||
|
|
||||||
|
expect(repliedEmbedVersionField.name).toBe("Version");
|
||||||
|
expect(repliedEmbedVersionField.value).toBe("VERSION");
|
||||||
|
expect(repliedEmbedVersionField.inline).toBeTruthy();
|
||||||
|
|
||||||
|
const repliedEmbedAuthorField = repliedEmbed.data.fields![1];
|
||||||
|
|
||||||
|
expect(repliedEmbedAuthorField.name).toBe("Author");
|
||||||
|
expect(repliedEmbedAuthorField.value).toBe("AUTHOR");
|
||||||
|
expect(repliedEmbedAuthorField.inline).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Expect embed send to have values', async () => {
|
test('GIVEN ABOUT_FUNDING is present in env var, EXPECT funding button to be sent', async () => {
|
||||||
process.env = {
|
// Setup
|
||||||
BOT_VER: "BOT_VER",
|
let replyOptions: InteractionReplyOptions | undefined;
|
||||||
BOT_AUTHOR: "BOT_AUTHOR",
|
|
||||||
BOT_DATE: "BOT_DATE"
|
|
||||||
};
|
|
||||||
|
|
||||||
const message = mock<Message>();
|
const interaction = {
|
||||||
message.channel.send = jest.fn();
|
reply: jest.fn((options: InteractionReplyOptions) => {
|
||||||
|
replyOptions = options;
|
||||||
|
}),
|
||||||
|
} as unknown as CommandInteraction;
|
||||||
|
|
||||||
const context: ICommandContext = {
|
// Execution
|
||||||
name: "about",
|
process.env.BOT_VER = "VERSION";
|
||||||
args: [],
|
process.env.BOT_AUTHOR = "AUTHOR";
|
||||||
message: message
|
process.env.ABOUT_FUNDING = "https://ko-fi.com/vylpes";
|
||||||
};
|
|
||||||
|
|
||||||
const about = new About();
|
const command = new About();
|
||||||
|
|
||||||
const result = await about.execute(context);
|
await command.execute(interaction);
|
||||||
|
|
||||||
expect(result.embeds.length).toBe(1);
|
// Assertion
|
||||||
|
expect(replyOptions?.components?.length).toBe(1);
|
||||||
|
|
||||||
const embed = result.embeds[0];
|
const repliedRow = replyOptions?.components![0] as ActionRowBuilder<ButtonBuilder>;
|
||||||
|
|
||||||
expect(embed.title).toBe('About');
|
expect(repliedRow.components?.length).toBe(1);
|
||||||
expect(embed.description).toBe('');
|
|
||||||
expect(embed.fields.length).toBe(3);
|
const repliedRowFundingComponent = repliedRow.components![0] as any;
|
||||||
|
|
||||||
|
expect(repliedRowFundingComponent.data.url).toBe("https://ko-fi.com/vylpes");
|
||||||
|
expect(repliedRowFundingComponent.data.label).toBe("Funding");
|
||||||
|
expect(repliedRowFundingComponent.data.style).toBe(ButtonStyle.Link);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Expect version field to have values', async () => {
|
test('GIVEN ABOUT_REPO is present in env var, EXPECT funding button to be sent', async () => {
|
||||||
process.env = {
|
// Setup
|
||||||
BOT_VER: "BOT_VER",
|
let replyOptions: InteractionReplyOptions | undefined;
|
||||||
BOT_AUTHOR: "BOT_AUTHOR",
|
|
||||||
BOT_DATE: "BOT_DATE"
|
|
||||||
};
|
|
||||||
|
|
||||||
const message = mock<Message>();
|
const interaction = {
|
||||||
message.channel.send = jest.fn();
|
reply: jest.fn((options: InteractionReplyOptions) => {
|
||||||
|
replyOptions = options;
|
||||||
|
}),
|
||||||
|
} as unknown as CommandInteraction;
|
||||||
|
|
||||||
const context: ICommandContext = {
|
// Execution
|
||||||
name: "about",
|
process.env.BOT_VER = "VERSION";
|
||||||
args: [],
|
process.env.BOT_AUTHOR = "AUTHOR";
|
||||||
message: message
|
process.env.ABOUT_REPO = "https://gitea.vylpes.xyz/rabbitlabs/vylbot-app";
|
||||||
};
|
|
||||||
|
|
||||||
const about = new About();
|
const command = new About();
|
||||||
|
|
||||||
const result = await about.execute(context);
|
await command.execute(interaction);
|
||||||
|
|
||||||
const embed = result.embeds[0];
|
// Assertion
|
||||||
const field = embed.fields[0];
|
expect(replyOptions?.components?.length).toBe(1);
|
||||||
|
|
||||||
expect(field.name).toBe('Version');
|
const repliedRow = replyOptions?.components![0] as ActionRowBuilder<ButtonBuilder>;
|
||||||
expect(field.value).toBe('BOT_VER');
|
|
||||||
|
expect(repliedRow.components?.length).toBe(1);
|
||||||
|
|
||||||
|
const repliedRowRepoComponent = repliedRow.components![0] as any;
|
||||||
|
|
||||||
|
expect(repliedRowRepoComponent.data.url).toBe("https://gitea.vylpes.xyz/rabbitlabs/vylbot-app");
|
||||||
|
expect(repliedRowRepoComponent.data.label).toBe("Repo");
|
||||||
|
expect(repliedRowRepoComponent.data.style).toBe(ButtonStyle.Link);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Expect author field to have values', async () => {
|
test('GIVEN ABOUT_REPO AND ABOUT_FUNDING is present in env var, EXPECT funding button to be sent', async () => {
|
||||||
process.env = {
|
// Setup
|
||||||
BOT_VER: "BOT_VER",
|
let replyOptions: InteractionReplyOptions | undefined;
|
||||||
BOT_AUTHOR: "BOT_AUTHOR",
|
|
||||||
BOT_DATE: "BOT_DATE"
|
|
||||||
};
|
|
||||||
|
|
||||||
const message = mock<Message>();
|
const interaction = {
|
||||||
message.channel.send = jest.fn();
|
reply: jest.fn((options: InteractionReplyOptions) => {
|
||||||
|
replyOptions = options;
|
||||||
|
}),
|
||||||
|
} as unknown as CommandInteraction;
|
||||||
|
|
||||||
const context: ICommandContext = {
|
// Execution
|
||||||
name: "about",
|
process.env.BOT_VER = "VERSION";
|
||||||
args: [],
|
process.env.BOT_AUTHOR = "AUTHOR";
|
||||||
message: message
|
process.env.ABOUT_REPO = "https://gitea.vylpes.xyz/rabbitlabs/vylbot-app";
|
||||||
};
|
process.env.ABOUT_FUNDING = "https://ko-fi.com/vylpes";
|
||||||
|
|
||||||
const about = new About();
|
const command = new About();
|
||||||
|
|
||||||
const result = await about.execute(context);
|
await command.execute(interaction);
|
||||||
|
|
||||||
const embed = result.embeds[0];
|
// Assertion
|
||||||
const field = embed.fields[1];
|
expect(replyOptions?.components?.length).toBe(1);
|
||||||
|
|
||||||
expect(field.name).toBe('Author');
|
const repliedRow = replyOptions?.components![0] as ActionRowBuilder<ButtonBuilder>;
|
||||||
expect(field.value).toBe('BOT_AUTHOR');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Expect version field to have values', async () => {
|
expect(repliedRow.components?.length).toBe(2);
|
||||||
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 = {
|
const repliedRowRepoComponent = repliedRow.components![0] as any;
|
||||||
name: "about",
|
|
||||||
args: [],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const about = new About();
|
expect(repliedRowRepoComponent.data.url).toBe("https://gitea.vylpes.xyz/rabbitlabs/vylbot-app");
|
||||||
|
expect(repliedRowRepoComponent.data.label).toBe("Repo");
|
||||||
|
expect(repliedRowRepoComponent.data.style).toBe(ButtonStyle.Link);
|
||||||
|
|
||||||
const result = await about.execute(context);
|
const repliedRowFundingComponent = repliedRow.components![1] as any;
|
||||||
|
|
||||||
const embed = result.embeds[0];
|
expect(repliedRowFundingComponent.data.url).toBe("https://ko-fi.com/vylpes");
|
||||||
const field = embed.fields[2];
|
expect(repliedRowFundingComponent.data.label).toBe("Funding");
|
||||||
|
expect(repliedRowFundingComponent.data.style).toBe(ButtonStyle.Link);
|
||||||
expect(field.name).toBe('Date');
|
|
||||||
expect(field.value).toBe('BOT_DATE');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
63
tests/commands/audits.test.ts
Normal file
63
tests/commands/audits.test.ts
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
describe("constructor", () => {
|
||||||
|
test.todo("EXPECT properties to be set");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('execute', () => {
|
||||||
|
test.todo("GIVEN interaction is not a chat input command, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN subcommand is invalid, EXPECT error");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("user", () => {
|
||||||
|
test.todo("EXPECT audits for user to be sent");
|
||||||
|
|
||||||
|
test.todo("GIVEN interaction.guildId is null, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN user is null, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN audits null, EXPECT no audits to be displayed");
|
||||||
|
|
||||||
|
test.todo("GIVEN audits length is 0, EXPECT no audits to be displayed");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("view", () => {
|
||||||
|
test.todo("EXPECT specific audit defaults to be sent");
|
||||||
|
|
||||||
|
test.todo("GIVEN interaction.guildId is null, expect nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN auditId is null, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN auditId.value is undefined, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN audit is not in database, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN audit.Reason was not supplied, EXPECT reason to be defaulted");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("clear", () => {
|
||||||
|
test.todo("EXPECT audit to be cleared");
|
||||||
|
|
||||||
|
test.todo("GIVEN interaction.guildId is null, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN auditId is null, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN auditId.value is undefined, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN audit is not found, EXPECT error");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("add", () => {
|
||||||
|
test.todo("EXPECT audit to be added");
|
||||||
|
|
||||||
|
test.todo("GIVEN interaction.guildId is null, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN user is null, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN auditType is null, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN auditType.value is undefined, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN reasonInput is null, EXPECT reason to be empty");
|
||||||
|
|
||||||
|
test.todo("GIVEN reasonType.value is undefined, EXPECT reason to be empty");
|
||||||
|
});
|
|
@ -1,6 +1,5 @@
|
||||||
import { GuildMember, Message, TextChannel, User } from "discord.js";
|
import { PermissionsBitField, SlashCommandBuilder, SlashCommandStringOption, SlashCommandUserOption } from "discord.js";
|
||||||
import Ban from "../../src/commands/ban";
|
import Ban from "../../src/commands/ban";
|
||||||
import { ICommandContext } from "../../src/contracts/ICommandContext";
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
process.env = {};
|
process.env = {};
|
||||||
|
@ -8,717 +7,52 @@ beforeEach(() => {
|
||||||
|
|
||||||
describe('Constructor', () => {
|
describe('Constructor', () => {
|
||||||
test('Expect values to be set', () => {
|
test('Expect values to be set', () => {
|
||||||
process.env.ROLES_MODERATOR = 'Moderator';
|
const command = new Ban();
|
||||||
|
|
||||||
const ban = new Ban();
|
expect(command.CommandBuilder).toBeDefined();
|
||||||
|
|
||||||
expect(ban._category).toBe('Moderation');
|
const commandBuilder = command.CommandBuilder as SlashCommandBuilder;
|
||||||
expect(ban._roles.length).toBe(1);
|
|
||||||
expect(ban._roles[0]).toBe('Moderator');
|
expect(commandBuilder.name).toBe("ban");
|
||||||
|
expect(commandBuilder.description).toBe("Ban a member from the server with an optional reason");
|
||||||
|
expect(commandBuilder.default_member_permissions).toBe(PermissionsBitField.Flags.BanMembers.toString());
|
||||||
|
expect(commandBuilder.options.length).toBe(2);
|
||||||
|
|
||||||
|
const commandBuilderTargetOption = commandBuilder.options[0] as SlashCommandUserOption;
|
||||||
|
|
||||||
|
expect(commandBuilderTargetOption.name).toBe("target");
|
||||||
|
expect(commandBuilderTargetOption.description).toBe("The user");
|
||||||
|
expect(commandBuilderTargetOption.required).toBeTruthy();
|
||||||
|
|
||||||
|
const commandBuilderReasonOption = commandBuilder.options[1] as SlashCommandStringOption;
|
||||||
|
|
||||||
|
expect(commandBuilderReasonOption.name).toBe("reason");
|
||||||
|
expect(commandBuilderReasonOption.description).toBe("The reason");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Execute', () => {
|
describe('Execute', () => {
|
||||||
test('Given user has permission, expect user to be banned', async () => {
|
test.todo('GIVEN command is valid, EXPECT user to be banned');
|
||||||
process.env = {
|
|
||||||
ROLES_MODERATOR: 'Moderator',
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs'
|
|
||||||
};
|
|
||||||
|
|
||||||
const mentionedUser = {
|
test.todo("GIVEN interaction is NOT a chat input command, EXPECT nothing to happen");
|
||||||
displayAvatarURL: jest.fn(),
|
|
||||||
tag: 'USERTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
const mentionedMember = {
|
|
||||||
bannable: true,
|
|
||||||
ban: jest.fn()
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
const logChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: jest.fn()
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const messageChannelSend = jest.fn();
|
test.todo("GIVEN interaction.guildId is null, EXPECT nothing to happen");
|
||||||
const messageMentionsUsersFirst = jest.fn()
|
|
||||||
.mockReturnValue(mentionedUser);
|
|
||||||
const messageGuildMember = jest.fn()
|
|
||||||
.mockReturnValue(mentionedMember);
|
|
||||||
const messageGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): TextChannel | undefined => {
|
|
||||||
const result = callback(logChannel);
|
|
||||||
|
|
||||||
if (!result) {
|
test.todo("GIVEN interaction.guild is null, EXPECT nothing to happen");
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return logChannel;
|
test.todo("GIVEN targetUser is null, EXPECT user not found error");
|
||||||
});
|
|
||||||
|
|
||||||
const message = {
|
test.todo("GIVEN targetUser.user is undefined, EXPECT user not found error");
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
mentions: {
|
|
||||||
users: {
|
|
||||||
first: messageMentionsUsersFirst
|
|
||||||
}
|
|
||||||
},
|
|
||||||
guild: {
|
|
||||||
member: messageGuildMember ,
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
},
|
|
||||||
available: true
|
|
||||||
},
|
|
||||||
author: {
|
|
||||||
tag: 'AUTHORTAG'
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
test.todo("GIVEN targetUser.member is undefined, EXPECT user not found error");
|
||||||
name: 'ban',
|
|
||||||
args: ['ban', 'Test', 'Reason'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const ban = new Ban();
|
test.todo("GIVEN reasonInput is null, EXPECT reason to be defaulted");
|
||||||
|
|
||||||
const result = await ban.execute(context);
|
test.todo("GIVEN reasonInput.value is null, EXPECT reason to be defaulted");
|
||||||
|
|
||||||
expect(messageChannelSend).toBeCalledTimes(1);
|
|
||||||
expect(logChannel.send).toBeCalledTimes(1);
|
|
||||||
expect(mentionedMember.ban).toBeCalledWith({ reason: 'Moderator: AUTHORTAG, Reason: Test Reason' });
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given moderator did not supply a reason, expect default message', async () => {
|
test.todo("GIVEN user is not bannable, EXPECT insufficient permissions error");
|
||||||
process.env = {
|
|
||||||
ROLES_MODERATOR: 'Moderator',
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs'
|
|
||||||
};
|
|
||||||
|
|
||||||
const mentionedUser = {
|
test.todo("GIVEN channels.log.mod setting is not set, EXPECT command to return");
|
||||||
displayAvatarURL: jest.fn(),
|
|
||||||
tag: 'USERTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
const mentionedMember = {
|
|
||||||
bannable: true,
|
|
||||||
ban: jest.fn()
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
const logChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: jest.fn()
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const messageChannelSend = jest.fn();
|
test.todo("GIVEN channel can NOT be found, EXPECT logEmbed not to be sent");
|
||||||
const messageMentionsUsersFirst = jest.fn()
|
|
||||||
.mockReturnValue(mentionedUser);
|
|
||||||
const messageGuildMember = jest.fn()
|
|
||||||
.mockReturnValue(mentionedMember);
|
|
||||||
const messageGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): TextChannel | undefined => {
|
|
||||||
const result = callback(logChannel);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return logChannel;
|
|
||||||
});
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
mentions: {
|
|
||||||
users: {
|
|
||||||
first: messageMentionsUsersFirst
|
|
||||||
}
|
|
||||||
},
|
|
||||||
guild: {
|
|
||||||
member: messageGuildMember ,
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
},
|
|
||||||
available: true
|
|
||||||
},
|
|
||||||
author: {
|
|
||||||
tag: 'AUTHORTAG'
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'ban',
|
|
||||||
args: ['ban'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const ban = new Ban();
|
|
||||||
|
|
||||||
const result = await ban.execute(context);
|
|
||||||
|
|
||||||
expect(messageChannelSend).toBeCalledTimes(1);
|
|
||||||
expect(logChannel.send).toBeCalledTimes(1);
|
|
||||||
expect(mentionedMember.ban).toBeCalledWith({ reason: 'Moderator: AUTHORTAG, Reason: *none*' });
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given user has permissions, expect embeds to be correct', async () => {
|
|
||||||
process.env = {
|
|
||||||
ROLES_MODERATOR: 'Moderator',
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs'
|
|
||||||
};
|
|
||||||
|
|
||||||
const mentionedUser = {
|
|
||||||
displayAvatarURL: jest.fn(),
|
|
||||||
tag: 'USERTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
const mentionedMember = {
|
|
||||||
bannable: true,
|
|
||||||
ban: jest.fn()
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
const logChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: jest.fn()
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
const messageMentionsUsersFirst = jest.fn()
|
|
||||||
.mockReturnValue(mentionedUser);
|
|
||||||
const messageGuildMember = jest.fn()
|
|
||||||
.mockReturnValue(mentionedMember);
|
|
||||||
const messageGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): TextChannel | undefined => {
|
|
||||||
const result = callback(logChannel);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return logChannel;
|
|
||||||
});
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
mentions: {
|
|
||||||
users: {
|
|
||||||
first: messageMentionsUsersFirst
|
|
||||||
}
|
|
||||||
},
|
|
||||||
guild: {
|
|
||||||
member: messageGuildMember ,
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
},
|
|
||||||
available: true
|
|
||||||
},
|
|
||||||
author: {
|
|
||||||
tag: 'AUTHORTAG'
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'ban',
|
|
||||||
args: ['ban', 'Test', 'Reason'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const ban = new Ban();
|
|
||||||
|
|
||||||
const result = await ban.execute(context);
|
|
||||||
|
|
||||||
expect(result.embeds.length).toBe(2);
|
|
||||||
|
|
||||||
const logEmbed = result.embeds[0];
|
|
||||||
const publicEmbed = result.embeds[1];
|
|
||||||
|
|
||||||
expect(logEmbed.title).toBe('Member Banned');
|
|
||||||
expect(publicEmbed.title).toBe("");
|
|
||||||
expect(publicEmbed.description).toBe('[object Object] has been banned');
|
|
||||||
expect(logEmbed.fields.length).toBe(3);
|
|
||||||
expect(publicEmbed.fields.length).toBe(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given user has permission, expect logEmbed fields to be correct', async () => {
|
|
||||||
process.env = {
|
|
||||||
ROLES_MODERATOR: 'Moderator',
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs'
|
|
||||||
};
|
|
||||||
|
|
||||||
const mentionedUser = {
|
|
||||||
displayAvatarURL: jest.fn().mockReturnValue('URL'),
|
|
||||||
tag: 'USERTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
const mentionedMember = {
|
|
||||||
bannable: true,
|
|
||||||
ban: jest.fn()
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
const logChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: jest.fn()
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
const messageMentionsUsersFirst = jest.fn()
|
|
||||||
.mockReturnValue(mentionedUser);
|
|
||||||
const messageGuildMember = jest.fn()
|
|
||||||
.mockReturnValue(mentionedMember);
|
|
||||||
const messageGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): TextChannel | undefined => {
|
|
||||||
const result = callback(logChannel);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return logChannel;
|
|
||||||
});
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
mentions: {
|
|
||||||
users: {
|
|
||||||
first: messageMentionsUsersFirst
|
|
||||||
}
|
|
||||||
},
|
|
||||||
guild: {
|
|
||||||
member: messageGuildMember ,
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
},
|
|
||||||
available: true
|
|
||||||
},
|
|
||||||
author: {
|
|
||||||
tag: 'AUTHORTAG'
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'ban',
|
|
||||||
args: ['ban', 'Test', 'Reason'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const ban = new Ban();
|
|
||||||
|
|
||||||
const result = await ban.execute(context);
|
|
||||||
|
|
||||||
const logEmbed = result.embeds[0];
|
|
||||||
|
|
||||||
const fieldUser = logEmbed.fields[0];
|
|
||||||
const fieldModerator = logEmbed.fields[1];
|
|
||||||
const fieldReason = logEmbed.fields[2];
|
|
||||||
|
|
||||||
expect(fieldUser.name).toBe("User");
|
|
||||||
expect(fieldUser.value).toBe("[object Object] `USERTAG`");
|
|
||||||
expect(logEmbed.thumbnail?.url).toBe("URL");
|
|
||||||
|
|
||||||
expect(fieldModerator.name).toBe('Moderator');
|
|
||||||
expect(fieldModerator.value).toBe('[object Object] `AUTHORTAG`');
|
|
||||||
|
|
||||||
expect(fieldReason.name).toBe('Reason');
|
|
||||||
expect(fieldReason.value).toBe('Test Reason');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given moderator did not supply a reason, expect reason field to be default message', async () => {
|
|
||||||
process.env = {
|
|
||||||
ROLES_MODERATOR: 'Moderator',
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs'
|
|
||||||
};
|
|
||||||
|
|
||||||
const mentionedUser = {
|
|
||||||
displayAvatarURL: jest.fn().mockReturnValue('URL'),
|
|
||||||
tag: 'USERTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
const mentionedMember = {
|
|
||||||
bannable: true,
|
|
||||||
ban: jest.fn()
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
const logChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: jest.fn()
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
const messageMentionsUsersFirst = jest.fn()
|
|
||||||
.mockReturnValue(mentionedUser);
|
|
||||||
const messageGuildMember = jest.fn()
|
|
||||||
.mockReturnValue(mentionedMember);
|
|
||||||
const messageGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): TextChannel | undefined => {
|
|
||||||
const result = callback(logChannel);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return logChannel;
|
|
||||||
});
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
mentions: {
|
|
||||||
users: {
|
|
||||||
first: messageMentionsUsersFirst
|
|
||||||
}
|
|
||||||
},
|
|
||||||
guild: {
|
|
||||||
member: messageGuildMember ,
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
},
|
|
||||||
available: true
|
|
||||||
},
|
|
||||||
author: {
|
|
||||||
tag: 'AUTHORTAG'
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'ban',
|
|
||||||
args: ['ban'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const ban = new Ban();
|
|
||||||
|
|
||||||
const result = await ban.execute(context);
|
|
||||||
|
|
||||||
const logEmbed = result.embeds[0];
|
|
||||||
|
|
||||||
const fieldUser = logEmbed.fields[0];
|
|
||||||
const fieldModerator = logEmbed.fields[1];
|
|
||||||
const fieldReason = logEmbed.fields[2];
|
|
||||||
|
|
||||||
expect(fieldUser.name).toBe("User");
|
|
||||||
expect(fieldUser.value).toBe("[object Object] `USERTAG`");
|
|
||||||
expect(logEmbed.thumbnail?.url).toBe("URL");
|
|
||||||
|
|
||||||
expect(fieldModerator.name).toBe('Moderator');
|
|
||||||
expect(fieldModerator.value).toBe('[object Object] `AUTHORTAG`');
|
|
||||||
|
|
||||||
expect(fieldReason.name).toBe('Reason');
|
|
||||||
expect(fieldReason.value).toBe('*none*');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given user is not mentioned, expect error embed to be sent', async () => {
|
|
||||||
process.env = {
|
|
||||||
ROLES_MODERATOR: 'Moderator',
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs'
|
|
||||||
};
|
|
||||||
|
|
||||||
const mentionedMember = {
|
|
||||||
bannable: true,
|
|
||||||
ban: jest.fn()
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
const logChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: jest.fn()
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
const messageMentionsUsersFirst = jest.fn()
|
|
||||||
.mockReturnValue(null);
|
|
||||||
const messageGuildMember = jest.fn()
|
|
||||||
.mockReturnValue(mentionedMember);
|
|
||||||
const messageGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): TextChannel | undefined => {
|
|
||||||
const result = callback(logChannel);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return logChannel;
|
|
||||||
});
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
mentions: {
|
|
||||||
users: {
|
|
||||||
first: messageMentionsUsersFirst
|
|
||||||
}
|
|
||||||
},
|
|
||||||
guild: {
|
|
||||||
member: messageGuildMember ,
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
},
|
|
||||||
available: true
|
|
||||||
},
|
|
||||||
author: {
|
|
||||||
tag: 'AUTHORTAG'
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'ban',
|
|
||||||
args: ['ban', 'Test', 'Reason'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const ban = new Ban();
|
|
||||||
|
|
||||||
const result = await ban.execute(context);
|
|
||||||
|
|
||||||
expect(messageChannelSend).toBeCalledTimes(1);
|
|
||||||
expect(logChannel.send).not.toBeCalled();
|
|
||||||
expect(mentionedMember.ban).not.toBeCalled();
|
|
||||||
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
const embedError = result.embeds[0];
|
|
||||||
|
|
||||||
expect(embedError.description).toBe('User does not exist');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given member is not in server, expect error embed to be sent', async () => {
|
|
||||||
process.env = {
|
|
||||||
ROLES_MODERATOR: 'Moderator',
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs'
|
|
||||||
};
|
|
||||||
|
|
||||||
const mentionedUser = {
|
|
||||||
displayAvatarURL: jest.fn(),
|
|
||||||
tag: 'USERTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
const mentionedMember = {
|
|
||||||
bannable: true,
|
|
||||||
ban: jest.fn()
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
const logChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: jest.fn()
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
const messageMentionsUsersFirst = jest.fn()
|
|
||||||
.mockReturnValue(mentionedUser);
|
|
||||||
const messageGuildMember = jest.fn()
|
|
||||||
.mockReturnValue(null);
|
|
||||||
const messageGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): TextChannel | undefined => {
|
|
||||||
const result = callback(logChannel);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return logChannel;
|
|
||||||
});
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
mentions: {
|
|
||||||
users: {
|
|
||||||
first: messageMentionsUsersFirst
|
|
||||||
}
|
|
||||||
},
|
|
||||||
guild: {
|
|
||||||
member: messageGuildMember ,
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
},
|
|
||||||
available: true
|
|
||||||
},
|
|
||||||
author: {
|
|
||||||
tag: 'AUTHORTAG'
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'ban',
|
|
||||||
args: ['ban', 'Test', 'Reason'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const ban = new Ban();
|
|
||||||
|
|
||||||
const result = await ban.execute(context);
|
|
||||||
|
|
||||||
expect(messageChannelSend).toBeCalledTimes(1);
|
|
||||||
expect(logChannel.send).not.toBeCalled();
|
|
||||||
expect(mentionedMember.ban).not.toBeCalled();
|
|
||||||
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
const embedError = result.embeds[0];
|
|
||||||
|
|
||||||
expect(embedError.description).toBe('User is not in this server');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given guild is unavailable, expect return and do nothing', async () => {
|
|
||||||
process.env = {
|
|
||||||
ROLES_MODERATOR: 'Moderator',
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs'
|
|
||||||
};
|
|
||||||
|
|
||||||
const mentionedUser = {
|
|
||||||
displayAvatarURL: jest.fn(),
|
|
||||||
tag: 'USERTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
const mentionedMember = {
|
|
||||||
bannable: true,
|
|
||||||
ban: jest.fn()
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
const logChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: jest.fn()
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
const messageMentionsUsersFirst = jest.fn()
|
|
||||||
.mockReturnValue(mentionedUser);
|
|
||||||
const messageGuildMember = jest.fn()
|
|
||||||
.mockReturnValue(mentionedMember);
|
|
||||||
const messageGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): TextChannel | undefined => {
|
|
||||||
const result = callback(logChannel);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return logChannel;
|
|
||||||
});
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
mentions: {
|
|
||||||
users: {
|
|
||||||
first: messageMentionsUsersFirst
|
|
||||||
}
|
|
||||||
},
|
|
||||||
guild: {
|
|
||||||
member: messageGuildMember ,
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
},
|
|
||||||
available: false
|
|
||||||
},
|
|
||||||
author: {
|
|
||||||
tag: 'AUTHORTAG'
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'ban',
|
|
||||||
args: ['ban', 'Test', 'Reason'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const ban = new Ban();
|
|
||||||
|
|
||||||
const result = await ban.execute(context);
|
|
||||||
|
|
||||||
expect(messageChannelSend).not.toBeCalled();
|
|
||||||
expect(logChannel.send).not.toBeCalled();
|
|
||||||
expect(mentionedMember.ban).not.toBeCalled();
|
|
||||||
expect(result.embeds.length).toBe(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given bot cant ban user, expect error embed to be sent', async () => {
|
|
||||||
process.env = {
|
|
||||||
ROLES_MODERATOR: 'Moderator',
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs'
|
|
||||||
};
|
|
||||||
|
|
||||||
const mentionedUser = {
|
|
||||||
displayAvatarURL: jest.fn(),
|
|
||||||
tag: 'USERTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
const mentionedMember = {
|
|
||||||
bannable: false,
|
|
||||||
ban: jest.fn()
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
const logChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: jest.fn()
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
const messageMentionsUsersFirst = jest.fn()
|
|
||||||
.mockReturnValue(mentionedUser);
|
|
||||||
const messageGuildMember = jest.fn()
|
|
||||||
.mockReturnValue(mentionedMember);
|
|
||||||
const messageGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): TextChannel | undefined => {
|
|
||||||
const result = callback(logChannel);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return logChannel;
|
|
||||||
});
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
mentions: {
|
|
||||||
users: {
|
|
||||||
first: messageMentionsUsersFirst
|
|
||||||
}
|
|
||||||
},
|
|
||||||
guild: {
|
|
||||||
member: messageGuildMember ,
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
},
|
|
||||||
available: true
|
|
||||||
},
|
|
||||||
author: {
|
|
||||||
tag: 'AUTHORTAG'
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'ban',
|
|
||||||
args: ['ban', 'Test', 'Reason'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const ban = new Ban();
|
|
||||||
|
|
||||||
const result = await ban.execute(context);
|
|
||||||
|
|
||||||
expect(messageChannelSend).toBeCalledTimes(1);
|
|
||||||
expect(logChannel.send).not.toBeCalled();
|
|
||||||
expect(mentionedMember.ban).not.toBeCalled();
|
|
||||||
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
const embedError = result.embeds[0];
|
|
||||||
|
|
||||||
expect(embedError.description).toBe('Unable to do this action, am I missing permissions?');
|
|
||||||
});
|
|
||||||
});
|
});
|
11
tests/commands/bunny.test.ts
Normal file
11
tests/commands/bunny.test.ts
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
describe('constructor', () => {
|
||||||
|
test.todo("EXPECT properties to be set");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('execute', () => {
|
||||||
|
test.todo("EXPECT embed to be sent");
|
||||||
|
|
||||||
|
test.todo("GIVEN interaction is not a chat input command, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN a result from random-bunny is failure, EXPECT error");
|
||||||
|
});
|
|
@ -1,178 +1,23 @@
|
||||||
import { Message } from "discord.js";
|
|
||||||
import Clear from "../../src/commands/clear";
|
|
||||||
import { ICommandContext } from "../../src/contracts/ICommandContext";
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
process.env = {};
|
process.env = {};
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Constructor', () => {
|
describe('Constructor', () => {
|
||||||
test('Expect values to be set', () => {
|
test.todo("EXPECT values to be set");
|
||||||
process.env = {
|
|
||||||
ROLES_MODERATOR: "Moderator"
|
|
||||||
};
|
|
||||||
|
|
||||||
const clear = new Clear();
|
|
||||||
|
|
||||||
expect(clear._category).toBe('Moderation');
|
|
||||||
expect(clear._roles.length).toBe(1);
|
|
||||||
expect(clear._roles[0]).toBe('Moderator');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Execute', () => {
|
describe('Execute', () => {
|
||||||
test('Given valid arguments, expect messages to be cleared', async () => {
|
test.todo("GIVEN input is valid, EXPECT messages to be cleared");
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
const messageChannelBulkDelete = jest.fn();
|
|
||||||
|
|
||||||
const message = {
|
test.todo("GIVEN interaction is NOT a chat input command, EXPECT nothing to happen");
|
||||||
channel: {
|
|
||||||
send: messageChannelSend,
|
|
||||||
bulkDelete: messageChannelBulkDelete
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
test.todo("GIVEN interaction.channel is null, EXPECT nothing to happen");
|
||||||
name: 'clear',
|
|
||||||
args: ['5'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const clear = new Clear();
|
test.todo("GIVEN totalClear input is NOT supplied, EXPECT invalid error");
|
||||||
const result = await clear.execute(context);
|
|
||||||
|
|
||||||
expect(messageChannelSend).toBeCalledTimes(1);
|
test.todo("GIVEN totalClear is less than or equal to 0, EXPECT invalid error");
|
||||||
expect(messageChannelBulkDelete).toBeCalledWith(5);
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
// PublicEmbed
|
test.todo("GIVEN totalClear is greater than 100, EXPECT invalid error");
|
||||||
const publicEmbed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(publicEmbed.title).toBe('');
|
test.todo("GIVEN channel is NOT manageable, EXPECT insufficient permissions error");
|
||||||
expect(publicEmbed.description).toBe('5 message(s) were removed');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given argument is not given, expect error embed to be sent', async () => {
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
const messageChannelBulkDelete = jest.fn();
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend,
|
|
||||||
bulkDelete: messageChannelBulkDelete
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'clear',
|
|
||||||
args: [],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const clear = new Clear();
|
|
||||||
const result = await clear.execute(context);
|
|
||||||
|
|
||||||
expect(messageChannelSend).toBeCalledTimes(1);
|
|
||||||
expect(messageChannelBulkDelete).not.toBeCalled();
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
// ErrorEmbed
|
|
||||||
const errorEmbed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(errorEmbed.title).toBeNull();
|
|
||||||
expect(errorEmbed.description).toBe('Please specify an amount between 1 and 100');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given argument is not a number, expect error embed to be sent', async () => {
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
const messageChannelBulkDelete = jest.fn();
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend,
|
|
||||||
bulkDelete: messageChannelBulkDelete
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'clear',
|
|
||||||
args: ['A'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const clear = new Clear();
|
|
||||||
const result = await clear.execute(context);
|
|
||||||
|
|
||||||
expect(messageChannelSend).toBeCalledTimes(1);
|
|
||||||
expect(messageChannelBulkDelete).not.toBeCalled();
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
// ErrorEmbed
|
|
||||||
const errorEmbed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(errorEmbed.title).toBeNull();
|
|
||||||
expect(errorEmbed.description).toBe('Please specify an amount between 1 and 100');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given argument is less than 1, expect error embed to be sent', async () => {
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
const messageChannelBulkDelete = jest.fn();
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend,
|
|
||||||
bulkDelete: messageChannelBulkDelete
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'clear',
|
|
||||||
args: ['0'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const clear = new Clear();
|
|
||||||
const result = await clear.execute(context);
|
|
||||||
|
|
||||||
expect(messageChannelSend).toBeCalledTimes(1);
|
|
||||||
expect(messageChannelBulkDelete).not.toBeCalled();
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
// ErrorEmbed
|
|
||||||
const errorEmbed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(errorEmbed.title).toBeNull();
|
|
||||||
expect(errorEmbed.description).toBe('Please specify an amount between 1 and 100');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given argument is more than 100, expect error embed to be sent', async () => {
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
const messageChannelBulkDelete = jest.fn();
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend,
|
|
||||||
bulkDelete: messageChannelBulkDelete
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'clear',
|
|
||||||
args: ['101'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const clear = new Clear();
|
|
||||||
const result = await clear.execute(context);
|
|
||||||
|
|
||||||
expect(messageChannelSend).toBeCalledTimes(1);
|
|
||||||
expect(messageChannelBulkDelete).not.toBeCalled();
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
// ErrorEmbed
|
|
||||||
const errorEmbed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(errorEmbed.title).toBeNull();
|
|
||||||
expect(errorEmbed.description).toBe('Please specify an amount between 1 and 100');
|
|
||||||
});
|
|
||||||
});
|
});
|
25
tests/commands/code.test.ts
Normal file
25
tests/commands/code.test.ts
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
describe('constructor', () => {
|
||||||
|
test.todo("EXPECT properties to be set");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("execute", () => {
|
||||||
|
test.todo("GIVEN interaction is not a chat input command, EXPECT nothing to happen");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("randomise", () => {
|
||||||
|
test.todo("EXPECT entry code to be randomised");
|
||||||
|
|
||||||
|
test.todo("GIVEN interaction.guildId is null, EXPECT nothing to happen");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("embed", () => {
|
||||||
|
test.todo("EXPECT embed to be sent");
|
||||||
|
|
||||||
|
test.todo("GIVEN interaction.guildId is null, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN interaction.channel is null, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN verification.code setting is null, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN verification.code setting is empty, EXPECT error");
|
||||||
|
});
|
65
tests/commands/config.test.ts
Normal file
65
tests/commands/config.test.ts
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
describe("constructor", () => {
|
||||||
|
test.todo("EXPECT properties to be set");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("execute", () => {
|
||||||
|
test.todo("GIVEN interaction is not a chat input command, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN interaction.guildId is null, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN server is not set up in the database, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN subcommand is invalid, EXPECT error");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("list", () => {
|
||||||
|
test.todo("EXPECT help text to be sent");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("reset", () => {
|
||||||
|
test.todo("EXPECT setting value to be set to default");
|
||||||
|
|
||||||
|
test.todo("GIVEN interaction.guildId is null, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN key is null, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN key.value is undefined, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN server is not found in database, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN setting is not found, EXPECT error");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("get", () => {
|
||||||
|
test.todo("EXPECT setting value to be sent");
|
||||||
|
|
||||||
|
test.todo("GIVEN interaction.guildId is null, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN key is null, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN key.value is undefined, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN server can not be found in database, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN setting can not be found AND a default value is found, EXPECT default to be shown");
|
||||||
|
|
||||||
|
test.todo("GIVEN setting can not be found AND a default value is not found, EXPECT none to be shown");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("set", () => {
|
||||||
|
test.todo("GIVEN setting already is set, EXPECT setting to be updated");
|
||||||
|
|
||||||
|
test.todo("GIVEN setting is not set, EXPECT setting to be added");
|
||||||
|
|
||||||
|
test.todo("GIVEN interaction.guildId is null, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN key is null, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN key.value is undefined, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN value is null, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN value.value is undefined, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN server can not be found in the database, EXPECT error");
|
||||||
|
});
|
35
tests/commands/disable.test.ts
Normal file
35
tests/commands/disable.test.ts
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
describe('constructor', () => {
|
||||||
|
test.todo('EXPECT properties to be set');
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('execute', () => {
|
||||||
|
test.todo("GIVEN interaction is not a chat input command, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN subcommand is invalid, EXPECT error");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('add', () => {
|
||||||
|
test.todo("EXPECT command to be added to disabled list");
|
||||||
|
|
||||||
|
test.todo("GIVEN interaction.guildId is null, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN commandName is null, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN commandName.value is undefined, EXEPCT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN disabledCommandsString is empty, EXPECT empty disabledCommands array to be used");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("remove", () => {
|
||||||
|
test.todo("EXPECT command to be removed from disabled list");
|
||||||
|
|
||||||
|
test.todo("GIVEN interaction.guildId is null, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN commandName is null, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN commandName.value is undefined, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN disabledCommandsString is empty, EXPECT empty disabledCommands array to be used");
|
||||||
|
|
||||||
|
test.todo("GIVEN instance of commandName is not found in disabledCommands array, EXPECT it not to try to remove it");
|
||||||
|
});
|
|
@ -1,136 +0,0 @@
|
||||||
import { Message } from "discord.js";
|
|
||||||
import Evaluate from "../../src/commands/eval";
|
|
||||||
import { ICommandContext } from "../../src/contracts/ICommandContext";
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
process.env = {};
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Constructor', () => {
|
|
||||||
test('Expect values to be set', () => {
|
|
||||||
const evaluate = new Evaluate();
|
|
||||||
|
|
||||||
expect(evaluate._category).toBe('Owner');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Execute', () => {
|
|
||||||
test('Given user has permission, expect eval statement ran', () => {
|
|
||||||
process.env = {
|
|
||||||
BOT_OWNERID: 'OWNERID'
|
|
||||||
};
|
|
||||||
|
|
||||||
console.log = jest.fn();
|
|
||||||
global.eval = jest.fn()
|
|
||||||
.mockReturnValue('General Kenobi');
|
|
||||||
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
author: {
|
|
||||||
id: 'OWNERID'
|
|
||||||
},
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'eval',
|
|
||||||
args: ['echo', 'Hello', 'there'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const evaluate = new Evaluate();
|
|
||||||
|
|
||||||
const result = evaluate.execute(context);
|
|
||||||
|
|
||||||
expect(console.log).toBeCalledWith('Eval Statement: echo Hello there');
|
|
||||||
expect(global.eval).toBeCalledWith('echo Hello there');
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
// PublicEmbed
|
|
||||||
const publicEmbed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(publicEmbed.title).toBe('');
|
|
||||||
expect(publicEmbed.description).toBe('General Kenobi');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given user does not have permission, expect nothing to occur', () => {
|
|
||||||
process.env = {
|
|
||||||
BOT_OWNERID: 'DIFFERENT'
|
|
||||||
};
|
|
||||||
|
|
||||||
console.log = jest.fn();
|
|
||||||
global.eval = jest.fn()
|
|
||||||
.mockReturnValue('General Kenobi');
|
|
||||||
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
author: {
|
|
||||||
id: 'OWNERID'
|
|
||||||
},
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'eval',
|
|
||||||
args: ['echo', 'Hello', 'there'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const evaluate = new Evaluate();
|
|
||||||
|
|
||||||
const result = evaluate.execute(context);
|
|
||||||
|
|
||||||
expect(console.log).not.toBeCalled();
|
|
||||||
expect(global.eval).not.toBeCalled();
|
|
||||||
expect(result.embeds.length).toBe(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given eval failed, expect error embed to be sent', () => {
|
|
||||||
process.env = {
|
|
||||||
BOT_OWNERID: 'OWNERID'
|
|
||||||
};
|
|
||||||
|
|
||||||
console.log = jest.fn();
|
|
||||||
global.eval = jest.fn()
|
|
||||||
.mockImplementation(() => {
|
|
||||||
throw new Error('Error message');
|
|
||||||
});
|
|
||||||
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
author: {
|
|
||||||
id: 'OWNERID'
|
|
||||||
},
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'eval',
|
|
||||||
args: ['echo', 'Hello', 'there'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const evaluate = new Evaluate();
|
|
||||||
|
|
||||||
const result = evaluate.execute(context);
|
|
||||||
|
|
||||||
expect(console.log).toBeCalledWith('Eval Statement: echo Hello there');
|
|
||||||
expect(global.eval).toBeCalledWith('echo Hello there');
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
// ErrorEmbed
|
|
||||||
const errorEmbed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(errorEmbed.title).toBeNull();
|
|
||||||
expect(errorEmbed.description).toBe('Error: Error message');
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -1,267 +0,0 @@
|
||||||
import Help, { ICommandData } from "../../src/commands/help";
|
|
||||||
import { Message } from "discord.js";
|
|
||||||
import { ICommandContext } from "../../src/contracts/ICommandContext";
|
|
||||||
|
|
||||||
const oldCwd = process.cwd();
|
|
||||||
|
|
||||||
describe('Constructor', () => {
|
|
||||||
test('Expect properties to be set', () => {
|
|
||||||
const help = new Help();
|
|
||||||
|
|
||||||
expect(help._category).toBe('General');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Execute', () => {
|
|
||||||
test('Given no arguments were given, expect SendAll to be executed', () => {
|
|
||||||
const message = {} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'help',
|
|
||||||
args: [],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const help = new Help();
|
|
||||||
|
|
||||||
help.SendAll = jest.fn();
|
|
||||||
help.SendSingle = jest.fn();
|
|
||||||
|
|
||||||
help.execute(context);
|
|
||||||
|
|
||||||
expect(help.SendAll).toBeCalled();
|
|
||||||
expect(help.SendSingle).not.toBeCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given an argument was given, expect SendSingle to be executed', () => {
|
|
||||||
const message = {} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'help',
|
|
||||||
args: ['about'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const help = new Help();
|
|
||||||
|
|
||||||
help.SendAll = jest.fn();
|
|
||||||
help.SendSingle = jest.fn();
|
|
||||||
|
|
||||||
help.execute(context);
|
|
||||||
|
|
||||||
expect(help.SendAll).not.toBeCalled();
|
|
||||||
expect(help.SendSingle).toBeCalled();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('SendAll', () => {
|
|
||||||
test('Expect embed with all commands to be sent', () => {
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'help',
|
|
||||||
args: [],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const help = new Help();
|
|
||||||
|
|
||||||
const commandData0: ICommandData = {
|
|
||||||
Exists: true,
|
|
||||||
Name: 'about',
|
|
||||||
Category: 'general',
|
|
||||||
Roles: []
|
|
||||||
};
|
|
||||||
|
|
||||||
const commandData1: ICommandData = {
|
|
||||||
Exists: true,
|
|
||||||
Name: 'role',
|
|
||||||
Category: 'general',
|
|
||||||
Roles: []
|
|
||||||
};
|
|
||||||
|
|
||||||
help.GetAllCommandData = jest.fn()
|
|
||||||
.mockReturnValue([commandData0, commandData1]);
|
|
||||||
|
|
||||||
const result = help.SendAll(context);
|
|
||||||
|
|
||||||
expect(help.GetAllCommandData).toBeCalled();
|
|
||||||
expect(messageChannelSend).toBeCalled();
|
|
||||||
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
// PublicEmbed
|
|
||||||
const publicEmbed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(publicEmbed.fields.length).toBe(1);
|
|
||||||
|
|
||||||
// PublicEmbed -> GeneralCategory Field
|
|
||||||
const publicEmbedFieldGeneral = publicEmbed.fields[0];
|
|
||||||
|
|
||||||
expect(publicEmbedFieldGeneral.name).toBe('General');
|
|
||||||
expect(publicEmbedFieldGeneral.value).toBe('about, role');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('SendSingle', () => {
|
|
||||||
test('Given command exists, expect embed to be sent with command fields', () => {
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'help',
|
|
||||||
args: ['about'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const commandData: ICommandData = {
|
|
||||||
Exists: true,
|
|
||||||
Name: 'about',
|
|
||||||
Category: 'general',
|
|
||||||
Roles: ['role1', 'role2']
|
|
||||||
};
|
|
||||||
|
|
||||||
const help = new Help();
|
|
||||||
|
|
||||||
help.GetCommandData = jest.fn()
|
|
||||||
.mockReturnValue(commandData);
|
|
||||||
|
|
||||||
const result = help.SendSingle(context);
|
|
||||||
|
|
||||||
expect(help.GetCommandData).toBeCalledWith('about');
|
|
||||||
expect(messageChannelSend).toBeCalled();
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
// PublicEmbed
|
|
||||||
const publicEmbed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(publicEmbed.title).toBe('About');
|
|
||||||
expect(publicEmbed.description).toBe('');
|
|
||||||
expect(publicEmbed.fields.length).toBe(2);
|
|
||||||
|
|
||||||
// PublicEmbed -> Category Field
|
|
||||||
const fieldCategory = publicEmbed.fields[0];
|
|
||||||
|
|
||||||
expect(fieldCategory.name).toBe('Category');
|
|
||||||
expect(fieldCategory.value).toBe('General');
|
|
||||||
|
|
||||||
// PublicEmbed -> RequiredRoles Field
|
|
||||||
const fieldRoles = publicEmbed.fields[1];
|
|
||||||
|
|
||||||
expect(fieldRoles.name).toBe('Required Roles');
|
|
||||||
expect(fieldRoles.value).toBe('Role1, Role2');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given command does not exist, expect error embed to be sent', () => {
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'help',
|
|
||||||
args: ['about'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const commandData: ICommandData = {
|
|
||||||
Exists: false
|
|
||||||
};
|
|
||||||
|
|
||||||
const help = new Help();
|
|
||||||
|
|
||||||
help.GetCommandData = jest.fn()
|
|
||||||
.mockReturnValue(commandData);
|
|
||||||
|
|
||||||
const result = help.SendSingle(context);
|
|
||||||
|
|
||||||
expect(help.GetCommandData).toBeCalledWith('about');
|
|
||||||
expect(messageChannelSend).toBeCalled();
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
// ErrorEmbed
|
|
||||||
const errorEmbed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(errorEmbed.description).toBe('Command does not exist');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('GetAllCommandData', () => {
|
|
||||||
test('Expect array of command data to be returned', () => {
|
|
||||||
process.env = {
|
|
||||||
FOLDERS_COMMANDS: "commands"
|
|
||||||
};
|
|
||||||
|
|
||||||
process.cwd = jest.fn()
|
|
||||||
.mockReturnValue(`${oldCwd}/tests/_mocks`);
|
|
||||||
|
|
||||||
const help = new Help();
|
|
||||||
|
|
||||||
const result = help.GetAllCommandData();
|
|
||||||
|
|
||||||
expect(result.length).toBe(1);
|
|
||||||
|
|
||||||
// Mock Command
|
|
||||||
const mockCommand = result[0];
|
|
||||||
|
|
||||||
expect(mockCommand.Exists).toBeTruthy();
|
|
||||||
expect(mockCommand.Name).toBe("mockCmd");
|
|
||||||
expect(mockCommand.Category).toBe("General");
|
|
||||||
|
|
||||||
expect(mockCommand.Roles!.length).toBe(1);
|
|
||||||
expect(mockCommand.Roles![0]).toBe("Moderator");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('GetCommandData', () => {
|
|
||||||
test('Given command exists, expect data to be returned', () => {
|
|
||||||
process.env = {
|
|
||||||
FOLDERS_COMMANDS: "commands"
|
|
||||||
};
|
|
||||||
|
|
||||||
process.cwd = jest.fn()
|
|
||||||
.mockReturnValue(`${oldCwd}/tests/_mocks`);
|
|
||||||
|
|
||||||
const help = new Help();
|
|
||||||
|
|
||||||
const result = help.GetCommandData('mockCmd');
|
|
||||||
|
|
||||||
expect(result.Exists).toBeTruthy();
|
|
||||||
expect(result.Name).toBe("mockCmd");
|
|
||||||
expect(result.Category).toBe("General");
|
|
||||||
|
|
||||||
expect(result.Roles!.length).toBe(1);
|
|
||||||
expect(result.Roles![0]).toBe("Moderator");
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given command does not exist, expect exists false to be returned', () => {
|
|
||||||
process.env = {
|
|
||||||
FOLDERS_COMMANDS: "commands"
|
|
||||||
};
|
|
||||||
|
|
||||||
const oldCwd = process.cwd();
|
|
||||||
|
|
||||||
process.cwd = jest.fn()
|
|
||||||
.mockReturnValue(`${oldCwd}/tests/_mocks`);
|
|
||||||
|
|
||||||
const help = new Help();
|
|
||||||
|
|
||||||
const result = help.GetCommandData('none');
|
|
||||||
|
|
||||||
expect(result.Exists).toBeFalsy();
|
|
||||||
});
|
|
||||||
});
|
|
11
tests/commands/ignore.test.ts
Normal file
11
tests/commands/ignore.test.ts
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
describe('constructor', () => {
|
||||||
|
test.todo("EXPECT properties to be set");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("execute", () => {
|
||||||
|
test.todo("GIVEN channel is currently ignored, EXPECT channel to be removed from list");
|
||||||
|
|
||||||
|
test.todo("GIVEN channel is not currently ignored, EXPECT channel to be added to list");
|
||||||
|
|
||||||
|
test.todo("GIVEN channel is currently ignored but not found in database, EXPECT error");
|
||||||
|
});
|
|
@ -1,549 +1,33 @@
|
||||||
import { mock } from "jest-mock-extended";
|
|
||||||
|
|
||||||
import { GuildMember, Message, TextChannel, User } from "discord.js";
|
|
||||||
import Kick from "../../src/commands/kick";
|
|
||||||
import { ICommandContext } from "../../src/contracts/ICommandContext";
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
process.env = {};
|
process.env = {};
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Constructor', () => {
|
describe('Constructor', () => {
|
||||||
test('Expect properties to be set', () => {
|
test.todo('EXPECT properties to be set');
|
||||||
process.env = {
|
|
||||||
ROLES_MODERATOR: "Moderator"
|
|
||||||
};
|
|
||||||
|
|
||||||
const kick = new Kick();
|
|
||||||
|
|
||||||
expect(kick._category).toBe('Moderation');
|
|
||||||
expect(kick._roles.length).toBe(1);
|
|
||||||
expect(kick._roles[0]).toBe('Moderator');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Execute', () => {
|
describe('Execute', () => {
|
||||||
test('Given user has permission, expect user to be kicked', async () => {
|
test.todo("GIVEN input is valid, EXPECT member to be kicked");
|
||||||
process.env = {
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs'
|
|
||||||
};
|
|
||||||
|
|
||||||
const user = {
|
test.todo("GIVEN interaction is NOT a chat input command, EXPECT nothing to happen");
|
||||||
displayAvatarURL: jest.fn(),
|
|
||||||
tag: 'USERTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
|
|
||||||
const member = {
|
test.todo("GIVEN interaction.guildId is null, EXPECT nothing to happen");
|
||||||
kickable: true,
|
|
||||||
kick: jest.fn()
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
|
|
||||||
const logChannel = {
|
test.todo("GIVEN interaction.guild is null, EXPECT nothing to happen");
|
||||||
name: 'mod-logs',
|
|
||||||
send: jest.fn()
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const messageMentionsUsersFirst = jest.fn()
|
test.todo("GIVEN targetUser is null, EXPECT user not found error");
|
||||||
.mockReturnValue(user);
|
|
||||||
const messageGuildMember = jest.fn()
|
|
||||||
.mockReturnValue(member);
|
|
||||||
const messageGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): TextChannel | undefined => {
|
|
||||||
const result = callback(logChannel);
|
|
||||||
|
|
||||||
if (!result) {
|
test.todo("GIVEN targetUser.user is undefined, EXPECT user not found error");
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return logChannel;
|
test.todo("GIVEN targetUser.member is undefined, EXPECT user not found error");
|
||||||
});
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
|
|
||||||
const message = {
|
test.todo("GIVEN reasonInput is null, EXPECT reason to be defaulted");
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
mentions: {
|
|
||||||
users: {
|
|
||||||
first: messageMentionsUsersFirst
|
|
||||||
}
|
|
||||||
},
|
|
||||||
guild: {
|
|
||||||
member: messageGuildMember,
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
},
|
|
||||||
available: true
|
|
||||||
},
|
|
||||||
author: {
|
|
||||||
tag: 'AUTHORTAG'
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
test.todo("GIVEN reasonInput.value is undefined, EXPECT reason to be defaulted");
|
||||||
name: "kick",
|
|
||||||
args: ["USER", "Test", "Reason"],
|
|
||||||
message: message
|
|
||||||
}
|
|
||||||
|
|
||||||
const kick = new Kick();
|
test.todo("GIVEN user is not kickable, EXPECT insufficient permissions error");
|
||||||
|
|
||||||
const result = await kick.execute(context);
|
test.todo("GIVEN channels.logs.mod setting can not be found, EXPECT command to return");
|
||||||
|
|
||||||
expect(messageChannelSend).toBeCalledTimes(1);
|
test.todo("GIVEN channel can not be found, EXPECT logEmbed not to be sent");
|
||||||
expect(logChannel.send).toBeCalledTimes(1);
|
|
||||||
expect(member.kick).toBeCalledWith('Moderator: AUTHORTAG, Reason: Test Reason');
|
|
||||||
|
|
||||||
expect(result.embeds.length).toBe(2);
|
|
||||||
|
|
||||||
// Log Embed
|
|
||||||
const logEmbed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(logEmbed.title).toBe('Member Kicked');
|
|
||||||
expect(logEmbed.fields.length).toBe(3);
|
|
||||||
|
|
||||||
// Log Embed -> User Field
|
|
||||||
const logEmbedFieldUser = logEmbed.fields[0];
|
|
||||||
|
|
||||||
expect(logEmbedFieldUser.name).toBe('User');
|
|
||||||
expect(logEmbedFieldUser.value).toBe('[object Object] `USERTAG`');
|
|
||||||
expect(logEmbedFieldUser.inline).toBeTruthy();
|
|
||||||
|
|
||||||
// Log Embed -> Moderator Field
|
|
||||||
const logEmbedFieldModerator = logEmbed.fields[1];
|
|
||||||
|
|
||||||
expect(logEmbedFieldModerator.name).toBe('Moderator');
|
|
||||||
expect(logEmbedFieldModerator.value).toBe('[object Object] `AUTHORTAG`');
|
|
||||||
|
|
||||||
// Log Embed -> Reason Field
|
|
||||||
const logEmbedFieldReason = logEmbed.fields[2];
|
|
||||||
|
|
||||||
expect(logEmbedFieldReason.name).toBe('Reason');
|
|
||||||
expect(logEmbedFieldReason.value).toBe('Test Reason');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given moderator did not supply a reason, expect default reason to be added', async () => {
|
|
||||||
process.env = {
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs'
|
|
||||||
};
|
|
||||||
|
|
||||||
const user = {
|
|
||||||
displayAvatarURL: jest.fn(),
|
|
||||||
tag: 'USERTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
|
|
||||||
const member = {
|
|
||||||
kickable: true,
|
|
||||||
kick: jest.fn()
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
|
|
||||||
const logChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: jest.fn()
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const messageMentionsUsersFirst = jest.fn()
|
|
||||||
.mockReturnValue(user);
|
|
||||||
const messageGuildMember = jest.fn()
|
|
||||||
.mockReturnValue(member);
|
|
||||||
const messageGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): TextChannel | undefined => {
|
|
||||||
const result = callback(logChannel);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return logChannel;
|
|
||||||
});
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
mentions: {
|
|
||||||
users: {
|
|
||||||
first: messageMentionsUsersFirst
|
|
||||||
}
|
|
||||||
},
|
|
||||||
guild: {
|
|
||||||
member: messageGuildMember,
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
},
|
|
||||||
available: true
|
|
||||||
},
|
|
||||||
author: {
|
|
||||||
tag: 'AUTHORTAG'
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: "kick",
|
|
||||||
args: ["USER"],
|
|
||||||
message: message
|
|
||||||
}
|
|
||||||
|
|
||||||
const kick = new Kick();
|
|
||||||
|
|
||||||
const result = await kick.execute(context);
|
|
||||||
|
|
||||||
expect(messageChannelSend).toBeCalledTimes(1);
|
|
||||||
expect(logChannel.send).toBeCalledTimes(1);
|
|
||||||
expect(member.kick).toBeCalledWith('Moderator: AUTHORTAG, Reason: *none*');
|
|
||||||
|
|
||||||
expect(result.embeds.length).toBe(2);
|
|
||||||
|
|
||||||
// Log Embed
|
|
||||||
const logEmbed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(logEmbed.title).toBe('Member Kicked');
|
|
||||||
expect(logEmbed.fields.length).toBe(3);
|
|
||||||
|
|
||||||
// Log Embed -> User Field
|
|
||||||
const logEmbedFieldUser = logEmbed.fields[0];
|
|
||||||
|
|
||||||
expect(logEmbedFieldUser.name).toBe('User');
|
|
||||||
expect(logEmbedFieldUser.value).toBe('[object Object] `USERTAG`');
|
|
||||||
expect(logEmbedFieldUser.inline).toBeTruthy();
|
|
||||||
|
|
||||||
// Log Embed -> Moderator Field
|
|
||||||
const logEmbedFieldModerator = logEmbed.fields[1];
|
|
||||||
|
|
||||||
expect(logEmbedFieldModerator.name).toBe('Moderator');
|
|
||||||
expect(logEmbedFieldModerator.value).toBe('[object Object] `AUTHORTAG`');
|
|
||||||
|
|
||||||
// Log Embed -> Reason Field
|
|
||||||
const logEmbedFieldReason = logEmbed.fields[2];
|
|
||||||
|
|
||||||
expect(logEmbedFieldReason.name).toBe('Reason');
|
|
||||||
expect(logEmbedFieldReason.value).toBe('*none*');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given target user is not found, expect user does not exist error', async () => {
|
|
||||||
process.env = {
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs'
|
|
||||||
}
|
|
||||||
|
|
||||||
const user = {
|
|
||||||
displayAvatarURL: jest.fn(),
|
|
||||||
tag: 'USERTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
|
|
||||||
const member = {
|
|
||||||
kickable: true,
|
|
||||||
kick: jest.fn()
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
|
|
||||||
const logChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: jest.fn()
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const messageMentionsUsersFirst = jest.fn()
|
|
||||||
.mockReturnValue(null);
|
|
||||||
const messageGuildMember = jest.fn()
|
|
||||||
.mockReturnValue(member);
|
|
||||||
const messageGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): TextChannel | undefined => {
|
|
||||||
const result = callback(logChannel);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return logChannel;
|
|
||||||
});
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
mentions: {
|
|
||||||
users: {
|
|
||||||
first: messageMentionsUsersFirst
|
|
||||||
}
|
|
||||||
},
|
|
||||||
guild: {
|
|
||||||
member: messageGuildMember,
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
},
|
|
||||||
available: true
|
|
||||||
},
|
|
||||||
author: {
|
|
||||||
tag: 'AUTHORTAG'
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: "kick",
|
|
||||||
args: ["USER", "Test", "Reason"],
|
|
||||||
message: message
|
|
||||||
}
|
|
||||||
|
|
||||||
const kick = new Kick();
|
|
||||||
|
|
||||||
const result = await kick.execute(context);
|
|
||||||
|
|
||||||
expect(messageChannelSend).toBeCalledTimes(1);
|
|
||||||
expect(logChannel.send).not.toBeCalled();
|
|
||||||
expect(member.kick).not.toBeCalled();
|
|
||||||
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
// Embed
|
|
||||||
const embed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(embed.title).toBe(null);
|
|
||||||
expect(embed.description).toBe('User does not exist');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given target member is not found, expect user is not in this server error', async () => {
|
|
||||||
process.env = {
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs'
|
|
||||||
}
|
|
||||||
|
|
||||||
const user = {
|
|
||||||
displayAvatarURL: jest.fn(),
|
|
||||||
tag: 'USERTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
|
|
||||||
const member = {
|
|
||||||
kickable: true,
|
|
||||||
kick: jest.fn()
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
|
|
||||||
const logChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: jest.fn()
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const messageMentionsUsersFirst = jest.fn()
|
|
||||||
.mockReturnValue(user);
|
|
||||||
const messageGuildMember = jest.fn()
|
|
||||||
.mockReturnValue(null);
|
|
||||||
const messageGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): TextChannel | undefined => {
|
|
||||||
const result = callback(logChannel);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return logChannel;
|
|
||||||
});
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
mentions: {
|
|
||||||
users: {
|
|
||||||
first: messageMentionsUsersFirst
|
|
||||||
}
|
|
||||||
},
|
|
||||||
guild: {
|
|
||||||
member: messageGuildMember,
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
},
|
|
||||||
available: true
|
|
||||||
},
|
|
||||||
author: {
|
|
||||||
tag: 'AUTHORTAG'
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: "kick",
|
|
||||||
args: ["USER", "Test", "Reason"],
|
|
||||||
message: message
|
|
||||||
}
|
|
||||||
|
|
||||||
const kick = new Kick();
|
|
||||||
|
|
||||||
const result = await kick.execute(context);
|
|
||||||
|
|
||||||
expect(messageChannelSend).toBeCalledTimes(1);
|
|
||||||
expect(logChannel.send).not.toBeCalled();
|
|
||||||
expect(member.kick).not.toBeCalled();
|
|
||||||
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
// Embed
|
|
||||||
const embed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(embed.title).toBe(null);
|
|
||||||
expect(embed.description).toBe('User is not in this server');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given guild is not available, expect to stop', async () => {
|
|
||||||
process.env = {
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs'
|
|
||||||
}
|
|
||||||
|
|
||||||
const user = {
|
|
||||||
displayAvatarURL: jest.fn(),
|
|
||||||
tag: 'USERTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
|
|
||||||
const member = {
|
|
||||||
kickable: true,
|
|
||||||
kick: jest.fn()
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
|
|
||||||
const logChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: jest.fn()
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const messageMentionsUsersFirst = jest.fn()
|
|
||||||
.mockReturnValue(user);
|
|
||||||
const messageGuildMember = jest.fn()
|
|
||||||
.mockReturnValue(member);
|
|
||||||
const messageGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): TextChannel | undefined => {
|
|
||||||
const result = callback(logChannel);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return logChannel;
|
|
||||||
});
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
mentions: {
|
|
||||||
users: {
|
|
||||||
first: messageMentionsUsersFirst
|
|
||||||
}
|
|
||||||
},
|
|
||||||
guild: {
|
|
||||||
member: messageGuildMember,
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
},
|
|
||||||
available: false
|
|
||||||
},
|
|
||||||
author: {
|
|
||||||
tag: 'AUTHORTAG'
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: "kick",
|
|
||||||
args: ["USER", "Test", "Reason"],
|
|
||||||
message: message
|
|
||||||
}
|
|
||||||
|
|
||||||
const kick = new Kick();
|
|
||||||
|
|
||||||
const result = await kick.execute(context);
|
|
||||||
|
|
||||||
expect(messageChannelSend).not.toBeCalled();
|
|
||||||
expect(logChannel.send).not.toBeCalled();
|
|
||||||
expect(member.kick).not.toBeCalled();
|
|
||||||
|
|
||||||
expect(result.embeds.length).toBe(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given client can not kick member, expect error', async () => {
|
|
||||||
process.env = {
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs'
|
|
||||||
}
|
|
||||||
|
|
||||||
const user = {
|
|
||||||
displayAvatarURL: jest.fn(),
|
|
||||||
tag: 'USERTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
|
|
||||||
const member = {
|
|
||||||
kickable: false,
|
|
||||||
kick: jest.fn()
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
|
|
||||||
const logChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: jest.fn()
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const messageMentionsUsersFirst = jest.fn()
|
|
||||||
.mockReturnValue(user);
|
|
||||||
const messageGuildMember = jest.fn()
|
|
||||||
.mockReturnValue(member);
|
|
||||||
const messageGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): TextChannel | undefined => {
|
|
||||||
const result = callback(logChannel);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return logChannel;
|
|
||||||
});
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
mentions: {
|
|
||||||
users: {
|
|
||||||
first: messageMentionsUsersFirst
|
|
||||||
}
|
|
||||||
},
|
|
||||||
guild: {
|
|
||||||
member: messageGuildMember,
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
},
|
|
||||||
available: true
|
|
||||||
},
|
|
||||||
author: {
|
|
||||||
tag: 'AUTHORTAG'
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: "kick",
|
|
||||||
args: ["USER", "Test", "Reason"],
|
|
||||||
message: message
|
|
||||||
}
|
|
||||||
|
|
||||||
const kick = new Kick();
|
|
||||||
|
|
||||||
const result = await kick.execute(context);
|
|
||||||
|
|
||||||
expect(messageChannelSend).toBeCalledTimes(1);
|
|
||||||
expect(logChannel.send).not.toBeCalled();
|
|
||||||
expect(member.kick).not.toBeCalled();
|
|
||||||
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
// Embed
|
|
||||||
const embed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(embed.title).toBe(null);
|
|
||||||
expect(embed.description).toBe('Unable to do this action, am I missing permissions?');
|
|
||||||
});
|
|
||||||
});
|
});
|
|
@ -1,815 +0,0 @@
|
||||||
import { mock } from "jest-mock-extended";
|
|
||||||
|
|
||||||
import { GuildMember, Message, Role, TextChannel, User } from "discord.js";
|
|
||||||
import Mute from "../../src/commands/mute";
|
|
||||||
import { ICommandContext } from "../../src/contracts/ICommandContext";
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
process.env = {};
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Constructor', () => {
|
|
||||||
test('Expect properties to be set', () => {
|
|
||||||
process.env = {
|
|
||||||
ROLES_MODERATOR: 'Moderator'
|
|
||||||
};
|
|
||||||
|
|
||||||
const mute = new Mute();
|
|
||||||
|
|
||||||
expect(mute._category).toBe("Moderation");
|
|
||||||
expect(mute._roles.length).toBe(1);
|
|
||||||
expect(mute._roles[0]).toBe('Moderator');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Execute', () => {
|
|
||||||
test('Given user has permission, expect user to be given muted role', async () => {
|
|
||||||
process.env = {
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs',
|
|
||||||
ROLES_MUTED: 'Muted'
|
|
||||||
};
|
|
||||||
|
|
||||||
const user = {
|
|
||||||
displayAvatarURL: jest.fn(),
|
|
||||||
tag: 'USERTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
|
|
||||||
const messageAuthor = {
|
|
||||||
tag: 'AUTHORTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
|
|
||||||
const member = {
|
|
||||||
manageable: true,
|
|
||||||
roles: {
|
|
||||||
add: jest.fn()
|
|
||||||
}
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
|
|
||||||
const role = {
|
|
||||||
name: 'Muted'
|
|
||||||
} as unknown as Role;
|
|
||||||
|
|
||||||
const logChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: jest.fn()
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const messageMentionsUsersFirst = jest.fn()
|
|
||||||
.mockReturnValue(user);
|
|
||||||
const messageGuildMember = jest.fn()
|
|
||||||
.mockReturnValue(member);
|
|
||||||
const messageGuildRolesCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): Role | undefined => {
|
|
||||||
const result = callback(role);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return role;
|
|
||||||
});
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
const messageGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): TextChannel | undefined => {
|
|
||||||
const result = callback(logChannel);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return logChannel;
|
|
||||||
});
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
mentions: {
|
|
||||||
users: {
|
|
||||||
first: messageMentionsUsersFirst
|
|
||||||
}
|
|
||||||
},
|
|
||||||
guild: {
|
|
||||||
member: messageGuildMember,
|
|
||||||
available: true,
|
|
||||||
roles: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildRolesCacheFind
|
|
||||||
}
|
|
||||||
},
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
author: messageAuthor
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'mute',
|
|
||||||
args: ['USER', 'Test', 'Reason'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const mute = new Mute();
|
|
||||||
|
|
||||||
const result = await mute.execute(context);
|
|
||||||
|
|
||||||
expect(messageMentionsUsersFirst).toBeCalledTimes(1);
|
|
||||||
expect(messageGuildMember).toBeCalledWith(user);
|
|
||||||
expect(messageGuildRolesCacheFind).toBeCalledTimes(1);
|
|
||||||
expect(messageGuildChannelsCacheFind).toBeCalledTimes(1);
|
|
||||||
expect(messageChannelSend).toBeCalledTimes(1);
|
|
||||||
expect(member.roles.add).toBeCalledWith(role, 'Moderator: AUTHORTAG, Reason: Test Reason');
|
|
||||||
|
|
||||||
expect(result.embeds.length).toBe(2);
|
|
||||||
|
|
||||||
// Log Embed
|
|
||||||
const logEmbed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(logEmbed.title).toBe('Member Muted');
|
|
||||||
expect(logEmbed.fields.length).toBe(3);
|
|
||||||
|
|
||||||
// Log Embed -> User Field
|
|
||||||
const logEmbedUserField = logEmbed.fields[0];
|
|
||||||
|
|
||||||
expect(logEmbedUserField.name).toBe('User');
|
|
||||||
expect(logEmbedUserField.value).toBe('[object Object] `USERTAG`');
|
|
||||||
expect(logEmbedUserField.inline).toBeTruthy();
|
|
||||||
|
|
||||||
// Log Embed -> Moderator Field
|
|
||||||
const logEmbedModeratorField = logEmbed.fields[1];
|
|
||||||
|
|
||||||
expect(logEmbedModeratorField.name).toBe('Moderator');
|
|
||||||
expect(logEmbedModeratorField.value).toBe('[object Object] `AUTHORTAG`');
|
|
||||||
|
|
||||||
// Log Embed -> Reason Field
|
|
||||||
const logEmbedFieldReason = logEmbed.fields[2];
|
|
||||||
|
|
||||||
expect(logEmbedFieldReason.name).toBe('Reason');
|
|
||||||
expect(logEmbedFieldReason.value).toBe('Test Reason');
|
|
||||||
|
|
||||||
// Public Embed
|
|
||||||
const publicEmbed = result.embeds[1];
|
|
||||||
|
|
||||||
expect(publicEmbed.title).toBe('');
|
|
||||||
expect(publicEmbed.description).toBe('[object Object] has been muted');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given moderator did not supply a reason, expect default reason used', async () => {
|
|
||||||
process.env = {
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs',
|
|
||||||
ROLES_MUTED: 'Muted'
|
|
||||||
};
|
|
||||||
|
|
||||||
const user = {
|
|
||||||
displayAvatarURL: jest.fn(),
|
|
||||||
tag: 'USERTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
|
|
||||||
const messageAuthor = {
|
|
||||||
tag: 'AUTHORTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
|
|
||||||
const member = {
|
|
||||||
manageable: true,
|
|
||||||
roles: {
|
|
||||||
add: jest.fn()
|
|
||||||
}
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
|
|
||||||
const role = {
|
|
||||||
name: 'Muted'
|
|
||||||
} as unknown as Role;
|
|
||||||
|
|
||||||
const logChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: jest.fn()
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const messageMentionsUsersFirst = jest.fn()
|
|
||||||
.mockReturnValue(user);
|
|
||||||
const messageGuildMember = jest.fn()
|
|
||||||
.mockReturnValue(member);
|
|
||||||
const messageGuildRolesCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): Role | undefined => {
|
|
||||||
const result = callback(role);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return role;
|
|
||||||
});
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
const messageGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): TextChannel | undefined => {
|
|
||||||
const result = callback(logChannel);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return logChannel;
|
|
||||||
});
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
mentions: {
|
|
||||||
users: {
|
|
||||||
first: messageMentionsUsersFirst
|
|
||||||
}
|
|
||||||
},
|
|
||||||
guild: {
|
|
||||||
member: messageGuildMember,
|
|
||||||
available: true,
|
|
||||||
roles: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildRolesCacheFind
|
|
||||||
}
|
|
||||||
},
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
author: messageAuthor
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'mute',
|
|
||||||
args: ['USER'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const mute = new Mute();
|
|
||||||
|
|
||||||
const result = await mute.execute(context);
|
|
||||||
|
|
||||||
expect(messageMentionsUsersFirst).toBeCalledTimes(1);
|
|
||||||
expect(messageGuildMember).toBeCalledWith(user);
|
|
||||||
expect(messageGuildRolesCacheFind).toBeCalledTimes(1);
|
|
||||||
expect(messageGuildChannelsCacheFind).toBeCalledTimes(1);
|
|
||||||
expect(messageChannelSend).toBeCalledTimes(1);
|
|
||||||
expect(member.roles.add).toBeCalledWith(role, 'Moderator: AUTHORTAG, Reason: *none*');
|
|
||||||
|
|
||||||
expect(result.embeds.length).toBe(2);
|
|
||||||
|
|
||||||
// Log Embed
|
|
||||||
const logEmbed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(logEmbed.title).toBe('Member Muted');
|
|
||||||
expect(logEmbed.fields.length).toBe(3);
|
|
||||||
|
|
||||||
// Log Embed -> User Field
|
|
||||||
const logEmbedUserField = logEmbed.fields[0];
|
|
||||||
|
|
||||||
expect(logEmbedUserField.name).toBe('User');
|
|
||||||
expect(logEmbedUserField.value).toBe('[object Object] `USERTAG`');
|
|
||||||
expect(logEmbedUserField.inline).toBeTruthy();
|
|
||||||
|
|
||||||
// Log Embed -> Moderator Field
|
|
||||||
const logEmbedModeratorField = logEmbed.fields[1];
|
|
||||||
|
|
||||||
expect(logEmbedModeratorField.name).toBe('Moderator');
|
|
||||||
expect(logEmbedModeratorField.value).toBe('[object Object] `AUTHORTAG`');
|
|
||||||
|
|
||||||
// Log Embed -> Reason Field
|
|
||||||
const logEmbedFieldReason = logEmbed.fields[2];
|
|
||||||
|
|
||||||
expect(logEmbedFieldReason.name).toBe('Reason');
|
|
||||||
expect(logEmbedFieldReason.value).toBe('*none*');
|
|
||||||
|
|
||||||
// Public Embed
|
|
||||||
const publicEmbed = result.embeds[1];
|
|
||||||
|
|
||||||
expect(publicEmbed.title).toBe('');
|
|
||||||
expect(publicEmbed.description).toBe('[object Object] has been muted');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given user did not mention a user, expect user not to exist', async () => {
|
|
||||||
process.env = {
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs',
|
|
||||||
ROLES_MUTED: 'Muted'
|
|
||||||
};
|
|
||||||
|
|
||||||
const user = {
|
|
||||||
displayAvatarURL: jest.fn(),
|
|
||||||
tag: 'USERTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
|
|
||||||
const messageAuthor = {
|
|
||||||
tag: 'AUTHORTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
|
|
||||||
const member = {
|
|
||||||
manageable: true,
|
|
||||||
roles: {
|
|
||||||
add: jest.fn()
|
|
||||||
}
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
|
|
||||||
const role = {
|
|
||||||
name: 'Muted'
|
|
||||||
} as unknown as Role;
|
|
||||||
|
|
||||||
const logChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: jest.fn()
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const messageMentionsUsersFirst = jest.fn()
|
|
||||||
.mockReturnValue(null);
|
|
||||||
const messageGuildMember = jest.fn()
|
|
||||||
.mockReturnValue(member);
|
|
||||||
const messageGuildRolesCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): Role | undefined => {
|
|
||||||
const result = callback(role);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return role;
|
|
||||||
});
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
const messageGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): TextChannel | undefined => {
|
|
||||||
const result = callback(logChannel);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return logChannel;
|
|
||||||
});
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
mentions: {
|
|
||||||
users: {
|
|
||||||
first: messageMentionsUsersFirst
|
|
||||||
}
|
|
||||||
},
|
|
||||||
guild: {
|
|
||||||
member: messageGuildMember,
|
|
||||||
available: true,
|
|
||||||
roles: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildRolesCacheFind
|
|
||||||
}
|
|
||||||
},
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
author: messageAuthor
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'mute',
|
|
||||||
args: ['USER', 'Test', 'Reason'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const mute = new Mute();
|
|
||||||
|
|
||||||
const result = await mute.execute(context);
|
|
||||||
|
|
||||||
expect(messageMentionsUsersFirst).toBeCalledTimes(1);
|
|
||||||
expect(messageGuildMember).not.toBeCalled();
|
|
||||||
expect(messageGuildRolesCacheFind).not.toBeCalled();
|
|
||||||
expect(messageGuildChannelsCacheFind).not.toBeCalled();
|
|
||||||
expect(messageChannelSend).toBeCalledTimes(1);
|
|
||||||
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
// Error Embed
|
|
||||||
const errorEmbed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(errorEmbed.description).toBe('User does not exist');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given member can not be found from user, expect user to not be in server', async () => {
|
|
||||||
process.env = {
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs',
|
|
||||||
ROLES_MUTED: 'Muted'
|
|
||||||
};
|
|
||||||
|
|
||||||
const user = {
|
|
||||||
displayAvatarURL: jest.fn(),
|
|
||||||
tag: 'USERTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
|
|
||||||
const messageAuthor = {
|
|
||||||
tag: 'AUTHORTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
|
|
||||||
const member = {
|
|
||||||
manageable: true,
|
|
||||||
roles: {
|
|
||||||
add: jest.fn()
|
|
||||||
}
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
|
|
||||||
const role = {
|
|
||||||
name: 'Muted'
|
|
||||||
} as unknown as Role;
|
|
||||||
|
|
||||||
const logChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: jest.fn()
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const messageMentionsUsersFirst = jest.fn()
|
|
||||||
.mockReturnValue(user);
|
|
||||||
const messageGuildMember = jest.fn()
|
|
||||||
.mockReturnValue(null);
|
|
||||||
const messageGuildRolesCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): Role | undefined => {
|
|
||||||
const result = callback(role);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return role;
|
|
||||||
});
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
const messageGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): TextChannel | undefined => {
|
|
||||||
const result = callback(logChannel);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return logChannel;
|
|
||||||
});
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
mentions: {
|
|
||||||
users: {
|
|
||||||
first: messageMentionsUsersFirst
|
|
||||||
}
|
|
||||||
},
|
|
||||||
guild: {
|
|
||||||
member: messageGuildMember,
|
|
||||||
available: true,
|
|
||||||
roles: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildRolesCacheFind
|
|
||||||
}
|
|
||||||
},
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
author: messageAuthor
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'mute',
|
|
||||||
args: ['USER', 'Test', 'Reason'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const mute = new Mute();
|
|
||||||
|
|
||||||
const result = await mute.execute(context);
|
|
||||||
|
|
||||||
expect(messageMentionsUsersFirst).toBeCalledTimes(1);
|
|
||||||
expect(messageGuildMember).toBeCalledWith(user);
|
|
||||||
expect(messageGuildRolesCacheFind).not.toBeCalled();
|
|
||||||
expect(messageGuildChannelsCacheFind).not.toBeCalled();
|
|
||||||
expect(messageChannelSend).toBeCalledTimes(1);
|
|
||||||
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
// Error Embed
|
|
||||||
const errorEmbed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(errorEmbed.description).toBe('User is not in this server');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given guild is unavailable, expect execution to stop', async () => {
|
|
||||||
process.env = {
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs',
|
|
||||||
ROLES_MUTED: 'Muted'
|
|
||||||
};
|
|
||||||
|
|
||||||
const user = {
|
|
||||||
displayAvatarURL: jest.fn(),
|
|
||||||
tag: 'USERTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
|
|
||||||
const messageAuthor = {
|
|
||||||
tag: 'AUTHORTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
|
|
||||||
const member = {
|
|
||||||
manageable: true,
|
|
||||||
roles: {
|
|
||||||
add: jest.fn()
|
|
||||||
}
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
|
|
||||||
const role = {
|
|
||||||
name: 'Muted'
|
|
||||||
} as unknown as Role;
|
|
||||||
|
|
||||||
const logChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: jest.fn()
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const messageMentionsUsersFirst = jest.fn()
|
|
||||||
.mockReturnValue(user);
|
|
||||||
const messageGuildMember = jest.fn()
|
|
||||||
.mockReturnValue(member);
|
|
||||||
const messageGuildRolesCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): Role | undefined => {
|
|
||||||
const result = callback(role);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return role;
|
|
||||||
});
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
const messageGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): TextChannel | undefined => {
|
|
||||||
const result = callback(logChannel);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return logChannel;
|
|
||||||
});
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
mentions: {
|
|
||||||
users: {
|
|
||||||
first: messageMentionsUsersFirst
|
|
||||||
}
|
|
||||||
},
|
|
||||||
guild: {
|
|
||||||
member: messageGuildMember,
|
|
||||||
available: false,
|
|
||||||
roles: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildRolesCacheFind
|
|
||||||
}
|
|
||||||
},
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
author: messageAuthor
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'mute',
|
|
||||||
args: ['USER', 'Test', 'Reason'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const mute = new Mute();
|
|
||||||
|
|
||||||
const result = await mute.execute(context);
|
|
||||||
|
|
||||||
expect(messageMentionsUsersFirst).toBeCalledTimes(1);
|
|
||||||
expect(messageGuildMember).toBeCalledWith(user);
|
|
||||||
expect(messageGuildRolesCacheFind).not.toBeCalled();
|
|
||||||
expect(messageGuildChannelsCacheFind).not.toBeCalled();
|
|
||||||
expect(messageChannelSend).not.toBeCalled();
|
|
||||||
|
|
||||||
expect(result.embeds.length).toBe(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given client can not manage user, expect insufficient permissions', async () => {
|
|
||||||
process.env = {
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs',
|
|
||||||
ROLES_MUTED: 'Muted'
|
|
||||||
};
|
|
||||||
|
|
||||||
const user = {
|
|
||||||
displayAvatarURL: jest.fn(),
|
|
||||||
tag: 'USERTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
|
|
||||||
const messageAuthor = {
|
|
||||||
tag: 'AUTHORTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
|
|
||||||
const member = {
|
|
||||||
manageable: false,
|
|
||||||
roles: {
|
|
||||||
add: jest.fn()
|
|
||||||
}
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
|
|
||||||
const role = {
|
|
||||||
name: 'Muted'
|
|
||||||
} as unknown as Role;
|
|
||||||
|
|
||||||
const logChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: jest.fn()
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const messageMentionsUsersFirst = jest.fn()
|
|
||||||
.mockReturnValue(user);
|
|
||||||
const messageGuildMember = jest.fn()
|
|
||||||
.mockReturnValue(member);
|
|
||||||
const messageGuildRolesCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): Role | undefined => {
|
|
||||||
const result = callback(role);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return role;
|
|
||||||
});
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
const messageGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): TextChannel | undefined => {
|
|
||||||
const result = callback(logChannel);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return logChannel;
|
|
||||||
});
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
mentions: {
|
|
||||||
users: {
|
|
||||||
first: messageMentionsUsersFirst
|
|
||||||
}
|
|
||||||
},
|
|
||||||
guild: {
|
|
||||||
member: messageGuildMember,
|
|
||||||
available: true,
|
|
||||||
roles: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildRolesCacheFind
|
|
||||||
}
|
|
||||||
},
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
author: messageAuthor
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'mute',
|
|
||||||
args: ['USER', 'Test', 'Reason'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const mute = new Mute();
|
|
||||||
|
|
||||||
const result = await mute.execute(context);
|
|
||||||
|
|
||||||
expect(messageMentionsUsersFirst).toBeCalledTimes(1);
|
|
||||||
expect(messageGuildMember).toBeCalledWith(user);
|
|
||||||
expect(messageGuildRolesCacheFind).not.toBeCalled();
|
|
||||||
expect(messageGuildChannelsCacheFind).not.toBeCalled();
|
|
||||||
expect(messageChannelSend).toBeCalledTimes(1);
|
|
||||||
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
// Error Embed
|
|
||||||
const errorEmbed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(errorEmbed.description).toBe('Unable to do this action, am I missing permissions?');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given muted role can not be found, expect role not found', async () => {
|
|
||||||
process.env = {
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs',
|
|
||||||
ROLES_MUTED: 'Muted'
|
|
||||||
};
|
|
||||||
|
|
||||||
const user = {
|
|
||||||
displayAvatarURL: jest.fn(),
|
|
||||||
tag: 'USERTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
|
|
||||||
const messageAuthor = {
|
|
||||||
tag: 'AUTHORTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
|
|
||||||
const member = {
|
|
||||||
manageable: true,
|
|
||||||
roles: {
|
|
||||||
add: jest.fn()
|
|
||||||
}
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
|
|
||||||
const role = {
|
|
||||||
name: 'Muted'
|
|
||||||
} as unknown as Role;
|
|
||||||
|
|
||||||
const logChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: jest.fn()
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const messageMentionsUsersFirst = jest.fn()
|
|
||||||
.mockReturnValue(user);
|
|
||||||
const messageGuildMember = jest.fn()
|
|
||||||
.mockReturnValue(member);
|
|
||||||
const messageGuildRolesCacheFind = jest.fn()
|
|
||||||
.mockReturnValue(undefined);
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
const messageGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): TextChannel | undefined => {
|
|
||||||
const result = callback(logChannel);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return logChannel;
|
|
||||||
});
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
mentions: {
|
|
||||||
users: {
|
|
||||||
first: messageMentionsUsersFirst
|
|
||||||
}
|
|
||||||
},
|
|
||||||
guild: {
|
|
||||||
member: messageGuildMember,
|
|
||||||
available: true,
|
|
||||||
roles: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildRolesCacheFind
|
|
||||||
}
|
|
||||||
},
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
author: messageAuthor
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'mute',
|
|
||||||
args: ['USER', 'Test', 'Reason'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const mute = new Mute();
|
|
||||||
|
|
||||||
const result = await mute.execute(context);
|
|
||||||
|
|
||||||
expect(messageMentionsUsersFirst).toBeCalledTimes(1);
|
|
||||||
expect(messageGuildMember).toBeCalledWith(user);
|
|
||||||
expect(messageGuildRolesCacheFind).toBeCalledTimes(1);
|
|
||||||
expect(messageGuildChannelsCacheFind).not.toBeCalled();
|
|
||||||
expect(messageChannelSend).toBeCalledTimes(1);
|
|
||||||
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
// Error Embed
|
|
||||||
const errorEmbed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(errorEmbed.description).toBe('Unable to find role');
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -1,262 +1,19 @@
|
||||||
import { Message, MessageEmbed } from "discord.js";
|
|
||||||
import Poll from "../../src/commands/poll";
|
|
||||||
import { ICommandContext } from "../../src/contracts/ICommandContext";
|
|
||||||
|
|
||||||
describe('Constructor', () => {
|
describe('Constructor', () => {
|
||||||
test('Expect properties to be set', () => {
|
test.todo('EXPECT properties to be set');
|
||||||
const poll = new Poll();
|
|
||||||
|
|
||||||
expect(poll._category).toBe('General');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Execute', () => {
|
describe('Execute', () => {
|
||||||
test('Given input is valid, expect poll to be generated', async () => {
|
test.todo("EXPECT a poll to be created");
|
||||||
const returnMessageReact = jest.fn();
|
|
||||||
|
|
||||||
const returnMessage = {
|
test.todo("GIVEN title is not supplied, EXPECT nothing to happen");
|
||||||
react: returnMessageReact
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const messageChannelSend = jest.fn()
|
test.todo("GIVEN option1 is not supplied, EXPECT nothing to happen");
|
||||||
.mockReturnValue(returnMessage);
|
|
||||||
const messageDelete = jest.fn();
|
|
||||||
|
|
||||||
const message = {
|
test.todo("GIVEN option2 is not supplied, EXPECT nothing to happen");
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
delete: messageDelete,
|
|
||||||
deletable: true
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
test.todo("GIVEN option3 is not supplied, EXPECT a 2 option poll to be created");
|
||||||
name: 'poll',
|
|
||||||
args: ['Test', 'title;', 'one;', 'two'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const poll = new Poll();
|
test.todo("GIVEN option4 is not supplied, EXPECT a 3 option poll to be created");
|
||||||
|
|
||||||
const result = await poll.execute(context);
|
test.todo("GIVEN option5 is not supplied, EXPECT a 4 option poll to be created");
|
||||||
|
|
||||||
expect(messageChannelSend).toBeCalledTimes(1);
|
|
||||||
expect(messageDelete).toBeCalledTimes(1);
|
|
||||||
expect(returnMessageReact).toBeCalledTimes(2);
|
|
||||||
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
// Embed
|
|
||||||
const embed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(embed.title).toBe('Test title');
|
|
||||||
expect(embed.description).toBe(':one: one\n:two: two');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given message is not deletable by client, expect it not to attempt deletion', async () => {
|
|
||||||
const returnMessageReact = jest.fn();
|
|
||||||
|
|
||||||
const returnMessage = {
|
|
||||||
react: returnMessageReact
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const messageChannelSend = jest.fn()
|
|
||||||
.mockReturnValue(returnMessage);
|
|
||||||
const messageDelete = jest.fn();
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
delete: messageDelete,
|
|
||||||
deletable: false
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'poll',
|
|
||||||
args: ['Test', 'title;', 'one;', 'two'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const poll = new Poll();
|
|
||||||
|
|
||||||
const result = await poll.execute(context);
|
|
||||||
|
|
||||||
expect(messageChannelSend).toBeCalledTimes(1);
|
|
||||||
expect(messageDelete).not.toBeCalled();
|
|
||||||
expect(returnMessageReact).toBeCalledTimes(2);
|
|
||||||
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
// Embed
|
|
||||||
const embed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(embed.title).toBe('Test title');
|
|
||||||
expect(embed.description).toBe(':one: one\n:two: two');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given no arguments, expect error embed', async () => {
|
|
||||||
const returnMessageReact = jest.fn();
|
|
||||||
|
|
||||||
const returnMessage = {
|
|
||||||
react: returnMessageReact
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const messageChannelSend = jest.fn()
|
|
||||||
.mockReturnValue(returnMessage);
|
|
||||||
const messageDelete = jest.fn();
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
delete: messageDelete,
|
|
||||||
deletable: true
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'poll',
|
|
||||||
args: [],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const poll = new Poll();
|
|
||||||
|
|
||||||
const result = await poll.execute(context);
|
|
||||||
|
|
||||||
expect(messageChannelSend).toBeCalledTimes(1);
|
|
||||||
expect(messageDelete).not.toBeCalled();
|
|
||||||
expect(returnMessageReact).not.toBeCalled();
|
|
||||||
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
// Error Embed
|
|
||||||
const errorEmbed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(errorEmbed.description).toBe('Usage: <title>;<option 1>;<option 2>... (separate options with semicolons), maximum of 9 options');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given only 1 option, expect error embed', async () => {
|
|
||||||
const returnMessageReact = jest.fn();
|
|
||||||
|
|
||||||
const returnMessage = {
|
|
||||||
react: returnMessageReact
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const messageChannelSend = jest.fn()
|
|
||||||
.mockReturnValue(returnMessage);
|
|
||||||
const messageDelete = jest.fn();
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
delete: messageDelete,
|
|
||||||
deletable: true
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'poll',
|
|
||||||
args: ['Test', 'title;', 'one'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const poll = new Poll();
|
|
||||||
|
|
||||||
const result = await poll.execute(context);
|
|
||||||
|
|
||||||
expect(messageChannelSend).toBeCalledTimes(1);
|
|
||||||
expect(messageDelete).not.toBeCalled();
|
|
||||||
expect(returnMessageReact).not.toBeCalled();
|
|
||||||
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
// Error Embed
|
|
||||||
const errorEmbed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(errorEmbed.description).toBe('Usage: <title>;<option 1>;<option 2>... (separate options with semicolons), maximum of 9 options');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given 9 options, expect poll to be generated', async () => {
|
|
||||||
const returnMessageReact = jest.fn();
|
|
||||||
|
|
||||||
const returnMessage = {
|
|
||||||
react: returnMessageReact
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const messageChannelSend = jest.fn()
|
|
||||||
.mockReturnValue(returnMessage);
|
|
||||||
const messageDelete = jest.fn();
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
delete: messageDelete,
|
|
||||||
deletable: true
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'poll',
|
|
||||||
args: ['Test', 'title;', 'one;', 'two;', 'three;', 'four;', 'five;', 'six;', 'seven;', 'eight;', 'nine'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const poll = new Poll();
|
|
||||||
|
|
||||||
const result = await poll.execute(context);
|
|
||||||
|
|
||||||
expect(messageChannelSend).toBeCalledTimes(1);
|
|
||||||
expect(messageDelete).toBeCalledTimes(1);
|
|
||||||
expect(returnMessageReact).toBeCalledTimes(9);
|
|
||||||
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
// Embed
|
|
||||||
const embed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(embed.title).toBe('Test title');
|
|
||||||
expect(embed.description).toBe(':one: one\n:two: two\n:three: three\n:four: four\n:five: five\n:six: six\n:seven: seven\n:eight: eight\n:nine: nine');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given 10 options, expect error embed', async () => {
|
|
||||||
const returnMessageReact = jest.fn();
|
|
||||||
|
|
||||||
const returnMessage = {
|
|
||||||
react: returnMessageReact
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const messageChannelSend = jest.fn()
|
|
||||||
.mockReturnValue(returnMessage);
|
|
||||||
const messageDelete = jest.fn();
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
delete: messageDelete,
|
|
||||||
deletable: true
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'poll',
|
|
||||||
args: ['Test', 'title;', 'one;', 'two;', 'three;', 'four;', 'five;', 'six;', 'seven;', 'eight;', 'nine;', 'ten'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const poll = new Poll();
|
|
||||||
|
|
||||||
const result = await poll.execute(context);
|
|
||||||
|
|
||||||
expect(messageChannelSend).toBeCalledTimes(1);
|
|
||||||
expect(messageDelete).not.toBeCalled();
|
|
||||||
expect(returnMessageReact).not.toBeCalled();
|
|
||||||
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
// Error Embed
|
|
||||||
const errorEmbed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(errorEmbed.description).toBe('Usage: <title>;<option 1>;<option 2>... (separate options with semicolons), maximum of 9 options');
|
|
||||||
});
|
|
||||||
});
|
});
|
|
@ -1,411 +0,0 @@
|
||||||
import { GuildMemberRoleManager, Message, Role as DiscordRole } from "discord.js";
|
|
||||||
import { mock } from "jest-mock-extended";
|
|
||||||
import Role from "../../src/commands/role";
|
|
||||||
import { ICommandContext } from "../../src/contracts/ICommandContext";
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
process.env = {};
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Constructor', () => {
|
|
||||||
test('Expect properties are set', () => {
|
|
||||||
const role = new Role();
|
|
||||||
|
|
||||||
expect(role._category).toBe("General");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Execute', () => {
|
|
||||||
test('Given no arguments were given, expect SendRolesList to be executed', async () => {
|
|
||||||
process.env = {
|
|
||||||
COMMANDS_ROLE_ROLES: 'One,Two'
|
|
||||||
};
|
|
||||||
|
|
||||||
const message = {} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'role',
|
|
||||||
args: [],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const role = new Role();
|
|
||||||
|
|
||||||
role.SendRolesList = jest.fn();
|
|
||||||
role.ToggleRole = jest.fn();
|
|
||||||
|
|
||||||
await role.execute(context);
|
|
||||||
|
|
||||||
expect(role.SendRolesList).toBeCalledWith(context, ['One', 'Two']);
|
|
||||||
expect(role.ToggleRole).not.toBeCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given an argument was given, expect ToggleRole to be executed', async () => {
|
|
||||||
process.env = {
|
|
||||||
COMMANDS_ROLE_ROLES: 'One,Two'
|
|
||||||
};
|
|
||||||
|
|
||||||
const message = {} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'role',
|
|
||||||
args: ['One'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const role = new Role();
|
|
||||||
|
|
||||||
role.SendRolesList = jest.fn();
|
|
||||||
role.ToggleRole = jest.fn();
|
|
||||||
|
|
||||||
await role.execute(context);
|
|
||||||
|
|
||||||
expect(role.SendRolesList).not.toBeCalled();
|
|
||||||
expect(role.ToggleRole).toBeCalledWith(context, ['One', 'Two']);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('SendRolesList', () => {
|
|
||||||
test('Expect embed with roles to be sent to the current channel', () => {
|
|
||||||
process.env = {
|
|
||||||
BOT_PREFIX: '!'
|
|
||||||
};
|
|
||||||
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'role',
|
|
||||||
args: [],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const roles = ['One', 'Two'];
|
|
||||||
|
|
||||||
const role = new Role();
|
|
||||||
|
|
||||||
const result = role.SendRolesList(context, roles);
|
|
||||||
|
|
||||||
expect(messageChannelSend).toBeCalledTimes(1);
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
// Embed
|
|
||||||
const embed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(embed.title).toBe('Roles');
|
|
||||||
expect(embed.description).toBe('Do !role <role> to get the role!\nOne\nTwo');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('ToggleRole', () => {
|
|
||||||
test('Given role name is a valid role AND user does not have the role, expect role to be added', async () => {
|
|
||||||
const discordRole = {} as unknown as DiscordRole;
|
|
||||||
|
|
||||||
const messageMemberRolesCacheFind = jest.fn()
|
|
||||||
.mockReturnValue(undefined);
|
|
||||||
const messageGuildRolesCacheFind = jest.fn()
|
|
||||||
.mockReturnValue(discordRole);
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
member: {
|
|
||||||
roles: {
|
|
||||||
cache: {
|
|
||||||
find: messageMemberRolesCacheFind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
guild: {
|
|
||||||
roles: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildRolesCacheFind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'role',
|
|
||||||
args: ['One'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const roles = ['One', 'Two'];
|
|
||||||
|
|
||||||
const role = new Role();
|
|
||||||
|
|
||||||
role.AddRole = jest.fn();
|
|
||||||
role.RemoveRole = jest.fn();
|
|
||||||
|
|
||||||
const result = await role.ToggleRole(context, roles);
|
|
||||||
|
|
||||||
expect(messageMemberRolesCacheFind).toBeCalledTimes(1);
|
|
||||||
expect(messageGuildRolesCacheFind).toBeCalledTimes(1);
|
|
||||||
expect(messageChannelSend).not.toBeCalled();
|
|
||||||
expect(role.AddRole).toBeCalledWith(context, discordRole);
|
|
||||||
expect(role.RemoveRole).not.toBeCalled();
|
|
||||||
|
|
||||||
expect(result.embeds.length).toBe(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given role name is a valid role AND user has the role, expect role to be removed', async () => {
|
|
||||||
const discordRole = {} as unknown as DiscordRole;
|
|
||||||
|
|
||||||
const messageMemberRolesCacheFind = jest.fn()
|
|
||||||
.mockReturnValue(discordRole);
|
|
||||||
const messageGuildRolesCacheFind = jest.fn()
|
|
||||||
.mockReturnValue(discordRole);
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
member: {
|
|
||||||
roles: {
|
|
||||||
cache: {
|
|
||||||
find: messageMemberRolesCacheFind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
guild: {
|
|
||||||
roles: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildRolesCacheFind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'role',
|
|
||||||
args: ['One'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const roles = ['One', 'Two'];
|
|
||||||
|
|
||||||
const role = new Role();
|
|
||||||
|
|
||||||
role.AddRole = jest.fn();
|
|
||||||
role.RemoveRole = jest.fn();
|
|
||||||
|
|
||||||
const result = await role.ToggleRole(context, roles);
|
|
||||||
|
|
||||||
expect(messageMemberRolesCacheFind).toBeCalledTimes(1);
|
|
||||||
expect(messageGuildRolesCacheFind).toBeCalledTimes(1);
|
|
||||||
expect(messageChannelSend).not.toBeCalled();
|
|
||||||
expect(role.AddRole).not.toBeCalled();
|
|
||||||
expect(role.RemoveRole).toBeCalledWith(context, discordRole);
|
|
||||||
|
|
||||||
expect(result.embeds.length).toBe(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given role requested is not in the roles array, expect role not assignable error', async () => {
|
|
||||||
const discordRole = {} as unknown as DiscordRole;
|
|
||||||
|
|
||||||
const messageMemberRolesCacheFind = jest.fn()
|
|
||||||
.mockReturnValue(undefined);
|
|
||||||
const messageGuildRolesCacheFind = jest.fn()
|
|
||||||
.mockReturnValue(discordRole);
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
member: {
|
|
||||||
roles: {
|
|
||||||
cache: {
|
|
||||||
find: messageMemberRolesCacheFind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
guild: {
|
|
||||||
roles: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildRolesCacheFind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'role',
|
|
||||||
args: ['Three'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const roles = ['One', 'Two'];
|
|
||||||
|
|
||||||
const role = new Role();
|
|
||||||
|
|
||||||
role.AddRole = jest.fn();
|
|
||||||
role.RemoveRole = jest.fn();
|
|
||||||
|
|
||||||
const result = await role.ToggleRole(context, roles);
|
|
||||||
|
|
||||||
expect(messageMemberRolesCacheFind).not.toBeCalled();
|
|
||||||
expect(messageGuildRolesCacheFind).not.toBeCalled();
|
|
||||||
expect(messageChannelSend).toBeCalledTimes(1);
|
|
||||||
expect(role.AddRole).not.toBeCalled();
|
|
||||||
expect(role.RemoveRole).not.toBeCalled();
|
|
||||||
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
// Error Embed
|
|
||||||
const errorEmbed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(errorEmbed.description).toBe("This role isn't marked as assignable, to see a list of assignable roles, run this command without any parameters");
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given the role is not in the guild, expect error', async () => {
|
|
||||||
const discordRole = {} as unknown as DiscordRole;
|
|
||||||
|
|
||||||
const messageMemberRolesCacheFind = jest.fn()
|
|
||||||
.mockReturnValue(undefined);
|
|
||||||
const messageGuildRolesCacheFind = jest.fn()
|
|
||||||
.mockReturnValue(undefined);
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
member: {
|
|
||||||
roles: {
|
|
||||||
cache: {
|
|
||||||
find: messageMemberRolesCacheFind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
guild: {
|
|
||||||
roles: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildRolesCacheFind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'role',
|
|
||||||
args: ['One'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const roles = ['One', 'Two'];
|
|
||||||
|
|
||||||
const role = new Role();
|
|
||||||
|
|
||||||
role.AddRole = jest.fn();
|
|
||||||
role.RemoveRole = jest.fn();
|
|
||||||
|
|
||||||
const result = await role.ToggleRole(context, roles);
|
|
||||||
|
|
||||||
expect(messageMemberRolesCacheFind).not.toBeCalled();
|
|
||||||
expect(messageGuildRolesCacheFind).toBeCalledTimes(1);
|
|
||||||
expect(messageChannelSend).toBeCalledTimes(1);
|
|
||||||
expect(role.AddRole).not.toBeCalled();
|
|
||||||
expect(role.RemoveRole).not.toBeCalled();
|
|
||||||
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
// Error Embed
|
|
||||||
const errorEmbed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(errorEmbed.description).toBe("The current server doesn't have this role. Please contact the server's moderators");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('AddRole', () => {
|
|
||||||
test('Expect role to be added to user', async () => {
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
|
|
||||||
const guildMemberRoleManager = mock<GuildMemberRoleManager>();
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
member: {
|
|
||||||
roles: guildMemberRoleManager
|
|
||||||
},
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'role',
|
|
||||||
args: ['One'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const discordRole = {
|
|
||||||
name: 'One'
|
|
||||||
} as unknown as DiscordRole;
|
|
||||||
|
|
||||||
const role = new Role();
|
|
||||||
|
|
||||||
const result = await role.AddRole(context, discordRole);
|
|
||||||
|
|
||||||
expect(guildMemberRoleManager.add).toBeCalledWith(discordRole, "Toggled with role command");
|
|
||||||
expect(messageChannelSend).toBeCalled();
|
|
||||||
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
// Embed
|
|
||||||
const embed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(embed.title).toBe('');
|
|
||||||
expect(embed.description).toBe('Gave role: One');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('RemoveRole', () => {
|
|
||||||
test('Expect role to be removed from user', async () => {
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
|
|
||||||
const guildMemberRoleManager = mock<GuildMemberRoleManager>();
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
member: {
|
|
||||||
roles: guildMemberRoleManager
|
|
||||||
},
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'role',
|
|
||||||
args: ['One'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const discordRole = {
|
|
||||||
name: 'One'
|
|
||||||
} as unknown as DiscordRole;
|
|
||||||
|
|
||||||
const role = new Role();
|
|
||||||
|
|
||||||
const result = await role.RemoveRole(context, discordRole);
|
|
||||||
|
|
||||||
expect(guildMemberRoleManager.remove).toBeCalledWith(discordRole, "Toggled with role command");
|
|
||||||
expect(messageChannelSend).toBeCalled();
|
|
||||||
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
// Embed
|
|
||||||
const embed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(embed.title).toBe('');
|
|
||||||
expect(embed.description).toBe('Removed role: One');
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -1,106 +1,19 @@
|
||||||
import { Message } from "discord.js";
|
|
||||||
import Rules from "../../src/commands/rules";
|
|
||||||
import { ICommandContext } from "../../src/contracts/ICommandContext";
|
|
||||||
|
|
||||||
const oldCwd = process.cwd();
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
process.env = {};
|
process.env = {};
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Constructor', () => {
|
describe('Constructor', () => {
|
||||||
test('Expect properties to be set', () => {
|
test.todo('EXPECT properties to be set');
|
||||||
process.env = {
|
|
||||||
ROLES_MODERATOR: "Moderator"
|
|
||||||
};
|
|
||||||
|
|
||||||
const rules = new Rules();
|
|
||||||
|
|
||||||
expect(rules._category).toBe("Admin");
|
|
||||||
expect(rules._roles.length).toBe(1);
|
|
||||||
expect(rules._roles[0]).toBe("Moderator");
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Execute', () => {
|
describe('Execute', () => {
|
||||||
test('Given rules exist, expect rules to be sent to current channel', () => {
|
test.todo("GIVEN interaction is not a chat input command, EXPECT nothing to happen");
|
||||||
process.env = {
|
|
||||||
COMMANDS_RULES_FILE: 'rules/rules.json'
|
|
||||||
};
|
|
||||||
|
|
||||||
process.cwd = jest.fn()
|
test.todo("GIVEN invalid subcommand is given, EXPECT invalid error");
|
||||||
.mockReturnValue(`${oldCwd}/tests/_mocks`);
|
});
|
||||||
|
|
||||||
const messageChannelSend = jest.fn();
|
describe("access", () => {
|
||||||
|
test.todo("GIVEN interaction.guildId is null, EXPECT nothing to happen");
|
||||||
|
|
||||||
const message = {
|
test.todo("GIVEN rules.access.label setting is not supplied, EXPECT label to be defaulted");
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'rules',
|
|
||||||
args: [],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const rules = new Rules();
|
|
||||||
|
|
||||||
const result = rules.execute(context);
|
|
||||||
|
|
||||||
expect(messageChannelSend).toBeCalledTimes(2);
|
|
||||||
expect(result.embeds.length).toBe(2);
|
|
||||||
|
|
||||||
// Header Embed
|
|
||||||
const embedHeader = result.embeds[0];
|
|
||||||
|
|
||||||
expect(embedHeader.title).toBe("");
|
|
||||||
expect(embedHeader.description).toBe("");
|
|
||||||
expect(embedHeader.image?.url).toBe("IMAGEURL");
|
|
||||||
expect(embedHeader.footer?.text).toBe("");
|
|
||||||
|
|
||||||
// Main Embed
|
|
||||||
const embedMain = result.embeds[1];
|
|
||||||
|
|
||||||
expect(embedMain.title).toBe("TITLE 1");
|
|
||||||
expect(embedMain.description).toBe("DESCRIPTION 1A\nDESCRIPTION 1B");
|
|
||||||
expect(embedMain.image?.url).toBe("");
|
|
||||||
expect(embedMain.footer?.text).toBe("FOOTER 1");
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given rules file does not exist, expect does not exist error', () => {
|
|
||||||
process.env = {
|
|
||||||
COMMANDS_RULES_FILE: 'rules/none.json'
|
|
||||||
};
|
|
||||||
|
|
||||||
process.cwd = jest.fn()
|
|
||||||
.mockReturnValue(`${oldCwd}/tests/_mocks`);
|
|
||||||
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'rules',
|
|
||||||
args: [],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const rules = new Rules();
|
|
||||||
|
|
||||||
const result = rules.execute(context);
|
|
||||||
|
|
||||||
expect(messageChannelSend).toBeCalledTimes(1);
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
// Error Embed
|
|
||||||
const errorEmbed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(errorEmbed.description).toBe("Rules file doesn't exist");
|
|
||||||
});
|
|
||||||
});
|
});
|
11
tests/commands/setup.test.ts
Normal file
11
tests/commands/setup.test.ts
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
describe("constructor", () => {
|
||||||
|
test.todo("EXPECT properties to be set");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('execute', () => {
|
||||||
|
test.todo("EXPECT server to be setup in database");
|
||||||
|
|
||||||
|
test.todo("GIVEN interaction.guildId is null, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN server is found in the database, EXPECT error");
|
||||||
|
});
|
|
@ -1,4 +1,4 @@
|
||||||
import { APIEmbed, CacheType, CommandInteraction, CommandInteractionOption, DMChannel, Embed, EmbedBuilder, EmbedField, Guild, GuildChannel, GuildMember, InteractionReplyOptions, JSONEncodable, Message, MessageCreateOptions, MessagePayload, SlashCommandBuilder, TextChannel, User } from "discord.js";
|
import { APIEmbed, CacheType, CommandInteraction, CommandInteractionOption, DMChannel, EmbedBuilder, EmbedField, Guild, GuildMember, InteractionReplyOptions, JSONEncodable, Message, MessageCreateOptions, SlashCommandBuilder, TextChannel, User } from "discord.js";
|
||||||
import { mock } from "jest-mock-extended";
|
import { mock } from "jest-mock-extended";
|
||||||
import Timeout from "../../src/commands/timeout";
|
import Timeout from "../../src/commands/timeout";
|
||||||
import SettingsHelper from "../../src/helpers/SettingsHelper";
|
import SettingsHelper from "../../src/helpers/SettingsHelper";
|
||||||
|
@ -58,6 +58,7 @@ describe('execute', () => {
|
||||||
id: 'userId',
|
id: 'userId',
|
||||||
tag: 'userTag',
|
tag: 'userTag',
|
||||||
createDM: jest.fn().mockResolvedValue(dmChannel),
|
createDM: jest.fn().mockResolvedValue(dmChannel),
|
||||||
|
avatarURL: jest.fn().mockReturnValue("https://google.com/test.png"),
|
||||||
} as unknown as User,
|
} as unknown as User,
|
||||||
member: {
|
member: {
|
||||||
manageable: true,
|
manageable: true,
|
||||||
|
@ -106,7 +107,7 @@ describe('execute', () => {
|
||||||
await command.execute(interaction);
|
await command.execute(interaction);
|
||||||
|
|
||||||
// EXPECT user to be timed out
|
// EXPECT user to be timed out
|
||||||
expect(timeoutFunc).toBeCalledWith(1000, 'Test reason');
|
expect(timeoutFunc).toHaveBeenCalledWith(1000, 'Test reason');
|
||||||
|
|
||||||
// EXPECT embeds to be sent
|
// EXPECT embeds to be sent
|
||||||
expect(embeds).toBeDefined();
|
expect(embeds).toBeDefined();
|
||||||
|
@ -116,6 +117,7 @@ describe('execute', () => {
|
||||||
const resultEmbed = embeds![0] as EmbedBuilder;
|
const resultEmbed = embeds![0] as EmbedBuilder;
|
||||||
|
|
||||||
expect(resultEmbed.data.description).toBe('<@userId> has been timed out');
|
expect(resultEmbed.data.description).toBe('<@userId> has been timed out');
|
||||||
|
|
||||||
expect(resultEmbed.data.fields).toBeDefined();
|
expect(resultEmbed.data.fields).toBeDefined();
|
||||||
expect(resultEmbed.data.fields!.length).toBe(1);
|
expect(resultEmbed.data.fields!.length).toBe(1);
|
||||||
|
|
||||||
|
@ -154,6 +156,7 @@ describe('execute', () => {
|
||||||
|
|
||||||
expect(logsChannelSentEmbed.color).toBe(EmbedColours.Ok);
|
expect(logsChannelSentEmbed.color).toBe(EmbedColours.Ok);
|
||||||
expect(logsChannelSentEmbed.title).toBe("Member Timed Out");
|
expect(logsChannelSentEmbed.title).toBe("Member Timed Out");
|
||||||
|
expect(logsChannelSentEmbed.thumbnail.url).toBe("https://google.com/test.png");
|
||||||
expect(logsChannelSentEmbed.description).toBe("<@userId> `userTag`");
|
expect(logsChannelSentEmbed.description).toBe("<@userId> `userTag`");
|
||||||
expect(logsChannelSentEmbed.fields?.length).toBe(4);
|
expect(logsChannelSentEmbed.fields?.length).toBe(4);
|
||||||
|
|
||||||
|
@ -415,7 +418,8 @@ describe('execute', () => {
|
||||||
user: {
|
user: {
|
||||||
id: 'userId',
|
id: 'userId',
|
||||||
tag: 'userTag',
|
tag: 'userTag',
|
||||||
} as User,
|
avatarURL: jest.fn().mockReturnValue("https://google.com/test.png"),
|
||||||
|
} as unknown as User,
|
||||||
member: {
|
member: {
|
||||||
manageable: false,
|
manageable: false,
|
||||||
} as GuildMember
|
} as GuildMember
|
||||||
|
@ -482,8 +486,9 @@ describe('execute', () => {
|
||||||
sentEmbeds.push(options.embeds![0] as EmbedBuilder);
|
sentEmbeds.push(options.embeds![0] as EmbedBuilder);
|
||||||
|
|
||||||
return mock<Message<false>>();
|
return mock<Message<false>>();
|
||||||
})
|
}),
|
||||||
}) as unknown as DMChannel,
|
}) as unknown as DMChannel,
|
||||||
|
avatarURL: jest.fn().mockReturnValue("https://google.com/test.png"),
|
||||||
} as unknown as User,
|
} as unknown as User,
|
||||||
member: {
|
member: {
|
||||||
manageable: true,
|
manageable: true,
|
||||||
|
@ -567,6 +572,7 @@ describe('execute', () => {
|
||||||
return mock<Message<false>>();
|
return mock<Message<false>>();
|
||||||
})
|
})
|
||||||
}) as unknown as DMChannel,
|
}) as unknown as DMChannel,
|
||||||
|
avatarURL: jest.fn().mockReturnValue("https://google.com/test.png"),
|
||||||
} as unknown as User,
|
} as unknown as User,
|
||||||
member: {
|
member: {
|
||||||
manageable: true,
|
manageable: true,
|
||||||
|
@ -641,6 +647,7 @@ describe('execute', () => {
|
||||||
return mock<Message<false>>();
|
return mock<Message<false>>();
|
||||||
})
|
})
|
||||||
}) as unknown as DMChannel,
|
}) as unknown as DMChannel,
|
||||||
|
avatarURL: jest.fn().mockReturnValue("https://google.com/test.png"),
|
||||||
} as unknown as User,
|
} as unknown as User,
|
||||||
member: {
|
member: {
|
||||||
manageable: true,
|
manageable: true,
|
||||||
|
@ -704,6 +711,7 @@ describe('execute', () => {
|
||||||
id: 'userId',
|
id: 'userId',
|
||||||
tag: 'userTag',
|
tag: 'userTag',
|
||||||
createDM: jest.fn().mockRejectedValue(undefined),
|
createDM: jest.fn().mockRejectedValue(undefined),
|
||||||
|
avatarURL: jest.fn().mockReturnValue("https://google.com/test.png"),
|
||||||
} as unknown as User,
|
} as unknown as User,
|
||||||
member: {
|
member: {
|
||||||
manageable: true,
|
manageable: true,
|
||||||
|
|
|
@ -1,813 +0,0 @@
|
||||||
import { GuildMember, Message, Role, TextChannel, User } from "discord.js";
|
|
||||||
import Unmute from "../../src/commands/unmute";
|
|
||||||
import { ICommandContext } from "../../src/contracts/ICommandContext";
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
process.env = {};
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Constructor', () => {
|
|
||||||
test('Expect properties to be set', () => {
|
|
||||||
process.env = {
|
|
||||||
ROLES_MODERATOR: 'Moderator'
|
|
||||||
};
|
|
||||||
|
|
||||||
const mute = new Unmute();
|
|
||||||
|
|
||||||
expect(mute._category).toBe("Moderation");
|
|
||||||
expect(mute._roles.length).toBe(1);
|
|
||||||
expect(mute._roles[0]).toBe('Moderator');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Execute', () => {
|
|
||||||
test('Given user has permission, expect user to be given muted role', async () => {
|
|
||||||
process.env = {
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs',
|
|
||||||
ROLES_MUTED: 'Muted'
|
|
||||||
};
|
|
||||||
|
|
||||||
const user = {
|
|
||||||
displayAvatarURL: jest.fn(),
|
|
||||||
tag: 'USERTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
|
|
||||||
const messageAuthor = {
|
|
||||||
tag: 'AUTHORTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
|
|
||||||
const member = {
|
|
||||||
manageable: true,
|
|
||||||
roles: {
|
|
||||||
remove: jest.fn()
|
|
||||||
}
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
|
|
||||||
const role = {
|
|
||||||
name: 'Muted'
|
|
||||||
} as unknown as Role;
|
|
||||||
|
|
||||||
const logChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: jest.fn()
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const messageMentionsUsersFirst = jest.fn()
|
|
||||||
.mockReturnValue(user);
|
|
||||||
const messageGuildMember = jest.fn()
|
|
||||||
.mockReturnValue(member);
|
|
||||||
const messageGuildRolesCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): Role | undefined => {
|
|
||||||
const result = callback(role);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return role;
|
|
||||||
});
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
const messageGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): TextChannel | undefined => {
|
|
||||||
const result = callback(logChannel);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return logChannel;
|
|
||||||
});
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
mentions: {
|
|
||||||
users: {
|
|
||||||
first: messageMentionsUsersFirst
|
|
||||||
}
|
|
||||||
},
|
|
||||||
guild: {
|
|
||||||
member: messageGuildMember,
|
|
||||||
available: true,
|
|
||||||
roles: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildRolesCacheFind
|
|
||||||
}
|
|
||||||
},
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
author: messageAuthor
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'mute',
|
|
||||||
args: ['USER', 'Test', 'Reason'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const mute = new Unmute();
|
|
||||||
|
|
||||||
const result = await mute.execute(context);
|
|
||||||
|
|
||||||
expect(messageMentionsUsersFirst).toBeCalledTimes(1);
|
|
||||||
expect(messageGuildMember).toBeCalledWith(user);
|
|
||||||
expect(messageGuildRolesCacheFind).toBeCalledTimes(1);
|
|
||||||
expect(messageGuildChannelsCacheFind).toBeCalledTimes(1);
|
|
||||||
expect(messageChannelSend).toBeCalledTimes(1);
|
|
||||||
expect(member.roles.remove).toBeCalledWith(role, 'Moderator: AUTHORTAG, Reason: Test Reason');
|
|
||||||
|
|
||||||
expect(result.embeds.length).toBe(2);
|
|
||||||
|
|
||||||
// Log Embed
|
|
||||||
const logEmbed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(logEmbed.title).toBe('Member Unmuted');
|
|
||||||
expect(logEmbed.fields.length).toBe(3);
|
|
||||||
|
|
||||||
// Log Embed -> User Field
|
|
||||||
const logEmbedUserField = logEmbed.fields[0];
|
|
||||||
|
|
||||||
expect(logEmbedUserField.name).toBe('User');
|
|
||||||
expect(logEmbedUserField.value).toBe('[object Object] `USERTAG`');
|
|
||||||
expect(logEmbedUserField.inline).toBeTruthy();
|
|
||||||
|
|
||||||
// Log Embed -> Moderator Field
|
|
||||||
const logEmbedModeratorField = logEmbed.fields[1];
|
|
||||||
|
|
||||||
expect(logEmbedModeratorField.name).toBe('Moderator');
|
|
||||||
expect(logEmbedModeratorField.value).toBe('[object Object] `AUTHORTAG`');
|
|
||||||
|
|
||||||
// Log Embed -> Reason Field
|
|
||||||
const logEmbedFieldReason = logEmbed.fields[2];
|
|
||||||
|
|
||||||
expect(logEmbedFieldReason.name).toBe('Reason');
|
|
||||||
expect(logEmbedFieldReason.value).toBe('Test Reason');
|
|
||||||
|
|
||||||
// Public Embed
|
|
||||||
const publicEmbed = result.embeds[1];
|
|
||||||
|
|
||||||
expect(publicEmbed.title).toBe('');
|
|
||||||
expect(publicEmbed.description).toBe('[object Object] has been unmuted');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given moderator did not supply a reason, expect default reason is used', async () => {
|
|
||||||
process.env = {
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs',
|
|
||||||
ROLES_MUTED: 'Muted'
|
|
||||||
};
|
|
||||||
|
|
||||||
const user = {
|
|
||||||
displayAvatarURL: jest.fn(),
|
|
||||||
tag: 'USERTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
|
|
||||||
const messageAuthor = {
|
|
||||||
tag: 'AUTHORTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
|
|
||||||
const member = {
|
|
||||||
manageable: true,
|
|
||||||
roles: {
|
|
||||||
remove: jest.fn()
|
|
||||||
}
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
|
|
||||||
const role = {
|
|
||||||
name: 'Muted'
|
|
||||||
} as unknown as Role;
|
|
||||||
|
|
||||||
const logChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: jest.fn()
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const messageMentionsUsersFirst = jest.fn()
|
|
||||||
.mockReturnValue(user);
|
|
||||||
const messageGuildMember = jest.fn()
|
|
||||||
.mockReturnValue(member);
|
|
||||||
const messageGuildRolesCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): Role | undefined => {
|
|
||||||
const result = callback(role);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return role;
|
|
||||||
});
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
const messageGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): TextChannel | undefined => {
|
|
||||||
const result = callback(logChannel);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return logChannel;
|
|
||||||
});
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
mentions: {
|
|
||||||
users: {
|
|
||||||
first: messageMentionsUsersFirst
|
|
||||||
}
|
|
||||||
},
|
|
||||||
guild: {
|
|
||||||
member: messageGuildMember,
|
|
||||||
available: true,
|
|
||||||
roles: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildRolesCacheFind
|
|
||||||
}
|
|
||||||
},
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
author: messageAuthor
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'mute',
|
|
||||||
args: ['USER'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const mute = new Unmute();
|
|
||||||
|
|
||||||
const result = await mute.execute(context);
|
|
||||||
|
|
||||||
expect(messageMentionsUsersFirst).toBeCalledTimes(1);
|
|
||||||
expect(messageGuildMember).toBeCalledWith(user);
|
|
||||||
expect(messageGuildRolesCacheFind).toBeCalledTimes(1);
|
|
||||||
expect(messageGuildChannelsCacheFind).toBeCalledTimes(1);
|
|
||||||
expect(messageChannelSend).toBeCalledTimes(1);
|
|
||||||
expect(member.roles.remove).toBeCalledWith(role, 'Moderator: AUTHORTAG, Reason: *none*');
|
|
||||||
|
|
||||||
expect(result.embeds.length).toBe(2);
|
|
||||||
|
|
||||||
// Log Embed
|
|
||||||
const logEmbed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(logEmbed.title).toBe('Member Unmuted');
|
|
||||||
expect(logEmbed.fields.length).toBe(3);
|
|
||||||
|
|
||||||
// Log Embed -> User Field
|
|
||||||
const logEmbedUserField = logEmbed.fields[0];
|
|
||||||
|
|
||||||
expect(logEmbedUserField.name).toBe('User');
|
|
||||||
expect(logEmbedUserField.value).toBe('[object Object] `USERTAG`');
|
|
||||||
expect(logEmbedUserField.inline).toBeTruthy();
|
|
||||||
|
|
||||||
// Log Embed -> Moderator Field
|
|
||||||
const logEmbedModeratorField = logEmbed.fields[1];
|
|
||||||
|
|
||||||
expect(logEmbedModeratorField.name).toBe('Moderator');
|
|
||||||
expect(logEmbedModeratorField.value).toBe('[object Object] `AUTHORTAG`');
|
|
||||||
|
|
||||||
// Log Embed -> Reason Field
|
|
||||||
const logEmbedFieldReason = logEmbed.fields[2];
|
|
||||||
|
|
||||||
expect(logEmbedFieldReason.name).toBe('Reason');
|
|
||||||
expect(logEmbedFieldReason.value).toBe('*none*');
|
|
||||||
|
|
||||||
// Public Embed
|
|
||||||
const publicEmbed = result.embeds[1];
|
|
||||||
|
|
||||||
expect(publicEmbed.title).toBe('');
|
|
||||||
expect(publicEmbed.description).toBe('[object Object] has been unmuted');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given user did not mention a user, expect user not to exist', async () => {
|
|
||||||
process.env = {
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs',
|
|
||||||
ROLES_MUTED: 'Muted'
|
|
||||||
};
|
|
||||||
|
|
||||||
const user = {
|
|
||||||
displayAvatarURL: jest.fn(),
|
|
||||||
tag: 'USERTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
|
|
||||||
const messageAuthor = {
|
|
||||||
tag: 'AUTHORTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
|
|
||||||
const member = {
|
|
||||||
manageable: true,
|
|
||||||
roles: {
|
|
||||||
remove: jest.fn()
|
|
||||||
}
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
|
|
||||||
const role = {
|
|
||||||
name: 'Muted'
|
|
||||||
} as unknown as Role;
|
|
||||||
|
|
||||||
const logChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: jest.fn()
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const messageMentionsUsersFirst = jest.fn()
|
|
||||||
.mockReturnValue(null);
|
|
||||||
const messageGuildMember = jest.fn()
|
|
||||||
.mockReturnValue(member);
|
|
||||||
const messageGuildRolesCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): Role | undefined => {
|
|
||||||
const result = callback(role);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return role;
|
|
||||||
});
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
const messageGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): TextChannel | undefined => {
|
|
||||||
const result = callback(logChannel);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return logChannel;
|
|
||||||
});
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
mentions: {
|
|
||||||
users: {
|
|
||||||
first: messageMentionsUsersFirst
|
|
||||||
}
|
|
||||||
},
|
|
||||||
guild: {
|
|
||||||
member: messageGuildMember,
|
|
||||||
available: true,
|
|
||||||
roles: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildRolesCacheFind
|
|
||||||
}
|
|
||||||
},
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
author: messageAuthor
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'mute',
|
|
||||||
args: ['USER', 'Test', 'Reason'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const mute = new Unmute();
|
|
||||||
|
|
||||||
const result = await mute.execute(context);
|
|
||||||
|
|
||||||
expect(messageMentionsUsersFirst).toBeCalledTimes(1);
|
|
||||||
expect(messageGuildMember).not.toBeCalled();
|
|
||||||
expect(messageGuildRolesCacheFind).not.toBeCalled();
|
|
||||||
expect(messageGuildChannelsCacheFind).not.toBeCalled();
|
|
||||||
expect(messageChannelSend).toBeCalledTimes(1);
|
|
||||||
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
// Error Embed
|
|
||||||
const errorEmbed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(errorEmbed.description).toBe('User does not exist');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given member can not be found from user, expect user to not be in server', async () => {
|
|
||||||
process.env = {
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs',
|
|
||||||
ROLES_MUTED: 'Muted'
|
|
||||||
};
|
|
||||||
|
|
||||||
const user = {
|
|
||||||
displayAvatarURL: jest.fn(),
|
|
||||||
tag: 'USERTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
|
|
||||||
const messageAuthor = {
|
|
||||||
tag: 'AUTHORTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
|
|
||||||
const member = {
|
|
||||||
manageable: true,
|
|
||||||
roles: {
|
|
||||||
remove: jest.fn()
|
|
||||||
}
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
|
|
||||||
const role = {
|
|
||||||
name: 'Muted'
|
|
||||||
} as unknown as Role;
|
|
||||||
|
|
||||||
const logChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: jest.fn()
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const messageMentionsUsersFirst = jest.fn()
|
|
||||||
.mockReturnValue(user);
|
|
||||||
const messageGuildMember = jest.fn()
|
|
||||||
.mockReturnValue(null);
|
|
||||||
const messageGuildRolesCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): Role | undefined => {
|
|
||||||
const result = callback(role);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return role;
|
|
||||||
});
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
const messageGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): TextChannel | undefined => {
|
|
||||||
const result = callback(logChannel);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return logChannel;
|
|
||||||
});
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
mentions: {
|
|
||||||
users: {
|
|
||||||
first: messageMentionsUsersFirst
|
|
||||||
}
|
|
||||||
},
|
|
||||||
guild: {
|
|
||||||
member: messageGuildMember,
|
|
||||||
available: true,
|
|
||||||
roles: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildRolesCacheFind
|
|
||||||
}
|
|
||||||
},
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
author: messageAuthor
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'mute',
|
|
||||||
args: ['USER', 'Test', 'Reason'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const mute = new Unmute();
|
|
||||||
|
|
||||||
const result = await mute.execute(context);
|
|
||||||
|
|
||||||
expect(messageMentionsUsersFirst).toBeCalledTimes(1);
|
|
||||||
expect(messageGuildMember).toBeCalledWith(user);
|
|
||||||
expect(messageGuildRolesCacheFind).not.toBeCalled();
|
|
||||||
expect(messageGuildChannelsCacheFind).not.toBeCalled();
|
|
||||||
expect(messageChannelSend).toBeCalledTimes(1);
|
|
||||||
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
// Error Embed
|
|
||||||
const errorEmbed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(errorEmbed.description).toBe('User is not in this server');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given guild is unavailable, expect execution to stop', async () => {
|
|
||||||
process.env = {
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs',
|
|
||||||
ROLES_MUTED: 'Muted'
|
|
||||||
};
|
|
||||||
|
|
||||||
const user = {
|
|
||||||
displayAvatarURL: jest.fn(),
|
|
||||||
tag: 'USERTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
|
|
||||||
const messageAuthor = {
|
|
||||||
tag: 'AUTHORTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
|
|
||||||
const member = {
|
|
||||||
manageable: true,
|
|
||||||
roles: {
|
|
||||||
remove: jest.fn()
|
|
||||||
}
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
|
|
||||||
const role = {
|
|
||||||
name: 'Muted'
|
|
||||||
} as unknown as Role;
|
|
||||||
|
|
||||||
const logChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: jest.fn()
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const messageMentionsUsersFirst = jest.fn()
|
|
||||||
.mockReturnValue(user);
|
|
||||||
const messageGuildMember = jest.fn()
|
|
||||||
.mockReturnValue(member);
|
|
||||||
const messageGuildRolesCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): Role | undefined => {
|
|
||||||
const result = callback(role);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return role;
|
|
||||||
});
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
const messageGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): TextChannel | undefined => {
|
|
||||||
const result = callback(logChannel);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return logChannel;
|
|
||||||
});
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
mentions: {
|
|
||||||
users: {
|
|
||||||
first: messageMentionsUsersFirst
|
|
||||||
}
|
|
||||||
},
|
|
||||||
guild: {
|
|
||||||
member: messageGuildMember,
|
|
||||||
available: false,
|
|
||||||
roles: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildRolesCacheFind
|
|
||||||
}
|
|
||||||
},
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
author: messageAuthor
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'mute',
|
|
||||||
args: ['USER', 'Test', 'Reason'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const mute = new Unmute();
|
|
||||||
|
|
||||||
const result = await mute.execute(context);
|
|
||||||
|
|
||||||
expect(messageMentionsUsersFirst).toBeCalledTimes(1);
|
|
||||||
expect(messageGuildMember).toBeCalledWith(user);
|
|
||||||
expect(messageGuildRolesCacheFind).not.toBeCalled();
|
|
||||||
expect(messageGuildChannelsCacheFind).not.toBeCalled();
|
|
||||||
expect(messageChannelSend).not.toBeCalled();
|
|
||||||
|
|
||||||
expect(result.embeds.length).toBe(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given client can not manage user, expect insufficient permissions', async () => {
|
|
||||||
process.env = {
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs',
|
|
||||||
ROLES_MUTED: 'Muted'
|
|
||||||
};
|
|
||||||
|
|
||||||
const user = {
|
|
||||||
displayAvatarURL: jest.fn(),
|
|
||||||
tag: 'USERTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
|
|
||||||
const messageAuthor = {
|
|
||||||
tag: 'AUTHORTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
|
|
||||||
const member = {
|
|
||||||
manageable: false,
|
|
||||||
roles: {
|
|
||||||
remove: jest.fn()
|
|
||||||
}
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
|
|
||||||
const role = {
|
|
||||||
name: 'Muted'
|
|
||||||
} as unknown as Role;
|
|
||||||
|
|
||||||
const logChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: jest.fn()
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const messageMentionsUsersFirst = jest.fn()
|
|
||||||
.mockReturnValue(user);
|
|
||||||
const messageGuildMember = jest.fn()
|
|
||||||
.mockReturnValue(member);
|
|
||||||
const messageGuildRolesCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): Role | undefined => {
|
|
||||||
const result = callback(role);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return role;
|
|
||||||
});
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
const messageGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): TextChannel | undefined => {
|
|
||||||
const result = callback(logChannel);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return logChannel;
|
|
||||||
});
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
mentions: {
|
|
||||||
users: {
|
|
||||||
first: messageMentionsUsersFirst
|
|
||||||
}
|
|
||||||
},
|
|
||||||
guild: {
|
|
||||||
member: messageGuildMember,
|
|
||||||
available: true,
|
|
||||||
roles: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildRolesCacheFind
|
|
||||||
}
|
|
||||||
},
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
author: messageAuthor
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'mute',
|
|
||||||
args: ['USER', 'Test', 'Reason'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const mute = new Unmute();
|
|
||||||
|
|
||||||
const result = await mute.execute(context);
|
|
||||||
|
|
||||||
expect(messageMentionsUsersFirst).toBeCalledTimes(1);
|
|
||||||
expect(messageGuildMember).toBeCalledWith(user);
|
|
||||||
expect(messageGuildRolesCacheFind).not.toBeCalled();
|
|
||||||
expect(messageGuildChannelsCacheFind).not.toBeCalled();
|
|
||||||
expect(messageChannelSend).toBeCalledTimes(1);
|
|
||||||
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
// Error Embed
|
|
||||||
const errorEmbed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(errorEmbed.description).toBe('Unable to do this action, am I missing permissions?');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given muted role can not be found, expect role not found', async () => {
|
|
||||||
process.env = {
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs',
|
|
||||||
ROLES_MUTED: 'Muted'
|
|
||||||
};
|
|
||||||
|
|
||||||
const user = {
|
|
||||||
displayAvatarURL: jest.fn(),
|
|
||||||
tag: 'USERTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
|
|
||||||
const messageAuthor = {
|
|
||||||
tag: 'AUTHORTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
|
|
||||||
const member = {
|
|
||||||
manageable: true,
|
|
||||||
roles: {
|
|
||||||
remove: jest.fn()
|
|
||||||
}
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
|
|
||||||
const role = {
|
|
||||||
name: 'Muted'
|
|
||||||
} as unknown as Role;
|
|
||||||
|
|
||||||
const logChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: jest.fn()
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const messageMentionsUsersFirst = jest.fn()
|
|
||||||
.mockReturnValue(user);
|
|
||||||
const messageGuildMember = jest.fn()
|
|
||||||
.mockReturnValue(member);
|
|
||||||
const messageGuildRolesCacheFind = jest.fn()
|
|
||||||
.mockReturnValue(undefined);
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
const messageGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): TextChannel | undefined => {
|
|
||||||
const result = callback(logChannel);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return logChannel;
|
|
||||||
});
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
mentions: {
|
|
||||||
users: {
|
|
||||||
first: messageMentionsUsersFirst
|
|
||||||
}
|
|
||||||
},
|
|
||||||
guild: {
|
|
||||||
member: messageGuildMember,
|
|
||||||
available: true,
|
|
||||||
roles: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildRolesCacheFind
|
|
||||||
}
|
|
||||||
},
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
author: messageAuthor
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'mute',
|
|
||||||
args: ['USER', 'Test', 'Reason'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const mute = new Unmute();
|
|
||||||
|
|
||||||
const result = await mute.execute(context);
|
|
||||||
|
|
||||||
expect(messageMentionsUsersFirst).toBeCalledTimes(1);
|
|
||||||
expect(messageGuildMember).toBeCalledWith(user);
|
|
||||||
expect(messageGuildRolesCacheFind).toBeCalledTimes(1);
|
|
||||||
expect(messageGuildChannelsCacheFind).not.toBeCalled();
|
|
||||||
expect(messageChannelSend).toBeCalledTimes(1);
|
|
||||||
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
// Error Embed
|
|
||||||
const errorEmbed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(errorEmbed.description).toBe('Unable to find role');
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -1,485 +1,29 @@
|
||||||
import { GuildMember, Message, TextChannel, User } from "discord.js";
|
|
||||||
import Warn from "../../src/commands/warn";
|
|
||||||
import { ICommandContext } from "../../src/contracts/ICommandContext";
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
process.env = {};
|
process.env = {};
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Constructor', () => {
|
describe('Constructor', () => {
|
||||||
test('Expect values to be set', () => {
|
test.todo('EXPECT values to be set');
|
||||||
process.env.ROLES_MODERATOR = 'Moderator';
|
|
||||||
|
|
||||||
const warn = new Warn();
|
|
||||||
|
|
||||||
expect(warn._category).toBe('Moderation');
|
|
||||||
expect(warn._roles.length).toBe(1);
|
|
||||||
expect(warn._roles[0]).toBe('Moderator');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Execute', () => {
|
describe('Execute', () => {
|
||||||
test('Given user has permission, expect user to be warnned', async () => {
|
test.todo("EXPECT user to be warned");
|
||||||
process.env = {
|
|
||||||
ROLES_MODERATOR: 'Moderator',
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs'
|
|
||||||
};
|
|
||||||
|
|
||||||
const mentionedUser = {
|
test.todo("GIVEN interaction.guild is null, EXPECT nothing to happen");
|
||||||
displayAvatarURL: jest.fn(),
|
|
||||||
tag: 'USERTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
const mentionedMember = {
|
|
||||||
warnnable: true,
|
|
||||||
warn: jest.fn()
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
const logChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: jest.fn()
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const messageChannelSend = jest.fn();
|
test.todo("GIVEN interaction.guildId is null, EXPECT nothing to happen");
|
||||||
const messageMentionsUsersFirst = jest.fn()
|
|
||||||
.mockReturnValue(mentionedUser);
|
|
||||||
const messageGuildMember = jest.fn()
|
|
||||||
.mockReturnValue(mentionedMember);
|
|
||||||
const messageGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): TextChannel | undefined => {
|
|
||||||
const result = callback(logChannel);
|
|
||||||
|
|
||||||
if (!result) {
|
test.todo("GIVEN targetUser is null, EXPECT error");
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return logChannel;
|
test.todo("GIVEN targetUser.user is undefined, EXPECT error");
|
||||||
});
|
|
||||||
|
|
||||||
const message = {
|
test.todo("GIVEN targetUser.member is undefined, EXPECT error");
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
mentions: {
|
|
||||||
users: {
|
|
||||||
first: messageMentionsUsersFirst
|
|
||||||
}
|
|
||||||
},
|
|
||||||
guild: {
|
|
||||||
member: messageGuildMember ,
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
},
|
|
||||||
available: true
|
|
||||||
},
|
|
||||||
author: {
|
|
||||||
tag: 'AUTHORTAG'
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
test.todo("GIVEN reasonInput is null, EXPECT reason to be defaulted");
|
||||||
name: 'warn',
|
|
||||||
args: ['warn', 'Test', 'Reason'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const warn = new Warn();
|
test.todo("GIVEN reasonInput.value is undefined, EXPECT reason to be defaulted");
|
||||||
|
|
||||||
const result = await warn.execute(context);
|
test.todo("GIVEN channels.logs.mod setting is not found, EXPECT command to return");
|
||||||
|
|
||||||
expect(messageChannelSend).toBeCalledTimes(1);
|
|
||||||
expect(logChannel.send).toBeCalledTimes(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given user has permissions, expect embeds to be correct', async () => {
|
test.todo("GIVEN channel is not found, EXPECT logEmbed to not be sent");
|
||||||
process.env = {
|
|
||||||
ROLES_MODERATOR: 'Moderator',
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs'
|
|
||||||
};
|
|
||||||
|
|
||||||
const mentionedUser = {
|
|
||||||
displayAvatarURL: jest.fn(),
|
|
||||||
tag: 'USERTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
const mentionedMember = {
|
|
||||||
warnnable: true,
|
|
||||||
warn: jest.fn()
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
const logChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: jest.fn()
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
const messageMentionsUsersFirst = jest.fn()
|
|
||||||
.mockReturnValue(mentionedUser);
|
|
||||||
const messageGuildMember = jest.fn()
|
|
||||||
.mockReturnValue(mentionedMember);
|
|
||||||
const messageGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): TextChannel | undefined => {
|
|
||||||
const result = callback(logChannel);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return logChannel;
|
|
||||||
});
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
mentions: {
|
|
||||||
users: {
|
|
||||||
first: messageMentionsUsersFirst
|
|
||||||
}
|
|
||||||
},
|
|
||||||
guild: {
|
|
||||||
member: messageGuildMember ,
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
},
|
|
||||||
available: true
|
|
||||||
},
|
|
||||||
author: {
|
|
||||||
tag: 'AUTHORTAG'
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'warn',
|
|
||||||
args: ['warn', 'Test', 'Reason'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const warn = new Warn();
|
|
||||||
|
|
||||||
const result = await warn.execute(context);
|
|
||||||
|
|
||||||
expect(result.embeds.length).toBe(2);
|
|
||||||
|
|
||||||
const logEmbed = result.embeds[0];
|
|
||||||
const publicEmbed = result.embeds[1];
|
|
||||||
|
|
||||||
expect(logEmbed.title).toBe('Member Warned');
|
|
||||||
expect(publicEmbed.title).toBe("");
|
|
||||||
expect(publicEmbed.description).toBe('[object Object] has been warned');
|
|
||||||
expect(logEmbed.fields.length).toBe(3);
|
|
||||||
expect(publicEmbed.fields.length).toBe(1);
|
|
||||||
expect(publicEmbed.fields[0].name).toBe('Reason');
|
|
||||||
expect(publicEmbed.fields[0].value).toBe('Test Reason');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given user has permission, expect logEmbed fields to be correct', async () => {
|
|
||||||
process.env = {
|
|
||||||
ROLES_MODERATOR: 'Moderator',
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs'
|
|
||||||
};
|
|
||||||
|
|
||||||
const mentionedUser = {
|
|
||||||
displayAvatarURL: jest.fn().mockReturnValue('URL'),
|
|
||||||
tag: 'USERTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
const mentionedMember = {
|
|
||||||
warnnable: true,
|
|
||||||
warn: jest.fn()
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
const logChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: jest.fn()
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
const messageMentionsUsersFirst = jest.fn()
|
|
||||||
.mockReturnValue(mentionedUser);
|
|
||||||
const messageGuildMember = jest.fn()
|
|
||||||
.mockReturnValue(mentionedMember);
|
|
||||||
const messageGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): TextChannel | undefined => {
|
|
||||||
const result = callback(logChannel);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return logChannel;
|
|
||||||
});
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
mentions: {
|
|
||||||
users: {
|
|
||||||
first: messageMentionsUsersFirst
|
|
||||||
}
|
|
||||||
},
|
|
||||||
guild: {
|
|
||||||
member: messageGuildMember ,
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
},
|
|
||||||
available: true
|
|
||||||
},
|
|
||||||
author: {
|
|
||||||
tag: 'AUTHORTAG'
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'warn',
|
|
||||||
args: ['warn', 'Test', 'Reason'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const warn = new Warn();
|
|
||||||
|
|
||||||
const result = await warn.execute(context);
|
|
||||||
|
|
||||||
const logEmbed = result.embeds[0];
|
|
||||||
|
|
||||||
const fieldUser = logEmbed.fields[0];
|
|
||||||
const fieldModerator = logEmbed.fields[1];
|
|
||||||
const fieldReason = logEmbed.fields[2];
|
|
||||||
|
|
||||||
expect(fieldUser.name).toBe("User");
|
|
||||||
expect(fieldUser.value).toBe("[object Object] `USERTAG`");
|
|
||||||
expect(logEmbed.thumbnail?.url).toBe("URL");
|
|
||||||
|
|
||||||
expect(fieldModerator.name).toBe('Moderator');
|
|
||||||
expect(fieldModerator.value).toBe('[object Object] `AUTHORTAG`');
|
|
||||||
|
|
||||||
expect(fieldReason.name).toBe('Reason');
|
|
||||||
expect(fieldReason.value).toBe('Test Reason');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given user is not mentioned, expect error embed to be sent', async () => {
|
|
||||||
process.env = {
|
|
||||||
ROLES_MODERATOR: 'Moderator',
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs'
|
|
||||||
};
|
|
||||||
|
|
||||||
const mentionedMember = {
|
|
||||||
warnnable: true,
|
|
||||||
warn: jest.fn()
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
const logChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: jest.fn()
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
const messageMentionsUsersFirst = jest.fn()
|
|
||||||
.mockReturnValue(null);
|
|
||||||
const messageGuildMember = jest.fn()
|
|
||||||
.mockReturnValue(mentionedMember);
|
|
||||||
const messageGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): TextChannel | undefined => {
|
|
||||||
const result = callback(logChannel);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return logChannel;
|
|
||||||
});
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
mentions: {
|
|
||||||
users: {
|
|
||||||
first: messageMentionsUsersFirst
|
|
||||||
}
|
|
||||||
},
|
|
||||||
guild: {
|
|
||||||
member: messageGuildMember ,
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
},
|
|
||||||
available: true
|
|
||||||
},
|
|
||||||
author: {
|
|
||||||
tag: 'AUTHORTAG'
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'warn',
|
|
||||||
args: ['warn', 'Test', 'Reason'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const warn = new Warn();
|
|
||||||
|
|
||||||
const result = await warn.execute(context);
|
|
||||||
|
|
||||||
expect(messageChannelSend).toBeCalledTimes(1);
|
|
||||||
expect(logChannel.send).not.toBeCalled();
|
|
||||||
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
const embedError = result.embeds[0];
|
|
||||||
|
|
||||||
expect(embedError.description).toBe('User does not exist');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given member is not in server, expect error embed to be sent', async () => {
|
|
||||||
process.env = {
|
|
||||||
ROLES_MODERATOR: 'Moderator',
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs'
|
|
||||||
};
|
|
||||||
|
|
||||||
const mentionedUser = {
|
|
||||||
displayAvatarURL: jest.fn(),
|
|
||||||
tag: 'USERTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
const mentionedMember = {
|
|
||||||
warnnable: true,
|
|
||||||
warn: jest.fn()
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
const logChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: jest.fn()
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
const messageMentionsUsersFirst = jest.fn()
|
|
||||||
.mockReturnValue(mentionedUser);
|
|
||||||
const messageGuildMember = jest.fn()
|
|
||||||
.mockReturnValue(null);
|
|
||||||
const messageGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): TextChannel | undefined => {
|
|
||||||
const result = callback(logChannel);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return logChannel;
|
|
||||||
});
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
mentions: {
|
|
||||||
users: {
|
|
||||||
first: messageMentionsUsersFirst
|
|
||||||
}
|
|
||||||
},
|
|
||||||
guild: {
|
|
||||||
member: messageGuildMember ,
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
},
|
|
||||||
available: true
|
|
||||||
},
|
|
||||||
author: {
|
|
||||||
tag: 'AUTHORTAG'
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'warn',
|
|
||||||
args: ['warn', 'Test', 'Reason'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const warn = new Warn();
|
|
||||||
|
|
||||||
const result = await warn.execute(context);
|
|
||||||
|
|
||||||
expect(messageChannelSend).toBeCalledTimes(1);
|
|
||||||
expect(logChannel.send).not.toBeCalled();
|
|
||||||
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
const embedError = result.embeds[0];
|
|
||||||
|
|
||||||
expect(embedError.description).toBe('User is not in this server');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given guild is unavailable, expect return and do nothing', async () => {
|
|
||||||
process.env = {
|
|
||||||
ROLES_MODERATOR: 'Moderator',
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs'
|
|
||||||
};
|
|
||||||
|
|
||||||
const mentionedUser = {
|
|
||||||
displayAvatarURL: jest.fn(),
|
|
||||||
tag: 'USERTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
const mentionedMember = {
|
|
||||||
warnnable: true,
|
|
||||||
warn: jest.fn()
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
const logChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: jest.fn()
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
const messageMentionsUsersFirst = jest.fn()
|
|
||||||
.mockReturnValue(mentionedUser);
|
|
||||||
const messageGuildMember = jest.fn()
|
|
||||||
.mockReturnValue(mentionedMember);
|
|
||||||
const messageGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockImplementation((callback): TextChannel | undefined => {
|
|
||||||
const result = callback(logChannel);
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return logChannel;
|
|
||||||
});
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
mentions: {
|
|
||||||
users: {
|
|
||||||
first: messageMentionsUsersFirst
|
|
||||||
}
|
|
||||||
},
|
|
||||||
guild: {
|
|
||||||
member: messageGuildMember ,
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: messageGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
},
|
|
||||||
available: false
|
|
||||||
},
|
|
||||||
author: {
|
|
||||||
tag: 'AUTHORTAG'
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'warn',
|
|
||||||
args: ['warn', 'Test', 'Reason'],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const warn = new Warn();
|
|
||||||
|
|
||||||
const result = await warn.execute(context);
|
|
||||||
|
|
||||||
expect(messageChannelSend).not.toBeCalled();
|
|
||||||
expect(logChannel.send).not.toBeCalled();
|
|
||||||
expect(result.embeds.length).toBe(0);
|
|
||||||
});
|
|
||||||
});
|
});
|
29
tests/contracts/BaseEntity.test.ts
Normal file
29
tests/contracts/BaseEntity.test.ts
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
describe('constructor', () => {
|
||||||
|
test.todo("EXPECT properties to be set");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Save", () => {
|
||||||
|
test.todo("EXPECT entity to be saved");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Remove", () => {
|
||||||
|
test.todo("EXPECT entity to be removed");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("FetchAll", () => {
|
||||||
|
test.todo("EXPECT all entities to be returned");
|
||||||
|
|
||||||
|
test.todo("GIVEN relations parameter is not supplied, EXPECT relations to be defaulted");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("FetchOneById", () => {
|
||||||
|
test.todo("EXPECT one entity to be returned");
|
||||||
|
|
||||||
|
test.todo("GIVEN relations parameter is not supplied, EXPECT relations to be defaulted");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Any", () => {
|
||||||
|
test.todo("GIVEN at least 1 entity is found, EXPECT true to be returned");
|
||||||
|
|
||||||
|
test.todo("GIVEN no entities are found, EXPECT false to be returned");
|
||||||
|
});
|
13
tests/database/entities/501231711271780357/Lobby.test.ts
Normal file
13
tests/database/entities/501231711271780357/Lobby.test.ts
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
describe("constructor", () => {
|
||||||
|
test.todo("EXPECT properties to be set");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("MarkAsUsed", () => {
|
||||||
|
test.todo("EXPECT LastUsed to be updated");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("FetchOneByChannelId", () => {
|
||||||
|
test.todo("EXPECT entity with channel id to be returned");
|
||||||
|
|
||||||
|
test.todo("GIVEN relations parameter is not supplied, EXPECT relations to be defaulted");
|
||||||
|
});
|
11
tests/database/entities/Audit.test.ts
Normal file
11
tests/database/entities/Audit.test.ts
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
describe("constructor", () => {
|
||||||
|
test.todo("EXPECT properties to be set");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("FetchAuditsByUserId", () => {
|
||||||
|
test.todo("EXPECT all entities with the user id and server id to be returned");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("FetchAuditByAuditId", () => {
|
||||||
|
test.todo("EXPECT audit with audit id to be returned");
|
||||||
|
});
|
7
tests/database/entities/IgnoredChannel.test.ts
Normal file
7
tests/database/entities/IgnoredChannel.test.ts
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
describe("constructor", () => {
|
||||||
|
test.todo("EXPECT properties to be defined");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("IsChannelIgnored", () => {
|
||||||
|
test.todo("EXPECT entity with channel id to be returned");
|
||||||
|
});
|
13
tests/database/entities/Role.test.ts
Normal file
13
tests/database/entities/Role.test.ts
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
describe("constructor", () => {
|
||||||
|
test.todo("EXPECT properties to be set");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("FetchOneByRoleId", () => {
|
||||||
|
test.todo("EXPECT entity with role id to be returned");
|
||||||
|
|
||||||
|
test.todo("GIVEN relations parameter is not supplied, EXPECT relations to be defaulted");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("FetchAllByServerId", () => {
|
||||||
|
test.todo("EXPECT all entities with server id to be returned");
|
||||||
|
});
|
11
tests/database/entities/Server.test.ts
Normal file
11
tests/database/entities/Server.test.ts
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
describe("constructor", () => {
|
||||||
|
test.todo("EXPECT properties to be set");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("AddSettingToServer", () => {
|
||||||
|
test.todo("EXPECT setting to be pushed to server relationship");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("AddRoleToServer", () => {
|
||||||
|
test.todo("EXPECT role to be pushed to server relationship");
|
||||||
|
});
|
13
tests/database/entities/Setting.test.ts
Normal file
13
tests/database/entities/Setting.test.ts
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
describe("constructor", () => {
|
||||||
|
test.todo("EXPECT properties to be set");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("UpdateBasicDetails", () => {
|
||||||
|
test.todo("EXPECT properties to be updated");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("FetchOneByKey", () => {
|
||||||
|
test.todo("EXPECT setting with key to be returned");
|
||||||
|
|
||||||
|
test.todo("GIVEN relations parameter is not supplied, EXPECT relations to be defaulted");
|
||||||
|
});
|
|
@ -1,164 +0,0 @@
|
||||||
import { GuildMember, TextChannel, User } from "discord.js";
|
|
||||||
import MemberEvents from "../../src/events/MemberEvents";
|
|
||||||
import GuildMemberUpdate from "../../src/events/MemberEvents/GuildMemberUpdate";
|
|
||||||
|
|
||||||
describe('GuildMemberAdd', () => {
|
|
||||||
test('When event is fired, expect embed to be sent to logs channel', async () => {
|
|
||||||
const currentDate = new Date();
|
|
||||||
|
|
||||||
const textChannel = {
|
|
||||||
send: jest.fn()
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const memberGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockReturnValue(textChannel);
|
|
||||||
const userDisplayAvatarURL = jest.fn();
|
|
||||||
|
|
||||||
const guildUser = {
|
|
||||||
tag: 'USERTAG',
|
|
||||||
createdAt: currentDate,
|
|
||||||
id: 'USERID',
|
|
||||||
displayAvatarURL: userDisplayAvatarURL
|
|
||||||
} as unknown as User;
|
|
||||||
|
|
||||||
const guildMember = {
|
|
||||||
user: guildUser,
|
|
||||||
guild: {
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: memberGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
|
|
||||||
const memberEvents = new MemberEvents();
|
|
||||||
|
|
||||||
const result = await memberEvents.guildMemberAdd(guildMember);
|
|
||||||
|
|
||||||
expect(textChannel.send).toBeCalledTimes(1);
|
|
||||||
expect(userDisplayAvatarURL).toBeCalledTimes(1);
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
// Embed
|
|
||||||
const embed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(embed.title).toBe("Member Joined");
|
|
||||||
expect(embed.footer?.text).toBe("Id: USERID");
|
|
||||||
expect(embed.fields.length).toBe(2);
|
|
||||||
|
|
||||||
// Embed -> User Field
|
|
||||||
const embedFieldUser = embed.fields[0];
|
|
||||||
|
|
||||||
expect(embedFieldUser.name).toBe("User");
|
|
||||||
expect(embedFieldUser.value).toBe("[object Object] `USERTAG`");
|
|
||||||
expect(embedFieldUser.inline).toBeTruthy();
|
|
||||||
|
|
||||||
// Embed -> Created Field
|
|
||||||
const embedFieldCreated = embed.fields[1];
|
|
||||||
|
|
||||||
expect(embedFieldCreated.name).toBe("Created");
|
|
||||||
expect(embedFieldCreated.value).toBe(currentDate.toString());
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('GuildMemberRemove', () => {
|
|
||||||
test('When event is fired, expect embed to be sent to logs channel', async () => {
|
|
||||||
const currentDate = new Date();
|
|
||||||
|
|
||||||
const textChannel = {
|
|
||||||
send: jest.fn()
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const memberGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockReturnValue(textChannel);
|
|
||||||
const userDisplayAvatarURL = jest.fn();
|
|
||||||
|
|
||||||
const guildUser = {
|
|
||||||
tag: 'USERTAG',
|
|
||||||
createdAt: currentDate,
|
|
||||||
id: 'USERID',
|
|
||||||
displayAvatarURL: userDisplayAvatarURL
|
|
||||||
} as unknown as User;
|
|
||||||
|
|
||||||
const guildMember = {
|
|
||||||
user: guildUser,
|
|
||||||
guild: {
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: memberGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
joinedAt: currentDate
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
|
|
||||||
const memberEvents = new MemberEvents();
|
|
||||||
|
|
||||||
const result = await memberEvents.guildMemberRemove(guildMember);
|
|
||||||
|
|
||||||
expect(textChannel.send).toBeCalledTimes(1);
|
|
||||||
expect(userDisplayAvatarURL).toBeCalledTimes(1);
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
// Embed
|
|
||||||
const embed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(embed.title).toBe("Member Left");
|
|
||||||
expect(embed.footer?.text).toBe("Id: USERID");
|
|
||||||
expect(embed.fields.length).toBe(2);
|
|
||||||
|
|
||||||
// Embed -> User Field
|
|
||||||
const embedFieldUser = embed.fields[0];
|
|
||||||
|
|
||||||
expect(embedFieldUser.name).toBe("User");
|
|
||||||
expect(embedFieldUser.value).toBe("[object Object] `USERTAG`");
|
|
||||||
expect(embedFieldUser.inline).toBeTruthy();
|
|
||||||
|
|
||||||
// Embed -> Joined Field
|
|
||||||
const embedFieldJoined = embed.fields[1];
|
|
||||||
|
|
||||||
expect(embedFieldJoined.name).toBe("Joined");
|
|
||||||
expect(embedFieldJoined.value).toBe(currentDate.toString());
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('GuildMemberUpdate', () => {
|
|
||||||
test('Given nicknames are the same, expect NicknameChanged NOT to be called', async () => {
|
|
||||||
const member = {
|
|
||||||
nickname: 'member'
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
|
|
||||||
const nicknameChanged = jest.fn();
|
|
||||||
|
|
||||||
GuildMemberUpdate.prototype.NicknameChanged = nicknameChanged;
|
|
||||||
|
|
||||||
const memberEvents = new MemberEvents();
|
|
||||||
|
|
||||||
const result = await memberEvents.guildMemberUpdate(member, member);
|
|
||||||
|
|
||||||
expect(result.embeds.length).toBe(0);
|
|
||||||
expect(nicknameChanged).not.toBeCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given nicknames are the different, expect NicknameChanged to be called', async () => {
|
|
||||||
const oldMember = {
|
|
||||||
nickname: 'oldMember'
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
|
|
||||||
const newMember = {
|
|
||||||
nickname: 'newMember'
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
|
|
||||||
const nicknameChanged = jest.fn();
|
|
||||||
|
|
||||||
GuildMemberUpdate.prototype.NicknameChanged = nicknameChanged;
|
|
||||||
|
|
||||||
const memberEvents = new MemberEvents();
|
|
||||||
|
|
||||||
const result = await memberEvents.guildMemberUpdate(oldMember, newMember);
|
|
||||||
|
|
||||||
expect(result.embeds.length).toBe(0);
|
|
||||||
expect(nicknameChanged).toBeCalledTimes(1);
|
|
||||||
});
|
|
||||||
});
|
|
13
tests/events/MemberEvents/GuildMemberAdd.test.ts
Normal file
13
tests/events/MemberEvents/GuildMemberAdd.test.ts
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
describe('GuildMemberAdd', () => {
|
||||||
|
test.todo('EXPECT embed to be logged');
|
||||||
|
|
||||||
|
test.todo("GIVEN member.guild is null, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN event.member.add.enabled setting is not found, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN event is not enabled, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN event.member.add.channel setting is not found, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN channel is not found, EXPECT nothing to happen");
|
||||||
|
});
|
15
tests/events/MemberEvents/GuildMemberRemove.test.ts
Normal file
15
tests/events/MemberEvents/GuildMemberRemove.test.ts
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
describe('GuildMemberRemove', () => {
|
||||||
|
test.todo("EXPECT embed to be logged");
|
||||||
|
|
||||||
|
test.todo("GIVEN member.guild is null, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN event.member.remove.enabled setting is not found, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN event is not enabled, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN member.joinedAt is null, EXPECT value to be defaulted");
|
||||||
|
|
||||||
|
test.todo("GIVEN event.member.remove.channel setting is not found, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN channel is not found, EXPECT nothing to happen");
|
||||||
|
});
|
|
@ -1,235 +1,5 @@
|
||||||
import { GuildMember, TextChannel } from "discord.js";
|
describe('GuildMemberUpdate', () => {
|
||||||
import GuildMemberUpdate from "../../../src/events/MemberEvents/GuildMemberUpdate";
|
test.todo("GIVEN user nickname has changed, EXPECT function to be executed");
|
||||||
|
|
||||||
beforeEach(() => {
|
test.todo("GIVEN nickname is the same, EXPECT nothing to happen");
|
||||||
process.env = {};
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Constructor', () => {
|
|
||||||
test('Expect properties are set', () => {
|
|
||||||
const oldMember = {
|
|
||||||
nickname: 'Old Nickname'
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
|
|
||||||
const newMember = {
|
|
||||||
nickname: 'New Nickname'
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
|
|
||||||
const guildMemberUpdate = new GuildMemberUpdate(oldMember, newMember);
|
|
||||||
|
|
||||||
expect(guildMemberUpdate.oldMember).toBe(oldMember);
|
|
||||||
expect(guildMemberUpdate.newMember).toBe(newMember);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('NicknameChanged', () => {
|
|
||||||
test('Given nickname has changed from one to another, expect embed to be sent with both', async () => {
|
|
||||||
process.env = {
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs'
|
|
||||||
}
|
|
||||||
|
|
||||||
const channelSend = jest.fn();
|
|
||||||
|
|
||||||
const textChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: channelSend
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const memberGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockReturnValue(textChannel);
|
|
||||||
const memberUserDisplayAvatarURL = jest.fn();
|
|
||||||
|
|
||||||
const oldMember = {
|
|
||||||
nickname: 'Old Nickname'
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
|
|
||||||
const newMember = {
|
|
||||||
nickname: 'New Nickname',
|
|
||||||
guild: {
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: memberGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
user: {
|
|
||||||
tag: 'USERTAG',
|
|
||||||
id: 'USERID',
|
|
||||||
displayAvatarURL: memberUserDisplayAvatarURL
|
|
||||||
}
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
|
|
||||||
const guildMemberUpdate = new GuildMemberUpdate(oldMember, newMember);
|
|
||||||
|
|
||||||
const result = await guildMemberUpdate.NicknameChanged();
|
|
||||||
|
|
||||||
expect(channelSend).toBeCalledTimes(1);
|
|
||||||
expect(memberGuildChannelsCacheFind).toBeCalledTimes(1);
|
|
||||||
expect(memberUserDisplayAvatarURL).toBeCalledTimes(1);
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
// Embed
|
|
||||||
const embed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(embed.title).toBe('Nickname Changed');
|
|
||||||
expect(embed.footer?.text).toBe('Id: USERID');
|
|
||||||
expect(embed.fields.length).toBe(3);
|
|
||||||
|
|
||||||
// Embed -> User Field
|
|
||||||
const embedFieldUser = embed.fields[0];
|
|
||||||
|
|
||||||
expect(embedFieldUser.name).toBe('User');
|
|
||||||
expect(embedFieldUser.value).toBe('[object Object] `USERTAG`');
|
|
||||||
|
|
||||||
// Embed -> Before Field
|
|
||||||
const embedFieldBefore = embed.fields[1];
|
|
||||||
|
|
||||||
expect(embedFieldBefore.name).toBe('Before');
|
|
||||||
expect(embedFieldBefore.value).toBe('Old Nickname');
|
|
||||||
|
|
||||||
// Embed -> After Field
|
|
||||||
const embedFieldAfter = embed.fields[2];
|
|
||||||
|
|
||||||
expect(embedFieldAfter.name).toBe('After');
|
|
||||||
expect(embedFieldAfter.value).toBe('New Nickname');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given old nickname was null, expect embed to say old nickname was none', async () => {
|
|
||||||
process.env = {
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs'
|
|
||||||
}
|
|
||||||
|
|
||||||
const channelSend = jest.fn();
|
|
||||||
|
|
||||||
const textChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: channelSend
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const memberGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockReturnValue(textChannel);
|
|
||||||
const memberUserDisplayAvatarURL = jest.fn();
|
|
||||||
|
|
||||||
const oldMember = {} as unknown as GuildMember;
|
|
||||||
|
|
||||||
const newMember = {
|
|
||||||
nickname: 'New Nickname',
|
|
||||||
guild: {
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: memberGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
user: {
|
|
||||||
tag: 'USERTAG',
|
|
||||||
id: 'USERID',
|
|
||||||
displayAvatarURL: memberUserDisplayAvatarURL
|
|
||||||
}
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
|
|
||||||
const guildMemberUpdate = new GuildMemberUpdate(oldMember, newMember);
|
|
||||||
|
|
||||||
const result = await guildMemberUpdate.NicknameChanged();
|
|
||||||
|
|
||||||
expect(channelSend).toBeCalledTimes(1);
|
|
||||||
expect(memberGuildChannelsCacheFind).toBeCalledTimes(1);
|
|
||||||
expect(memberUserDisplayAvatarURL).toBeCalledTimes(1);
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
// Embed
|
|
||||||
const embed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(embed.title).toBe('Nickname Changed');
|
|
||||||
expect(embed.footer?.text).toBe('Id: USERID');
|
|
||||||
expect(embed.fields.length).toBe(3);
|
|
||||||
|
|
||||||
// Embed -> User Field
|
|
||||||
const embedFieldUser = embed.fields[0];
|
|
||||||
|
|
||||||
expect(embedFieldUser.name).toBe('User');
|
|
||||||
expect(embedFieldUser.value).toBe('[object Object] `USERTAG`');
|
|
||||||
|
|
||||||
// Embed -> Before Field
|
|
||||||
const embedFieldBefore = embed.fields[1];
|
|
||||||
|
|
||||||
expect(embedFieldBefore.name).toBe('Before');
|
|
||||||
expect(embedFieldBefore.value).toBe('*none*');
|
|
||||||
|
|
||||||
// Embed -> After Field
|
|
||||||
const embedFieldAfter = embed.fields[2];
|
|
||||||
|
|
||||||
expect(embedFieldAfter.name).toBe('After');
|
|
||||||
expect(embedFieldAfter.value).toBe('New Nickname');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given new nickname was null, expect embed to say new nickname was none', async () => {
|
|
||||||
process.env = {
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs'
|
|
||||||
}
|
|
||||||
|
|
||||||
const channelSend = jest.fn();
|
|
||||||
|
|
||||||
const textChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: channelSend
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const memberGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockReturnValue(textChannel);
|
|
||||||
const memberUserDisplayAvatarURL = jest.fn();
|
|
||||||
|
|
||||||
const oldMember = {
|
|
||||||
nickname: 'Old Nickname'
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
|
|
||||||
const newMember = {
|
|
||||||
guild: {
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: memberGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
user: {
|
|
||||||
tag: 'USERTAG',
|
|
||||||
id: 'USERID',
|
|
||||||
displayAvatarURL: memberUserDisplayAvatarURL
|
|
||||||
}
|
|
||||||
} as unknown as GuildMember;
|
|
||||||
|
|
||||||
const guildMemberUpdate = new GuildMemberUpdate(oldMember, newMember);
|
|
||||||
|
|
||||||
const result = await guildMemberUpdate.NicknameChanged();
|
|
||||||
|
|
||||||
expect(channelSend).toBeCalledTimes(1);
|
|
||||||
expect(memberGuildChannelsCacheFind).toBeCalledTimes(1);
|
|
||||||
expect(memberUserDisplayAvatarURL).toBeCalledTimes(1);
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
// Embed
|
|
||||||
const embed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(embed.title).toBe('Nickname Changed');
|
|
||||||
expect(embed.footer?.text).toBe('Id: USERID');
|
|
||||||
expect(embed.fields.length).toBe(3);
|
|
||||||
|
|
||||||
// Embed -> User Field
|
|
||||||
const embedFieldUser = embed.fields[0];
|
|
||||||
|
|
||||||
expect(embedFieldUser.name).toBe('User');
|
|
||||||
expect(embedFieldUser.value).toBe('[object Object] `USERTAG`');
|
|
||||||
|
|
||||||
// Embed -> Before Field
|
|
||||||
const embedFieldBefore = embed.fields[1];
|
|
||||||
|
|
||||||
expect(embedFieldBefore.name).toBe('Before');
|
|
||||||
expect(embedFieldBefore.value).toBe('Old Nickname');
|
|
||||||
|
|
||||||
// Embed -> After Field
|
|
||||||
const embedFieldAfter = embed.fields[2];
|
|
||||||
|
|
||||||
expect(embedFieldAfter.name).toBe('After');
|
|
||||||
expect(embedFieldAfter.value).toBe('*none*');
|
|
||||||
});
|
|
||||||
});
|
});
|
|
@ -0,0 +1,15 @@
|
||||||
|
describe('NicknameChanged', () => {
|
||||||
|
test.todo('EXPECT embed to be logged');
|
||||||
|
|
||||||
|
test.todo("GIVEN event.member.update.enabled setting is not found, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN event is not enabled, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN oldNickname is null, EXPECT oldNickname to be defaulted");
|
||||||
|
|
||||||
|
test.todo("GIVEN newNickname is null, EXPECT newNickname to be defaulted");
|
||||||
|
|
||||||
|
test.todo("GIVEN event.member.update.channel setting is not found, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN log channel can not be found, EXPECT nothing to happen");
|
||||||
|
});
|
|
@ -1,648 +0,0 @@
|
||||||
import { Collection, Message, MessageAttachment, TextChannel } from "discord.js";
|
|
||||||
import MessageEvents from "../../src/events/MessageEvents";
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
process.env = {};
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('MessageDelete', () => {
|
|
||||||
test('Given message was in a guild AND user was NOT a bot, expect message deleted embed to be sent', async () => {
|
|
||||||
process.env = {
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs'
|
|
||||||
}
|
|
||||||
|
|
||||||
const channelSend = jest.fn();
|
|
||||||
|
|
||||||
const textChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: channelSend
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const memberGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockReturnValue(textChannel);
|
|
||||||
const messageAuthorDisplayAvatarURL = jest.fn();
|
|
||||||
|
|
||||||
const messageAttachments = new Collection<string, MessageAttachment>([
|
|
||||||
[
|
|
||||||
"0",
|
|
||||||
{
|
|
||||||
url: 'image0.png'
|
|
||||||
} as unknown as MessageAttachment
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"1",
|
|
||||||
{
|
|
||||||
url: 'image1.png'
|
|
||||||
} as unknown as MessageAttachment
|
|
||||||
]
|
|
||||||
]);
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
guild: {
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: memberGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
author: {
|
|
||||||
bot: false,
|
|
||||||
displayAvatarURL: messageAuthorDisplayAvatarURL,
|
|
||||||
tag: 'USERTAG'
|
|
||||||
},
|
|
||||||
channel: {},
|
|
||||||
content: 'Message Content',
|
|
||||||
attachments: messageAttachments
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const messageEvents = new MessageEvents();
|
|
||||||
|
|
||||||
const result = await messageEvents.messageDelete(message);
|
|
||||||
|
|
||||||
expect(channelSend).toBeCalledTimes(1);
|
|
||||||
expect(memberGuildChannelsCacheFind).toBeCalledTimes(1);
|
|
||||||
expect(messageAuthorDisplayAvatarURL).toBeCalledTimes(1);
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
// Embed
|
|
||||||
const embed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(embed.title).toBe('Message Deleted');
|
|
||||||
expect(embed.fields.length).toBe(4);
|
|
||||||
|
|
||||||
// Embed -> User Field
|
|
||||||
const embedFieldUser = embed.fields[0];
|
|
||||||
|
|
||||||
expect(embedFieldUser.name).toBe('User');
|
|
||||||
expect(embedFieldUser.value).toBe('[object Object] `USERTAG`');
|
|
||||||
|
|
||||||
// Embed -> Channel Field
|
|
||||||
const embedFieldChannel = embed.fields[1];
|
|
||||||
|
|
||||||
expect(embedFieldChannel.name).toBe('Channel');
|
|
||||||
expect(embedFieldChannel.value).toBe('[object Object]');
|
|
||||||
|
|
||||||
// Embed -> Content Field
|
|
||||||
const embedFieldContent = embed.fields[2];
|
|
||||||
|
|
||||||
expect(embedFieldContent.name).toBe('Content');
|
|
||||||
expect(embedFieldContent.value).toBe('```Message Content```');
|
|
||||||
|
|
||||||
// Embed -> Attachments Field
|
|
||||||
const embedFieldAttachments = embed.fields[3];
|
|
||||||
|
|
||||||
expect(embedFieldAttachments.name).toBe('Attachments');
|
|
||||||
expect(embedFieldAttachments.value).toBe('```image0.png\nimage1.png```');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given message was not sent in a guild, expect execution stopped', async () => {
|
|
||||||
process.env = {
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs'
|
|
||||||
}
|
|
||||||
|
|
||||||
const channelSend = jest.fn();
|
|
||||||
|
|
||||||
const textChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: channelSend
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const memberGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockReturnValue(textChannel);
|
|
||||||
const messageAuthorDisplayAvatarURL = jest.fn();
|
|
||||||
|
|
||||||
const messageAttachments = new Collection<string, MessageAttachment>([
|
|
||||||
[
|
|
||||||
"0",
|
|
||||||
{
|
|
||||||
url: 'image0.png'
|
|
||||||
} as unknown as MessageAttachment
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"1",
|
|
||||||
{
|
|
||||||
url: 'image1.png'
|
|
||||||
} as unknown as MessageAttachment
|
|
||||||
]
|
|
||||||
]);
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
author: {
|
|
||||||
bot: false,
|
|
||||||
displayAvatarURL: messageAuthorDisplayAvatarURL,
|
|
||||||
tag: 'USERTAG'
|
|
||||||
},
|
|
||||||
channel: {},
|
|
||||||
content: 'Message Content',
|
|
||||||
attachments: messageAttachments
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const messageEvents = new MessageEvents();
|
|
||||||
|
|
||||||
const result = await messageEvents.messageDelete(message);
|
|
||||||
|
|
||||||
expect(channelSend).not.toBeCalled();
|
|
||||||
expect(memberGuildChannelsCacheFind).not.toBeCalled();
|
|
||||||
expect(messageAuthorDisplayAvatarURL).not.toBeCalled();
|
|
||||||
expect(result.embeds.length).toBe(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given author is a bot, expect execution stopped', async () => {
|
|
||||||
process.env = {
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs'
|
|
||||||
}
|
|
||||||
|
|
||||||
const channelSend = jest.fn();
|
|
||||||
|
|
||||||
const textChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: channelSend
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const memberGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockReturnValue(textChannel);
|
|
||||||
const messageAuthorDisplayAvatarURL = jest.fn();
|
|
||||||
|
|
||||||
const messageAttachments = new Collection<string, MessageAttachment>([
|
|
||||||
[
|
|
||||||
"0",
|
|
||||||
{
|
|
||||||
url: 'image0.png'
|
|
||||||
} as unknown as MessageAttachment
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"1",
|
|
||||||
{
|
|
||||||
url: 'image1.png'
|
|
||||||
} as unknown as MessageAttachment
|
|
||||||
]
|
|
||||||
]);
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
guild: {
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: memberGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
author: {
|
|
||||||
bot: true,
|
|
||||||
displayAvatarURL: messageAuthorDisplayAvatarURL,
|
|
||||||
tag: 'USERTAG'
|
|
||||||
},
|
|
||||||
channel: {},
|
|
||||||
content: 'Message Content',
|
|
||||||
attachments: messageAttachments
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const messageEvents = new MessageEvents();
|
|
||||||
|
|
||||||
const result = await messageEvents.messageDelete(message);
|
|
||||||
|
|
||||||
expect(channelSend).not.toBeCalled();
|
|
||||||
expect(memberGuildChannelsCacheFind).not.toBeCalled();
|
|
||||||
expect(messageAuthorDisplayAvatarURL).not.toBeCalled();
|
|
||||||
expect(result.embeds.length).toBe(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given message does not contain any attachments, expect attachments field to be omitted', async () => {
|
|
||||||
process.env = {
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs'
|
|
||||||
}
|
|
||||||
|
|
||||||
const channelSend = jest.fn();
|
|
||||||
|
|
||||||
const textChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: channelSend
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const memberGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockReturnValue(textChannel);
|
|
||||||
const messageAuthorDisplayAvatarURL = jest.fn();
|
|
||||||
|
|
||||||
const messageAttachments = new Collection<string, MessageAttachment>([]);
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
guild: {
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: memberGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
author: {
|
|
||||||
bot: false,
|
|
||||||
displayAvatarURL: messageAuthorDisplayAvatarURL,
|
|
||||||
tag: 'USERTAG'
|
|
||||||
},
|
|
||||||
channel: {},
|
|
||||||
content: 'Message Content',
|
|
||||||
attachments: messageAttachments
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const messageEvents = new MessageEvents();
|
|
||||||
|
|
||||||
const result = await messageEvents.messageDelete(message);
|
|
||||||
|
|
||||||
expect(channelSend).toBeCalledTimes(1);
|
|
||||||
expect(memberGuildChannelsCacheFind).toBeCalledTimes(1);
|
|
||||||
expect(messageAuthorDisplayAvatarURL).toBeCalledTimes(1);
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
// Embed
|
|
||||||
const embed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(embed.title).toBe('Message Deleted');
|
|
||||||
expect(embed.fields.length).toBe(3);
|
|
||||||
|
|
||||||
// Embed -> User Field
|
|
||||||
const embedFieldUser = embed.fields[0];
|
|
||||||
|
|
||||||
expect(embedFieldUser.name).toBe('User');
|
|
||||||
expect(embedFieldUser.value).toBe('[object Object] `USERTAG`');
|
|
||||||
|
|
||||||
// Embed -> Channel Field
|
|
||||||
const embedFieldChannel = embed.fields[1];
|
|
||||||
|
|
||||||
expect(embedFieldChannel.name).toBe('Channel');
|
|
||||||
expect(embedFieldChannel.value).toBe('[object Object]');
|
|
||||||
|
|
||||||
// Embed -> Content Field
|
|
||||||
const embedFieldContent = embed.fields[2];
|
|
||||||
|
|
||||||
expect(embedFieldContent.name).toBe('Content');
|
|
||||||
expect(embedFieldContent.value).toBe('```Message Content```');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('MessageUpdate', () => {
|
|
||||||
test('Given message is in a guild AND user is not a bot AND the content has actually changed, e xpect log embed to be sent', async () => {
|
|
||||||
process.env = {
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs'
|
|
||||||
}
|
|
||||||
|
|
||||||
const channelSend = jest.fn();
|
|
||||||
|
|
||||||
const textChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: channelSend
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const memberGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockReturnValue(textChannel);
|
|
||||||
const messageAuthorDisplayAvatarURL = jest.fn();
|
|
||||||
|
|
||||||
const oldMessage = {
|
|
||||||
content: 'Old Message'
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const newMessage = {
|
|
||||||
guild: {
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: memberGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
author: {
|
|
||||||
bot: false,
|
|
||||||
displayAvatarURL: messageAuthorDisplayAvatarURL,
|
|
||||||
tag: 'USERTAG'
|
|
||||||
},
|
|
||||||
content: 'New Message',
|
|
||||||
channel: {},
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const messageEvents = new MessageEvents();
|
|
||||||
|
|
||||||
const result = await messageEvents.messageUpdate(oldMessage, newMessage);
|
|
||||||
|
|
||||||
expect(channelSend).toBeCalledTimes(1);
|
|
||||||
expect(memberGuildChannelsCacheFind).toBeCalledTimes(1);
|
|
||||||
expect(messageAuthorDisplayAvatarURL).toBeCalledTimes(1);
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
// Embed
|
|
||||||
const embed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(embed.title).toBe('Message Edited');
|
|
||||||
expect(embed.fields.length).toBe(4);
|
|
||||||
|
|
||||||
// Embed -> User Field
|
|
||||||
const embedFieldUser = embed.fields[0];
|
|
||||||
|
|
||||||
expect(embedFieldUser.name).toBe('User');
|
|
||||||
expect(embedFieldUser.value).toBe('[object Object] `USERTAG`');
|
|
||||||
expect(embedFieldUser.inline).toBeTruthy();
|
|
||||||
|
|
||||||
// Embed -> Channel Field
|
|
||||||
const embedFieldChannel = embed.fields[1];
|
|
||||||
|
|
||||||
expect(embedFieldChannel.name).toBe('Channel');
|
|
||||||
expect(embedFieldChannel.value).toBe('[object Object]');
|
|
||||||
expect(embedFieldChannel.inline).toBeTruthy();
|
|
||||||
|
|
||||||
// Embed -> Before Field
|
|
||||||
const embedFieldBefore = embed.fields[2];
|
|
||||||
|
|
||||||
expect(embedFieldBefore.name).toBe('Before');
|
|
||||||
expect(embedFieldBefore.value).toBe('```Old Message```');
|
|
||||||
|
|
||||||
// Embed -> After Field
|
|
||||||
const embedFieldAfter = embed.fields[3];
|
|
||||||
|
|
||||||
expect(embedFieldAfter.name).toBe('After');
|
|
||||||
expect(embedFieldAfter.value).toBe('```New Message```');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given message was not in a guild, expect execution stopped', async () => {
|
|
||||||
process.env = {
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs'
|
|
||||||
}
|
|
||||||
|
|
||||||
const channelSend = jest.fn();
|
|
||||||
|
|
||||||
const textChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: channelSend
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const memberGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockReturnValue(textChannel);
|
|
||||||
const messageAuthorDisplayAvatarURL = jest.fn();
|
|
||||||
|
|
||||||
const oldMessage = {
|
|
||||||
content: 'Old Message'
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const newMessage = {
|
|
||||||
author: {
|
|
||||||
bot: false,
|
|
||||||
displayAvatarURL: messageAuthorDisplayAvatarURL,
|
|
||||||
tag: 'USERTAG'
|
|
||||||
},
|
|
||||||
content: 'New Message',
|
|
||||||
channel: {},
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const messageEvents = new MessageEvents();
|
|
||||||
|
|
||||||
const result = await messageEvents.messageUpdate(oldMessage, newMessage);
|
|
||||||
|
|
||||||
expect(channelSend).not.toBeCalled();
|
|
||||||
expect(memberGuildChannelsCacheFind).not.toBeCalled();
|
|
||||||
expect(messageAuthorDisplayAvatarURL).not.toBeCalled();
|
|
||||||
expect(result.embeds.length).toBe(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given author is a bot, expect execution stopped', async () => {
|
|
||||||
process.env = {
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs'
|
|
||||||
}
|
|
||||||
|
|
||||||
const channelSend = jest.fn();
|
|
||||||
|
|
||||||
const textChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: channelSend
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const memberGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockReturnValue(textChannel);
|
|
||||||
const messageAuthorDisplayAvatarURL = jest.fn();
|
|
||||||
|
|
||||||
const oldMessage = {
|
|
||||||
content: 'Old Message'
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const newMessage = {
|
|
||||||
guild: {
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: memberGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
author: {
|
|
||||||
bot: true,
|
|
||||||
displayAvatarURL: messageAuthorDisplayAvatarURL,
|
|
||||||
tag: 'USERTAG'
|
|
||||||
},
|
|
||||||
content: 'New Message',
|
|
||||||
channel: {},
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const messageEvents = new MessageEvents();
|
|
||||||
|
|
||||||
const result = await messageEvents.messageUpdate(oldMessage, newMessage);
|
|
||||||
|
|
||||||
expect(channelSend).not.toBeCalled();
|
|
||||||
expect(memberGuildChannelsCacheFind).not.toBeCalled();
|
|
||||||
expect(messageAuthorDisplayAvatarURL).not.toBeCalled();
|
|
||||||
expect(result.embeds.length).toBe(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given the message contents are the same, expect execution stopped', async () => {
|
|
||||||
process.env = {
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs'
|
|
||||||
}
|
|
||||||
|
|
||||||
const channelSend = jest.fn();
|
|
||||||
|
|
||||||
const textChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: channelSend
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const memberGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockReturnValue(textChannel);
|
|
||||||
const messageAuthorDisplayAvatarURL = jest.fn();
|
|
||||||
|
|
||||||
const oldMessage = {
|
|
||||||
content: 'Message'
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const newMessage = {
|
|
||||||
guild: {
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: memberGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
author: {
|
|
||||||
bot: false,
|
|
||||||
displayAvatarURL: messageAuthorDisplayAvatarURL,
|
|
||||||
tag: 'USERTAG'
|
|
||||||
},
|
|
||||||
content: 'Message',
|
|
||||||
channel: {},
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const messageEvents = new MessageEvents();
|
|
||||||
|
|
||||||
const result = await messageEvents.messageUpdate(oldMessage, newMessage);
|
|
||||||
|
|
||||||
expect(channelSend).not.toBeCalled();
|
|
||||||
expect(memberGuildChannelsCacheFind).not.toBeCalled();
|
|
||||||
expect(messageAuthorDisplayAvatarURL).not.toBeCalled();
|
|
||||||
expect(result.embeds.length).toBe(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given Old Message did not have a content, expect field to account for this', async () => {
|
|
||||||
process.env = {
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs'
|
|
||||||
}
|
|
||||||
|
|
||||||
const channelSend = jest.fn();
|
|
||||||
|
|
||||||
const textChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: channelSend
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const memberGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockReturnValue(textChannel);
|
|
||||||
const messageAuthorDisplayAvatarURL = jest.fn();
|
|
||||||
|
|
||||||
const oldMessage = {} as unknown as Message;
|
|
||||||
|
|
||||||
const newMessage = {
|
|
||||||
guild: {
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: memberGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
author: {
|
|
||||||
bot: false,
|
|
||||||
displayAvatarURL: messageAuthorDisplayAvatarURL,
|
|
||||||
tag: 'USERTAG'
|
|
||||||
},
|
|
||||||
content: 'New Message',
|
|
||||||
channel: {},
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const messageEvents = new MessageEvents();
|
|
||||||
|
|
||||||
const result = await messageEvents.messageUpdate(oldMessage, newMessage);
|
|
||||||
|
|
||||||
expect(channelSend).toBeCalledTimes(1);
|
|
||||||
expect(memberGuildChannelsCacheFind).toBeCalledTimes(1);
|
|
||||||
expect(messageAuthorDisplayAvatarURL).toBeCalledTimes(1);
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
// Embed
|
|
||||||
const embed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(embed.title).toBe('Message Edited');
|
|
||||||
expect(embed.fields.length).toBe(4);
|
|
||||||
|
|
||||||
// Embed -> User Field
|
|
||||||
const embedFieldUser = embed.fields[0];
|
|
||||||
|
|
||||||
expect(embedFieldUser.name).toBe('User');
|
|
||||||
expect(embedFieldUser.value).toBe('[object Object] `USERTAG`');
|
|
||||||
expect(embedFieldUser.inline).toBeTruthy();
|
|
||||||
|
|
||||||
// Embed -> Channel Field
|
|
||||||
const embedFieldChannel = embed.fields[1];
|
|
||||||
|
|
||||||
expect(embedFieldChannel.name).toBe('Channel');
|
|
||||||
expect(embedFieldChannel.value).toBe('[object Object]');
|
|
||||||
expect(embedFieldChannel.inline).toBeTruthy();
|
|
||||||
|
|
||||||
// Embed -> Before Field
|
|
||||||
const embedFieldBefore = embed.fields[2];
|
|
||||||
|
|
||||||
expect(embedFieldBefore.name).toBe('Before');
|
|
||||||
expect(embedFieldBefore.value).toBe('```*none*```');
|
|
||||||
|
|
||||||
// Embed -> After Field
|
|
||||||
const embedFieldAfter = embed.fields[3];
|
|
||||||
|
|
||||||
expect(embedFieldAfter.name).toBe('After');
|
|
||||||
expect(embedFieldAfter.value).toBe('```New Message```');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given New Message does not have a content, expect field to account for this', async () => {
|
|
||||||
process.env = {
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs'
|
|
||||||
}
|
|
||||||
|
|
||||||
const channelSend = jest.fn();
|
|
||||||
|
|
||||||
const textChannel = {
|
|
||||||
name: 'mod-logs',
|
|
||||||
send: channelSend
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const memberGuildChannelsCacheFind = jest.fn()
|
|
||||||
.mockReturnValue(textChannel);
|
|
||||||
const messageAuthorDisplayAvatarURL = jest.fn();
|
|
||||||
|
|
||||||
const oldMessage = {
|
|
||||||
content: 'Old Message'
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const newMessage = {
|
|
||||||
guild: {
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: memberGuildChannelsCacheFind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
author: {
|
|
||||||
bot: false,
|
|
||||||
displayAvatarURL: messageAuthorDisplayAvatarURL,
|
|
||||||
tag: 'USERTAG'
|
|
||||||
},
|
|
||||||
channel: {},
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const messageEvents = new MessageEvents();
|
|
||||||
|
|
||||||
const result = await messageEvents.messageUpdate(oldMessage, newMessage);
|
|
||||||
|
|
||||||
expect(channelSend).toBeCalledTimes(1);
|
|
||||||
expect(memberGuildChannelsCacheFind).toBeCalledTimes(1);
|
|
||||||
expect(messageAuthorDisplayAvatarURL).toBeCalledTimes(1);
|
|
||||||
expect(result.embeds.length).toBe(1);
|
|
||||||
|
|
||||||
// Embed
|
|
||||||
const embed = result.embeds[0];
|
|
||||||
|
|
||||||
expect(embed.title).toBe('Message Edited');
|
|
||||||
expect(embed.fields.length).toBe(4);
|
|
||||||
|
|
||||||
// Embed -> User Field
|
|
||||||
const embedFieldUser = embed.fields[0];
|
|
||||||
|
|
||||||
expect(embedFieldUser.name).toBe('User');
|
|
||||||
expect(embedFieldUser.value).toBe('[object Object] `USERTAG`');
|
|
||||||
expect(embedFieldUser.inline).toBeTruthy();
|
|
||||||
|
|
||||||
// Embed -> Channel Field
|
|
||||||
const embedFieldChannel = embed.fields[1];
|
|
||||||
|
|
||||||
expect(embedFieldChannel.name).toBe('Channel');
|
|
||||||
expect(embedFieldChannel.value).toBe('[object Object]');
|
|
||||||
expect(embedFieldChannel.inline).toBeTruthy();
|
|
||||||
|
|
||||||
// Embed -> Before Field
|
|
||||||
const embedFieldBefore = embed.fields[2];
|
|
||||||
|
|
||||||
expect(embedFieldBefore.name).toBe('Before');
|
|
||||||
expect(embedFieldBefore.value).toBe('```Old Message```');
|
|
||||||
|
|
||||||
// Embed -> After Field
|
|
||||||
const embedFieldAfter = embed.fields[3];
|
|
||||||
|
|
||||||
expect(embedFieldAfter.name).toBe('After');
|
|
||||||
expect(embedFieldAfter.value).toBe('```*none*```');
|
|
||||||
});
|
|
||||||
});
|
|
11
tests/events/MessageEvents/MessageCreate.test.ts
Normal file
11
tests/events/MessageEvents/MessageCreate.test.ts
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
describe('MessageCreate', () => {
|
||||||
|
test.todo("GIVEN verification is enabled, EXPECT function to execute");
|
||||||
|
|
||||||
|
test.todo("GIVEN verification is not enabled, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN message.guild is null, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN message author is a bot, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN verification.enabled is not found, EXPECT nothing to happen");
|
||||||
|
});
|
|
@ -0,0 +1,23 @@
|
||||||
|
describe("VerificationCheck", () => {
|
||||||
|
test.todo("GIVEN validation is correct, EXPECT role given");
|
||||||
|
|
||||||
|
test.todo("GIVEN validation is incorrect, EXPECT only message to be deleted");
|
||||||
|
|
||||||
|
test.todo("GIVEN message.guild is null, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN verification.channel setting is not found, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN channel is not found, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN currentChannel is not found, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN currentChannel is not the verification channel, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN verification.code is null, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN verification.code is empty, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN verification.role is null, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN role is not found, EXPECT error");
|
||||||
|
});
|
21
tests/events/MessageEvents/MessageDelete.test.ts
Normal file
21
tests/events/MessageEvents/MessageDelete.test.ts
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
describe('MessageDelete', () => {
|
||||||
|
test.todo('EXPECT embed to be logged');
|
||||||
|
|
||||||
|
test.todo("GIVEN message.guild is null, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN message author is a bot, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN event.message.delete.enabled setting is not found, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN event is not enabled, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN channel is ignored, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN message content is null, EXPECT content to be defaulted");
|
||||||
|
|
||||||
|
test.todo("GIVEN message had at least 1 attachment, EXPECT attachments field to be added");
|
||||||
|
|
||||||
|
test.todo("GIVEN event.message.delete.channel setting is not found, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN channel is not found, EXPECT nothing to happen");
|
||||||
|
});
|
23
tests/events/MessageEvents/MessageUpdate.test.ts
Normal file
23
tests/events/MessageEvents/MessageUpdate.test.ts
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
describe('MessageUpdate', () => {
|
||||||
|
test.todo("EXPECT embed to be logged");
|
||||||
|
|
||||||
|
test.todo("GIVEN newMessage.guild is null, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN message author is a bot, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN message contents are the same, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN event.message.update.enabled setting is not found, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN event is not enabled, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN channel is ignored, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN oldMessage.content is null, EXPECT oldMessage to be defaulted");
|
||||||
|
|
||||||
|
test.todo("GIVEN newMessage.content is null, EXPECT newMessage to be defaulted");
|
||||||
|
|
||||||
|
test.todo("GIVEN event.message.delete.channel setting is not found, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN channel is not found, EXPECT nothing to happen");
|
||||||
|
});
|
31
tests/helpers/AuditTools.test.ts
Normal file
31
tests/helpers/AuditTools.test.ts
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
describe('TypeToFriendlyText', () => {
|
||||||
|
test.todo("GIVEN auditType is General, EXPECT General to be returned");
|
||||||
|
|
||||||
|
test.todo("GIVEN auditType is Warn, EXPECT Warn to be returned");
|
||||||
|
|
||||||
|
test.todo("GIVEN auditType is Mute, EXPECT Mute to be returned");
|
||||||
|
|
||||||
|
test.todo("GIVEN auditType is Kick, EXPECT Kick to be returned");
|
||||||
|
|
||||||
|
test.todo("GIVEN auditType is Ban, EXPECT Ban to be returned");
|
||||||
|
|
||||||
|
test.todo("GIVEN auditType is Timeout, EXPECT Timeout to be returned");
|
||||||
|
|
||||||
|
test.todo("GIVEN auditType is none of these, EXPECT Other to be returned");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('StringToType', () => {
|
||||||
|
test.todo("GIVEN string is general, EXPECT General to be returned");
|
||||||
|
|
||||||
|
test.todo("GIVEN string is warn, EXPECT Warn to be returned");
|
||||||
|
|
||||||
|
test.todo("GIVEN string is mute, EXPECT Mute to be returned");
|
||||||
|
|
||||||
|
test.todo("GIVEN string is kick, EXPECT Kick to be returned");
|
||||||
|
|
||||||
|
test.todo("GIVEN string is ban, EXPECT Ban to be returned");
|
||||||
|
|
||||||
|
test.todo("GIVEN string is timeout, EXPECT Timeout to be returned");
|
||||||
|
|
||||||
|
test.todo("GIVEN string is none of these, EXPECT General to be returned");
|
||||||
|
});
|
7
tests/helpers/MigrationHelper.test.ts
Normal file
7
tests/helpers/MigrationHelper.test.ts
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
describe('Up', () => {
|
||||||
|
test.todo("EXPECT up query to be executed");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Down", () => {
|
||||||
|
test.todo("EXPECT down query to be executed");
|
||||||
|
});
|
15
tests/helpers/SettingsHelper.test.ts
Normal file
15
tests/helpers/SettingsHelper.test.ts
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
describe("GetSetting", () => {
|
||||||
|
test.todo("EXPECT setting value to be returned");
|
||||||
|
|
||||||
|
test.todo("GIVEN server is not set up, EXPECT default value to be returned");
|
||||||
|
|
||||||
|
test.todo("GIVEN setting is not set, EXPECT default value to be returned");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("SetSetting", () => {
|
||||||
|
test.todo("GIVEN setting is not set, EXPECT value to be added");
|
||||||
|
|
||||||
|
test.todo("GIVEN setting is already set, EXPECT value to be updated");
|
||||||
|
|
||||||
|
test.todo("GIVEN server is not set up, EXPECT nothing to happen");
|
||||||
|
});
|
|
@ -1,11 +1,15 @@
|
||||||
import StringTools from "../../src/helpers/StringTools";
|
|
||||||
|
|
||||||
describe('Capitalise', () => {
|
describe('Capitalise', () => {
|
||||||
test('Expect sentence to be captilised', () => {
|
test.todo('EXPECT sentence to be capitalised');
|
||||||
const inputString = 'the big brown fox jumps over the lazy dog';
|
});
|
||||||
|
|
||||||
const result = StringTools.Capitalise(inputString);
|
describe('CapitaliseArray', () => {
|
||||||
|
test.todo("EXPECT words in array to be capitalised");
|
||||||
|
});
|
||||||
|
|
||||||
expect(result).toBe('The Big Brown Fox Jumps Over The Lazy Dog');
|
describe("RandomString", () => {
|
||||||
});
|
test.todo("EXPECT random string of length to be returned");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("ReplaceAll", () => {
|
||||||
|
test.todo("EXPECT all instances of substring to be replaced");
|
||||||
});
|
});
|
37
tests/helpers/TimeLengthInput.test.ts
Normal file
37
tests/helpers/TimeLengthInput.test.ts
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
describe('constructor', () => {
|
||||||
|
test.todo("EXPECT properties to be set");
|
||||||
|
|
||||||
|
test.todo("GIVEN input has commas, EXPECT these to be removed");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('GetDays', () => {
|
||||||
|
test.todo("EXPECT day value to be returned");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('GetHours', () => {
|
||||||
|
test.todo("EXPECT hour value to be returned");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('GetMinutes', () => {
|
||||||
|
test.todo("EXPECT minute value to be returned");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('GetSeconds', () => {
|
||||||
|
test.todo("EXPECT second value to be returned");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('GetMiliseconds', () => {
|
||||||
|
test.todo("EXPECT total time returned in miliseconds");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('GetDateFromNow', () => {
|
||||||
|
test.todo("EXPECT date returned to be value added to now");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("GetLength", () => {
|
||||||
|
test.todo("EXPECT stringified value to be returned");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("GetLengthShort", () => {
|
||||||
|
test.todo("EXPECT stringified value to be returned");
|
||||||
|
});
|
|
@ -1,57 +0,0 @@
|
||||||
import { Message } from "discord.js";
|
|
||||||
import { ICommandContext } from "../../../src/contracts/ICommandContext";
|
|
||||||
import ErrorEmbed from "../../../src/helpers/embeds/ErrorEmbed";
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
process.env = {};
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Constructor', () => {
|
|
||||||
test('Expect properties to be set', () => {
|
|
||||||
process.env = {
|
|
||||||
EMBED_COLOUR_ERROR: '0xd52803'
|
|
||||||
}
|
|
||||||
|
|
||||||
const message = {} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'command',
|
|
||||||
args: [],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const errorEmbed = new ErrorEmbed(context, 'Error Message');
|
|
||||||
|
|
||||||
expect(errorEmbed.color?.toString()).toBe('13969411'); // 0xd52803 in decimal
|
|
||||||
expect(errorEmbed.description).toBe('Error Message');
|
|
||||||
expect(errorEmbed.context).toBe(context);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('SendToCurrentChannel', () => {
|
|
||||||
test('Expect embed to be sent to the current channel in context', () => {
|
|
||||||
process.env = {
|
|
||||||
EMBED_COLOUR_ERROR: '0xd52803'
|
|
||||||
}
|
|
||||||
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'command',
|
|
||||||
args: [],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const errorEmbed = new ErrorEmbed(context, 'Error Message');
|
|
||||||
|
|
||||||
errorEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
expect(messageChannelSend).toBeCalledWith(errorEmbed);
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -1,292 +0,0 @@
|
||||||
import { Guild, Message, TextChannel, User } from "discord.js";
|
|
||||||
import { ICommandContext } from "../../../src/contracts/ICommandContext";
|
|
||||||
import EventEmbed from "../../../src/helpers/embeds/EventEmbed";
|
|
||||||
import SettingsHelper from "../../../src/helpers/SettingsHelper";
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
process.env = {};
|
|
||||||
jest.resetAllMocks();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Constructor', () => {
|
|
||||||
test('Expect properties to be set', () => {
|
|
||||||
const guild = {} as unknown as Guild;
|
|
||||||
|
|
||||||
const errorEmbed = new EventEmbed(guild, 'Event Message');
|
|
||||||
|
|
||||||
expect(errorEmbed.color?.toString()).toBe('3166394'); // 0x3050ba in decimal
|
|
||||||
expect(errorEmbed.title).toBe('Event Message');
|
|
||||||
expect(errorEmbed.guild).toBe(guild);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('AddUser', () => {
|
|
||||||
test('Given setThumbnail is false, add field WITHOUT user thumbnail', () => {
|
|
||||||
process.env = {
|
|
||||||
EMBED_COLOUR: '0xd52803',
|
|
||||||
CHANNELS_LOGS_MESSAGE: 'message-logs',
|
|
||||||
CHANNELS_LOGS_MEMBER: 'member-logs',
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs'
|
|
||||||
}
|
|
||||||
|
|
||||||
const addField = jest.fn();
|
|
||||||
const setThumbnail = jest.fn();
|
|
||||||
|
|
||||||
const guild = {} as unknown as Guild;
|
|
||||||
|
|
||||||
const user = {
|
|
||||||
tag: 'USERTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
|
|
||||||
const errorEmbed = new EventEmbed(guild, 'Event Message');
|
|
||||||
|
|
||||||
errorEmbed.addField = addField;
|
|
||||||
errorEmbed.setThumbnail = setThumbnail;
|
|
||||||
|
|
||||||
errorEmbed.AddUser('User', user);
|
|
||||||
|
|
||||||
expect(addField).toBeCalledWith('User', '[object Object] `USERTAG`', true);
|
|
||||||
expect(setThumbnail).not.toBeCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given setThumbnail is true, add field WITH user thumbnail', () => {
|
|
||||||
process.env = {
|
|
||||||
EMBED_COLOUR: '0xd52803',
|
|
||||||
CHANNELS_LOGS_MESSAGE: 'message-logs',
|
|
||||||
CHANNELS_LOGS_MEMBER: 'member-logs',
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs'
|
|
||||||
}
|
|
||||||
|
|
||||||
const addField = jest.fn();
|
|
||||||
const setThumbnail = jest.fn();
|
|
||||||
const displayAvatarURL = jest.fn()
|
|
||||||
.mockReturnValue('image0.png');
|
|
||||||
|
|
||||||
const guild = {} as unknown as Guild;
|
|
||||||
|
|
||||||
const user = {
|
|
||||||
tag: 'USERTAG',
|
|
||||||
displayAvatarURL: displayAvatarURL
|
|
||||||
} as unknown as User;
|
|
||||||
|
|
||||||
const errorEmbed = new EventEmbed(guild, 'Event Message');
|
|
||||||
|
|
||||||
errorEmbed.addField = addField;
|
|
||||||
errorEmbed.setThumbnail = setThumbnail;
|
|
||||||
|
|
||||||
errorEmbed.AddUser('User', user, true);
|
|
||||||
|
|
||||||
expect(addField).toBeCalledWith('User', '[object Object] `USERTAG`', true);
|
|
||||||
expect(setThumbnail).toBeCalledWith('image0.png');
|
|
||||||
expect(displayAvatarURL).toBeCalled();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('AddReason', () => {
|
|
||||||
test('Given a non-empty string is supplied, expect field with message', () => {
|
|
||||||
const guild = {} as Guild;
|
|
||||||
|
|
||||||
const eventEmbed = new EventEmbed(guild, "Event Embed");
|
|
||||||
|
|
||||||
eventEmbed.addField = jest.fn();
|
|
||||||
|
|
||||||
eventEmbed.AddReason("Test reason");
|
|
||||||
|
|
||||||
expect(eventEmbed.addField).toBeCalledWith("Reason", "Test reason");
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given an empty string is supplied, expect field with default message', () => {
|
|
||||||
const guild = {} as Guild;
|
|
||||||
|
|
||||||
const eventEmbed = new EventEmbed(guild, "Event Embed");
|
|
||||||
|
|
||||||
eventEmbed.addField = jest.fn();
|
|
||||||
|
|
||||||
eventEmbed.AddReason("");
|
|
||||||
|
|
||||||
expect(eventEmbed.addField).toBeCalledWith("Reason", "*none*");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('SendToChannel', () => {
|
|
||||||
test('Given channel can be found, expect embed to be sent to that channel', () => {
|
|
||||||
const channelSend = jest.fn();
|
|
||||||
|
|
||||||
const channel = {
|
|
||||||
send: channelSend
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const guildChannelsCacheFind = jest.fn()
|
|
||||||
.mockReturnValue(channel);
|
|
||||||
|
|
||||||
const guild = {
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: guildChannelsCacheFind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} as unknown as Guild;
|
|
||||||
|
|
||||||
const errorEmbed = new EventEmbed(guild, 'Event Message');
|
|
||||||
|
|
||||||
errorEmbed.SendToChannel('channel-name');
|
|
||||||
|
|
||||||
expect(guildChannelsCacheFind).toBeCalledTimes(1);
|
|
||||||
expect(channelSend).toBeCalledWith(errorEmbed);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given channel can NOT be found, expect error logged', () => {
|
|
||||||
process.env = {
|
|
||||||
EMBED_COLOUR: '0xd52803',
|
|
||||||
CHANNELS_LOGS_MESSAGE: 'message-logs',
|
|
||||||
CHANNELS_LOGS_MEMBER: 'member-logs',
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs'
|
|
||||||
}
|
|
||||||
|
|
||||||
const guildChannelsCacheFind = jest.fn()
|
|
||||||
.mockReturnValue(null);
|
|
||||||
|
|
||||||
const guild = {
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: guildChannelsCacheFind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} as unknown as Guild;
|
|
||||||
|
|
||||||
console.error = jest.fn();
|
|
||||||
|
|
||||||
const errorEmbed = new EventEmbed(guild, 'Event Message');
|
|
||||||
|
|
||||||
errorEmbed.SendToChannel('channel-name');
|
|
||||||
|
|
||||||
expect(guildChannelsCacheFind).toBeCalledTimes(1);
|
|
||||||
expect(console.error).toBeCalledWith('Unable to find channel channel-name');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('SendToMessageLogsChannel', () => {
|
|
||||||
test('Given setting is set, expect SendToChannel to be called with value', async () => {
|
|
||||||
const sendToChannel = jest.fn();
|
|
||||||
const getSetting = jest.fn().mockResolvedValue("message-logs");
|
|
||||||
|
|
||||||
const guild = {
|
|
||||||
id: "guildId"
|
|
||||||
} as unknown as Guild;
|
|
||||||
|
|
||||||
SettingsHelper.GetSetting = getSetting;
|
|
||||||
|
|
||||||
const errorEmbed = new EventEmbed(guild, 'Event Message');
|
|
||||||
|
|
||||||
errorEmbed.SendToChannel = sendToChannel;
|
|
||||||
|
|
||||||
await errorEmbed.SendToMessageLogsChannel();
|
|
||||||
|
|
||||||
expect(sendToChannel).toBeCalledWith('message-logs');
|
|
||||||
expect(getSetting).toBeCalledWith("channels.logs.message", "guildId");
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given setting is not set, expect function to return', async () => {
|
|
||||||
const sendToChannel = jest.fn();
|
|
||||||
const getSetting = jest.fn().mockResolvedValue(undefined);
|
|
||||||
|
|
||||||
const guild = {
|
|
||||||
id: "guildId"
|
|
||||||
} as unknown as Guild;
|
|
||||||
|
|
||||||
SettingsHelper.GetSetting = getSetting;
|
|
||||||
|
|
||||||
const errorEmbed = new EventEmbed(guild, 'Event Message');
|
|
||||||
|
|
||||||
errorEmbed.SendToChannel = sendToChannel;
|
|
||||||
|
|
||||||
await errorEmbed.SendToMessageLogsChannel();
|
|
||||||
|
|
||||||
expect(sendToChannel).not.toBeCalled();
|
|
||||||
expect(getSetting).toBeCalledWith("channels.logs.message", "guildId");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('SendToMemberLogsChannel', () => {
|
|
||||||
test('Given setting is set, expect SendToChannel to be called with value', async () => {
|
|
||||||
const sendToChannel = jest.fn();
|
|
||||||
const getSetting = jest.fn().mockResolvedValue("member-logs");
|
|
||||||
|
|
||||||
const guild = {
|
|
||||||
id: "guildId"
|
|
||||||
} as unknown as Guild;
|
|
||||||
|
|
||||||
SettingsHelper.GetSetting = getSetting;
|
|
||||||
|
|
||||||
const errorEmbed = new EventEmbed(guild, 'Event Message');
|
|
||||||
|
|
||||||
errorEmbed.SendToChannel = sendToChannel;
|
|
||||||
|
|
||||||
await errorEmbed.SendToMemberLogsChannel();
|
|
||||||
|
|
||||||
expect(sendToChannel).toBeCalledWith('member-logs');
|
|
||||||
expect(getSetting).toBeCalledWith("channels.logs.member", "guildId");
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given setting is not set, expect function to return', async () => {
|
|
||||||
const sendToChannel = jest.fn();
|
|
||||||
const getSetting = jest.fn().mockResolvedValue(undefined);
|
|
||||||
|
|
||||||
const guild = {
|
|
||||||
id: "guildId"
|
|
||||||
} as unknown as Guild;
|
|
||||||
|
|
||||||
SettingsHelper.GetSetting = getSetting;
|
|
||||||
|
|
||||||
const errorEmbed = new EventEmbed(guild, 'Event Message');
|
|
||||||
|
|
||||||
errorEmbed.SendToChannel = sendToChannel;
|
|
||||||
|
|
||||||
await errorEmbed.SendToMemberLogsChannel();
|
|
||||||
|
|
||||||
expect(sendToChannel).not.toBeCalled();
|
|
||||||
expect(getSetting).toBeCalledWith("channels.logs.member", "guildId");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('SendToModLogsChannel', () => {
|
|
||||||
test('Given setting is set, expect SendToChannel to be called with value', async () => {
|
|
||||||
const sendToChannel = jest.fn();
|
|
||||||
const getSetting = jest.fn().mockResolvedValue("mod-logs");
|
|
||||||
|
|
||||||
const guild = {
|
|
||||||
id: "guildId"
|
|
||||||
} as unknown as Guild;
|
|
||||||
|
|
||||||
SettingsHelper.GetSetting = getSetting;
|
|
||||||
|
|
||||||
const errorEmbed = new EventEmbed(guild, 'Event Message');
|
|
||||||
|
|
||||||
errorEmbed.SendToChannel = sendToChannel;
|
|
||||||
|
|
||||||
await errorEmbed.SendToModLogsChannel();
|
|
||||||
|
|
||||||
expect(sendToChannel).toBeCalledWith('mod-logs');
|
|
||||||
expect(getSetting).toBeCalledWith("channels.logs.mod", "guildId");
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given setting is not set, expect function to return', async () => {
|
|
||||||
const sendToChannel = jest.fn();
|
|
||||||
const getSetting = jest.fn().mockResolvedValue(undefined);
|
|
||||||
|
|
||||||
const guild = {
|
|
||||||
id: "guildId"
|
|
||||||
} as unknown as Guild;
|
|
||||||
|
|
||||||
SettingsHelper.GetSetting = getSetting;
|
|
||||||
|
|
||||||
const errorEmbed = new EventEmbed(guild, 'Event Message');
|
|
||||||
|
|
||||||
errorEmbed.SendToChannel = sendToChannel;
|
|
||||||
|
|
||||||
await errorEmbed.SendToModLogsChannel();
|
|
||||||
|
|
||||||
expect(sendToChannel).not.toBeCalled();
|
|
||||||
expect(getSetting).toBeCalledWith("channels.logs.mod", "guildId");
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -1,407 +0,0 @@
|
||||||
import { Guild, Message, TextChannel, User } from "discord.js";
|
|
||||||
import { ICommandContext } from "../../../src/contracts/ICommandContext";
|
|
||||||
import LogEmbed from "../../../src/helpers/embeds/LogEmbed";
|
|
||||||
import SettingsHelper from "../../../src/helpers/SettingsHelper";
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
process.env = {};
|
|
||||||
jest.resetAllMocks();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Constructor', () => {
|
|
||||||
test('Expect properties to be set', () => {
|
|
||||||
process.env = {
|
|
||||||
EMBED_COLOUR: '0xd52803',
|
|
||||||
CHANNELS_LOGS_MESSAGE: 'message-logs',
|
|
||||||
CHANNELS_LOGS_MEMBER: 'member-logs',
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs'
|
|
||||||
}
|
|
||||||
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'command',
|
|
||||||
args: [],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const errorEmbed = new LogEmbed(context, 'Log Message');
|
|
||||||
|
|
||||||
expect(errorEmbed.color?.toString()).toBe('3166394'); // 0x3050ba in decimal
|
|
||||||
expect(errorEmbed.title).toBe('Log Message');
|
|
||||||
expect(errorEmbed.context).toBe(context);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('AddUser', () => {
|
|
||||||
test('Given setThumbnail is false, add field WITHOUT user thumbnail', () => {
|
|
||||||
process.env = {
|
|
||||||
EMBED_COLOUR: '0xd52803',
|
|
||||||
CHANNELS_LOGS_MESSAGE: 'message-logs',
|
|
||||||
CHANNELS_LOGS_MEMBER: 'member-logs',
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs'
|
|
||||||
}
|
|
||||||
|
|
||||||
const addField = jest.fn();
|
|
||||||
const setThumbnail = jest.fn();
|
|
||||||
|
|
||||||
const user = {
|
|
||||||
tag: 'USERTAG'
|
|
||||||
} as unknown as User;
|
|
||||||
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
author: user
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'command',
|
|
||||||
args: [],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const errorEmbed = new LogEmbed(context, 'Event Message');
|
|
||||||
|
|
||||||
errorEmbed.addField = addField;
|
|
||||||
errorEmbed.setThumbnail = setThumbnail;
|
|
||||||
|
|
||||||
errorEmbed.AddUser('User', user);
|
|
||||||
|
|
||||||
expect(addField).toBeCalledWith('User', '[object Object] `USERTAG`', true);
|
|
||||||
expect(setThumbnail).not.toBeCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given setThumbnail is true, add field WITH user thumbnail', () => {
|
|
||||||
process.env = {
|
|
||||||
EMBED_COLOUR: '0xd52803',
|
|
||||||
CHANNELS_LOGS_MESSAGE: 'message-logs',
|
|
||||||
CHANNELS_LOGS_MEMBER: 'member-logs',
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs'
|
|
||||||
}
|
|
||||||
|
|
||||||
const addField = jest.fn();
|
|
||||||
const setThumbnail = jest.fn();
|
|
||||||
const displayAvatarURL = jest.fn()
|
|
||||||
.mockReturnValue('image0.png');
|
|
||||||
|
|
||||||
const user = {
|
|
||||||
tag: 'USERTAG',
|
|
||||||
displayAvatarURL: displayAvatarURL
|
|
||||||
} as unknown as User;
|
|
||||||
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
author: user
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'command',
|
|
||||||
args: [],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const errorEmbed = new LogEmbed(context, 'Event Message');
|
|
||||||
|
|
||||||
errorEmbed.addField = addField;
|
|
||||||
errorEmbed.setThumbnail = setThumbnail;
|
|
||||||
|
|
||||||
errorEmbed.AddUser('User', user, true);
|
|
||||||
|
|
||||||
expect(addField).toBeCalledWith('User', '[object Object] `USERTAG`', true);
|
|
||||||
expect(setThumbnail).toBeCalledWith('image0.png');
|
|
||||||
expect(displayAvatarURL).toBeCalled();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('SendToChannel', () => {
|
|
||||||
test('Given channel can be found, expect embed to be sent to that channel', () => {
|
|
||||||
process.env = {
|
|
||||||
EMBED_COLOUR: '0xd52803',
|
|
||||||
CHANNELS_LOGS_MESSAGE: 'message-logs',
|
|
||||||
CHANNELS_LOGS_MEMBER: 'member-logs',
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs'
|
|
||||||
}
|
|
||||||
|
|
||||||
const channelSend = jest.fn();
|
|
||||||
|
|
||||||
const channel = {
|
|
||||||
send: channelSend
|
|
||||||
} as unknown as TextChannel;
|
|
||||||
|
|
||||||
const guildChannelsCacheFind = jest.fn()
|
|
||||||
.mockReturnValue(channel);
|
|
||||||
|
|
||||||
const guild = {
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: guildChannelsCacheFind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} as unknown as Guild;
|
|
||||||
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
guild: guild
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'command',
|
|
||||||
args: [],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const errorEmbed = new LogEmbed(context, 'Event Message');
|
|
||||||
|
|
||||||
errorEmbed.SendToChannel('channel-name');
|
|
||||||
|
|
||||||
expect(guildChannelsCacheFind).toBeCalledTimes(1);
|
|
||||||
expect(channelSend).toBeCalledWith(errorEmbed);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given channel can NOT be found, expect error logged', () => {
|
|
||||||
process.env = {
|
|
||||||
EMBED_COLOUR: '0xd52803',
|
|
||||||
CHANNELS_LOGS_MESSAGE: 'message-logs',
|
|
||||||
CHANNELS_LOGS_MEMBER: 'member-logs',
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs'
|
|
||||||
}
|
|
||||||
|
|
||||||
const guildChannelsCacheFind = jest.fn()
|
|
||||||
.mockReturnValue(null);
|
|
||||||
|
|
||||||
const guild = {
|
|
||||||
channels: {
|
|
||||||
cache: {
|
|
||||||
find: guildChannelsCacheFind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} as unknown as Guild;
|
|
||||||
|
|
||||||
console.error = jest.fn();
|
|
||||||
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
},
|
|
||||||
guild: guild
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'command',
|
|
||||||
args: [],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const errorEmbed = new LogEmbed(context, 'Event Message');
|
|
||||||
|
|
||||||
errorEmbed.SendToChannel('channel-name');
|
|
||||||
|
|
||||||
expect(guildChannelsCacheFind).toBeCalledTimes(1);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('SendToMessageLogsChannel', () => {
|
|
||||||
test('Given setting is set, expect SendToChannel to be called with value', async () => {
|
|
||||||
const sendToChannel = jest.fn();
|
|
||||||
const getSetting = jest.fn().mockResolvedValue("message-logs");
|
|
||||||
|
|
||||||
const guild = {
|
|
||||||
id: "guildId"
|
|
||||||
} as unknown as Guild;
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
guild: guild
|
|
||||||
} as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'log',
|
|
||||||
args: [],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
SettingsHelper.GetSetting = getSetting;
|
|
||||||
|
|
||||||
const logEmbed = new LogEmbed(context, 'Event Message');
|
|
||||||
|
|
||||||
logEmbed.SendToChannel = sendToChannel;
|
|
||||||
|
|
||||||
await logEmbed.SendToMessageLogsChannel();
|
|
||||||
|
|
||||||
expect(sendToChannel).toBeCalledWith('message-logs');
|
|
||||||
expect(getSetting).toBeCalledWith("channels.logs.message", "guildId");
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given setting is not set, expect function to return', async () => {
|
|
||||||
const sendToChannel = jest.fn();
|
|
||||||
const getSetting = jest.fn().mockResolvedValue(undefined);
|
|
||||||
|
|
||||||
const guild = {
|
|
||||||
id: "guildId"
|
|
||||||
} as unknown as Guild;
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
guild: guild
|
|
||||||
} as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'log',
|
|
||||||
args: [],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
SettingsHelper.GetSetting = getSetting;
|
|
||||||
|
|
||||||
const logEmbed = new LogEmbed(context, 'Event Message');
|
|
||||||
|
|
||||||
logEmbed.SendToChannel = sendToChannel;
|
|
||||||
|
|
||||||
await logEmbed.SendToMessageLogsChannel();
|
|
||||||
|
|
||||||
expect(sendToChannel).not.toBeCalled();
|
|
||||||
expect(getSetting).toBeCalledWith("channels.logs.message", "guildId");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('SendToMemberLogsChannel', () => {
|
|
||||||
test('Given setting is set, expect SendToChannel to be called with value', async () => {
|
|
||||||
const sendToChannel = jest.fn();
|
|
||||||
const getSetting = jest.fn().mockResolvedValue("member-logs");
|
|
||||||
|
|
||||||
const guild = {
|
|
||||||
id: "guildId"
|
|
||||||
} as unknown as Guild;
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
guild: guild
|
|
||||||
} as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'log',
|
|
||||||
args: [],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
SettingsHelper.GetSetting = getSetting;
|
|
||||||
|
|
||||||
const logEmbed = new LogEmbed(context, 'Event Message');
|
|
||||||
|
|
||||||
logEmbed.SendToChannel = sendToChannel;
|
|
||||||
|
|
||||||
await logEmbed.SendToMemberLogsChannel();
|
|
||||||
|
|
||||||
expect(sendToChannel).toBeCalledWith('member-logs');
|
|
||||||
expect(getSetting).toBeCalledWith("channels.logs.member", "guildId");
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given setting is not set, expect function to return', async () => {
|
|
||||||
const sendToChannel = jest.fn();
|
|
||||||
const getSetting = jest.fn().mockResolvedValue(undefined);
|
|
||||||
|
|
||||||
const guild = {
|
|
||||||
id: "guildId"
|
|
||||||
} as unknown as Guild;
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
guild: guild
|
|
||||||
} as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'log',
|
|
||||||
args: [],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
SettingsHelper.GetSetting = getSetting;
|
|
||||||
|
|
||||||
const logEmbed = new LogEmbed(context, 'Event Message');
|
|
||||||
|
|
||||||
logEmbed.SendToChannel = sendToChannel;
|
|
||||||
|
|
||||||
await logEmbed.SendToMemberLogsChannel();
|
|
||||||
|
|
||||||
expect(sendToChannel).not.toBeCalled();
|
|
||||||
expect(getSetting).toBeCalledWith("channels.logs.member", "guildId");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('SendToModLogsChannel', () => {
|
|
||||||
test('Given setting is set, expect SendToChannel to be called with value', async () => {
|
|
||||||
const sendToChannel = jest.fn();
|
|
||||||
const getSetting = jest.fn().mockResolvedValue("mod-logs");
|
|
||||||
|
|
||||||
const guild = {
|
|
||||||
id: "guildId"
|
|
||||||
} as unknown as Guild;
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
guild: guild
|
|
||||||
} as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'log',
|
|
||||||
args: [],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
SettingsHelper.GetSetting = getSetting;
|
|
||||||
|
|
||||||
const logEmbed = new LogEmbed(context, 'Event Message');
|
|
||||||
|
|
||||||
logEmbed.SendToChannel = sendToChannel;
|
|
||||||
|
|
||||||
await logEmbed.SendToModLogsChannel();
|
|
||||||
|
|
||||||
expect(sendToChannel).toBeCalledWith('mod-logs');
|
|
||||||
expect(getSetting).toBeCalledWith("channels.logs.mod", "guildId");
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Given setting is not set, expect function to return', async () => {
|
|
||||||
const sendToChannel = jest.fn();
|
|
||||||
const getSetting = jest.fn().mockResolvedValue(undefined);
|
|
||||||
|
|
||||||
const guild = {
|
|
||||||
id: "guildId"
|
|
||||||
} as unknown as Guild;
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
guild: guild
|
|
||||||
} as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'log',
|
|
||||||
args: [],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
SettingsHelper.GetSetting = getSetting;
|
|
||||||
|
|
||||||
const logEmbed = new LogEmbed(context, 'Event Message');
|
|
||||||
|
|
||||||
logEmbed.SendToChannel = sendToChannel;
|
|
||||||
|
|
||||||
await logEmbed.SendToModLogsChannel();
|
|
||||||
|
|
||||||
expect(sendToChannel).not.toBeCalled();
|
|
||||||
expect(getSetting).toBeCalledWith("channels.logs.mod", "guildId");
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -1,67 +0,0 @@
|
||||||
import { Guild, Message, TextChannel, User } from "discord.js";
|
|
||||||
import { ICommandContext } from "../../../src/contracts/ICommandContext";
|
|
||||||
import PublicEmbed from "../../../src/helpers/embeds/PublicEmbed";
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
process.env = {};
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Constructor', () => {
|
|
||||||
test('Expect properties to be set', () => {
|
|
||||||
process.env = {
|
|
||||||
EMBED_COLOUR: '0xd52803',
|
|
||||||
CHANNELS_LOGS_MESSAGE: 'message-logs',
|
|
||||||
CHANNELS_LOGS_MEMBER: 'member-logs',
|
|
||||||
CHANNELS_LOGS_MOD: 'mod-logs'
|
|
||||||
}
|
|
||||||
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'command',
|
|
||||||
args: [],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const errorEmbed = new PublicEmbed(context, 'Log Message', 'Log Description');
|
|
||||||
|
|
||||||
expect(errorEmbed.color?.toString()).toBe('13969411'); // 0xd52803 in decimal
|
|
||||||
expect(errorEmbed.title).toBe('Log Message');
|
|
||||||
expect(errorEmbed.description).toBe('Log Description');
|
|
||||||
expect(errorEmbed.context).toBe(context);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('SendToCurrentChannel', () => {
|
|
||||||
test('Expect embed to be sent to the current channel in context', () => {
|
|
||||||
process.env = {
|
|
||||||
EMBED_COLOUR_ERROR: '0xd52803'
|
|
||||||
}
|
|
||||||
|
|
||||||
const messageChannelSend = jest.fn();
|
|
||||||
|
|
||||||
const message = {
|
|
||||||
channel: {
|
|
||||||
send: messageChannelSend
|
|
||||||
}
|
|
||||||
} as unknown as Message;
|
|
||||||
|
|
||||||
const context: ICommandContext = {
|
|
||||||
name: 'command',
|
|
||||||
args: [],
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const errorEmbed = new PublicEmbed(context, 'Message', 'Description');
|
|
||||||
|
|
||||||
errorEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
expect(messageChannelSend).toBeCalledWith(errorEmbed);
|
|
||||||
});
|
|
||||||
});
|
|
11
tests/registry.test.ts
Normal file
11
tests/registry.test.ts
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
describe('RegisterCommands', () => {
|
||||||
|
test.todo("EXPECT commands to be registered");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('RegisterEvents', () => {
|
||||||
|
test.todo("EXPECT events to be registered");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('RegisterButtonEvents', () => {
|
||||||
|
test.todo("EXPECT button events to be registered");
|
||||||
|
});
|
Loading…
Reference in a new issue