/home/techb158/cosmic.abdallabala.com/tests
Edit: /home/techb158/cosmic.abdallabala.com/tests/reporting-workflow.test.js (3800B)
const assert = require("assert");
const fs = require("fs");
const path = require("path");
const os = require("os");
const { JsonDatabase } = require("../src/storage/jsonDatabase.js");
const { ReportingService } = require("../src/services/reportingService.js");
const { DashboardService } = require("../src/services/dashboardService.js");
const source = path.join(__dirname, "..", "data", "database.json");
const temp = path.join(os.tmpdir(), `cosmic-reporting-db-${Date.now()}.json`);
fs.copyFileSync(source, temp);
const database = new JsonDatabase(temp);
const reporting = new ReportingService(database);
const dashboardService = new DashboardService(database);
const projectId = "cosmic-ai-risk-001";
const dashboard = dashboardService.getDashboard(projectId);
assert.ok(dashboard, "Dashboard should load for reporting tests");
const executive = reporting.getExecutiveReport(projectId);
assert.strictEqual(executive.reportType, "Executive COSMIC AI-Risk report", "Executive report type should be explicit");
assert.strictEqual(executive.summary.totalRisks, 35, "Executive report should include all seed risks");
assert.ok(executive.dimensions.Technical >= 0, "Executive report should include governance triangle dimensions");
assert.ok(executive.topRisks.length > 0, "Executive report should include top risks");
assert.ok(executive.integrationSummary.supportedApplications.includes("Microsoft Planner"), "Executive report should include Microsoft Planner integration evidence");
const riskCsv = reporting.getRiskRegisterCsv(projectId);
assert.ok(riskCsv.startsWith("Risk ID,Risk title,Dimension"), "Risk register CSV should have expected headers");
assert.ok(riskCsv.includes("Prompt injection can override customer-support chatbot safeguards"), "Risk CSV should include seed risk titles");
assert.strictEqual(riskCsv.trim().split("\n").length, 36, "Risk CSV should include header plus 35 seed risks");
const mitigationCsv = reporting.getMitigationCsv(projectId);
assert.ok(mitigationCsv.startsWith("Mitigation ID,Risk ID,Linked risk"), "Mitigation CSV should have expected headers");
assert.ok(mitigationCsv.split("\n").length > 50, "Mitigation CSV should include seed mitigation actions");
const gateReport = reporting.getGateReport(projectId);
assert.ok(["Ready", "Warning", "Blocked"].includes(gateReport.currentGate.status), "Gate report should include calculated gate status");
assert.ok(Array.isArray(gateReport.currentGate.criteria), "Gate report should include current criteria");
const indicators = reporting.getIndicatorReport(projectId);
assert.ok(indicators.indicators.length >= 6, "Indicator report should expose ISO-style indicator catalog");
assert.ok(indicators.indicators.every(item => item.measurand && item.unit), "Indicators should include measurand and unit");
const integrations = reporting.getIntegrationReport(projectId);
assert.strictEqual(integrations.integrations.length, 4, "Integration report should include four PM applications");
const full = reporting.getFullReport(projectId);
assert.ok(full.executive && full.riskRegister && full.mitigations && full.gate && full.indicators && full.integrations && full.audit, "Full report should include all report sections");
const html = reporting.renderExecutiveHtml(projectId);
assert.ok(html.includes("COSMIC AI-Risk Management"), "HTML report should include COSMIC project heading");
assert.ok(html.includes("Print or save as PDF"), "HTML report should include print action");
assert.ok(html.includes("Top residual risks"), "HTML report should include top residual risks section");
assert.throws(() => reporting.getExecutiveReport("missing-project"), /Project not found/, "Missing project should produce clear error");
fs.unlinkSync(temp);
console.log("All COSMIC AI-Risk reporting workflow tests passed.");