diff --git a/src/__tests__/whoop/client.test.ts b/src/__tests__/whoop/client.test.ts index 3557135..7a22490 100644 --- a/src/__tests__/whoop/client.test.ts +++ b/src/__tests__/whoop/client.test.ts @@ -232,6 +232,19 @@ describe("WHOOP v2 client", () => { ); }); + it("treats a live null next token as collection exhaustion", async () => { + vi.spyOn(globalThis, "fetch").mockResolvedValue(jsonResponse({ + records: [SLEEP], + next_token: null, + })); + const client = new WhoopClient(ENV, "access"); + + await expect(client.getCollection("sleep")).resolves.toMatchObject({ + nextToken: undefined, + records: [{ id: SLEEP.id }], + }); + }); + it("rejects provider collection limits outside the whole-number range 1 through 25 before fetching", async () => { const fetchMock = vi.spyOn(globalThis, "fetch"); const client = new WhoopClient(ENV, "access"); diff --git a/src/schemas/whoop.ts b/src/schemas/whoop.ts index 916f1e0..bd1adb2 100644 --- a/src/schemas/whoop.ts +++ b/src/schemas/whoop.ts @@ -105,7 +105,7 @@ export const whoopWorkoutSchema = z.object({ export const whoopCollectionResponseSchema = (recordSchema: T) => z.object({ records: z.array(recordSchema), - next_token: z.string().optional(), + next_token: z.string().nullish(), }).passthrough(); export type WhoopWebhook = z.infer; diff --git a/src/services/whoop/client.ts b/src/services/whoop/client.ts index 00f35e6..b3fd685 100644 --- a/src/services/whoop/client.ts +++ b/src/services/whoop/client.ts @@ -234,7 +234,7 @@ export class WhoopClient { record, rawRecords[index], )) as Array>, - nextToken: parsed.data.next_token, + nextToken: parsed.data.next_token ?? undefined, }; }