From c698c77bdfb8c7bb130fd9d4f970246fa36d3962 Mon Sep 17 00:00:00 2001 From: gc <30398469+gc@users.noreply.github.com> Date: Sun, 10 Mar 2024 15:30:47 +1100 Subject: [PATCH] commit --- tests/integration/allCommandsBase.test.ts | 50 +++++++++++++++-------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/tests/integration/allCommandsBase.test.ts b/tests/integration/allCommandsBase.test.ts index ee20c8be04..0aa916f9ea 100644 --- a/tests/integration/allCommandsBase.test.ts +++ b/tests/integration/allCommandsBase.test.ts @@ -1,5 +1,5 @@ import { ApplicationCommandOptionType } from 'discord.js'; -import { randInt } from 'e'; +import { randInt, shuffleArr } from 'e'; import { CommandOption } from 'mahoji/dist/lib/types'; import { test, vi } from 'vitest'; @@ -40,7 +40,18 @@ import { smeltingCommand } from '../../src/mahoji/commands/smelt'; import { stealCommand } from '../../src/mahoji/commands/steal'; import { toolsCommand } from '../../src/mahoji/commands/tools'; import { randomMock } from './setup'; -import { createTestUser } from './util'; +import { createTestUser, TestUser } from './util'; + +// Don't let any of these commands create an activity +vi.mock('../../../src/lib/util/addSubTaskToActivityTask', async () => { + const actual: any = await vi.importActual('../../../src/lib/util/addSubTaskToActivityTask'); + return { + ...actual, + default: async (args: any) => { + console.log(`Sending ${args}`); + } + }; +}); const commands = [ activitiesCommand, @@ -83,7 +94,11 @@ const commands = [ ]; type CommandInput = Record; -function generateCommandInputs(options: CommandOption[], currentPath: CommandInput = {}): CommandInput[] { +async function generateCommandInputs( + user: TestUser, + options: CommandOption[], + currentPath: CommandInput = {} +): Promise { let results: CommandInput[] = []; for (const option of options) { @@ -91,13 +106,21 @@ function generateCommandInputs(options: CommandOption[], currentPath: CommandInp case ApplicationCommandOptionType.SubcommandGroup: case ApplicationCommandOptionType.Subcommand: if (option.options) { - const subOptionsResults = generateCommandInputs(option.options); + const subOptionsResults = await generateCommandInputs(user, option.options); subOptionsResults.forEach(subResult => { results.push({ [option.name]: subResult }); }); } break; case ApplicationCommandOptionType.String: + if ('autocomplete' in option && option.autocomplete) { + const autoCompleteResults = await option.autocomplete('', { id: user.id } as any, {} as any); + shuffleArr(autoCompleteResults) + .slice(0, 5) + .forEach(result => { + results.push({ ...currentPath, [option.name]: result.value as string }); + }); + } if (option.choices) { option.choices.forEach(choice => { results.push({ ...currentPath, [option.name]: choice.value }); @@ -135,26 +158,17 @@ function generateCommandInputs(options: CommandOption[], currentPath: CommandInp return results; } -// Don't let any of these commands create an activity -vi.mock('../../src/lib/util/addSubTaskToActivityTask', async () => { - const actual: any = await vi.importActual('../../src/lib/util/addSubTaskToActivityTask'); - return { - ...actual, - default: async (args: any) => { - console.log(`Sending ${args}`); - } - }; -}); - test('All Commands Base Test', async () => { randomMock(); const user = await createTestUser(); for (const command of commands) { - const options = generateCommandInputs(command.options!); + const options = await generateCommandInputs(user, command.options!); for (const option of options) { try { - await user.runCommand(command, option); - console.log(`Ran command ${command.name}`); + const res = await user.runCommand(command, option); + console.log(`Ran command ${command.name} +Options: ${JSON.stringify(option)} +Result: ${res}`); } catch (err) { console.error(`Failed to run command ${command.name} with options ${JSON.stringify(option)}`); }