850ba3ac9e
The app's App.tsx calls /api/setup/status after auth resolution when
authDisabled=true and a dev user is present. If this endpoint is not
mocked, the browser's network request to the live dev API returns a
200 with needsSetup:true, triggering a redirect to /setup before the
test content can render.
This caused the "no services available" and "clients page" tests to
fail with element not found, since the SetupWizard page was shown
instead of the admin book/clients pages.
Added mock for /api/setup/status in fixtures.ts returning
{needsSetup:false} to match the existing mocking strategy for other
dev-mode API endpoints.
Co-Authored-By: Paperclip <noreply@paperclip.ing>
62 lines
2.1 KiB
TypeScript
62 lines
2.1 KiB
TypeScript
import { test as base } from "@playwright/test";
|
|
|
|
/**
|
|
* Custom test fixture that bypasses auth for E2E tests.
|
|
*
|
|
* When authDisabled=true, the app uses the dev login selector instead of
|
|
* Better Auth signIn.social(). This fixture:
|
|
* 1. Mocks /api/dev/config to return authDisabled: true
|
|
* 2. Seeds localStorage with a dev user so the selector auto-selects a session
|
|
*
|
|
* This ensures E2E tests render pages directly without the auth redirect.
|
|
*/
|
|
const MOCK_DEV_USERS = {
|
|
staff: [
|
|
{ id: "staff-1", name: "Alice Groomer", email: "alice@groombook.dev", role: "groomer" },
|
|
{ id: "staff-2", name: "Bob Manager", email: "bob@groombook.dev", role: "manager" },
|
|
],
|
|
clients: [
|
|
{ id: "client-1", name: "Carol Client", email: "carol@example.com", petCount: 2 },
|
|
{ id: "client-2", name: "Dave Client", email: null, petCount: 1 },
|
|
],
|
|
};
|
|
|
|
export const test = base.extend({
|
|
page: async ({ page }, use) => {
|
|
// Mock the dev config endpoint so the app uses dev login selector (bypasses Better Auth)
|
|
await page.route("**/api/dev/config", (route) =>
|
|
route.fulfill({ json: { authDisabled: true } })
|
|
);
|
|
// Mock the dev users endpoint for login selector tests
|
|
await page.route("**/api/dev/users", (route) =>
|
|
route.fulfill({ json: MOCK_DEV_USERS })
|
|
);
|
|
// Mock the branding endpoint so BrandingProvider resolves immediately
|
|
await page.route("**/api/branding", (route) =>
|
|
route.fulfill({
|
|
json: {
|
|
businessName: "GroomBook",
|
|
primaryColor: "#4f8a6f",
|
|
accentColor: "#8b7355",
|
|
logoBase64: null,
|
|
logoMimeType: null,
|
|
},
|
|
})
|
|
);
|
|
// Mock the setup status endpoint so the app does not redirect to /setup
|
|
await page.route("**/api/setup/status", (route) =>
|
|
route.fulfill({ json: { needsSetup: false } })
|
|
);
|
|
// Seed localStorage as a fallback in case the mock is bypassed
|
|
await page.addInitScript(() => {
|
|
localStorage.setItem(
|
|
"dev-user",
|
|
JSON.stringify({ type: "staff", id: "dev-user", name: "Dev User" })
|
|
);
|
|
});
|
|
await use(page);
|
|
},
|
|
});
|
|
|
|
export { expect } from "@playwright/test";
|