diff --git a/e2e/api.spec.ts b/e2e/api.spec.ts index a7771eba4..74bea902b 100644 --- a/e2e/api.spec.ts +++ b/e2e/api.spec.ts @@ -103,7 +103,8 @@ test("[API E2E] /api/auth/session returns a JSON object", async ({ }) => { const res = await request.get("/api/auth/session"); expect(res.status()).toBe(200); - const body = await res.json(); + if (!res.ok) throw new Error("Request failed"); +const body = await res.json(); // An unauthenticated session is an empty object {}, never null/undefined. expect(typeof body).toBe("object"); }); diff --git a/src/lib/consistency-score.ts b/src/lib/consistency-score.ts index 66b9604a5..d7ac2ab34 100644 --- a/src/lib/consistency-score.ts +++ b/src/lib/consistency-score.ts @@ -133,7 +133,7 @@ export function calculateConsistencyScore( activeDates: Set, timeZone = "UTC", ): ConsistencyScoreResult { - const sortedDates = Array.from(activeDates).sort(); + const sortedDates = Array.from(activeDates).sort((a, b) => a - b); const today = todayInTimezone(timeZone); const weeklyConsistency = computeWeeklyConsistency(activeDates); diff --git a/src/lib/date-utils.ts b/src/lib/date-utils.ts index c02fc1fba..ee59ed435 100644 --- a/src/lib/date-utils.ts +++ b/src/lib/date-utils.ts @@ -249,7 +249,7 @@ export function calculateStreak( return `${yyyy}-${mm}-${dd}`; })(); - const uniqueDates = [...new Set(dates)].sort().reverse(); + const uniqueDates = [...new Set(dates)].sort((a, b) => a - b).reverse(); if (uniqueDates[0] !== today && uniqueDates[0] !== yesterday) { return 0; diff --git a/src/lib/streak-utils.ts b/src/lib/streak-utils.ts index ae8b24d7b..3bf616253 100644 --- a/src/lib/streak-utils.ts +++ b/src/lib/streak-utils.ts @@ -20,7 +20,7 @@ function getSortedUniqueDays(dates: StreakDate[]): string[] { if (key) dayKeys.add(key); } - return Array.from(dayKeys).sort(); + return Array.from(dayKeys).sort((a, b) => a - b); } function getRuns(dates: StreakDate[]): { end: string; length: number }[] { diff --git a/src/lib/streak.ts b/src/lib/streak.ts index 239d86dfa..89ffde189 100644 --- a/src/lib/streak.ts +++ b/src/lib/streak.ts @@ -62,7 +62,7 @@ export function calculateStreakFromDates( ...Array.from(activeDates), ...Array.from(freezeDates), ]); - const commitDays = Array.from(combinedDates).sort(); + const commitDays = Array.from(combinedDates).sort((a, b) => a - b); if (commitDays.length === 0) { return {