test(e2e): stubbed /activity feed scenarios (auth bypass)

This commit is contained in:
Kunal
2026-02-07 16:29:14 +00:00
parent 03803f21fb
commit 0f9d040792
2 changed files with 112 additions and 0 deletions

View File

@@ -0,0 +1,94 @@
describe("/activity feed", () => {
const apiBase = "**/api/v1";
function stubStreamEmpty() {
// Return a minimal SSE response that ends immediately.
cy.intercept(
"GET",
`${apiBase}/activity/task-comments/stream*`,
{
statusCode: 200,
headers: {
"content-type": "text/event-stream",
},
body: "",
},
).as("activityStream");
}
it("happy path: renders task comment cards", () => {
cy.intercept("GET", `${apiBase}/activity/task-comments*`, {
statusCode: 200,
body: {
items: [
{
id: "c1",
message: "Hello world",
agent_name: "Kunal",
agent_role: "QA 2",
board_id: "b1",
board_name: "Testing",
task_id: "t1",
task_title: "CI hardening",
created_at: "2026-02-07T00:00:00Z",
},
{
id: "c2",
message: "Second comment",
agent_name: "Riya",
agent_role: "QA",
board_id: "b1",
board_name: "Testing",
task_id: "t2",
task_title: "Coverage policy",
created_at: "2026-02-07T00:01:00Z",
},
],
},
}).as("activityList");
stubStreamEmpty();
cy.visit("/activity", {
onBeforeLoad(win) {
win.localStorage.clear();
},
});
cy.wait("@activityList");
cy.contains(/live feed/i).should("be.visible");
cy.contains("CI hardening").should("be.visible");
cy.contains("Coverage policy").should("be.visible");
cy.contains("Hello world").should("be.visible");
});
it("empty state: shows waiting message when no items", () => {
cy.intercept("GET", `${apiBase}/activity/task-comments*`, {
statusCode: 200,
body: { items: [] },
}).as("activityList");
stubStreamEmpty();
cy.visit("/activity");
cy.wait("@activityList");
cy.contains(/waiting for new comments/i).should("be.visible");
});
it("error state: shows failure UI when API errors", () => {
cy.intercept("GET", `${apiBase}/activity/task-comments*`, {
statusCode: 500,
body: { detail: "boom" },
}).as("activityList");
stubStreamEmpty();
cy.visit("/activity");
cy.wait("@activityList");
// UI uses query.error.message or fallback.
cy.contains(/unable to load feed|boom/i).should("be.visible");
});
});

View File

@@ -19,20 +19,29 @@ import type { ComponentProps } from "react";
import { isLikelyValidClerkPublishableKey } from "@/auth/clerkKey"; import { isLikelyValidClerkPublishableKey } from "@/auth/clerkKey";
function isE2EAuthBypassEnabled(): boolean {
// Used only for Cypress E2E to keep tests secretless and deterministic.
// When enabled, we treat the user as signed in and skip Clerk entirely.
return process.env.NEXT_PUBLIC_E2E_AUTH_BYPASS === "1";
}
export function isClerkEnabled(): boolean { export function isClerkEnabled(): boolean {
// IMPORTANT: keep this in sync with AuthProvider; otherwise components like // IMPORTANT: keep this in sync with AuthProvider; otherwise components like
// <SignedOut/> may render without a <ClerkProvider/> and crash during prerender. // <SignedOut/> may render without a <ClerkProvider/> and crash during prerender.
if (isE2EAuthBypassEnabled()) return false;
return isLikelyValidClerkPublishableKey( return isLikelyValidClerkPublishableKey(
process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY, process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY,
); );
} }
export function SignedIn(props: { children: ReactNode }) { export function SignedIn(props: { children: ReactNode }) {
if (isE2EAuthBypassEnabled()) return <>{props.children}</>;
if (!isClerkEnabled()) return null; if (!isClerkEnabled()) return null;
return <ClerkSignedIn>{props.children}</ClerkSignedIn>; return <ClerkSignedIn>{props.children}</ClerkSignedIn>;
} }
export function SignedOut(props: { children: ReactNode }) { export function SignedOut(props: { children: ReactNode }) {
if (isE2EAuthBypassEnabled()) return null;
if (!isClerkEnabled()) return <>{props.children}</>; if (!isClerkEnabled()) return <>{props.children}</>;
return <ClerkSignedOut>{props.children}</ClerkSignedOut>; return <ClerkSignedOut>{props.children}</ClerkSignedOut>;
} }
@@ -58,6 +67,15 @@ export function useUser() {
} }
export function useAuth() { export function useAuth() {
if (isE2EAuthBypassEnabled()) {
return {
isLoaded: true,
isSignedIn: true,
userId: "e2e-user",
sessionId: "e2e-session",
getToken: async () => "e2e-token",
} as const;
}
if (!isClerkEnabled()) { if (!isClerkEnabled()) {
return { return {
isLoaded: true, isLoaded: true,