Fix E2E test reliability issues and stale data bugs
- Fix race conditions: Set workers: 1 since all tests share test user state - Fix stale data: GET /api/user and /api/cycle/current now fetch fresh data from database instead of returning stale PocketBase auth store cache - Fix timing: Replace waitForTimeout with retry-based Playwright assertions - Fix mobile test: Use exact heading match to avoid strict mode violation - Add test user setup: Include notificationTime and update rule for users All 1014 unit tests and 190 E2E tests pass. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -13,23 +13,28 @@ const TIME_FORMAT_REGEX = /^([01]\d|2[0-3]):([0-5]\d)$/;
|
||||
/**
|
||||
* GET /api/user
|
||||
* Returns the authenticated user's profile.
|
||||
* Fetches fresh data from database to ensure updates are reflected.
|
||||
* Excludes sensitive fields like encrypted tokens.
|
||||
*/
|
||||
export const GET = withAuth(async (_request, user, _pb) => {
|
||||
export const GET = withAuth(async (_request, user, pb) => {
|
||||
// Fetch fresh user data from database to get latest values
|
||||
// The user param from withAuth is from auth store cache which may be stale
|
||||
const freshUser = await pb.collection("users").getOne(user.id);
|
||||
|
||||
// Format date for consistent API response
|
||||
const lastPeriodDate = user.lastPeriodDate
|
||||
? user.lastPeriodDate.toISOString().split("T")[0]
|
||||
const lastPeriodDate = freshUser.lastPeriodDate
|
||||
? new Date(freshUser.lastPeriodDate as string).toISOString().split("T")[0]
|
||||
: null;
|
||||
|
||||
return NextResponse.json({
|
||||
id: user.id,
|
||||
email: user.email,
|
||||
garminConnected: user.garminConnected,
|
||||
cycleLength: user.cycleLength,
|
||||
id: freshUser.id,
|
||||
email: freshUser.email,
|
||||
garminConnected: freshUser.garminConnected ?? false,
|
||||
cycleLength: freshUser.cycleLength,
|
||||
lastPeriodDate,
|
||||
notificationTime: user.notificationTime,
|
||||
timezone: user.timezone,
|
||||
activeOverrides: user.activeOverrides,
|
||||
notificationTime: freshUser.notificationTime,
|
||||
timezone: freshUser.timezone,
|
||||
activeOverrides: freshUser.activeOverrides ?? [],
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user