From dddd2164b130e5c45ec325216eaad1bd095a9578 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Tue, 28 Jul 2026 00:07:53 +0200 Subject: [PATCH] test(withings): teach the fallback mock the shape its function now returns The sync function was widened to answer with what it wrote rather than a bare count. This mock still resolved to a number, so the handler destructured `imported` off it, got undefined, and reported `measurements_imported: NaN`. Nothing in the type system could see it: `vi.fn().mockResolvedValue(0)` carries no relation to the real signature, so a widened contract drifts past every mock in the tree unnoticed. This was the only sibling; the class is worth a sweep of its own. --- src/lib/jobs/__tests__/withings-subscription-retry.test.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lib/jobs/__tests__/withings-subscription-retry.test.ts b/src/lib/jobs/__tests__/withings-subscription-retry.test.ts index be6de5b0e..393d9ecd3 100644 --- a/src/lib/jobs/__tests__/withings-subscription-retry.test.ts +++ b/src/lib/jobs/__tests__/withings-subscription-retry.test.ts @@ -4,7 +4,9 @@ import type { Job } from "pg-boss"; const retryDueWithingsWebhookSubscriptions = vi.hoisted(() => vi.fn().mockResolvedValue(0), ); -const syncUserMeasurements = vi.hoisted(() => vi.fn().mockResolvedValue(0)); +const syncUserMeasurements = vi.hoisted(() => + vi.fn().mockResolvedValue({ imported: 0, failed: false }), +); const findMany = vi.hoisted(() => vi.fn().mockResolvedValue([])); const addWarning = vi.hoisted(() => vi.fn()); @@ -63,7 +65,7 @@ beforeEach(() => { vi.clearAllMocks(); findMany.mockResolvedValue([]); retryDueWithingsWebhookSubscriptions.mockResolvedValue(0); - syncUserMeasurements.mockResolvedValue(0); + syncUserMeasurements.mockResolvedValue({ imported: 0, failed: false }); }); describe("handleWithingsFallbackSync subscription repair", () => {