const { test } = require("node:test"); const assert = require("node:assert"); const { buildSnapshot } = require("../src/commands/fetch-lineworks"); test("buildSnapshot fetches all five resource types and stamps fetchedAt", async () => { const calls = []; const deps = { fetchAccessToken: async () => "tok", fetchUsers: async () => { calls.push("users"); return [{ userId: "u1" }]; }, fetchOrgUnits: async () => { calls.push("orgUnits"); return [{ orgUnitId: "o1" }]; }, fetchPositions: async () => { calls.push("positions"); return [{ positionId: "p1" }]; }, fetchLevels: async () => { calls.push("levels"); return [{ levelId: "l1" }]; }, fetchUserTypes: async () => { calls.push("userTypes"); return [{ userTypeId: "t1" }]; }, now: () => new Date("2026-08-08T01:00:00Z"), }; const snapshot = await buildSnapshot({ clientId: "cid", clientSecret: "sec", serviceAccount: "svc", privateKey: "pk", scope: "directory.read", }, deps); assert.deepStrictEqual(calls.sort(), ["levels", "orgUnits", "positions", "userTypes", "users"]); assert.strictEqual(snapshot.fetchedAt, "2026-08-08T01:00:00.000Z"); assert.strictEqual(snapshot.users.length, 1); assert.strictEqual(snapshot.orgUnits[0].orgUnitId, "o1"); });