import assert from "node:assert/strict"; import test from "node:test"; import type { EventsCountReaders } from "../src/pages/events/lib/counts.ts"; const { loadEventCounts } = await import("../src/pages/events/lib/counts.ts"); /** Readers standing in for api.captures and api.mappings. */ function readers(overrides: Partial = {}): EventsCountReaders { return { captures: async () => ({ captures: [{}, {}] }), mappings: async () => ({ mappings: [{}] }), ...overrides, }; } test("each count is the length of what its own read answered with", async () => { assert.deepEqual(await loadEventCounts(readers()), { inspector: 2, mappings: 1, }); }); test("a count that could not be read stays blank, not zero", async () => { const counts = await loadEventCounts( readers({ mappings: async () => { throw new Error("offline"); }, }), ); assert.equal(counts.mappings, undefined); assert.equal(counts.inspector, 2, "a failed sibling read blanked its count"); }); test("a response without its list counts as an empty list", async () => { const counts = await loadEventCounts( readers({ captures: async () => null, mappings: async () => ({}), }), ); assert.equal(counts.inspector, 0); assert.equal(counts.mappings, 0); });