1import type { NotifyDeviceInfo } from "@nzip/shared";2import { filterNotificationDevices, parseNotifyInvocation } from "./notify.ts";34function assertEquals(actual: unknown, expected: unknown): void {5 if (JSON.stringify(actual) !== JSON.stringify(expected)) {6 throw new Error(`expected ${JSON.stringify(expected)}, got ${JSON.stringify(actual)}`);7 }8}910Deno.test("notify parses the explicit send shape", () => {11 assertEquals(parseNotifyInvocation(["send", "report ready"]), {12 kind: "send",13 body: "report ready",14 });15});1617Deno.test("notify parses test and device management subcommands", () => {18 assertEquals(parseNotifyInvocation(["test"]), { kind: "test" });19 assertEquals(parseNotifyInvocation(["pair"]), { kind: "pair" });20 assertEquals(parseNotifyInvocation(["approve", "ABCD-1234"]), {21 kind: "approve",22 code: "ABCD-1234",23 });24 assertEquals(parseNotifyInvocation(["devices"]), { kind: "devices" });25 assertEquals(parseNotifyInvocation(["revoke", "device-1"]), {26 kind: "revoke",27 deviceId: "device-1",28 });29});3031Deno.test("notify devices hides tombstones unless all devices are requested", () => {32 const devices = ["pending", "approved", "active", "disabled", "revoked", "expired"].map(33 (status) => ({ status } as NotifyDeviceInfo),34 );3536 assertEquals(37 filterNotificationDevices(devices, false).map((device) => device.status),38 ["pending", "approved", "active"],39 );40 assertEquals(filterNotificationDevices(devices, true), devices);41});