test: give every case its own mock state under a shuffled order

Cases leaned on what an earlier case set up or left behind: a once-value
the code under test never consumed, an implementation swapped in and
kept by clearAllMocks, a payload only another block's setup provided,
the zone resolver's per-user cache, module state in a hoisted object,
and a scope set one case discovered for the next. Each now resets or
states what it reads.
This commit is contained in:
Marc-André Bombeck committed 2026-11-03 20:58:38 +01:00
1 parent 4f7802ba28
commit 227c80878c
11 files changed
+90 -37

No files matched your search

@@ -60,6 +60,14 @@ import { GET } from "../route";
import { prisma } from "@/lib/db";
import { requireAdmin } from "@/lib/api-handler";
// Reset, not clear, before every case: cases replace the paused rows, the
// settings row and the account groups, and a cleared mock would hand the
// next case whatever the last one left there. A reset mock goes back to the
// empty answer it was created with.
beforeEach(() => {
vi.resetAllMocks();
});
const groupBy = vi.mocked(prisma.providerHealth.groupBy);
const usageRows = vi.mocked(prisma.coachUsage.findMany);
@@ -101,7 +109,6 @@ function group(
describe("GET /api/admin/provider-health", () => {
beforeEach(() => {
vi.clearAllMocks();
vi.mocked(requireAdmin).mockResolvedValue({
user: { id: "admin1" },
} as never);
@@ -302,7 +309,6 @@ describe("GET /api/admin/provider-health — pause and model check (v1.42)", ()
const settings = vi.mocked(prisma.appSettings.findUnique);
beforeEach(() => {
vi.clearAllMocks();
vi.mocked(requireAdmin).mockResolvedValue({
user: { id: "admin" },
} as never);