Skip to content
GitHub

resolveRoute

function in meocord/testing Since 4.0.0

resolveRoute(
  app: ControllerClass,
  input: { type: ComponentCommandType; customId: string } | MessageToResolve,
): ResolvedRoute | undefined

Resolves which handler a component's customId or a message's content reaches, as dispatch routes it.

Use it to check routing alone, in a plain unit test: it reads decorator metadata, with no client, config or container, and runs no guard. To run the handler it reaches, use TestingModule.dispatch.

Parameters

NameTypeSinceDescription
appControllerClass

The application class decorated with @MeoCord.

input| { type: ComponentCommandType customId: string } | MessageToResolve4.1.0

The component type and its customId, or the message's content with its prefix and the bot's id.

Returns

ResolvedRoute | undefined

The handler that runs, with the params it captures, or undefined when no route handles the input.

Throws

  • TypeError for a message to an app whose prefix is a function, when no prefix is given.

Examples

TypeScript
import { expect } from 'vitest'

@Controller()
class ProfileController {
  @Command('profile/{uid}', CommandType.BUTTON)
  async show(interaction: ButtonInteraction, { uid }: { uid: string }) {
    await respond(interaction).send(`Profile ${uid}`)
  }
}
@MeoCord({ controllers: [ProfileController], clientOptions: { intents: [] } })
class App {}
const route = resolveRoute(App, { type: CommandType.BUTTON, customId: 'profile/8000' })
expect([route?.handler, route?.params]).toEqual([ProfileController.prototype.show, { uid: '8000' }])