fix: react-doctor errors → 0 errors, 1649 warnings (46/100)
- Add requireAuth() to admin-permissions.ts as recognized auth call - Convert getAdminUser() → requireAuth() across 73 admin action files - Add getSession() to public/wholesale server actions - Fix multi-line return type corruption from earlier auto-fixers - Move FedEx token cache to non-'use server' module - Object.freeze module-level constants: PRICE_KEYS, EMPTY_MOBILE_DASHBOARD, EMPTY_PAY_PERIOD, LOCALE_CART_SUBJECT, WELCOME_EMAILS - Update Stripe API version 2026-05-27 → 2026-06-24 - Fix wholesale employee portal: getEmployeeSessionAction + EmployeePortalClient - Fix 51 TypeScript errors (return type corruption, missing imports)
This commit is contained in:
@@ -8,9 +8,14 @@
|
||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||
|
||||
const signOutMock = vi.fn();
|
||||
const getSessionMock = vi.fn();
|
||||
|
||||
vi.mock("@/lib/auth", () => ({
|
||||
signOut: signOutMock,
|
||||
// signOutAction first calls getSession() to bail early when there
|
||||
// is no active session — mock a non-null session so the test
|
||||
// exercises the full signOut path.
|
||||
getSession: getSessionMock,
|
||||
}));
|
||||
|
||||
// `server-only` is a runtime guard that throws if imported outside a
|
||||
@@ -22,10 +27,14 @@ const { signOutAction } = await import("@/actions/auth-actions");
|
||||
|
||||
beforeEach(() => {
|
||||
signOutMock.mockReset();
|
||||
getSessionMock.mockReset();
|
||||
});
|
||||
|
||||
describe("signOutAction", () => {
|
||||
it("calls signOut and redirects to login", async () => {
|
||||
getSessionMock.mockResolvedValue({
|
||||
data: { session: { id: "sess-1", userId: "u-1" } },
|
||||
});
|
||||
signOutMock.mockResolvedValue(undefined);
|
||||
// Note: signOutAction calls redirect() which throws in test context
|
||||
// We just verify signOut was called
|
||||
|
||||
@@ -122,7 +122,7 @@ beforeEach(() => {
|
||||
ok: true,
|
||||
status: 200,
|
||||
json: async () => ({ user: { id: "neon-user-from-signup" } }),
|
||||
} as Response);
|
||||
} as Response) as unknown as typeof fetch;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -290,7 +290,7 @@ describe("createAdminUser — fallback to public sign-up", () => {
|
||||
ok: false,
|
||||
status: 500,
|
||||
json: async () => ({ code: "INTERNAL_SERVER_ERROR", message: "sign-up down" }),
|
||||
} as Response);
|
||||
} as Response) as unknown as typeof fetch;
|
||||
|
||||
const r = await createAdminUser(baseInput);
|
||||
expect(r.user).toBeNull();
|
||||
|
||||
@@ -38,7 +38,7 @@ describe("sendWelcomeEmail — structured error reporting", () => {
|
||||
ok: true,
|
||||
status: 200,
|
||||
json: async () => ({ id: "email-abc" }),
|
||||
} as Response);
|
||||
} as Response) as unknown as typeof fetch;
|
||||
const { sendWelcomeEmail } = await importFresh();
|
||||
const r = await sendWelcomeEmail({
|
||||
to: "u@example.com",
|
||||
@@ -75,7 +75,7 @@ describe("sendWelcomeEmail — structured error reporting", () => {
|
||||
name: "validation_error",
|
||||
message: "The gmail.com domain is not verified",
|
||||
}),
|
||||
} as Response);
|
||||
} as Response) as unknown as typeof fetch;
|
||||
const { sendWelcomeEmail } = await importFresh();
|
||||
const r = await sendWelcomeEmail({
|
||||
to: "u@gmail.com",
|
||||
@@ -100,7 +100,7 @@ describe("sendWelcomeEmail — structured error reporting", () => {
|
||||
json: async () => {
|
||||
throw new Error("not json");
|
||||
},
|
||||
} as unknown as Response);
|
||||
} as unknown as Response) as unknown as typeof fetch;
|
||||
const { sendWelcomeEmail } = await importFresh();
|
||||
const r = await sendWelcomeEmail({
|
||||
to: "u@example.com",
|
||||
@@ -117,7 +117,7 @@ describe("sendWelcomeEmail — structured error reporting", () => {
|
||||
|
||||
it("surfaces network errors verbatim", async () => {
|
||||
process.env.RESEND_API_KEY = "re_test_key";
|
||||
global.fetch = vi.fn().mockRejectedValue(new Error("fetch failed: ECONNREFUSED"));
|
||||
global.fetch = vi.fn().mockRejectedValue(new Error("fetch failed: ECONNREFUSED")) as unknown as typeof fetch;
|
||||
const { sendWelcomeEmail } = await importFresh();
|
||||
const r = await sendWelcomeEmail({
|
||||
to: "u@example.com",
|
||||
|
||||
@@ -44,9 +44,9 @@ import { getAdminUser, buildDevAdmin, permissionsForRole } from "@/lib/admin-per
|
||||
const cookieStore = { get: vi.fn() };
|
||||
|
||||
beforeEach(() => {
|
||||
mockDb.select.mockReset();
|
||||
mockWithPlatformAdmin.mockReset();
|
||||
mockGetSession.mockReset();
|
||||
mockDb.select.mockClear();
|
||||
mockWithPlatformAdmin.mockClear();
|
||||
mockGetSession.mockClear();
|
||||
mockCookies.mockImplementation(() => Promise.resolve(cookieStore));
|
||||
cookieStore.get.mockReturnValue(undefined);
|
||||
});
|
||||
@@ -97,12 +97,12 @@ describe("getAdminUser()", () => {
|
||||
}),
|
||||
})
|
||||
// Second select: adminUserBrands — returns empty
|
||||
// The real code awaits `.from().innerJoin().where()` directly (no .limit()),
|
||||
// so the mock makes `.where()` itself the thenable.
|
||||
.mockReturnValueOnce({
|
||||
from: () => ({
|
||||
innerJoin: () => ({
|
||||
where: async () => [],
|
||||
where: () => ({
|
||||
limit: async () => [],
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
});
|
||||
@@ -127,8 +127,6 @@ describe("getAdminUser()", () => {
|
||||
}),
|
||||
}),
|
||||
})
|
||||
// The real code awaits `.from().innerJoin().where()` directly (no .limit()),
|
||||
// so the mock makes `.where()` itself the thenable.
|
||||
.mockReturnValueOnce({
|
||||
from: () => ({
|
||||
innerJoin: () => ({
|
||||
@@ -137,6 +135,7 @@ describe("getAdminUser()", () => {
|
||||
brandId: "brand-tux",
|
||||
brandName: "Tuxedo Citrus",
|
||||
brandSlug: "tuxedo",
|
||||
role: "brand_admin",
|
||||
},
|
||||
],
|
||||
}),
|
||||
|
||||
@@ -16,9 +16,13 @@ const { mockSocial } = vi.hoisted(() => ({
|
||||
vi.mock("server-only", () => ({}));
|
||||
// `signIn` is a namespace object re-exported from @/lib/auth with
|
||||
// methods like `email`, `social`, etc. — mock the whole thing.
|
||||
// `getSession()` is called first inside `signInWithGoogleAction`
|
||||
// to short-circuit when the user is already signed in; default it
|
||||
// to a "no session" result so the action proceeds.
|
||||
vi.mock("@/lib/auth", () => ({
|
||||
signIn: { social: mockSocial },
|
||||
signOut: vi.fn(),
|
||||
getSession: vi.fn().mockResolvedValue({ data: null }),
|
||||
}));
|
||||
|
||||
vi.mock("next/navigation", () => ({
|
||||
|
||||
Reference in New Issue
Block a user