Enable 5 previously skipped e2e tests
All checks were successful
Deploy / deploy (push) Successful in 1m37s
All checks were successful
Deploy / deploy (push) Successful in 1m37s
- Fix OIDC tests with route interception for auth-methods API - Add data-testid to DecisionCard for reliable test selection - Fix /api/today to fetch fresh user data instead of stale cookie data - Fix period logging test timing with proper API wait patterns - Fix decision engine test with waitForResponse instead of timeout - Simplify mobile viewport test locator All 206 e2e tests now pass with 0 skipped. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -14,7 +14,22 @@ let currentMockDailyLog: DailyLog | null = null;
|
||||
|
||||
// Create mock PocketBase client
|
||||
const mockPb = {
|
||||
collection: vi.fn(() => ({
|
||||
collection: vi.fn((collectionName: string) => ({
|
||||
// Mock getOne for fetching fresh user data
|
||||
getOne: vi.fn(async () => {
|
||||
if (collectionName === "users" && currentMockUser) {
|
||||
// Return user data in PocketBase record format
|
||||
return {
|
||||
id: currentMockUser.id,
|
||||
email: currentMockUser.email,
|
||||
lastPeriodDate: currentMockUser.lastPeriodDate?.toISOString(),
|
||||
cycleLength: currentMockUser.cycleLength,
|
||||
activeOverrides: currentMockUser.activeOverrides,
|
||||
garminConnected: currentMockUser.garminConnected,
|
||||
};
|
||||
}
|
||||
throw new Error("Record not found");
|
||||
}),
|
||||
getFirstListItem: vi.fn(async () => {
|
||||
if (!currentMockDailyLog) {
|
||||
const error = new Error("No DailyLog found");
|
||||
|
||||
@@ -28,8 +28,13 @@ const DEFAULT_BIOMETRICS: {
|
||||
};
|
||||
|
||||
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
|
||||
// (e.g., after logging a period, the cookie still has old data)
|
||||
const freshUser = await pb.collection("users").getOne(user.id);
|
||||
|
||||
// Validate required user data
|
||||
if (!user.lastPeriodDate) {
|
||||
if (!freshUser.lastPeriodDate) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
error:
|
||||
@@ -38,14 +43,13 @@ export const GET = withAuth(async (_request, user, pb) => {
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
const lastPeriodDate = new Date(freshUser.lastPeriodDate as string);
|
||||
const cycleLength = freshUser.cycleLength as number;
|
||||
const activeOverrides = (freshUser.activeOverrides as string[]) || [];
|
||||
|
||||
// Calculate cycle information
|
||||
const cycleDay = getCycleDay(
|
||||
new Date(user.lastPeriodDate),
|
||||
user.cycleLength,
|
||||
new Date(),
|
||||
);
|
||||
const phase = getPhase(cycleDay, user.cycleLength);
|
||||
const cycleDay = getCycleDay(lastPeriodDate, cycleLength, new Date());
|
||||
const phase = getPhase(cycleDay, cycleLength);
|
||||
const phaseConfig = getPhaseConfig(phase);
|
||||
const phaseLimit = getPhaseLimit(phase);
|
||||
|
||||
@@ -54,16 +58,16 @@ export const GET = withAuth(async (_request, user, pb) => {
|
||||
// EARLY_LUTEAL (cl-13)-(cl-7), LATE_LUTEAL (cl-6)-cl
|
||||
let daysUntilNextPhase: number;
|
||||
if (phase === "LATE_LUTEAL") {
|
||||
daysUntilNextPhase = user.cycleLength - cycleDay + 1;
|
||||
daysUntilNextPhase = cycleLength - cycleDay + 1;
|
||||
} else if (phase === "MENSTRUAL") {
|
||||
daysUntilNextPhase = 4 - cycleDay;
|
||||
} else if (phase === "FOLLICULAR") {
|
||||
daysUntilNextPhase = user.cycleLength - 15 - cycleDay;
|
||||
daysUntilNextPhase = cycleLength - 15 - cycleDay;
|
||||
} else if (phase === "OVULATION") {
|
||||
daysUntilNextPhase = user.cycleLength - 13 - cycleDay;
|
||||
daysUntilNextPhase = cycleLength - 13 - cycleDay;
|
||||
} else {
|
||||
// EARLY_LUTEAL
|
||||
daysUntilNextPhase = user.cycleLength - 6 - cycleDay;
|
||||
daysUntilNextPhase = cycleLength - 6 - cycleDay;
|
||||
}
|
||||
|
||||
// Try to fetch today's DailyLog for biometrics
|
||||
@@ -99,7 +103,10 @@ export const GET = withAuth(async (_request, user, pb) => {
|
||||
};
|
||||
|
||||
// Get training decision with override handling
|
||||
const decision = getDecisionWithOverrides(dailyData, user.activeOverrides);
|
||||
const decision = getDecisionWithOverrides(
|
||||
dailyData,
|
||||
activeOverrides as import("@/types").OverrideType[],
|
||||
);
|
||||
|
||||
// Log decision calculation per observability spec
|
||||
logger.info(
|
||||
@@ -120,7 +127,7 @@ export const GET = withAuth(async (_request, user, pb) => {
|
||||
phase,
|
||||
phaseConfig,
|
||||
daysUntilNextPhase,
|
||||
cycleLength: user.cycleLength,
|
||||
cycleLength,
|
||||
biometrics,
|
||||
nutrition,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user