Files
phaseflow/e2e/global-setup.ts
Petru Paler ff3d8fad2c Add Playwright fixtures with 5 test user types for e2e tests
Creates test infrastructure to enable previously skipped e2e tests:
- Onboarding user (no period data) for setup flow tests
- Established user (period 14 days ago) for normal usage tests
- Calendar user (with calendarToken) for ICS feed tests
- Garmin user (valid tokens) for connected state tests
- Garmin expired user (expired tokens) for expiry warning tests

Also fixes ICS feed route to strip .ics suffix from Next.js dynamic
route param, adds calendarToken to /api/user response, and sets
viewRule on users collection for unauthenticated ICS access.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-15 05:54:49 +00:00

51 lines
2.0 KiB
TypeScript

// ABOUTME: Playwright global setup - starts PocketBase and sets test environment variables.
// ABOUTME: Runs before all e2e tests to provide a fresh database with test data.
import * as fs from "node:fs";
import * as path from "node:path";
import { DEFAULT_CONFIG, start, TEST_USERS } from "./pocketbase-harness";
const STATE_FILE = path.join(__dirname, ".harness-state.json");
export default async function globalSetup(): Promise<void> {
console.log("Starting PocketBase for e2e tests...");
const state = await start(DEFAULT_CONFIG);
// Save state for teardown
fs.writeFileSync(
STATE_FILE,
JSON.stringify({
dataDir: state.dataDir,
url: state.url,
pid: state.process.pid,
}),
);
// Set environment variables for the test process
process.env.NEXT_PUBLIC_POCKETBASE_URL = state.url;
process.env.POCKETBASE_URL = state.url;
// Export credentials for each test user type
process.env.TEST_USER_ONBOARDING_EMAIL = TEST_USERS.onboarding.email;
process.env.TEST_USER_ONBOARDING_PASSWORD = TEST_USERS.onboarding.password;
process.env.TEST_USER_ESTABLISHED_EMAIL = TEST_USERS.established.email;
process.env.TEST_USER_ESTABLISHED_PASSWORD = TEST_USERS.established.password;
process.env.TEST_USER_CALENDAR_EMAIL = TEST_USERS.calendar.email;
process.env.TEST_USER_CALENDAR_PASSWORD = TEST_USERS.calendar.password;
process.env.TEST_USER_GARMIN_EMAIL = TEST_USERS.garmin.email;
process.env.TEST_USER_GARMIN_PASSWORD = TEST_USERS.garmin.password;
process.env.TEST_USER_GARMIN_EXPIRED_EMAIL = TEST_USERS.garminExpired.email;
process.env.TEST_USER_GARMIN_EXPIRED_PASSWORD =
TEST_USERS.garminExpired.password;
// Keep backward compatibility - default to established user
process.env.TEST_USER_EMAIL = TEST_USERS.established.email;
process.env.TEST_USER_PASSWORD = TEST_USERS.established.password;
console.log(`PocketBase running at ${state.url}`);
console.log("Test users created:");
for (const [preset, user] of Object.entries(TEST_USERS)) {
console.log(` ${preset}: ${user.email}`);
}
}