Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/__tests__/whoop/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion src/schemas/whoop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const whoopWorkoutSchema = z.object({

export const whoopCollectionResponseSchema = <T extends z.ZodTypeAny>(recordSchema: T) => z.object({
records: z.array(recordSchema),
next_token: z.string().optional(),
next_token: z.string().nullish(),
}).passthrough();

export type WhoopWebhook = z.infer<typeof whoopWebhookSchema>;
Expand Down
2 changes: 1 addition & 1 deletion src/services/whoop/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export class WhoopClient {
record,
rawRecords[index],
)) as Array<WhoopProviderRecord<WhoopCollectionRecordMap[R]>>,
nextToken: parsed.data.next_token,
nextToken: parsed.data.next_token ?? undefined,
};
}

Expand Down
Loading