Add list moons command #449

Merged
Vylpes merged 15 commits from feature/195-list-moons into develop 2024-08-17 16:47:14 +01:00
30 changed files with 70 additions and 8489 deletions
Showing only changes of commit dc9963c7fb - Show all commits

View file

@ -29,7 +29,7 @@ jobs:
needs: build
runs-on: node
steps:
- uses: https://github.com/appleboy/ssh-action@v1.0.0
- uses: https://github.com/appleboy/ssh-action@v1.0.3
env:
DB_NAME: ${{ secrets.PROD_DB_NAME }}
DB_AUTH_USER: ${{ secrets.PROD_DB_AUTH_USER }}

View file

@ -29,7 +29,7 @@ jobs:
needs: build
runs-on: node
steps:
- uses: https://github.com/appleboy/ssh-action@v1.0.0
- uses: https://github.com/appleboy/ssh-action@v1.0.3
env:
DB_NAME: ${{ secrets.STAGE_DB_NAME }}
DB_AUTH_USER: ${{ secrets.STAGE_DB_AUTH_USER }}

View file

@ -8,7 +8,7 @@
"clean": "rm -rf node_modules/ dist/",
"build": "tsc",
"start": "node ./dist/vylbot",
"test": "echo true",
"test": "jest . --passWithNoTests",
"db:up": "typeorm migration:run -d dist/database/dataSources/appDataSource.js",
"db:down": "typeorm migration:revert -d dist/database/dataSources/appDataSource.js",
"db:create": "typeorm migration:create ./src/database/migrations",

View file

@ -1,10 +0,0 @@
import { Command } from "../../../src/type/command";
export default class MockCmd extends Command {
constructor() {
super();
super._category = "General";
super._roles = ["Moderator"];
}
}

View file

@ -1,13 +0,0 @@
[
{
"image": "IMAGEURL"
},
{
"title": "TITLE 1",
"description": [
"DESCRIPTION 1A",
"DESCRIPTION 1B"
],
"footer": "FOOTER 1"
}
]

View file

@ -1,153 +0,0 @@
import { mock } from "jest-mock-extended";
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");
jest.mock("dotenv");
jest.mock("../../src/client/events");
jest.mock("../../src/client/util");
jest.mock("../../src/constants/DefaultValues");
import { CoreClient } from "../../src/client/client";
import { Client } from "discord.js";
import * as dotenv from "dotenv";
import { Events } from "../../src/client/events";
import { Util } from "../../src/client/util";
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', () => {
test('Expect command added to register', () => {
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', () => {
test('Expect event added to register', () => {
const evt = mock<Event>();
const client = new CoreClient();
client.RegisterEvent(evt);
expect(client.eventItems.length).toBe(1);
expect(client.eventItems[0].Event).toBe(evt);
});
});

View file

@ -1,241 +0,0 @@
import { Events } from "../../src/client/events";
import { Message } from "discord.js";
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");
beforeEach(() => {
Util.prototype.loadCommand = jest.fn();
});
describe('OnMessage', () => {
test('Given Message Is Valid Expect Message Sent', 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: "!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");
});
});

View file

@ -1,370 +0,0 @@
import { Util } from "../../src/client/util";
import { Client, Message } from "discord.js";
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', () => {
test('Given Successful Exection, 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>();
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).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>();
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("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>();
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).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>();
cmd._roles = [ "Moderator" ];
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("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);
});
});

View file

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

View file

@ -1,724 +0,0 @@
import { GuildMember, Message, TextChannel, User } from "discord.js";
import Ban from "../../src/commands/ban";
import { ICommandContext } from "../../src/contracts/ICommandContext";
beforeEach(() => {
process.env = {};
});
describe('Constructor', () => {
test('Expect values to be set', () => {
process.env.ROLES_MODERATOR = 'Moderator';
const ban = new Ban();
expect(ban._category).toBe('Moderation');
expect(ban._roles.length).toBe(1);
expect(ban._roles[0]).toBe('Moderator');
});
});
describe('Execute', () => {
test('Given user has permission, expect user to be banned', 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(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 () => {
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'],
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?');
});
});

View file

@ -1,178 +0,0 @@
import { Message } from "discord.js";
import Clear from "../../src/commands/clear";
import { ICommandContext } from "../../src/contracts/ICommandContext";
beforeEach(() => {
process.env = {};
});
describe('Constructor', () => {
test('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', () => {
test('Given valid arguments, expect messages to be cleared', 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: ['5'],
message: message
};
const clear = new Clear();
const result = await clear.execute(context);
expect(messageChannelSend).toBeCalledTimes(1);
expect(messageChannelBulkDelete).toBeCalledWith(5);
expect(result.embeds.length).toBe(1);
// PublicEmbed
const publicEmbed = result.embeds[0];
expect(publicEmbed.title).toBe('');
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');
});
});

View file

@ -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');
});
});

View file

@ -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();
});
});

View file

@ -1,549 +0,0 @@
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(() => {
process.env = {};
});
describe('Constructor', () => {
test('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', () => {
test('Given user has permission, expect user to be kicked', 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", "Test", "Reason"],
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: 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?');
});
});

View file

@ -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');
});
});

View file

@ -1,262 +0,0 @@
import { Message, MessageEmbed } from "discord.js";
import Poll from "../../src/commands/poll";
import { ICommandContext } from "../../src/contracts/ICommandContext";
describe('Constructor', () => {
test('Expect properties to be set', () => {
const poll = new Poll();
expect(poll._category).toBe('General');
});
});
describe('Execute', () => {
test('Given input is valid, 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'],
message: message
};
const poll = new Poll();
const result = await poll.execute(context);
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');
});
});

View file

@ -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');
});
});

View file

