test: fix stale requireSession mocks after auth-widening pass (v0.30.1)

Four route test files still mocked requireSession after their routes
were converted to requireSessionOrApiKey in an earlier commit this
session — every test in them was failing at the auth call before
reaching the logic under test. Also adds the missing inArray export
to one file's @epicure/db mock, uncovered once its auth mock was
fixed and the test could actually run further.

No production code changed; two unrelated pre-existing failures
(lib/__tests__/tiers.test.ts, lib/__tests__/webhooks.test.ts) remain
and are confirmed present on main before this session's changes.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Arnaud
2026-07-14 14:15:12 +02:00
parent affa6f5c3d
commit 894784afda
8 changed files with 24 additions and 14 deletions
@@ -4,7 +4,7 @@ import { NextRequest } from "next/server";
const mockSession = { user: { id: "user-2" } };
vi.mock("@/lib/api-auth", () => ({
requireSession: vi.fn(),
requireSessionOrApiKey: vi.fn(),
}));
vi.mock("@/lib/webhooks", () => ({
@@ -37,9 +37,10 @@ vi.mock("@epicure/db", () => ({
and: vi.fn((...args) => ({ args, op: "and" })),
or: vi.fn((...args) => ({ args, op: "or" })),
ne: vi.fn((a, b) => ({ a, b, op: "ne" })),
inArray: vi.fn((a, b) => ({ a, b, op: "inArray" })),
}));
const { requireSession } = await import("@/lib/api-auth");
const { requireSessionOrApiKey } = await import("@/lib/api-auth");
import { POST, DELETE } from "../route";
const ctx = { params: Promise.resolve({ mealPlanId: "plan-1" }) };
@@ -54,7 +55,7 @@ function makeRequest(method: string, body?: unknown, search = "") {
beforeEach(() => {
vi.clearAllMocks();
vi.mocked(requireSession).mockResolvedValue({ session: mockSession as never, response: null });
vi.mocked(requireSessionOrApiKey).mockResolvedValue({ session: mockSession as never, response: null });
mockPlanFindFirst.mockResolvedValue({ id: "plan-1", userId: "user-1" });
});