import assert from "node:assert/strict"; import { describe, it } from "node:test"; import { buildConnectorActionFollowup } from "./connectorActionFollowup.ts"; import type { ActionResult } from "../types/appops.ts"; const result = (overrides: Partial): ActionResult => ({ success: false, decision: "approval_required", status: "failed", result: "approval_required", message: "Action requires approval before execution.", ...overrides, }); describe("buildConnectorActionFollowup", () => { it("links approval-required Deluge actions to approvals, audit and Deluge detail", () => { const view = buildConnectorActionFollowup(result({ approvalId: "apr-deluge", auditId: "audit-deluge", }), { connectorId: "deluge", connectorLabel: "Deluge", success: "Deluge actie uitgevoerd.", approval: "Deluge approval aangevraagd.", failure: "Deluge actie vereist aandacht.", }); assert.equal(view.tone, "approval"); assert.equal(view.title, "Approval handoff klaar"); assert.deepEqual(view.links, [ { label: "Open approvals", href: "/approvals?query=apr-deluge" }, { label: "Open audit", href: "/audit?query=audit-deluge" }, { label: "Open Deluge", href: "/apps/deluge" }, ]); assert.match(view.safetyNote, /delete-with-data blijft geblokkeerd/i); }); it("links successful Plex scans to jobs, audit and Plex detail", () => { const view = buildConnectorActionFollowup(result({ success: true, decision: "allowed", policy_decision: "allowed", status: "success", result: "success", jobId: "job-plex", auditId: "audit-plex", }), { connectorId: "plex", connectorLabel: "Plex", success: "Plex scan gestart.", approval: "Plex scan-approval aangevraagd.", failure: "Plex scan vereist aandacht.", }); assert.equal(view.tone, "success"); assert.deepEqual(view.links, [ { label: "Open job", href: "/jobs?query=job-plex" }, { label: "Open audit", href: "/audit?query=audit-plex" }, { label: "Open Plex", href: "/apps/plex" }, ]); }); it("links missing Sonarr config to setup and Sonarr detail", () => { const view = buildConnectorActionFollowup(result({ decision: "allowed", policy_decision: "allowed", result: "failed", status: "missing_config", missing_config: true, }), { connectorId: "sonarr", connectorLabel: "Sonarr", success: "Serie toegevoegd aan Sonarr.", approval: "Sonarr approval aangevraagd.", failure: "Sonarr actie mislukt.", }); assert.equal(view.tone, "error"); assert.deepEqual(view.links, [ { label: "Open setup", href: "/setup?step=connectors&connector=sonarr" }, { label: "Open Sonarr", href: "/apps/sonarr" }, ]); assert.match(view.safetyNote, /series add.*policy/i); }); it("links approval-required Widefrog retries to approval, audit and Widefrog detail", () => { const view = buildConnectorActionFollowup(result({ approvalId: "apr-widefrog", auditId: "audit-widefrog", }), { connectorId: "widefrog", connectorLabel: "Widefrog", success: "Widefrog actie gestart.", approval: "Widefrog approval aangevraagd.", failure: "Widefrog actie mislukt.", }); assert.equal(view.tone, "approval"); assert.deepEqual(view.links, [ { label: "Open approvals", href: "/approvals?query=apr-widefrog" }, { label: "Open audit", href: "/audit?query=audit-widefrog" }, { label: "Open Widefrog", href: "/apps/widefrog" }, ]); assert.match(view.safetyNote, /retry.*scan/i); }); it("links blocked Radarr add attempts to audit and Radarr detail", () => { const view = buildConnectorActionFollowup(result({ decision: "blocked", policy_decision: "blocked", result: "blocked", status: "blocked", auditId: "audit-radarr", }), { connectorId: "radarr", connectorLabel: "Radarr", success: "Film toegevoegd aan Radarr.", approval: "Radarr approval aangevraagd.", failure: "Radarr actie mislukt.", }); assert.equal(view.tone, "error"); assert.deepEqual(view.links, [ { label: "Open audit", href: "/audit?query=audit-radarr" }, { label: "Open Radarr", href: "/apps/radarr" }, ]); assert.match(view.safetyNote, /movie add.*policy/i); }); });