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:
@@ -4,7 +4,7 @@ import { NextRequest } from "next/server";
|
||||
const mockSession = { user: { id: "user-1" } };
|
||||
|
||||
vi.mock("@/lib/api-auth", () => ({
|
||||
requireSession: vi.fn(),
|
||||
requireSessionOrApiKey: vi.fn(),
|
||||
}));
|
||||
|
||||
const { mockPlanFindFirst, mockMemberFindFirst, mockMemberFindMany, mockUserFindFirst, mockInsertValues, mockInsertPlanValues, mockDeleteWhere } = vi.hoisted(() => ({
|
||||
@@ -34,7 +34,7 @@ vi.mock("@epicure/db", () => ({
|
||||
and: vi.fn((...args) => ({ args, op: "and" })),
|
||||
}));
|
||||
|
||||
const { requireSession } = await import("@/lib/api-auth");
|
||||
const { requireSessionOrApiKey } = await import("@/lib/api-auth");
|
||||
import { GET, POST, DELETE } from "../route";
|
||||
|
||||
const ctx = { params: Promise.resolve({ weekStart: "2026-06-01" }) };
|
||||
@@ -49,7 +49,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 });
|
||||
});
|
||||
|
||||
describe("GET /api/v1/meal-plans/[weekStart]/members", () => {
|
||||
@@ -123,7 +123,7 @@ describe("DELETE /api/v1/meal-plans/[weekStart]/members", () => {
|
||||
it("returns 403 when caller is neither owner nor the member themselves", async () => {
|
||||
mockPlanFindFirst.mockResolvedValue({ id: "plan-1", userId: "user-1" });
|
||||
mockMemberFindFirst.mockResolvedValue({ id: "m1", userId: "user-2" });
|
||||
vi.mocked(requireSession).mockResolvedValue({ session: { user: { id: "user-3" } } as never, response: null });
|
||||
vi.mocked(requireSessionOrApiKey).mockResolvedValue({ session: { user: { id: "user-3" } } as never, response: null });
|
||||
const res = await DELETE(makeRequest("DELETE", undefined, "?memberId=m1"), ctx);
|
||||
expect(res.status).toBe(403);
|
||||
});
|
||||
|
||||
@@ -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" });
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user