import { describe, expect, it, vi } from "vitest"; const mocks = vi.hoisted(() => ({ list: vi.fn() })); vi.mock("@hivegrid/chat/mentions.server", () => ({ listChatMentionSuggestions: mocks.list })); import { loadChatMentionSuggestions } from "./ChatMentionsService.server"; describe("loadChatMentionSuggestions", () => { it("passes the route identity to the fresh repository and returns the pure grouped VM", async () => { mocks.list.mockResolvedValue([ { type: "user", id: "user_1", label: "Raffael", detail: "raffael@example.test" }, { type: "project", id: "project_1", label: "P-100", detail: "P-100" }, ]); const context = { tenantId: "tenant_1", tenantUserId: "tenant_user_1", userId: "user_1", permissions: ["chat.read_own_channels"], hasModule: true as const, }; const vm = await loadChatMentionSuggestions({ context, tenantSlug: "acme", chatId: "chat_1", query: "ra", type: null }); expect(mocks.list).toHaveBeenCalledWith( expect.objectContaining({ tenantId: "tenant_1", userId: "user_1", chatId: "chat_1", query: "ra", limit: 10 }) ); expect(vm.groups.map((group) => group.kind)).toEqual(["user", "project"]); }); });