fix unit test

This commit is contained in:
Marius Begby committed 2023-12-23 23:29:00 +01:00
1 parent 733b638cb0
commit 40b1d86554
2 files changed
+10 -8

No files matched your search

+6 -6
View File
@@ -7,6 +7,7 @@ import {
ChatInputCommandInteraction, ChatInputCommandInteraction,
Collection, Collection,
ComponentType, ComponentType,
LocaleString,
EmbedBuilder, EmbedBuilder,
SlashCommandBuilder, SlashCommandBuilder,
SlashCommandNumberOption, SlashCommandNumberOption,
@@ -91,22 +92,22 @@ class HelpCommand extends BaseSlashCommandInteraction {
): Promise<string> { ): Promise<string> {
const commandCollection = this.getNonSystemCommands(client!); const commandCollection = this.getNonSystemCommands(client!);
const locale = interaction.guildLocale ?? 'en-US';
const commandStringList = commandCollection.map((command: BaseSlashCommandInteraction) => { const commandStringList = commandCollection.map((command: BaseSlashCommandInteraction) => {
return this.getCommandString(command, interaction); return this.getCommandString(command, locale);
}); });
const commandString = commandStringList.join('\n'); const commandString = commandStringList.join('\n');
return commandString; return commandString;
} }
private getCommandString(command: BaseSlashCommandInteraction, interaction: ChatInputCommandInteraction): string { private getCommandString(command: BaseSlashCommandInteraction, locale: LocaleString): string {
const commandName = command.data.name; const commandName = command.data.name;
const metadataKey = `commands.${commandName}.metadata`; const metadataKey = `commands.${commandName}.metadata`;
const locale = interaction.guildLocale ?? 'en-US';
let translatedData: CommandMetadata | undefined = undefined; let translatedData: CommandMetadata | undefined = undefined;
translatedData = translatorInstance.getResource(locale, 'bot', metadataKey) as CommandMetadata | undefined; translatedData = translatorInstance.getResource(locale, 'bot', metadataKey) as CommandMetadata | undefined;
const commandParams: string = this.getCommandParams(command, interaction); const commandParams: string = this.getCommandParams(command, locale);
const beta: string = command.isBeta ? `${this.embedOptions.icons.beta} ` : ''; const beta: string = command.isBeta ? `${this.embedOptions.icons.beta} ` : '';
const newCommand: string = command.isNew ? `${this.embedOptions.icons.new} ` : ''; const newCommand: string = command.isNew ? `${this.embedOptions.icons.new} ` : '';
@@ -116,13 +117,12 @@ class HelpCommand extends BaseSlashCommandInteraction {
}`; }`;
} }
private getCommandParams(command: BaseSlashCommandInteraction, interaction: ChatInputCommandInteraction): string { private getCommandParams(command: BaseSlashCommandInteraction, locale: LocaleString): string {
const commandName = command.data.name; const commandName = command.data.name;
const option = command.data.options[0]; const option = command.data.options[0];
if (option instanceof SlashCommandNumberOption || option instanceof SlashCommandStringOption) { if (option instanceof SlashCommandNumberOption || option instanceof SlashCommandStringOption) {
const metadataKey = `commands.${commandName}.metadata.options.${option.name}`; const metadataKey = `commands.${commandName}.metadata.options.${option.name}`;
const locale = interaction.guildLocale ?? 'en-US';
let translatedData: CommandMetadata | undefined = undefined; let translatedData: CommandMetadata | undefined = undefined;
translatedData = translatorInstance.getResource(locale, 'bot', metadataKey) as CommandMetadata | undefined; translatedData = translatorInstance.getResource(locale, 'bot', metadataKey) as CommandMetadata | undefined;
return `**\`${translatedData?.name ?? option.name}\`** `; return `**\`${translatedData?.name ?? option.name}\`** `;
+4 -2
View File
@@ -16,7 +16,8 @@ describe('HelpCommand', () => {
} }
} as unknown as BaseSlashCommandInteraction; } as unknown as BaseSlashCommandInteraction;
const commandParams = helpCommand['getCommandParams'](command); const locale = 'en-US';
const commandParams = helpCommand['getCommandParams'](command, locale);
expect(commandParams).toBe('**`optionname`** '); expect(commandParams).toBe('**`optionname`** ');
}); });
@@ -28,7 +29,8 @@ describe('HelpCommand', () => {
} }
} as unknown as BaseSlashCommandInteraction; } as unknown as BaseSlashCommandInteraction;
const commandParams = helpCommand['getCommandParams'](command); const locale = 'en-US';
const commandParams = helpCommand['getCommandParams'](command, locale);
expect(commandParams).toBe(''); expect(commandParams).toBe('');
}); });