@ -1,106 +0,0 @@
import { Message } from "discord.js";
import Rules from "../../src/commands/rules";
import { ICommandContext } from "../../src/contracts/ICommandContext";
const oldCwd = process.cwd();
beforeEach(() => {
process.env = {};
});
describe('Constructor', () => {
test('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', () => {
test('Given rules exist, expect rules to be sent to current channel', () => {
process.env = {
COMMANDS_RULES_FILE: 'rules/rules.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(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");
});
});

View file

@ -1,766 +0,0 @@
import { APIEmbed, CacheType, CommandInteraction, CommandInteractionOption, DMChannel, Embed, EmbedBuilder, EmbedField, Guild, GuildChannel, GuildMember, InteractionReplyOptions, JSONEncodable, Message, MessageCreateOptions, MessagePayload, SlashCommandBuilder, TextChannel, User } from "discord.js";
import { mock } from "jest-mock-extended";
import Timeout from "../../src/commands/timeout";
import SettingsHelper from "../../src/helpers/SettingsHelper";
import Audit from "../../src/database/entities/Audit";
import EmbedColours from "../../src/constants/EmbedColours";
import { DeepPartial, EntityTarget } from "typeorm";
import BaseEntity from "../../src/contracts/BaseEntity";
import { AuditType } from "../../src/constants/AuditType";
describe('Constructor', () => {
test('EXPECT CommandBuilder to be configured', () => {
const command = new Timeout();
expect(command.CommandBuilder).toBeDefined();
const commandBuilder = command.CommandBuilder as SlashCommandBuilder;
expect(commandBuilder.name).toBe("timeout");
expect(commandBuilder.description).toBe("Timeouts a user out, sending them a DM with the reason if possible");
expect(commandBuilder.options.length).toBe(3);
});
});
describe('execute', () => {
// Happy flow
test('GIVEN all checks have passed, EXPECT user to be timed out', async () => {
let embeds: APIEmbed[] | undefined;
const command = new Timeout();
const interactionReply = jest.fn((options: InteractionReplyOptions) => {
embeds = options.embeds as APIEmbed[];
});
let savedAudit: DeepPartial<Audit> | undefined;
const getSetting = jest.spyOn(SettingsHelper, 'GetSetting').mockResolvedValue('mod-logs');
const auditSave = jest.spyOn(Audit.prototype, 'Save').mockImplementation((target: EntityTarget<BaseEntity>, entity: DeepPartial<BaseEntity>): Promise<void> => {
savedAudit = entity;
return Promise.resolve();
});
const timeoutFunc = jest.fn();
let dmChannelSentEmbeds: (APIEmbed | JSONEncodable<APIEmbed>)[] | undefined;
let logsChannelSentEmbeds: (APIEmbed | JSONEncodable<APIEmbed>)[] | undefined;
const dmChannel = {
send: jest.fn().mockImplementation((options: MessageCreateOptions) => {
dmChannelSentEmbeds = options.embeds;
}),
} as unknown as DMChannel;
const userInput = {
user: {
id: 'userId',
tag: 'userTag',
createDM: jest.fn().mockResolvedValue(dmChannel),
} as unknown as User,
member: {
manageable: true,
timeout: timeoutFunc,
} as unknown as GuildMember,
} as CommandInteractionOption;
const lengthInput = {
value: '1s',
} as CommandInteractionOption;
const reasonInput = {
value: 'Test reason',
} as CommandInteractionOption;
const logsChannel = {
name: 'mod-logs',
send: jest.fn().mockImplementation((options: MessageCreateOptions) => {
logsChannelSentEmbeds = options.embeds;
}),
} as unknown as TextChannel;
const interaction = {
guild: {
channels: {
cache: {
find: jest.fn()
.mockReturnValue(logsChannel),
}
},
name: "Test Guild",
} as unknown as Guild,
guildId: 'guildId',
reply: interactionReply,
options: {
get: jest.fn()
.mockReturnValueOnce(userInput)
.mockReturnValueOnce(lengthInput)
.mockReturnValue(reasonInput),
},
user: {
id: 'moderatorId'
}
} as unknown as CommandInteraction;
await command.execute(interaction);
// EXPECT user to be timed out
expect(timeoutFunc).toBeCalledWith(1000, 'Test reason');
// EXPECT embeds to be sent
expect(embeds).toBeDefined();
expect(embeds!.length).toBe(1);
// EXPECT resultEmbed to be correctly configured
const resultEmbed = embeds![0] as EmbedBuilder;
expect(resultEmbed.data.description).toBe('<@userId> has been timed out');
expect(resultEmbed.data.fields).toBeDefined();
expect(resultEmbed.data.fields!.length).toBe(1);
// EXPECT DM field to be configured
const resultEmbedDMField = resultEmbed.data.fields![0];
expect(resultEmbedDMField.name).toBe("DM Sent");
expect(resultEmbedDMField.value).toBe("true");
// EXPECT user to be DM's with embed
expect(dmChannel.send).toBeCalled();
expect(dmChannelSentEmbeds).toBeDefined();
expect(dmChannelSentEmbeds?.length).toBe(1);
const dmChannelSentEmbed = (dmChannelSentEmbeds![0] as any).data;
expect(dmChannelSentEmbed.color).toBe(EmbedColours.Ok);
expect(dmChannelSentEmbed.description).toBe("You have been timed out in Test Guild");
expect(dmChannelSentEmbed.fields?.length).toBe(3);
expect(dmChannelSentEmbed.fields![0].name).toBe("Reason");
expect(dmChannelSentEmbed.fields![0].value).toBe("Test reason");
expect(dmChannelSentEmbed.fields![1].name).toBe("Length");
expect(dmChannelSentEmbed.fields![1].value).toBe("1s");
expect(dmChannelSentEmbed.fields![2].name).toBe("Until");
expect(dmChannelSentEmbed.fields![2].value).toBeDefined();
// EXPECT log embed to be sent
expect(logsChannel.send).toBeCalled();
expect(logsChannelSentEmbeds).toBeDefined();
expect(logsChannelSentEmbeds?.length).toBe(1);
const logsChannelSentEmbed = (logsChannelSentEmbeds![0] as any).data;
expect(logsChannelSentEmbed.color).toBe(EmbedColours.Ok);
expect(logsChannelSentEmbed.title).toBe("Member Timed Out");
expect(logsChannelSentEmbed.description).toBe("<@userId> `userTag`");
expect(logsChannelSentEmbed.fields?.length).toBe(4);
expect(logsChannelSentEmbed.fields![0].name).toBe("Moderator");
expect(logsChannelSentEmbed.fields![0].value).toBe("<@moderatorId>");
expect(logsChannelSentEmbed.fields![1].name).toBe("Reason");
expect(logsChannelSentEmbed.fields![1].value).toBe("Test reason");
expect(logsChannelSentEmbed.fields![2].name).toBe("Length");
expect(logsChannelSentEmbed.fields![2].value).toBe("1s");
expect(logsChannelSentEmbed.fields![3].name).toBe("Until");
expect(logsChannelSentEmbed.fields![3].value).toBeDefined();
// EXPECT Audit to be saved
expect(auditSave).toBeCalled();
expect(savedAudit).toBeDefined();
expect(savedAudit?.UserId).toBe('userId');
expect(savedAudit?.AuditType).toBe(AuditType.Timeout);
expect(savedAudit?.Reason).toBe("Test reason");
expect(savedAudit?.ModeratorId).toBe('moderatorId');
expect(savedAudit?.ServerId).toBe('guildId');
});
// Null checks
test('GIVEN interaction.guild IS NULL, EXPECT nothing to happen', async () => {
const command = new Timeout();
const interaction = {
guild: null,
reply: jest.fn(),
} as unknown as CommandInteraction;
await command.execute(interaction);
expect(interaction.reply).not.toBeCalled();
});
test('GIVEN interaction.guildId IS NULL, EXPECT nothing to happen', async () => {
const command = new Timeout();
const interaction = {
guild: mock<Guild>(),
guildId: null,
reply: jest.fn(),
} as unknown as CommandInteraction;
await command.execute(interaction);
expect(interaction.reply).not.toBeCalled();
});
// Validation
test('GIVEN targetUser IS NULL, EXPECT validation error', async () => {
const command = new Timeout();
const interaction = {
reply: jest.fn(),
guild: mock<Guild>(),
guildId: 'guildId',
options: {
get: jest.fn().mockReturnValue(undefined),
}
} as unknown as CommandInteraction;
await command.execute(interaction);
expect(interaction.reply).toBeCalledWith('Fields are required.');
});
test('GIVEN targetUser.user IS NULL, EXPECT validation error', async () => {
const command = new Timeout();
const interaction = {
reply: jest.fn(),
guild: mock<Guild>(),
guildId: 'guildId',
options: {
get: jest.fn((value: string): CommandInteractionOption<CacheType> | null => {
switch (value) {
case 'target':
return {} as CommandInteractionOption;
case 'length':
return {
value: '1m',
} as CommandInteractionOption;
case 'reason':
return {
value: 'Test reason',
} as CommandInteractionOption;
default:
return null;
}
}),
}
} as unknown as CommandInteraction;
await command.execute(interaction);
expect(interaction.reply).toBeCalledWith('Fields are required.');
});
test('GIVEN targetUser.member IS NULL, EXPECT validation error', async () => {
const command = new Timeout();
const interaction = {
reply: jest.fn(),
guild: mock<Guild>(),
guildId: 'guildId',
options: {
get: jest.fn((value: string): CommandInteractionOption<CacheType> | null => {
switch (value) {
case 'target':
return {
user: {} as User,
} as CommandInteractionOption;
case 'length':
return {
value: '1m',
} as CommandInteractionOption;
case 'reason':
return {
value: 'Test reason',
} as CommandInteractionOption;
default:
return null;
}
}),
}
} as unknown as CommandInteraction;
await command.execute(interaction);
expect(interaction.reply).toBeCalledWith('Fields are required.');
});
test('GIVEN lengthInput IS NULL, EXPECT validation error', async () => {
const command = new Timeout();
const interaction = {
reply: jest.fn(),
guild: mock<Guild>(),
guildId: 'guildId',
options: {
get: jest.fn((value: string): CommandInteractionOption<CacheType> | null => {
switch (value) {
case 'target':
return {
user: {} as User,
member: {} as GuildMember
} as CommandInteractionOption;
case 'length':
return null;
case 'reason':
return {
value: 'Test reason',
} as CommandInteractionOption;
default:
return null;
}
}),
}
} as unknown as CommandInteraction;
await command.execute(interaction);
expect(interaction.reply).toBeCalledWith('Fields are required.');
});
test('GIVEN lengthInput.value IS NULL, EXPECT validation error', async () => {
const command = new Timeout();
const interaction = {
reply: jest.fn(),
guild: mock<Guild>(),
guildId: 'guildId',
options: {
get: jest.fn((value: string): CommandInteractionOption<CacheType> | null => {
switch (value) {
case 'target':
return {
user: {} as User,
member: {} as GuildMember
} as CommandInteractionOption;
case 'length':
return {
value: undefined,
} as CommandInteractionOption;
case 'reason':
return {
value: 'Test reason',
} as CommandInteractionOption;
default:
return null;
}
}),
}
} as unknown as CommandInteraction;
await command.execute(interaction);
expect(interaction.reply).toBeCalledWith('Fields are required.');
});
test('GIVEN targetUser is a bot, EXPECT error', async () => {
const interaction = {
reply: jest.fn(),
guild: mock<Guild>(),
guildId: 'guildId',
options: {
get: jest.fn((value: string): CommandInteractionOption<CacheType> | null => {
switch (value) {
case 'target':
return {
user: {
bot: true,
} as User,
member: {} as GuildMember
} as CommandInteractionOption;
case 'length':
return {
value: '1m',
} as CommandInteractionOption;
case 'reason':
return {
value: 'Test reason',
} as CommandInteractionOption;
default:
return null;
}
}),
}
} as unknown as CommandInteraction;
const command = new Timeout();
await command.execute(interaction);
expect(interaction.reply).toBeCalledWith('Cannot timeout bots.');
});
test('GIVEN targetMember IS NOT manageable by the bot, EXPECT insufficient permissions error', async () => {
const command = new Timeout();
const interaction = {
reply: jest.fn(),
guild: mock<Guild>(),
guildId: 'guildId',
user: {
id: 'moderatorId',
},
options: {
get: jest.fn((value: string): CommandInteractionOption<CacheType> | null => {
switch (value) {
case 'target':
return {
user: {
id: 'userId',
tag: 'userTag',
} as User,
member: {
manageable: false,
} as GuildMember
} as CommandInteractionOption;
case 'length':
return {
value: '1m',
} as CommandInteractionOption;
case 'reason':
return {
value: 'Test reason',
} as CommandInteractionOption;
default:
return null;
}
}),
}
} as unknown as CommandInteraction;
await command.execute(interaction);
expect(interaction.reply).toBeCalledWith('Insufficient bot permissions. Please contact a moderator.');
});
// Reason variable
test('GIVEN reason IS NULL, EXPECT to be ran with empty string', async () => {
const command = new Timeout();
let savedAudit: DeepPartial<Audit> | undefined;
const auditSave = jest.spyOn(Audit.prototype, 'Save').mockImplementation((target: EntityTarget<BaseEntity>, entity: DeepPartial<BaseEntity>): Promise<void> => {
savedAudit = entity;
return Promise.resolve();
});
const timeoutFunc = jest.fn();
const sentEmbeds: EmbedBuilder[] = [];
const interaction = {
reply: jest.fn(),
guild: {
channels: {
cache: {
find: jest.fn().mockReturnValue(mock<TextChannel>()),
}
}
},
guildId: 'guildId',
user: {
id: 'moderatorId',
},
options: {
get: jest.fn((value: string): CommandInteractionOption<CacheType> | null => {
switch (value) {
case 'target':
return {
user: {
id: 'userId',
tag: 'userTag',
createDM: jest.fn().mockReturnValue({
send: jest.fn(async (options: MessageCreateOptions): Promise<Message<false>> => {
sentEmbeds.push(options.embeds![0] as EmbedBuilder);
return mock<Message<false>>();
})
}) as unknown as DMChannel,
} as unknown as User,
member: {
manageable: true,
timeout: timeoutFunc,
} as unknown as GuildMember
} as CommandInteractionOption;
case 'length':
return {
value: '1m'
} as CommandInteractionOption;
case 'reason':
return {
value: undefined,
} as CommandInteractionOption;
default:
return null;
}
}),
}
} as unknown as CommandInteraction;
await command.execute(interaction);
expect(timeoutFunc).toBeCalledWith(1000 * 60 * 1, "");
expect(savedAudit?.Reason).toBe("*none*");
const dmEmbed = (sentEmbeds[0] as any).data;
const dmEmbedReasonField = dmEmbed.fields![0] as EmbedField;
expect(dmEmbedReasonField.value).toBe("*none*");
});
// Log embed
test('GIVEN channelName IS NULL, EXPECT execution to return', async () => {
const command = new Timeout();
let savedAudit: DeepPartial<Audit> | undefined;
const auditSave = jest.spyOn(Audit.prototype, 'Save').mockImplementation((target: EntityTarget<BaseEntity>, entity: DeepPartial<BaseEntity>): Promise<void> => {
savedAudit = entity;
return Promise.resolve();
});
const settingsGet = jest.spyOn(SettingsHelper, 'GetSetting').mockResolvedValue(undefined);
const timeoutFunc = jest.fn();
const sentEmbeds: EmbedBuilder[] = [];
const logChannelSendFunc = jest.fn();
const interaction = {
reply: jest.fn(),
guild: {
channels: {
cache: {
find: jest.fn().mockReturnValue({
send: logChannelSendFunc,
} as unknown as TextChannel),
}
}
},
guildId: 'guildId',
user: {
id: 'moderatorId',
},
options: {
get: jest.fn((value: string): CommandInteractionOption<CacheType> | null => {
switch (value) {
case 'target':
return {
user: {
id: 'userId',
tag: 'userTag',
createDM: jest.fn().mockReturnValue({
send: jest.fn(async (options: MessageCreateOptions): Promise<Message<false>> => {
sentEmbeds.push(options.embeds![0] as EmbedBuilder);
return mock<Message<false>>();
})
}) as unknown as DMChannel,
} as unknown as User,
member: {
manageable: true,
timeout: timeoutFunc,
} as unknown as GuildMember
} as CommandInteractionOption;
case 'length':
return {
value: '1m'
} as CommandInteractionOption;
case 'reason':
return {
value: 'Test reason',
} as CommandInteractionOption;
default:
return null;
}
}),
}
} as unknown as CommandInteraction;
await command.execute(interaction);
expect(timeoutFunc).toBeCalled();
expect(sentEmbeds.length).toBe(0);
expect(logChannelSendFunc).not.toBeCalled();
});
test('GIVEN channel IS NULL, EXPECT embed to not be sent', async () => {
const command = new Timeout();
let savedAudit: DeepPartial<Audit> | undefined;
const auditSave = jest.spyOn(Audit.prototype, 'Save').mockImplementation((target: EntityTarget<BaseEntity>, entity: DeepPartial<BaseEntity>): Promise<void> => {
savedAudit = entity;
return Promise.resolve();
});
const settingsGet = jest.spyOn(SettingsHelper, 'GetSetting').mockResolvedValue('mod-logs');
const timeoutFunc = jest.fn();
const sentEmbeds: EmbedBuilder[] = [];
const interaction = {
reply: jest.fn(),
guild: {
channels: {
cache: {
find: jest.fn().mockReturnValue(undefined),
}
}
},
guildId: 'guildId',
user: {
id: 'moderatorId',
},
options: {
get: jest.fn((value: string): CommandInteractionOption<CacheType> | null => {
switch (value) {
case 'target':
return {
user: {
id: 'userId',
tag: 'userTag',
createDM: jest.fn().mockReturnValue({
send: jest.fn(async (options: MessageCreateOptions): Promise<Message<false>> => {
sentEmbeds.push(options.embeds![0] as EmbedBuilder);
return mock<Message<false>>();
})
}) as unknown as DMChannel,
} as unknown as User,
member: {
manageable: true,
timeout: timeoutFunc,
} as unknown as GuildMember
} as CommandInteractionOption;
case 'length':
return {
value: '1m'
} as CommandInteractionOption;
case 'reason':
return {
value: 'Test reason',
} as CommandInteractionOption;
default:
return null;
}
}),
}
} as unknown as CommandInteraction;
await command.execute(interaction);
expect(timeoutFunc).toBeCalled();
expect(sentEmbeds.length).toBeGreaterThan(0);
});
// DM user
test('GIVEN user can NOT be messaged, EXPECT resultEmbed to contain "DM Sent = false"', async () => {
let embeds: APIEmbed[] | undefined;
const command = new Timeout();
const interactionReply = jest.fn((options: InteractionReplyOptions) => {
embeds = options.embeds as APIEmbed[];
});
let savedAudit: DeepPartial<Audit> | undefined;
const getSetting = jest.spyOn(SettingsHelper, 'GetSetting').mockResolvedValue('mod-logs');
const auditSave = jest.spyOn(Audit.prototype, 'Save').mockImplementation((target: EntityTarget<BaseEntity>, entity: DeepPartial<BaseEntity>): Promise<void> => {
savedAudit = entity;
return Promise.resolve();
});
const timeoutFunc = jest.fn();
let dmChannelSentEmbeds: (APIEmbed | JSONEncodable<APIEmbed>)[] | undefined;
let logsChannelSentEmbeds: (APIEmbed | JSONEncodable<APIEmbed>)[] | undefined;
const dmChannel = {
send: jest.fn().mockImplementation((options: MessageCreateOptions) => {
dmChannelSentEmbeds = options.embeds;
}),
} as unknown as DMChannel;
const userInput = {
user: {
id: 'userId',
tag: 'userTag',
createDM: jest.fn().mockRejectedValue(undefined),
} as unknown as User,
member: {
manageable: true,
timeout: timeoutFunc,
} as unknown as GuildMember,
} as CommandInteractionOption;
const lengthInput = {
value: '1s',
} as CommandInteractionOption;
const reasonInput = {
value: 'Test reason',
} as CommandInteractionOption;
const logsChannel = {
name: 'mod-logs',
send: jest.fn().mockImplementation((options: MessageCreateOptions) => {
logsChannelSentEmbeds = options.embeds;
}),
} as unknown as TextChannel;
const interaction = {
guild: {
channels: {
cache: {
find: jest.fn()
.mockReturnValue(logsChannel),
}
},
name: "Test Guild",
} as unknown as Guild,
guildId: 'guildId',
reply: interactionReply,
options: {
get: jest.fn()
.mockReturnValueOnce(userInput)
.mockReturnValueOnce(lengthInput)
.mockReturnValue(reasonInput),
},
user: {
id: 'moderatorId'
}
} as unknown as CommandInteraction;
await command.execute(interaction);
// EXPECT embeds to be sent
expect(embeds).toBeDefined();
expect(embeds!.length).toBe(1);
const resultEmbed = embeds![0] as EmbedBuilder;
// EXPECT DM field to be configured
const resultEmbedDMField = resultEmbed.data.fields![0];
expect(resultEmbedDMField.name).toBe("DM Sent");
expect(resultEmbedDMField.value).toBe("false");
});
});

View file

@ -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');
});
});

View file

@ -1,485 +0,0 @@
import { GuildMember, Message, TextChannel, User } from "discord.js";
import Warn from "../../src/commands/warn";
import { ICommandContext } from "../../src/contracts/ICommandContext";
beforeEach(() => {
process.env = {};
});
describe('Constructor', () => {
test('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', () => {
test('Given user has permission, expect user to be warnned', 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: 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).toBeCalledTimes(1);
});
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 = {
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);
});
});

View file

@ -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);
});
});

View file

@ -1,235 +0,0 @@
import { GuildMember, TextChannel } from "discord.js";
import GuildMemberUpdate from "../../../src/events/MemberEvents/GuildMemberUpdate";
beforeEach(() => {
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*');
});
});

View file

@ -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*```');
});
});

View file

@ -1,11 +0,0 @@
import StringTools from "../../src/helpers/StringTools";
describe('Capitalise', () => {
test('Expect sentence to be captilised', () => {
const inputString = 'the big brown fox jumps over the lazy dog';
const result = StringTools.Capitalise(inputString);
expect(result).toBe('The Big Brown Fox Jumps Over The Lazy Dog');
});
});

View file

@ -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);
});
});

View file

@ -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");
});
});

View file

@ -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");
});
});

View file

@ -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);
});
});

221
yarn.lock
View file

@ -367,9 +367,9 @@
ws "^8.16.0"
"@inquirer/figures@^1.0.3":
version "1.0.3"
resolved "https://registry.yarnpkg.com/@inquirer/figures/-/figures-1.0.3.tgz#1227cc980f88e6d6ab85abadbf164f5038041edd"
integrity sha512-ErXXzENMH5pJt5/ssXV0DfWUZqly8nGzf0UcBV9xTnP+KyffE2mqyxIMBrZ8ijQck2nU0TQm40EQB53YreyWHw==
version "1.0.5"
resolved "https://registry.yarnpkg.com/@inquirer/figures/-/figures-1.0.5.tgz#57f9a996d64d3e3345d2a3ca04d36912e94f8790"
integrity sha512-79hP/VWdZ2UVc9bFGJnoQ/lQMpL74mGgzSYX1xUqCVk7/v73vJCMw1VuyWN1jGkZ9B3z7THAbySqGbCNefcjfA==
"@isaacs/cliui@^8.0.2":
version "8.0.2"
@ -705,11 +705,6 @@
resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-4.6.0.tgz#3c7c9c46e678feefe7a2e5bb609d3dbd665ffb3f"
integrity sha512-t09vSN3MdfsyCHoFcTRCH/iUtG7OJ0CsjzB8cjAmKc/va/kIgeDI/TxsigdncE/4be734m0cvIYwNaV4i2XqAw==
"@sindresorhus/is@^5.2.0":
version "5.6.0"
resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-5.6.0.tgz#41dd6093d34652cddb5d5bdeee04eafc33826668"
integrity sha512-TV7t8GKYaJWsn00tFDqBw8+Uqmr8A0fRU1tvTQhyZzGv0sJCGRQL3JGMI3ucuKo3XIZdUP+Lx7/gh2t3lewy7g==
"@sinonjs/commons@^3.0.0":
version "3.0.1"
resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-3.0.1.tgz#1029357e44ca901a615585f6d27738dbc89084cd"
@ -736,13 +731,6 @@
dependencies:
defer-to-connect "^2.0.0"
"@szmarczak/http-timer@^5.0.1":
version "5.0.1"
resolved "https://registry.yarnpkg.com/@szmarczak/http-timer/-/http-timer-5.0.1.tgz#c7c1bf1141cdd4751b0399c8fc7b8b664cd5be3a"
integrity sha512-+PmQX0PiAYPMeVYe237LJAYvOMYW1j2rH5YROyS3b4CTVJum34HfRvKvAzozHAQG0TnHNdUfY9nCeUyRAs//cw==
dependencies:
defer-to-connect "^2.0.1"
"@types/babel__core@^7.1.14":
version "7.20.5"
resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.20.5.tgz#3df15f27ba85319caa07ba08d0721889bb39c017"
@ -783,11 +771,6 @@
dependencies:
"@types/node" "*"
"@types/http-cache-semantics@^4.0.2":
version "4.0.4"
resolved "https://registry.yarnpkg.com/@types/http-cache-semantics/-/http-cache-semantics-4.0.4.tgz#b979ebad3919799c979b17c72621c0bc0a31c6c4"
integrity sha512-1m0bIFVc7eJWyve9S0RnuRgcQqF/Xd5QsUZAZeQFr1Q3/p9JWoQQEqmVy+DPTNpGXwhgIetAoYF8JSc33q29QA==
"@types/istanbul-lib-coverage@*", "@types/istanbul-lib-coverage@^2.0.0", "@types/istanbul-lib-coverage@^2.0.1":
version "2.0.6"
resolved "https://registry.yarnpkg.com/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.6.tgz#7739c232a1fee9b4d3ce8985f314c0c6d33549d7"
@ -815,10 +798,17 @@
expect "^29.0.0"
pretty-format "^29.0.0"
"@types/node@*", "@types/node@^20.0.0":
version "20.14.9"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.14.9.tgz#12e8e765ab27f8c421a1820c99f5f313a933b420"
integrity sha512-06OCtnTXtWOZBJlRApleWndH4JsRVs1pDCc8dLSQp+7PpUpX3ePdHyeNSFTeSe7FtKyQkrlPvHwJOW3SLd8Oyg==
"@types/node@*":
version "22.1.0"
resolved "https://registry.yarnpkg.com/@types/node/-/node-22.1.0.tgz#6d6adc648b5e03f0e83c78dc788c2b037d0ad94b"
integrity sha512-AOmuRF0R2/5j1knA3c6G3HOk523Ga+l+ZXltX8SF1+5oqcXijjfTd8fY3XRZqSihEu9XhtQnKYLmkFaoxgsJHw==
dependencies:
undici-types "~6.13.0"
"@types/node@^20.0.0":
version "20.14.14"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.14.14.tgz#6b655d4a88623b0edb98300bb9dd2107225f885e"
integrity sha512-d64f00982fS9YoOgJkAMolK7MN8Iq3TDdVjchbYHdEmjth/DHowx82GnoA+tVUAN+7vxfYUgAzi+JXbKNd2SDQ==
dependencies:
undici-types "~5.26.4"
@ -1168,11 +1158,6 @@ cacheable-lookup@6.1.0:
resolved "https://registry.yarnpkg.com/cacheable-lookup/-/cacheable-lookup-6.1.0.tgz#0330a543471c61faa4e9035db583aad753b36385"
integrity sha512-KJ/Dmo1lDDhmW2XDPMo+9oiy/CeqosPguPCrgcVzKyZrL6pM1gU2GmPY/xo6OQPTUaA/c0kwHuywB4E6nmT9ww==
cacheable-lookup@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/cacheable-lookup/-/cacheable-lookup-7.0.0.tgz#3476a8215d046e5a3202a9209dd13fec1f933a27"
integrity sha512-+qJyx4xiKra8mZrcwhjMRMUhD5NR1R8esPkzIYxX96JiecFoxAXFuz/GpR3+ev4PE1WamHip78wV0vcmPQtp8w==
cacheable-request@7.0.2:
version "7.0.2"
resolved "https://registry.yarnpkg.com/cacheable-request/-/cacheable-request-7.0.2.tgz#ea0d0b889364a25854757301ca12b2da77f91d27"
@ -1186,19 +1171,6 @@ cacheable-request@7.0.2:
normalize-url "^6.0.1"
responselike "^2.0.0"
cacheable-request@^10.2.8:
version "10.2.14"
resolved "https://registry.yarnpkg.com/cacheable-request/-/cacheable-request-10.2.14.tgz#eb915b665fda41b79652782df3f553449c406b9d"
integrity sha512-zkDT5WAF4hSSoUgyfg5tFIxz8XQK+25W/TLVojJTMKBaxevLBBtLxgqguAuVQB8PVW79FVjHcU+GJ9tVbDZ9mQ==
dependencies:
"@types/http-cache-semantics" "^4.0.2"
get-stream "^6.0.1"
http-cache-semantics "^4.1.1"
keyv "^4.5.3"
mimic-response "^4.0.0"
normalize-url "^8.0.0"
responselike "^3.0.0"
callsites@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/callsites/-/callsites-3.1.0.tgz#b3630abd8943432f54b3f0519238e33cd7df2f73"
@ -1556,7 +1528,7 @@ defaults@^1.0.3:
dependencies:
clone "^1.0.2"
defer-to-connect@^2.0.0, defer-to-connect@^2.0.1:
defer-to-connect@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/defer-to-connect/-/defer-to-connect-2.0.1.tgz#8016bdb4143e4632b77a3449c6236277de520587"
integrity sha512-4tvttepXG1VaYGrRibk5EwJd1t4udunSOVMdLSAL6mId1ix438oPwPZMALY41FCijukO1L0twNcGsdzS7dHgDg==
@ -1896,11 +1868,6 @@ form-data-encoder@1.7.2:
resolved "https://registry.yarnpkg.com/form-data-encoder/-/form-data-encoder-1.7.2.tgz#1f1ae3dccf58ed4690b86d87e4f57c654fbab040"
integrity sha512-qfqtYan3rxrnCk1VYaA4H+Ms9xdpPqvLZa6xmMgFvhO32x7/3J/ExcTd6qpxM0vH2GdMI+poehyBZvqfMTto8A==
form-data-encoder@^2.1.2:
version "2.1.4"
resolved "https://registry.yarnpkg.com/form-data-encoder/-/form-data-encoder-2.1.4.tgz#261ea35d2a70d48d30ec7a9603130fa5515e9cd5"
integrity sha512-yDYSgNMraqvnxiEXO4hi88+YZxaHC6QKzb5N84iRCTDeRO7ZALpir/lVmf/uXUhnwUr2O4HU8s/n6x+yNjQkHw==
fs.realpath@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
@ -1998,13 +1965,6 @@ global-directory@^4.0.1:
dependencies:
ini "4.1.1"
global-dirs@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/global-dirs/-/global-dirs-3.0.1.tgz#0c488971f066baceda21447aecb1a8b911d22485"
integrity sha512-NBcGGFbBA9s1VzD41QXDG+3++t9Mn5t1FpLdhESY6oKY4gYTFpX4wO3sqGUa0Srjtbfj3szX0RnemmrVRUdULA==
dependencies:
ini "2.0.0"
globals@^11.1.0:
version "11.12.0"
resolved "https://registry.yarnpkg.com/globals/-/globals-11.12.0.tgz#ab8795338868a0babd8525758018c2a7eb95c42e"
@ -2039,23 +1999,6 @@ got-cjs@^12.5.4:
p-cancelable "2.1.1"
responselike "2.0.1"
got@^12.1.0:
version "12.6.1"
resolved "https://registry.yarnpkg.com/got/-/got-12.6.1.tgz#8869560d1383353204b5a9435f782df9c091f549"
integrity sha512-mThBblvlAF1d4O5oqyvN+ZxLAYwIJK7bpMxgYqPD9okW0C3qm5FFn7k811QrcuEBwaogR3ngOFoCfs6mRv7teQ==
dependencies:
"@sindresorhus/is" "^5.2.0"
"@szmarczak/http-timer" "^5.0.1"
cacheable-lookup "^7.0.0"
cacheable-request "^10.2.8"
decompress-response "^6.0.0"
form-data-encoder "^2.1.2"
get-stream "^6.0.1"
http2-wrapper "^2.1.10"
lowercase-keys "^3.0.0"
p-cancelable "^3.0.0"
responselike "^3.0.0"
graceful-fs@4.2.10:
version "4.2.10"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.10.tgz#147d3a006da4ca3ce14728c7aefc287c367d7a6c"
@ -2117,7 +2060,7 @@ htmlparser2@^9.1.0:
domutils "^3.1.0"
entities "^4.5.0"
http-cache-semantics@^4.0.0, http-cache-semantics@^4.1.1:
http-cache-semantics@^4.0.0:
version "4.1.1"
resolved "https://registry.yarnpkg.com/http-cache-semantics/-/http-cache-semantics-4.1.1.tgz#abe02fcb2985460bf0323be664436ec3476a6d5a"
integrity sha512-er295DKPVsV82j5kw1Gjt+ADA/XYHsajl82cGNQG2eyoPkvgUhX+nDIyelzhIWbbsXP39EHcI6l5tYs2FYqYXQ==
@ -2218,11 +2161,6 @@ inherits@2, inherits@^2.0.1, inherits@^2.0.3, inherits@^2.0.4, inherits@~2.0.3:
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c"
integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==
ini@2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ini/-/ini-2.0.0.tgz#e5fd556ecdd5726be978fa1001862eacb0a94bc5"
integrity sha512-7PnF4oN3CvZF23ADhA5wRaYEQpJ8qygSkbtTXWBeXWXmEVRXK+1ITciHWwHhsjv1TmW0MgacIv6hEi5pX5NQdA==
ini@4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/ini/-/ini-4.1.1.tgz#d95b3d843b1e906e56d6747d5447904ff50ce7a1"
@ -2281,9 +2219,9 @@ inquirer@^7.0.0:
through "^2.3.6"
inquirer@^9.2.15:
version "9.3.1"
resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-9.3.1.tgz#71482e4fd283deebe9d175dc7c78b12fb5ff6a7c"
integrity sha512-A5IdVr1I04XqPlwrGgTJMKmzRg5ropqNpSeqo0vj1ZmluSCNSFaPZz4eazdPrhVcZfej7fCEYvD2NYa1KjkTJA==
version "9.3.6"
resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-9.3.6.tgz#670f1e9408743c3ed23df576f94fe5369f353055"
integrity sha512-riK/iQB2ctwkpWYgjjWIRv3MBLt2gzb2Sj0JNQNbyTXgyXsLWcDPJ5WS5ZDTCx7BRFnJsARtYh+58fjP5M2Y0Q==
dependencies:
"@inquirer/figures" "^1.0.3"
ansi-escapes "^4.3.2"
@ -2291,12 +2229,12 @@ inquirer@^9.2.15:
external-editor "^3.1.0"
mute-stream "1.0.0"
ora "^5.4.1"
picocolors "^1.0.1"
run-async "^3.0.0"
rxjs "^7.8.1"
string-width "^4.2.3"
strip-ansi "^6.0.1"
wrap-ansi "^6.2.0"
yoctocolors-cjs "^2.1.2"
is-arrayish@^0.2.1:
version "0.2.1"
@ -2361,14 +2299,6 @@ is-inside-container@^1.0.0:
dependencies:
is-docker "^3.0.0"
is-installed-globally@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/is-installed-globally/-/is-installed-globally-0.4.0.tgz#9a0fd407949c30f86eb6959ef1b7994ed0b7b520"
integrity sha512-iwGqO3J21aaSkC7jWnHP/difazwS7SFeIqxv6wEtLU8Y5KlzFTjyqcSIT0d8s4+dDhKytsk9PJZ2BkS5eZwQRQ==
dependencies:
global-dirs "^3.0.0"
is-path-inside "^3.0.2"
is-installed-globally@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/is-installed-globally/-/is-installed-globally-1.0.0.tgz#08952c43758c33d815692392f7f8437b9e436d5a"
@ -2414,11 +2344,6 @@ is-path-cwd@^3.0.0:
resolved "https://registry.yarnpkg.com/is-path-cwd/-/is-path-cwd-3.0.0.tgz#889b41e55c8588b1eb2a96a61d05740a674521c7"
integrity sha512-kyiNFFLU0Ampr6SDZitD/DwUo4Zs1nSdnygUBqsu3LooL00Qvb5j+UnvApUn/TTj1J3OuE6BTdQ5rudKmU2ZaA==
is-path-inside@^3.0.2:
version "3.0.3"
resolved "https://registry.yarnpkg.com/is-path-inside/-/is-path-inside-3.0.3.tgz#d231362e53a07ff2b0e0ea7fed049161ffd16283"
integrity sha512-Fd4gABb+ycGAmKou8eMftCupSir5lRxqf4aD/vd0cD2qc4HL07OjCeuHMr8Ro4CoMaeCKDB0/ECBOVWjTwUvPQ==
is-path-inside@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/is-path-inside/-/is-path-inside-4.0.0.tgz#805aeb62c47c1b12fc3fd13bfb3ed1e7430071db"
@ -2960,7 +2885,7 @@ json5@^2.2.3:
resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.3.tgz#78cd6f1a19bdc12b73db5ad0c61efd66c1e29283"
integrity sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==
keyv@^4.0.0, keyv@^4.5.3:
keyv@^4.0.0:
version "4.5.4"
resolved "https://registry.yarnpkg.com/keyv/-/keyv-4.5.4.tgz#a879a99e29452f942439f2a405e3af8b31d4de93"
integrity sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==
@ -2977,12 +2902,12 @@ ky@^1.2.0:
resolved "https://registry.yarnpkg.com/ky/-/ky-1.4.0.tgz#68b4a71eccfb4177199fe6ee2d5041b50bb41931"
integrity sha512-tPhhoGUiEiU/WXR4rt8klIoLdnTtyu+9jVKHd/wauEjYud32jyn63mzKWQweaQrHWxBQtYoVtdcEnYX1LosnFQ==
latest-version@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/latest-version/-/latest-version-7.0.0.tgz#843201591ea81a4d404932eeb61240fe04e9e5da"
integrity sha512-KvNT4XqAMzdcL6ka6Tl3i2lYeFDgXNCuIX+xNx6ZMVR1dFq+idXd9FLKNMOIx0t9mJ9/HudyX4oZWXZQ0UJHeg==
latest-version@^9.0.0:
version "9.0.0"
resolved "https://registry.yarnpkg.com/latest-version/-/latest-version-9.0.0.tgz#e91ed216e7a4badc6f73b66c65adb46c58ec6ba1"
integrity sha512-7W0vV3rqv5tokqkBAFV1LbR7HPOWzXQDpDgEuib/aJ1jsZZx6x3c2mBI+TJhJzOhkGeaLbCKEHXEXLfirtG2JA==
dependencies:
package-json "^8.1.0"
package-json "^10.0.0"
leven@^3.1.0:
version "3.1.0"
@ -3117,12 +3042,12 @@ lowercase-keys@2.0.0, lowercase-keys@^2.0.0:
resolved "https://registry.yarnpkg.com/lowercase-keys/-/lowercase-keys-2.0.0.tgz#2603e78b7b4b0006cbca2fbcc8a3202558ac9479"
integrity sha512-tqNXrS78oMOE73NMxK4EMLQsQowWf8jKooH9g7xPavRT706R6bkQJ6DY2Te7QukaZsulxa30wQ7bk0pm4XiHmA==
lowercase-keys@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/lowercase-keys/-/lowercase-keys-3.0.0.tgz#c5e7d442e37ead247ae9db117a9d0a467c89d4f2"
integrity sha512-ozCC6gdQ+glXOQsveKD0YsDy8DSQFjDTz4zyzEHNV5+JP5D62LmfDZ6o1cycFx9ouG940M5dE8C8CTewdj2YWQ==
lru-cache@^10.0.1:
version "10.4.3"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-10.4.3.tgz#410fc8a17b70e598013df257c2446b7f3383f119"
integrity sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==
lru-cache@^10.0.1, lru-cache@^10.2.0:
lru-cache@^10.2.0:
version "10.3.0"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-10.3.0.tgz#4a4aaf10c84658ab70f79a85a9a3f1e1fb11196b"
integrity sha512-CQl19J/g+Hbjbv4Y3mFNNXFEL/5t/KCg8POCuUqd4rMKjGG+j1ybER83hxV58zL+dFI1PTkt3GNFSHRt+d8qEQ==
@ -3211,11 +3136,6 @@ mimic-response@^3.1.0:
resolved "https://registry.yarnpkg.com/mimic-response/-/mimic-response-3.1.0.tgz#2d1d59af9c1b129815accc2c46a022a5ce1fa3c9"
integrity sha512-z0yWI+4FDrrweS8Zmt4Ej5HdJmky15+L2e6Wgn3+iK5fWzb6T3fhNFq2+MeTRb064c6Wr4N/wv0DzQTjNzHNGQ==
mimic-response@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/mimic-response/-/mimic-response-4.0.0.tgz#35468b19e7c75d10f5165ea25e75a5ceea7cf70f"
integrity sha512-e5ISH9xMYU0DzrT+jl8q2ze9D6eWBto+I8CNpe+VI+K2J/F/k3PdkdTdz4wvGVH4NTpo+NRYTVIuMQEMMcsLqg==
minimatch@9.0.5, minimatch@^9.0.0, minimatch@^9.0.4:
version "9.0.5"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-9.0.5.tgz#d74f9dd6b57d83d8e98cfb82133b03978bc929e5"
@ -3325,15 +3245,10 @@ normalize-url@^6.0.1:
resolved "https://registry.yarnpkg.com/normalize-url/-/normalize-url-6.1.0.tgz#40d0885b535deffe3f3147bec877d05fe4c5668a"
integrity sha512-DlL+XwOy3NxAQ8xuC0okPgK46iuVNAK01YN7RueYBqqFeGsBjV9XmCAzAdgt+667bCl5kPh9EqKKDwnaPG1I7A==
normalize-url@^8.0.0:
version "8.0.1"
resolved "https://registry.yarnpkg.com/normalize-url/-/normalize-url-8.0.1.tgz#9b7d96af9836577c58f5883e939365fa15623a4a"
integrity sha512-IO9QvjUMWxPQQhs60oOu10CRkWCiZzSUkzbXGGV9pviYl1fXYcvkzQ5jV9z8Y6un8ARoVRl4EtC6v6jNqbaJ/w==
np@^10.0.0:
version "10.0.6"
resolved "https://registry.yarnpkg.com/np/-/np-10.0.6.tgz#054d1ac283c995fb29cfa38bfabeaf483406317e"
integrity sha512-173uUvFDmHtme1ra3JDMjYzqa94XHJAHoNae6lCA4mJWMIz073x9FE2O8SHMMjKXlHetRdOXufLUjdimRxXR3A==
version "10.0.7"
resolved "https://registry.yarnpkg.com/np/-/np-10.0.7.tgz#6f0dc3c7440c8ac95d55a2fa5d488c3d0848b7a5"
integrity sha512-vIPKQwOYKpQU40PU5x/vLfN2haj8ObxMvR1QGt7EZnBPWdm4WEbHdumYAnMV7AeR9kACsMqcqAP37sAo5cW5jA==
dependencies:
chalk "^5.3.0"
chalk-template "^1.1.0"
@ -3486,11 +3401,6 @@ p-cancelable@2.1.1:
resolved "https://registry.yarnpkg.com/p-cancelable/-/p-cancelable-2.1.1.tgz#aab7fbd416582fa32a3db49859c122487c5ed2cf"
integrity sha512-BZOr3nRQHOntUjTrH8+Lh54smKHoHyur8We1V8DSMVrl5A2malOOwuJRnKRDjSnkoeBh4at6BwEnb5I7Jl31wg==
p-cancelable@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/p-cancelable/-/p-cancelable-3.0.0.tgz#63826694b54d61ca1c20ebcb6d3ecf5e14cd8050"
integrity sha512-mlVgR3PGuzlo0MmTdk4cXqXWlwQDLnONTAg6sm62XkMJEiRxN3GL3SffkYvqwonbkJBcrI7Uvv5Zh9yjvn2iUw==
p-limit@^2.2.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-2.3.0.tgz#3dd33c647a214fdfffd835933eb086da0dc21db1"
@ -3552,15 +3462,15 @@ package-json-from-dist@^1.0.0:
resolved "https://registry.yarnpkg.com/package-json-from-dist/-/package-json-from-dist-1.0.0.tgz#e501cd3094b278495eb4258d4c9f6d5ac3019f00"
integrity sha512-dATvCeZN/8wQsGywez1mzHtTlP22H8OEfPrVMLNr4/eGa+ijtLn/6M5f0dY8UKNrC2O9UCU6SSoG3qRKnt7STw==
package-json@^8.1.0:
version "8.1.1"
resolved "https://registry.yarnpkg.com/package-json/-/package-json-8.1.1.tgz#3e9948e43df40d1e8e78a85485f1070bf8f03dc8"
integrity sha512-cbH9IAIJHNj9uXi196JVsRlt7cHKak6u/e6AkL/bkRelZ7rlL3X1YKxsZwa36xipOEKAsdtmaG6aAJoM1fx2zA==
package-json@^10.0.0:
version "10.0.1"
resolved "https://registry.yarnpkg.com/package-json/-/package-json-10.0.1.tgz#e49ee07b8de63b638e7f1b5bb353733e428fe7d7"
integrity sha512-ua1L4OgXSBdsu1FPb7F3tYH0F48a6kxvod4pLUlGY9COeJAJQNX/sNH2IiEmsxw7lqYiAwrdHMjz1FctOsyDQg==
dependencies:
got "^12.1.0"
registry-auth-token "^5.0.1"
registry-url "^6.0.0"
semver "^7.3.7"
ky "^1.2.0"
registry-auth-token "^5.0.2"
registry-url "^6.0.1"
semver "^7.6.0"
parent-module@^1.0.0:
version "1.0.1"
@ -3807,14 +3717,14 @@ reflect-metadata@^0.2.1:
resolved "https://registry.yarnpkg.com/reflect-metadata/-/reflect-metadata-0.2.2.tgz#400c845b6cba87a21f2c65c4aeb158f4fa4d9c5b"
integrity sha512-urBwgfrvVP/eAyXx4hluJivBKzuEbSQs9rKWCrCkbSxNv8mxPcUZKeuoF3Uy4mJl3Lwprp6yy5/39VWigZ4K6Q==
registry-auth-token@^5.0.1, registry-auth-token@^5.0.2:
registry-auth-token@^5.0.2:
version "5.0.2"
resolved "https://registry.yarnpkg.com/registry-auth-token/-/registry-auth-token-5.0.2.tgz#8b026cc507c8552ebbe06724136267e63302f756"
integrity sha512-o/3ikDxtXaA59BmZuZrJZDJv8NMDGSj+6j6XaeBmHw8eY1i1qd9+6H+LjVvQXx3HN6aRCGa1cUdJ9RaJZUugnQ==
dependencies:
"@pnpm/npm-conf" "^2.1.0"
registry-url@^6.0.0, registry-url@^6.0.1:
registry-url@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/registry-url/-/registry-url-6.0.1.tgz#056d9343680f2f64400032b1e199faa692286c58"
integrity sha512-+crtS5QjFRqFCoQmvGduwYWEBng99ZvmFvF+cUJkGYF1L1BfU8C6Zp9T7f5vPAwyLkUExpvK+ANVZmGU49qi4Q==
@ -3869,13 +3779,6 @@ responselike@2.0.1, responselike@^2.0.0:
dependencies:
lowercase-keys "^2.0.0"
responselike@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/responselike/-/responselike-3.0.0.tgz#20decb6c298aff0dbee1c355ca95461d42823626"
integrity sha512-40yHxbNcl2+rzXvZuVkrYohathsSJlMTXKryG5y8uciHv1+xDLHQpgjG64JUO9nrEq2jGLH6IZ8BcZyw3wrweg==
dependencies:
lowercase-keys "^3.0.0"
restore-cursor@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/restore-cursor/-/restore-cursor-2.0.0.tgz#9f7ee287f82fd326d4fd162923d62129eee0dfaf"
@ -3967,7 +3870,7 @@ semver-diff@^4.0.0:
dependencies:
semver "^7.3.5"
semver@^6.3.0, semver@^6.3.1, semver@^7.3.5, semver@^7.3.7, semver@^7.5.2, semver@^7.5.3, semver@^7.5.4, semver@^7.6.0:
semver@^6.3.0, semver@^6.3.1, semver@^7.3.5, semver@^7.5.2, semver@^7.5.3, semver@^7.5.4, semver@^7.6.0, semver@^7.6.2:
version "7.6.2"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.6.2.tgz#1e3b34759f896e8f14d6134732ce798aeb0c6e13"
integrity sha512-FNAIBWCx9qcRhoHcgcJ0gvU7SN1lYU2ZXuSfl04bSC5OpvDHFyJCjdNHomPXxjQlCBU67YW64PzY7/VIEH7F2w==
@ -4385,9 +4288,9 @@ type-fest@^3.0.0:
integrity sha512-tLq3bSNx+xSpwvAJnzrK0Ep5CLNWjvFTOp71URMaAEWBfRb9nnJiBoUe0tF8bI4ZFO3omgBR6NvnbzVUT3Ly4g==
type-fest@^4.6.0, type-fest@^4.7.1:
version "4.20.1"
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-4.20.1.tgz#d97bb1e923bf524e5b4b43421d586760fb2ee8be"
integrity sha512-R6wDsVsoS9xYOpy8vgeBlqpdOyzJ12HNfQhC/aAKWM3YoCV9TtunJzh/QpkMgeDhkoynDcw5f1y+qF9yc/HHyg==
version "4.22.1"
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-4.22.1.tgz#cc493ba0c1fb7faecb80d13a70525a75afd9d8d6"
integrity sha512-9tHNEa0Ov81YOopiVkcCJVz5TM6AEQ+CHHjFIktqPnE3NV0AHIkx+gh9tiCl58m/66wWxkOC9eltpa75J4lQPA==
typedarray-to-buffer@^3.1.5:
version "3.1.5"
@ -4418,15 +4321,20 @@ typeorm@0.3.20:
yargs "^17.6.2"
typescript@^5.0.0:
version "5.5.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.5.2.tgz#c26f023cb0054e657ce04f72583ea2d85f8d0507"
integrity sha512-NcRtPEOsPFFWjobJEtfihkLCZCXZt/os3zf8nTxjVH3RvTSxjrCamJpbExGvYOF+tFHc3pA65qpdwPbzjohhew==
version "5.5.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.5.4.tgz#d9852d6c82bad2d2eda4fd74a5762a8f5909e9ba"
integrity sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==
undici-types@~5.26.4:
version "5.26.5"
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617"
integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==
undici-types@~6.13.0:
version "6.13.0"
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-6.13.0.tgz#e3e79220ab8c81ed1496b5812471afd7cf075ea5"
integrity sha512-xtFJHudx8S2DSoujjMd1WeWvn7KKWFRESZTMeL1RptAYERu29D6jphMjjY+vn96jvN3kVPDNxU/E13VTaXj6jg==
undici@6.13.0, undici@^6.0.0:
version "6.19.2"
resolved "https://registry.yarnpkg.com/undici/-/undici-6.19.2.tgz#231bc5de78d0dafb6260cf454b294576c2f3cd31"
@ -4453,20 +4361,20 @@ update-browserslist-db@^1.0.16:
picocolors "^1.0.1"
update-notifier@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/update-notifier/-/update-notifier-7.0.0.tgz#295aa782dadab784ed4073f7ffaea1fb2123031c"
integrity sha512-Hv25Bh+eAbOLlsjJreVPOs4vd51rrtCrmhyOJtbpAojro34jS4KQaEp4/EvlHJX7jSO42VvEFpkastVyXyIsdQ==
version "7.1.0"
resolved "https://registry.yarnpkg.com/update-notifier/-/update-notifier-7.1.0.tgz#b8f43cc2dc094c221f179bfab9eba9f4b1469965"
integrity sha512-8SV3rIqVY6EFC1WxH6L0j55s0MO79MFBS1pivmInRJg3pCEDgWHBj1Q6XByTtCLOZIFA0f6zoG9ZWf2Ks9lvTA==
dependencies:
boxen "^7.1.1"
chalk "^5.3.0"
configstore "^6.0.0"
import-lazy "^4.0.0"
is-in-ci "^0.1.0"
is-installed-globally "^0.4.0"
is-installed-globally "^1.0.0"
is-npm "^6.0.0"
latest-version "^7.0.0"
latest-version "^9.0.0"
pupa "^3.1.0"
semver "^7.5.4"
semver "^7.6.2"
semver-diff "^4.0.0"
xdg-basedir "^5.1.0"
@ -4657,3 +4565,8 @@ yocto-queue@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b"
integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==
yoctocolors-cjs@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/yoctocolors-cjs/-/yoctocolors-cjs-2.1.2.tgz#f4b905a840a37506813a7acaa28febe97767a242"
integrity sha512-cYVsTjKl8b+FrnidjibDWskAv7UKOfcwaVZdp/it9n1s9fU3IkgDbhdIRKCW4JDsAlECJY0ytoVPT3sK6kideA==