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.
This commit is contained in:
Marc-André Bombeck committed 2026-11-03 22:22:32 +01:00
1 parent 9a3140a4d3
commit 1ac69420d5
2 files changed
+8 -19

No files matched your search

@@ -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,
@@ -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", () => {