test(documents): wire content-index mocks into the list route test

P2-1. The list GET now issues a documentContentIndex lookup and unions a
content-token OR branch when a search term is present, so the existing route
test gains the mock + the third OR branch in its where assertion. Fix the
backfill test's findFirst mock signature under strict tsc.
This commit is contained in:
Marc-André Bombeck committed 2026-07-07 18:41:09 +02:00
1 parent b210c743e9
commit 1f7807aead
16 files changed
+211 -55

No files matched your search

@@ -39,6 +39,9 @@ vi.mock("@/lib/db", () => {
documentConditionLink: {
findMany: vi.fn(),
},
documentContentIndex: {
findMany: vi.fn(),
},
illnessEpisode: {
findMany: vi.fn(),
},
@@ -155,6 +158,9 @@ beforeEach(() => {
vi.mocked(prisma.documentConditionLink.findMany).mockResolvedValue(
[] as never,
);
vi.mocked(prisma.documentContentIndex.findMany).mockResolvedValue(
[] as never,
);
vi.mocked(prisma.inboundDocument.findFirst).mockResolvedValue(null as never);
// No settings row / no user override → policy defaults (25 MiB / 1 GiB).
vi.mocked(prisma.appSettings.findUnique).mockResolvedValue(null as never);
@@ -346,9 +352,12 @@ describe("GET /api/documents/inbound (list)", () => {
expect(where.deletedAt).toBeNull();
expect(where.kind).toEqual({ in: ["LAB_RESULT", "IMAGING"] });
expect(where.conditionLinks).toEqual({ some: { episodeId: "ep-1" } });
// Title/filename substring branches, unioned with the blind content-token
// overlap (the third branch carries the HMAC'd query tokens for "panel").
expect(where.OR).toEqual([
{ title: { contains: "panel", mode: "insensitive" } },
{ filename: { contains: "panel", mode: "insensitive" } },
{ contentIndex: { is: { searchTokens: { hasSome: expect.any(Array) } } } },
]);
// limit+1 fetched for the has-more probe.
expect(arg.take).toBe(11);