import test from "node:test"; import assert from "node:assert/strict"; import { buildWidgetActionablePayload } from "./widgetActionable"; const row = ( slug: string, undownloaded: number, untranscribed: number, digestReachable = 0, ) => ({ slug, undownloaded, untranscribed, digestReachable }); test("a channel with neither backlog is dropped", () => { const payload = buildWidgetActionablePayload([ row("idle", 0, 0, 9_000), row("busy", 1, 0), ]); assert.deepEqual( payload.channels.map((c) => c.slug), ["busy"], ); }); test("digestReachable is carried but never makes a channel actionable", () => { const payload = buildWidgetActionablePayload([row("digest-only", 0, 0, 77_000)]); assert.deepEqual(payload.channels, []); }); test("the larger combined backlog sorts first", () => { const payload = buildWidgetActionablePayload([ row("third", 1, 1), row("first", 10, 30), row("second", 20, 5), ]); assert.deepEqual( payload.channels.map((c) => c.slug), ["first", "second", "third"], ); }); test("either bucket alone is enough to be listed", () => { const payload = buildWidgetActionablePayload([ row("downloads-only", 3, 0), row("transcripts-only", 0, 4), ]); assert.deepEqual( payload.channels.map((c) => c.slug), ["transcripts-only", "downloads-only"], ); }); test("a tie keeps the order the census handed over", () => { const payload = buildWidgetActionablePayload([ row("alpha", 2, 2), row("beta", 3, 1), ]); assert.deepEqual( payload.channels.map((c) => c.slug), ["alpha", "beta"], ); }); test("every field survives the fold", () => { const payload = buildWidgetActionablePayload([row("a", 2, 3, 400)]); assert.deepEqual(payload.channels, [ { slug: "a", undownloaded: 2, untranscribed: 3, digestReachable: 400 }, ]); });