From cd98db82eb309bf605f7de88a99aaae05cea04c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Thu, 29 Oct 2026 23:16:00 +0100 Subject: [PATCH] test(insights): date the comparison's sleep readings by calendar day The readings sat at now minus n times 24 hours, which keeps the wall-clock hour only between two clock changes. Run late in the evening after the October change, two of them fell into the same night and the average read 525 minutes instead of 420. --- .../__tests__/comparison-snapshot-window.test.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/lib/insights/__tests__/comparison-snapshot-window.test.ts b/src/lib/insights/__tests__/comparison-snapshot-window.test.ts index 809ed61cc..1311c733f 100644 --- a/src/lib/insights/__tests__/comparison-snapshot-window.test.ts +++ b/src/lib/insights/__tests__/comparison-snapshot-window.test.ts @@ -305,10 +305,21 @@ describe("buildComparisonSnapshotForUser — output-equivalence to the raw-avera ? { _avg: { value: args.where.measuredAt.lte ? 82 : 80 } } : { _avg: { value: null } }, ); - // Seven-hour nights, stored in minutes. + // Seven-hour nights, stored in minutes. Each at midday UTC of its own + // calendar day: `now - n * DAY` keeps the wall-clock hour only between + // two clock changes, and run late in the evening across one, two of the + // readings fell into the same night. + const today = new Date(); measurementFindMany.mockResolvedValue( Array.from({ length: 5 }, (_, i) => ({ - measuredAt: new Date(Date.now() - (i + 2) * DAY), + measuredAt: new Date( + Date.UTC( + today.getUTCFullYear(), + today.getUTCMonth(), + today.getUTCDate() - (i + 2), + 12, + ), + ), value: 420, sleepStage: null, source: "APPLE_HEALTH",