From 42b361ddd95ee9357d897f5e4938cdcf419a4030 Mon Sep 17 00:00:00 2001 From: Abhimanyu Saharan Date: Wed, 25 Feb 2026 02:32:42 +0530 Subject: [PATCH] test(frontend): stabilize auth boundary tests for local auth mode --- frontend/src/app/activity/page.test.tsx | 30 +++++++++++++++++------- frontend/src/app/approvals/page.test.tsx | 30 +++++++++++++++++------- 2 files changed, 44 insertions(+), 16 deletions(-) diff --git a/frontend/src/app/activity/page.test.tsx b/frontend/src/app/activity/page.test.tsx index 981934c1..388a5826 100644 --- a/frontend/src/app/activity/page.test.tsx +++ b/frontend/src/app/activity/page.test.tsx @@ -62,19 +62,33 @@ vi.mock("@clerk/nextjs", () => { describe("/activity auth boundary", () => { it("renders without ClerkProvider runtime errors when publishable key is a placeholder", () => { + const previousAuthMode = process.env.NEXT_PUBLIC_AUTH_MODE; + const previousPublishableKey = process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY; + // Simulate CI/secretless env where an arbitrary placeholder value may be present. // AuthProvider should treat this as disabled, and the auth wrappers must not render // Clerk SignedOut/SignedIn components. + process.env.NEXT_PUBLIC_AUTH_MODE = "local"; process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY = "placeholder"; + window.sessionStorage.clear(); - render( - - - - - , - ); + try { + render( + + + + + , + ); - expect(screen.getByText(/sign in to view the feed/i)).toBeInTheDocument(); + expect( + screen.getByRole("heading", { name: /local authentication/i }), + ).toBeInTheDocument(); + expect(screen.getByLabelText(/access token/i)).toBeInTheDocument(); + } finally { + process.env.NEXT_PUBLIC_AUTH_MODE = previousAuthMode; + process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY = previousPublishableKey; + window.sessionStorage.clear(); + } }); }); diff --git a/frontend/src/app/approvals/page.test.tsx b/frontend/src/app/approvals/page.test.tsx index f747b5bf..cb812fac 100644 --- a/frontend/src/app/approvals/page.test.tsx +++ b/frontend/src/app/approvals/page.test.tsx @@ -59,16 +59,30 @@ vi.mock("@clerk/nextjs", () => { describe("/approvals auth boundary", () => { it("renders without ClerkProvider runtime errors when publishable key is a placeholder", () => { + const previousAuthMode = process.env.NEXT_PUBLIC_AUTH_MODE; + const previousPublishableKey = process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY; + + process.env.NEXT_PUBLIC_AUTH_MODE = "local"; process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY = "placeholder"; + window.sessionStorage.clear(); - render( - - - - - , - ); + try { + render( + + + + + , + ); - expect(screen.getByText(/sign in to view approvals/i)).toBeInTheDocument(); + expect( + screen.getByRole("heading", { name: /local authentication/i }), + ).toBeInTheDocument(); + expect(screen.getByLabelText(/access token/i)).toBeInTheDocument(); + } finally { + process.env.NEXT_PUBLIC_AUTH_MODE = previousAuthMode; + process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY = previousPublishableKey; + window.sessionStorage.clear(); + } }); });