/** * store-sync-poll unit tests (node:test). * * Run from apps/web: * node --experimental-strip-types --test src/lib/store-sync-poll.test.ts */ import assert from "node:assert/strict"; import { describe, it } from "node:test"; import { isRetryableStoreSyncStatus, readStoreSyncSnapshot, storeSyncPhase } from "./store-sync-poll.ts"; describe("store-sync-poll", () => { it("reads product snapshot fields", () => { const snap = readStoreSyncSnapshot( { pending_sync: true, last_synced_at: "2026-01-01T00:00:00Z", last_sync_status: "success", last_sync_error: "", last_sync_summary: { total: 3, created: 1, updated: 2, failed: 0, skipped: 0 } }, "products" ); assert.equal(snap.pending, true); assert.equal(snap.summary?.total, 3); }); it("maps pending to queued, claimed to running, advanced synced_at to completed", () => { assert.equal( storeSyncPhase( { pending: true, syncedAt: "a", status: "", error: "", summary: null }, "a" ), "queued" ); assert.equal( storeSyncPhase( { pending: false, syncedAt: "a", status: "", error: "", summary: null }, "a" ), "running" ); assert.equal( storeSyncPhase( { pending: false, syncedAt: "b", status: "success", error: "", summary: null }, "a" ), "completed" ); }); it("marks failed and partial as retryable", () => { assert.equal(isRetryableStoreSyncStatus("failed"), true); assert.equal(isRetryableStoreSyncStatus("partial"), true); assert.equal(isRetryableStoreSyncStatus("success"), false); }); });