import { describe, expect, it, vi } from "vitest"; const mocks = vi.hoisted(() => ({ loadContext: vi.fn(), loadSuggestions: vi.fn() })); vi.mock("~/modules/chat/routes/chatAccess.server", () => ({ loadChatContext: mocks.loadContext })); vi.mock("~/modules/chat/services/ChatMentionsService.server", () => ({ loadChatMentionSuggestions: mocks.loadSuggestions })); import { loader } from "./chat.$id.mentions"; describe("chat mention resource route", () => { it("normalizes the requested kind and returns the server-built VM", async () => { const context = { tenantId: "tenant_1", userId: "user_1", permissions: [], hasModule: true }; mocks.loadContext.mockResolvedValue(context); mocks.loadSuggestions.mockResolvedValue({ groups: [], total: 0 }); const response = await loader({ request: new Request("https://app.test/acme/chat/chat_1/mentions?q=anna&type=contact"), params: { tenant: "acme", id: "chat_1" }, context: {}, } as never); expect(response.status).toBe(200); expect(mocks.loadSuggestions).toHaveBeenCalledWith({ context, tenantSlug: "acme", chatId: "chat_1", query: "anna", type: "contact" }); }); it("does not pass an unsupported kind into the repository", async () => { mocks.loadContext.mockResolvedValue({ tenantId: "tenant_1", userId: "user_1", permissions: [], hasModule: true }); mocks.loadSuggestions.mockResolvedValue({ groups: [], total: 0 }); await loader({ request: new Request("https://app.test/acme/chat/chat_1/mentions?type=deal"), params: { tenant: "acme", id: "chat_1" }, context: {}, } as never); expect(mocks.loadSuggestions).toHaveBeenLastCalledWith(expect.objectContaining({ type: null })); }); });