mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-19 08:12:52 +00:00
fix(integrations): end a page walk on an empty cursor
WHOOP and Oura answer the last page with an empty next_token as well as with null. The walk followed the empty string as a cursor, the client sent no token, read the first page a second time and the walk ended as a repeat, so the records came in twice and the backfill stayed incomplete for good. An empty cursor now ends the walk, for every provider that walks through it.
This commit is contained in:
1 parent
34eea153a8
commit
d770f81278
4 files changed
+53
-3
No files matched your search
@@ -32,6 +32,16 @@ describe("walkPages", () => {
|
||||
expect(walk.items).toEqual([0, 1, 2, 3]);
|
||||
});
|
||||
|
||||
it("ends on an empty cursor instead of following it back to the first page", async () => {
|
||||
const fetchPage = vi.fn(async (cursor: string | undefined) => ({
|
||||
items: [cursor ?? "first"],
|
||||
next: "",
|
||||
}));
|
||||
const walk = await walkPages<string, string>("test.empty", 10, fetchPage);
|
||||
expect(walk).toEqual({ items: ["first"], pages: 1, truncated: false });
|
||||
expect(fetchPage).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("stops on a cursor it already followed, the first one included", async () => {
|
||||
const fetchPage = vi.fn(async () => ({ items: [1], next: 0 }));
|
||||
const walk = await walkPages<number, number>(
|
||||
|
||||
Reference in new issue
Block a user