import test from "node:test"; import assert from "node:assert/strict"; import { buildCleanablePayload } from "./cleanable"; // The whole builder is a sum and a wrap, which is why it is here rather than in // a route: the number in the widget's badge and the numbers in its list are now // provably the same numbers. test("bytes is the sum of the rows, and the rows pass through in order", () => { const payload = buildCleanablePayload([ { slug: "big", count: 31, bytes: 3_000 }, { slug: "small", count: 2, bytes: 500 }, ]); assert.equal(payload.bytes, 3_500); assert.deepEqual( payload.channels.map((c) => c.slug), ["big", "small"], ); assert.equal(payload.channels[0].count, 31); }); test("no rows is zero bytes and an empty list, not a missing field", () => { assert.deepEqual(buildCleanablePayload([]), { bytes: 0, channels: [] }); }); test("the input array is not mutated or aliased", () => { const rows = [{ slug: "a", count: 1, bytes: 10 }]; const payload = buildCleanablePayload(rows); assert.notEqual(payload.channels, rows); payload.channels.push({ slug: "b", count: 1, bytes: 1 }); assert.equal(rows.length, 1); });