mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-01 14:38:48 +00:00
add unit test for help command
This commit is contained in:
1 parent
0bb44f18fd
commit
2679cdc463
2 files changed
+36
-4
No files matched your search
@@ -122,7 +122,7 @@ class HelpCommand extends BaseSlashCommandInteraction {
|
||||
}`;
|
||||
}
|
||||
|
||||
private getCommandParams(command: BaseSlashCommandInteraction, locale: LocaleString): string {
|
||||
public getCommandParams(command: BaseSlashCommandInteraction, locale: LocaleString): string {
|
||||
const commandName = command.data.name;
|
||||
const option = command.data.options[0];
|
||||
|
||||
|
||||
@@ -1,6 +1,38 @@
|
||||
import helpCommand from '../../../interactions/slashcommands/help';
|
||||
import { SlashCommandNumberOption } from 'discord.js';
|
||||
import Discord, { Client, SlashCommandNumberOption, ChatInputCommandInteraction } from 'discord.js';
|
||||
import { BaseSlashCommandInteraction } from '../../../common/classes/interactions';
|
||||
import { ExtendedClient } from '../../../types/clientTypes';
|
||||
|
||||
describe('Discord bot command test', () => {
|
||||
let client: ExtendedClient;
|
||||
let mockInteraction: ChatInputCommandInteraction;
|
||||
|
||||
beforeEach(() => {
|
||||
client = new Client({
|
||||
intents: [Discord.GatewayIntentBits.Guilds, Discord.GatewayIntentBits.GuildVoiceStates]
|
||||
});
|
||||
|
||||
client.slashCommandInteractions = new Discord.Collection<string, BaseSlashCommandInteraction>();
|
||||
client.slashCommandInteractions.set('help', helpCommand);
|
||||
|
||||
mockInteraction = {
|
||||
reply: jest.fn(),
|
||||
commandName: 'help'
|
||||
} as unknown as ChatInputCommandInteraction;
|
||||
});
|
||||
|
||||
it('should reply when receiving a valid help command', async () => {
|
||||
// Execute the help command with the mock interaction
|
||||
await helpCommand.execute({
|
||||
executionId: '123',
|
||||
client,
|
||||
interaction: mockInteraction as ChatInputCommandInteraction
|
||||
});
|
||||
|
||||
// Check if the reply method was called
|
||||
expect(mockInteraction.reply).toHaveBeenCalledWith(expect.anything());
|
||||
});
|
||||
});
|
||||
|
||||
describe('HelpCommand', () => {
|
||||
describe('getCommandParams', () => {
|
||||
@@ -17,7 +49,7 @@ describe('HelpCommand', () => {
|
||||
} as unknown as BaseSlashCommandInteraction;
|
||||
|
||||
const locale = 'en-US';
|
||||
const commandParams = helpCommand['getCommandParams'](command, locale);
|
||||
const commandParams = helpCommand.getCommandParams(command, locale);
|
||||
|
||||
expect(commandParams).toBe('**`optionname`** ');
|
||||
});
|
||||
@@ -30,7 +62,7 @@ describe('HelpCommand', () => {
|
||||
} as unknown as BaseSlashCommandInteraction;
|
||||
|
||||
const locale = 'en-US';
|
||||
const commandParams = helpCommand['getCommandParams'](command, locale);
|
||||
const commandParams = helpCommand.getCommandParams(command, locale);
|
||||
|
||||
expect(commandParams).toBe('');
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user