Feature/12 create tests #102
3 changed files with 707 additions and 7 deletions
|
@ -1,5 +1,6 @@
|
|||
import ErrorMessages from "../constants/ErrorMessages";
|
||||
import { ICommandContext } from "../contracts/ICommandContext";
|
||||
import ICommandReturnContext from "../contracts/ICommandReturnContext";
|
||||
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
|
||||
import LogEmbed from "../helpers/embeds/LogEmbed";
|
||||
import PublicEmbed from "../helpers/embeds/PublicEmbed";
|
||||
|
@ -15,13 +16,17 @@ export default class Mute extends Command {
|
|||
];
|
||||
}
|
||||
|
||||
public override async execute(context: ICommandContext) {
|
||||
public override async execute(context: ICommandContext): Promise<ICommandReturnContext> {
|
||||
const targetUser = context.message.mentions.users.first();
|
||||
|
||||
if (!targetUser) {
|
||||
const embed = new ErrorEmbed(context, "User does not exist");
|
||||
embed.SendToCurrentChannel();
|
||||
return;
|
||||
|
||||
return {
|
||||
commandContext: context,
|
||||
embeds: [embed]
|
||||
};
|
||||
}
|
||||
|
||||
const targetMember = context.message.guild?.member(targetUser);
|
||||
|
@ -29,7 +34,11 @@ export default class Mute extends Command {
|
|||
if (!targetMember) {
|
||||
const embed = new ErrorEmbed(context, "User is not in this server");
|
||||
embed.SendToCurrentChannel();
|
||||
return;
|
||||
|
||||
return {
|
||||
commandContext: context,
|
||||
embeds: [embed]
|
||||
};
|
||||
}
|
||||
|
||||
const reasonArgs = context.args;
|
||||
|
@ -38,13 +47,20 @@ export default class Mute extends Command {
|
|||
const reason = reasonArgs.join(" ");
|
||||
|
||||
if (!context.message.guild?.available) {
|
||||
return;
|
||||
return {
|
||||
commandContext: context,
|
||||
embeds: []
|
||||
};
|
||||
}
|
||||
|
||||
if (!targetMember.manageable) {
|
||||
const embed = new ErrorEmbed(context, ErrorMessages.InsufficientBotPermissions);
|
||||
embed.SendToCurrentChannel();
|
||||
return;
|
||||
|
||||
return {
|
||||
commandContext: context,
|
||||
embeds: [embed]
|
||||
};
|
||||
}
|
||||
|
||||
const logEmbed = new LogEmbed(context, "Member Muted");
|
||||
|
@ -60,12 +76,21 @@ export default class Mute extends Command {
|
|||
if (!mutedRole) {
|
||||
const embed = new ErrorEmbed(context, ErrorMessages.RoleNotFound);
|
||||
embed.SendToCurrentChannel();
|
||||
return;
|
||||
|
||||
return {
|
||||
commandContext: context,
|
||||
embeds: [embed]
|
||||
};
|
||||
}
|
||||
|
||||
await targetMember.roles.add(mutedRole, reason);
|
||||
|
||||
logEmbed.SendToModLogsChannel();
|
||||
publicEmbed.SendToCurrentChannel();
|
||||
|
||||
return {
|
||||
commandContext: context,
|
||||
embeds: [logEmbed, publicEmbed]
|
||||
};
|
||||
}
|
||||
}
|
|
@ -26,7 +26,7 @@ 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(),
|
||||
|
|
675
tests/commands/mute.test.ts
Normal file
675
tests/commands/mute.test.ts
Normal file
|
@ -0,0 +1,675 @@
|
|||
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, '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`');
|
||||
|
||||
// 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');
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue