Compare commits

..

3 commits

Author SHA1 Message Date
c387eb5b02 Add targetMember is not manageable test
Some checks failed
continuous-integration/drone/push Build is failing
2023-05-22 18:26:30 +01:00
4d75a11016 Add lengthInput.value IS NULL test 2023-05-22 18:23:43 +01:00
e1bfd3d09d Create lengthInput is NULL test 2023-05-22 18:21:55 +01:00

View file

@ -1,4 +1,4 @@
import { APIEmbed, CommandInteraction, CommandInteractionOption, DMChannel, Embed, EmbedBuilder, Guild, GuildChannel, GuildMember, InteractionReplyOptions, JSONEncodable, MessageCreateOptions, SlashCommandBuilder, TextChannel, User } from "discord.js";
import { APIEmbed, CacheType, CommandInteraction, CommandInteractionOption, DMChannel, Embed, EmbedBuilder, Guild, GuildChannel, GuildMember, InteractionReplyOptions, JSONEncodable, MessageCreateOptions, SlashCommandBuilder, TextChannel, User } from "discord.js";
import { mock } from "jest-mock-extended";
import Timeout from "../../src/commands/timeout";
import SettingsHelper from "../../src/helpers/SettingsHelper";
@ -217,17 +217,27 @@ describe('execute', () => {
test('GIVEN targetUser.user IS NULL, EXPECT validation error', async () => {
const command = new Timeout();
const interactionOption = {
user: undefined,
member: {} as GuildMember
} as CommandInteractionOption;
const interaction = {
reply: jest.fn(),
guild: mock<Guild>(),
guildId: 'guildId',
options: {
get: jest.fn().mockReturnValue(interactionOption),
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;
@ -239,17 +249,29 @@ describe('execute', () => {
test('GIVEN targetUser.member IS NULL, EXPECT validation error', async () => {
const command = new Timeout();
const interactionOption = {
user: {} as User,
member: undefined
} as CommandInteractionOption;
const interaction = {
reply: jest.fn(),
guild: mock<Guild>(),
guildId: 'guildId',
options: {
get: jest.fn().mockReturnValue(interactionOption),
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;
@ -258,11 +280,116 @@ describe('execute', () => {
expect(interaction.reply).toBeCalledWith('Fields are required.');
});
test.todo('GIVEN lengthInput IS NULL, EXPECT validation error');
test('GIVEN lengthInput IS NULL, EXPECT validation error', async () => {
const command = new Timeout();
test.todo('GIVEN lengthInput.value IS NULL, EXPECT validation error');
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;
test.todo('GIVEN targetMember IS NOT manageable by the bot, EXPECT insufficient permissions error');
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 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.todo('GIVEN reason IS NOT NULL, EXPECT to be ran with reason set');