Vylpes
f61c4c728a
* Fix tests * Update coverage * Remove unrequired mock files * Add about command test * Update about tests * Ban command tests * eval command tests * Start help command tests * Add help command tests * Add kick command tests * Mute command tests * Poll command tests * Add role command tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add rules command tests * Add unmute command tests * Add warn command tests * Add MemberEvents tests * Add GuildMemberUpdate tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add MessageEvents tests * Add StringTools test Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add embed tests Signed-off-by: Ethan Lane <ethan@vylpes.com> * Add GitHub Actions Signed-off-by: Ethan Lane <ethan@vylpes.com> * Move to tslint Signed-off-by: Ethan Lane <ethan@vylpes.com> * Remove tslint Signed-off-by: Ethan Lane <ethan@vylpes.com> * Remove linting script Signed-off-by: Ethan Lane <ethan@vylpes.com>
106 lines
No EOL
2.8 KiB
TypeScript
106 lines
No EOL
2.8 KiB
TypeScript
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");
|
|
});
|
|
}); |