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