From 1ac69420d533700ba094f93f3c47b566fd4a1397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Tue, 3 Nov 2026 22:22:32 +0100 Subject: [PATCH] test: reset to the factory answer instead of casting a new one A reset mock goes back to the implementation its factory gave it, which is the fresh session and the open capability these cases want; the cast replacements grew the test-realism count. --- .../export/__tests__/soft-delete-filter.test.ts | 14 ++++---------- .../chat/[id]/attachments/__tests__/route.test.ts | 13 ++++--------- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/src/app/api/export/__tests__/soft-delete-filter.test.ts b/src/app/api/export/__tests__/soft-delete-filter.test.ts index 50363cc58..5b3478183 100644 --- a/src/app/api/export/__tests__/soft-delete-filter.test.ts +++ b/src/app/api/export/__tests__/soft-delete-filter.test.ts @@ -174,16 +174,10 @@ beforeEach(() => { vi.mocked(isModuleEnabled).mockResolvedValue(true); vi.mocked(requireModuleEnabled).mockResolvedValue({ enabled: true } as never); vi.mocked(getSession).mockResolvedValue(SESSION_OK as never); - // A session that signed in just now. Reset, not only cleared: a case below - // swaps in a stale session, and `clearAllMocks` keeps the implementation - // it left behind for whichever case runs next. - vi.mocked(prisma.session.findUnique) - .mockReset() - .mockImplementation((async () => ({ - createdAt: new Date(), - mfaVerifiedAt: null, - reproofAt: null, - })) as never); + // A session that signed in just now, the factory's own answer. Reset, not + // only cleared: a case below swaps in a stale session, and `clearAllMocks` + // keeps the implementation it left behind for whichever case runs next. + vi.mocked(prisma.session.findUnique).mockReset(); vi.mocked(checkRateLimit).mockResolvedValue({ allowed: true, limit: 60, diff --git a/src/app/api/insights/chat/[id]/attachments/__tests__/route.test.ts b/src/app/api/insights/chat/[id]/attachments/__tests__/route.test.ts index be0ab6d2e..f5636ee79 100644 --- a/src/app/api/insights/chat/[id]/attachments/__tests__/route.test.ts +++ b/src/app/api/insights/chat/[id]/attachments/__tests__/route.test.ts @@ -87,15 +87,10 @@ beforeEach(() => { vi.clearAllMocks(); vi.mocked(getSession).mockResolvedValue(SESSION_OK as never); vi.mocked(validateAttachmentCandidate).mockResolvedValue({ ok: true }); - // Open again for every case: the detach case closes every capability, and - // `clearAllMocks` would carry that refusal into whichever case runs next. - vi.mocked(requireAiCapability) - .mockReset() - .mockResolvedValue({ - available: true, - reason: null, - onDeviceAllowed: true, - } as never); + // Open again for every case (the factory's own answer): the detach case + // closes every capability, and `clearAllMocks` would carry that refusal + // into whichever case runs next. + vi.mocked(requireAiCapability).mockReset(); }); describe("POST attach", () => {