Create timeout command #302
1 changed files with 75 additions and 3 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, CacheType, CommandInteraction, CommandInteractionOption, DMChannel, Embed, EmbedBuilder, EmbedField, Guild, GuildChannel, GuildMember, InteractionReplyOptions, JSONEncodable, Message, MessageCreateOptions, MessagePayload, SlashCommandBuilder, TextChannel, User } from "discord.js";
|
||||
import { mock } from "jest-mock-extended";
|
||||
import Timeout from "../../src/commands/timeout";
|
||||
import SettingsHelper from "../../src/helpers/SettingsHelper";
|
||||
|
@ -392,9 +392,81 @@ describe('execute', () => {
|
|||
});
|
||||
|
||||
// Reason variable
|
||||
test.todo('GIVEN reason IS NOT NULL, EXPECT to be ran with reason set');
|
||||
test('GIVEN reason IS NULL, EXPECT to be ran with empty string', async () => {
|
||||
const command = new Timeout();
|
||||
|
||||
test.todo('GIVEN reason IS NULL, EXPECT to be ran with empty string');
|
||||
let savedAudit: DeepPartial<Audit> | undefined;
|
||||
|
||||
const auditSave = jest.spyOn(Audit.prototype, 'Save').mockImplementation((target: EntityTarget<BaseEntity>, entity: DeepPartial<BaseEntity>): Promise<void> => {
|
||||
savedAudit = entity;
|
||||
|
||||
return Promise.resolve();
|
||||
});
|
||||
|
||||
const timeoutFunc = jest.fn();
|
||||
|
||||
const sentEmbeds: EmbedBuilder[] = [];
|
||||
|
||||
const interaction = {
|
||||
reply: jest.fn(),
|
||||
guild: {
|
||||
channels: {
|
||||
cache: {
|
||||
find: jest.fn().mockReturnValue(mock<TextChannel>()),
|
||||
}
|
||||
}
|
||||
},
|
||||
guildId: 'guildId',
|
||||
user: {
|
||||
id: 'moderatorId',
|
||||
},
|
||||
options: {
|
||||
get: jest.fn((value: string): CommandInteractionOption<CacheType> | null => {
|
||||
switch (value) {
|
||||
case 'target':
|
||||
return {
|
||||
user: {
|
||||
id: 'userId',
|
||||
tag: 'userTag',
|
||||
createDM: jest.fn().mockReturnValue({
|
||||
send: jest.fn(async (options: MessageCreateOptions): Promise<Message<false>> => {
|
||||
sentEmbeds.push(options.embeds![0] as EmbedBuilder);
|
||||
|
||||
return mock<Message<false>>();
|
||||
})
|
||||
}) as unknown as DMChannel,
|
||||
} as unknown as User,
|
||||
member: {
|
||||
manageable: true,
|
||||
timeout: timeoutFunc,
|
||||
} as unknown as GuildMember
|
||||
} as CommandInteractionOption;
|
||||
case 'length':
|
||||
return {
|
||||
value: '1m'
|
||||
} as CommandInteractionOption;
|
||||
case 'reason':
|
||||
return {
|
||||
value: undefined,
|
||||
} as CommandInteractionOption;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}),
|
||||
}
|
||||
} as unknown as CommandInteraction;
|
||||
|
||||
|
||||
await command.execute(interaction);
|
||||
|
||||
expect(timeoutFunc).toBeCalledWith(1000 * 60 * 1, "");
|
||||
expect(savedAudit?.Reason).toBe("*none*");
|
||||
|
||||
const dmEmbed = (sentEmbeds[0] as any).data;
|
||||
const dmEmbedReasonField = dmEmbed.fields![0] as EmbedField;
|
||||
|
||||
expect(dmEmbedReasonField.value).toBe("*none*");
|
||||
});
|
||||
|
||||
// Log embed
|
||||
test.todo('GIVEN channelName IS NULL, EXPECT execution to return');
|
||||
|
|
Loading…
Reference in a new issue