const { test } = require("node:test"); const assert = require("node:assert"); const { fetchUsers, fetchOrgUnits } = require("../src/lib/lineworksClient"); test("fetchUsers follows responseMetaData.nextCursor until it is null", async () => { const pages = [ { users: [{ userId: "u1" }], responseMetaData: { nextCursor: "cursor-2" } }, { users: [{ userId: "u2" }], responseMetaData: { nextCursor: null } }, ]; let call = 0; const fetchImpl = async () => { const body = pages[call++]; return { ok: true, json: async () => body }; }; const users = await fetchUsers({ accessToken: "tok", fetchImpl }); assert.strictEqual(call, 2); assert.deepStrictEqual(users.map((u) => u.userId), ["u1", "u2"]); }); test("fetchOrgUnits returns items directly when there is no next cursor", async () => { const fetchImpl = async () => ({ ok: true, json: async () => ({ orgUnits: [{ orgUnitId: "o1" }, { orgUnitId: "o2" }], responseMetaData: {} }), }); const orgUnits = await fetchOrgUnits({ accessToken: "tok", fetchImpl }); assert.strictEqual(orgUnits.length, 2); });