~james/core

core/web/src/lib/status.test.ts -rw-r--r-- 706 bytes
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 15 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { describe, expect, it } from "vitest";
import { summarize } from "#lib/status.ts";

const beats = (...latest: number[]) =>
	Object.fromEntries(latest.map((status, i) => [String(i), [{ status: 1 }, { status }]]));

describe("summarize", () => {
	it.each([
		["up", beats(1, 1)],
		["degraded", beats(1, 0)],
		["degraded", beats(1, 2)],
		["down", beats(0, 0)],
		["maintenance", beats(1, 3)],
		["degraded", beats(0, 3)],
		["unknown", {}],
		["unknown", { "1": [] }]
	])("reads %s", (expected, heartbeats) => {
		expect(summarize(heartbeats)).toBe(expected);
	});

	it("goes by each monitor's latest beat", () => {
		expect(summarize({ "1": [{ status: 0 }, { status: 1 }] })).toBe("up");
	});
});