Compare commits
No commits in common. "c387eb5b02cf55aa4a30c66e2106825fc7efada1" and "9dff741971861439421eeb58a29c34e27630340c" have entirely different histories.
c387eb5b02
...
9dff741971
1 changed files with 16 additions and 143 deletions
|
@ -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 { mock } from "jest-mock-extended";
|
||||||
import Timeout from "../../src/commands/timeout";
|
import Timeout from "../../src/commands/timeout";
|
||||||
import SettingsHelper from "../../src/helpers/SettingsHelper";
|
import SettingsHelper from "../../src/helpers/SettingsHelper";
|
||||||
|
@ -217,27 +217,17 @@ describe('execute', () => {
|
||||||
test('GIVEN targetUser.user IS NULL, EXPECT validation error', async () => {
|
test('GIVEN targetUser.user IS NULL, EXPECT validation error', async () => {
|
||||||
const command = new Timeout();
|
const command = new Timeout();
|
||||||
|
|
||||||
|
const interactionOption = {
|
||||||
|
user: undefined,
|
||||||
|
member: {} as GuildMember
|
||||||
|
} as CommandInteractionOption;
|
||||||
|
|
||||||
const interaction = {
|
const interaction = {
|
||||||
reply: jest.fn(),
|
reply: jest.fn(),
|
||||||
guild: mock<Guild>(),
|
guild: mock<Guild>(),
|
||||||
guildId: 'guildId',
|
guildId: 'guildId',
|
||||||
options: {
|
options: {
|
||||||
get: jest.fn((value: string): CommandInteractionOption<CacheType> | null => {
|
get: jest.fn().mockReturnValue(interactionOption),
|
||||||
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;
|
} as unknown as CommandInteraction;
|
||||||
|
|
||||||
|
@ -249,29 +239,17 @@ describe('execute', () => {
|
||||||
test('GIVEN targetUser.member IS NULL, EXPECT validation error', async () => {
|
test('GIVEN targetUser.member IS NULL, EXPECT validation error', async () => {
|
||||||
const command = new Timeout();
|
const command = new Timeout();
|
||||||
|
|
||||||
|
const interactionOption = {
|
||||||
|
user: {} as User,
|
||||||
|
member: undefined
|
||||||
|
} as CommandInteractionOption;
|
||||||
|
|
||||||
const interaction = {
|
const interaction = {
|
||||||
reply: jest.fn(),
|
reply: jest.fn(),
|
||||||
guild: mock<Guild>(),
|
guild: mock<Guild>(),
|
||||||
guildId: 'guildId',
|
guildId: 'guildId',
|
||||||
options: {
|
options: {
|
||||||
get: jest.fn((value: string): CommandInteractionOption<CacheType> | null => {
|
get: jest.fn().mockReturnValue(interactionOption),
|
||||||
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;
|
} as unknown as CommandInteraction;
|
||||||
|
|
||||||
|
@ -280,116 +258,11 @@ describe('execute', () => {
|
||||||
expect(interaction.reply).toBeCalledWith('Fields are required.');
|
expect(interaction.reply).toBeCalledWith('Fields are required.');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('GIVEN lengthInput IS NULL, EXPECT validation error', async () => {
|
test.todo('GIVEN lengthInput IS NULL, EXPECT validation error');
|
||||||
const command = new Timeout();
|
|
||||||
|
|
||||||
const interaction = {
|
test.todo('GIVEN lengthInput.value IS NULL, EXPECT validation error');
|
||||||
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);
|
test.todo('GIVEN targetMember IS NOT manageable by the bot, EXPECT insufficient permissions error');
|
||||||
|
|
||||||
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
|
// Reason variable
|
||||||
test.todo('GIVEN reason IS NOT NULL, EXPECT to be ran with reason set');
|
test.todo('GIVEN reason IS NOT NULL, EXPECT to be ran with reason set');
|
||||||
|
|
Loading…
Reference in a new issue