From d222aa2354c249df173b288fa8990dfcc75f04d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Mon, 27 Jul 2026 13:52:17 +0200 Subject: [PATCH] test(measurements): pin the null-trigger stamp on a batch that declares none --- .../batch/__tests__/pr-detection-hook.test.ts | 7 ++++++- .../settings/integrations/apple-health-card.tsx | 9 ++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/app/api/measurements/batch/__tests__/pr-detection-hook.test.ts b/src/app/api/measurements/batch/__tests__/pr-detection-hook.test.ts index 200546d61..ab6f7dcf3 100644 --- a/src/app/api/measurements/batch/__tests__/pr-detection-hook.test.ts +++ b/src/app/api/measurements/batch/__tests__/pr-detection-hook.test.ts @@ -153,7 +153,12 @@ describe("POST /api/measurements/batch — PR detection enqueue (v1.4.25 W16c)", expect(prisma.user.update).toHaveBeenCalledTimes(1); expect(prisma.user.update).toHaveBeenCalledWith({ where: { id: "user-1" }, - data: { healthKitLastSyncedAt: expect.any(Date) }, + // This batch declares no trigger, so the trigger field is nulled and the + // background timestamp is not written — see the sync-trigger suite. + data: { + healthKitLastSyncedAt: expect.any(Date), + healthKitLastSyncTrigger: null, + }, }); }); diff --git a/src/components/settings/integrations/apple-health-card.tsx b/src/components/settings/integrations/apple-health-card.tsx index 5a8e6ccab..858573373 100644 --- a/src/components/settings/integrations/apple-health-card.tsx +++ b/src/components/settings/integrations/apple-health-card.tsx @@ -64,10 +64,14 @@ const TRIGGER_KEYS: Record = { function DeliveryDiagnostic({ status, t, + now, }: { status: HealthKitStatus; t: (key: string, params?: Record) => string; + /** Injectable reference instant, mirroring the pill's own prop. */ + now?: Date; }) { + const reference = now ?? new Date(); const trigger = status.lastSyncTrigger ?? null; const triggerLabel = t( trigger @@ -96,7 +100,10 @@ function DeliveryDiagnostic({
{backgroundAt ? formatRelative( - Math.max(0, Date.now() - new Date(backgroundAt).getTime()), + Math.max( + 0, + reference.getTime() - new Date(backgroundAt).getTime(), + ), t, ) : t("settings.appleHealth.delivery.backgroundNever")}