import { describe, expect, it } from "vitest"; import { recordPage, RESTATE_MS, type PassFigures } from "../src/sync_status.ts"; import type { StoredRow } from "../src/store.ts"; // RULE: A caught-up device whose pull brought nothing new has its row written again only once `RESTATE_MS` has passed. describe("an idle device's row", () => { const now = new Date("2026-11-15T10:00:00.000Z"); const figures: PassFigures = { total: 7, pass: 0, passLive: 0, sent: 0, sentLive: 0, tables: {} }; const held = (ago: number): StoredRow => ({ id: "d1", table: "device", data: { caught_up: true, sync_rows_total: 7, sync_rows_done: 7, synced_at: new Date(now.getTime() - ago).toISOString() } }) as unknown as StoredRow; const writes = (row: StoredRow, rows: StoredRow[] = []): boolean => recordPage(row, { rows, version: 3, more: false, figures, now }, () => {}); it("is left alone inside the quarter hour", () => { expect(RESTATE_MS).toBe(15 * 60_000); expect(writes(held(60_000))).toBe(false); expect(writes(held(RESTATE_MS - 1))).toBe(false); }); it("is written once the quarter hour has passed, or when the pull carried another row", () => { expect(writes(held(RESTATE_MS))).toBe(true); expect(writes(held(1_000), [{ id: "t1", table: "todo" } as unknown as StoredRow])).toBe(true); }); });