// The notifications page's helpers for the router's deliveries and dry run. // Run by `npm test`. import assert from "node:assert/strict"; import { test } from "node:test"; import { hitsOf, issueRef, outcomeText, unavailableText, } from "../src/pages/notifications/RouterLive.ts"; const dry = { events: 50, flows: [ { flow: "assigned", nodes: [ { node: "source", hits: 49 }, { node: "sink", hits: 0 }, ], }, ], }; test("hitsOf maps a flow's node ids to their counts, zero included", () => { const hits = hitsOf(dry, "assigned"); assert.equal(hits.get("source"), 49); assert.equal(hits.get("sink"), 0); }); test("hitsOf has nothing for a flow the dry run left out, or no dry run", () => { assert.equal(hitsOf(dry, "closed"), undefined); assert.equal(hitsOf(null, "assigned"), undefined); }); test("a delivery reads as its issue and its outcome", () => { assert.equal(issueRef({ repo: "o/r", number: 9 }), "o/r#9"); assert.equal( outcomeText({ ok: true, detail: "upsert forge:o/r#9:assignment" }), "ok: upsert forge:o/r#9:assignment", ); assert.equal(outcomeText({ ok: true, detail: "" }), "ok"); assert.equal( outcomeText({ ok: false, detail: "the forge said no" }), "error: the forge said no", ); }); test("a 503 reads as not available, any other failure as failed to load", () => { assert.equal( unavailableText("the deliveries log", { status: 503, detail: "the notification router does not answer this", }), "the deliveries log not available: the notification router does not answer this", ); assert.equal( unavailableText("hit counts", { status: 502, detail: "bad" }), "hit counts failed to load: bad", ); assert.equal( unavailableText("hit counts", { status: 503 }), "hit counts not available: no reason given", ); });