Create timeout command #302

Merged
Vylpes merged 16 commits from feature/98-timeout-command into develop 2023-06-16 18:01:46 +01:00
Showing only changes of commit e1bfd3d09d - Show all commits

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,7 +280,38 @@ 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();
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.todo('GIVEN lengthInput.value IS NULL, EXPECT validation error');