/** * Phase 9 — command-aware autocomplete dispatcher tests. * * Uses the injectable _handlers parameter to test the dispatch seam without * requiring real Tag/Ticket DB access. * * Covers: * (a) commandName 'response' → response handler called * (b) unknown commandName → no handler called (no-op) * (c) handler receives the interaction object unchanged */ import { describe, it, expect, vi } from 'vitest'; import { handleAutocomplete } from '../handlers/commands/index.js'; function makeInteraction(commandName) { return { commandName, options: { getSubcommand: vi.fn().mockReturnValue('send'), getFocused: vi.fn().mockReturnValue('') }, respond: vi.fn().mockResolvedValue(undefined) }; } describe('autocomplete dispatcher', () => { it('routes commandName "response" to the response handler', async () => { const responseHandler = vi.fn().mockResolvedValue(undefined); const interaction = makeInteraction('response'); await handleAutocomplete(interaction, { response: responseHandler }); expect(responseHandler).toHaveBeenCalledTimes(1); expect(responseHandler).toHaveBeenCalledWith(interaction); }); it('routes commandName "stats" to the stats handler', async () => { const statsHandler = vi.fn().mockResolvedValue(undefined); const interaction = makeInteraction('stats'); await handleAutocomplete(interaction, { stats: statsHandler }); expect(statsHandler).toHaveBeenCalledTimes(1); expect(statsHandler).toHaveBeenCalledWith(interaction); }); it('no-ops for an unknown commandName', async () => { const responseHandler = vi.fn().mockResolvedValue(undefined); const interaction = makeInteraction('unknown-command'); await handleAutocomplete(interaction, { response: responseHandler }); expect(responseHandler).not.toHaveBeenCalled(); }); it('passes the interaction object through to the handler unchanged', async () => { let received = null; const handler = vi.fn().mockImplementation(async i => { received = i; }); const interaction = makeInteraction('response'); await handleAutocomplete(interaction, { response: handler }); expect(received).toBe(interaction); }); });