// The walk goes by source: by date, each recording's clips together in start // order -- not in the cut's order. // // Run with: pnpm test:scripts import assert from "node:assert/strict"; import test from "node:test"; import { clipDateKey, walkOrder, walkReadiness } from "../projects/report.mjs"; const clip = (id, video, start, date, extra = {}) => ({ type: "clip", id, video, start, end: start + 5, onscreen: date ? { title: date } : undefined, ...extra, }); test("a clip's date: its on-screen date first, else the record's upload date", () => { assert.equal(clipDateKey({ onscreen: { title: "26 Aug 2026" } }), 20260826); assert.equal(clipDateKey({ onscreen: { title: "8 Apr 2021" }, uploadDate: "20250101" }), 20210408); assert.equal(clipDateKey({ uploadDate: "20190613" }), 20190613); assert.equal(clipDateKey({ onscreen: { title: "The finale" } }), null); assert.equal(clipDateKey({}), null); }); test("by date, a recording's clips together and in start order, not the cut's order", () => { const cut = [ clip("open", "B", 300, "26 Aug 2026"), clip("finale", "Z", 10, "8 Apr 2021"), clip("late", "B", 50, "26 Aug 2026"), clip("other-same-day", "C", 5, "26 Aug 2026"), clip("early", "B", 10, "26 Aug 2026"), { type: "post", id: "p1" }, ]; assert.deepEqual(walkOrder(cut).map((e) => e.id), ["finale", "early", "late", "open", "other-same-day"]); }); test("a clip with no date stays beside the clips the cut put it with", () => { const cut = [clip("a", "A", 0, "1 Jan 2020"), clip("x", "X", 0, null), clip("b", "B", 0, "1 Jan 2019")]; assert.deepEqual(walkOrder(cut).map((e) => e.id), ["b", "a", "x"]); }); test("the walk's ready list comes in walk order", () => { const cut = [ { ...clip("new", "N", 0, "1 Jan 2026"), kind: "clip", fetched: true }, { ...clip("old", "O", 0, "1 Jan 2019"), kind: "clip", fetched: true }, { ...clip("judged", "O", 50, "1 Jan 2019"), kind: "clip", fetched: true, verdict: "confirmed" }, ]; assert.deepEqual(walkReadiness(cut).readyIds, ["old", "new"]); });