/**
 * Tests for compliance report generator
 */
import { describe, it, expect } from "vitest";
import { formatComplianceReportAsMarkdown, formatMultiFrameworkReportAsMarkdown, formatComplianceReportAsJson, generateCompactComplianceSummary, } from "./report.js";
import { generateComplianceReport, generateMultiFrameworkReport } from "./mapper.js";
describe("compliance report", () => {
    const mockFindings = [
        {
            id: "sec-001",
            severity: "critical",
            category: "sql-injection",
            description: "SQL injection vulnerability in user query",
            evidence: "Test evidence",
            confidence: 90,
            file: "db/queries.ts",
            line: 42,
            verifications: [],
            created_at: new Date().toISOString(),
        },
        {
            id: "sec-002",
            severity: "high",
            category: "xss",
            description: "Cross-site scripting in user input",
            evidence: "Test evidence",
            confidence: 85,
            file: "components/Form.tsx",
            line: 15,
            verifications: [],
            created_at: new Date().toISOString(),
        },
    ];
    describe("formatComplianceReportAsMarkdown", () => {
        it("generates markdown with header", () => {
            const report = generateComplianceReport(mockFindings, "SOC2", "/test/path");
            const markdown = formatComplianceReportAsMarkdown(report);
            expect(markdown).toContain("# SOC2 Compliance Report");
            expect(markdown).toContain("## Compliance Status");
        });
        it("includes compliance status table", () => {
            const report = generateComplianceReport(mockFindings, "SOC2", "/test/path");
            const markdown = formatComplianceReportAsMarkdown(report);
            expect(markdown).toContain("**Compliance Score**");
            expect(markdown).toContain("**Risk Score**");
            expect(markdown).toContain("Total Controls");
        });
        it("includes non-compliant controls section", () => {
            const report = generateComplianceReport(mockFindings, "SOC2", "/test/path");
            const markdown = formatComplianceReportAsMarkdown(report);
            expect(markdown).toContain("## Non-Compliant Controls");
        });
        it("includes recommendations section", () => {
            const report = generateComplianceReport(mockFindings, "SOC2", "/test/path");
            const markdown = formatComplianceReportAsMarkdown(report);
            expect(markdown).toContain("## Recommendations");
        });
        it("includes footer", () => {
            const report = generateComplianceReport(mockFindings, "SOC2", "/test/path");
            const markdown = formatComplianceReportAsMarkdown(report);
            expect(markdown).toContain("Vaspera Hardening");
        });
        it("includes certification ID when provided", () => {
            const report = generateComplianceReport(mockFindings, "SOC2", "/test/path", "cert-123");
            const markdown = formatComplianceReportAsMarkdown(report);
            expect(markdown).toContain("cert-123");
        });
    });
    describe("formatMultiFrameworkReportAsMarkdown", () => {
        it("generates markdown for multiple frameworks", () => {
            const report = generateMultiFrameworkReport(mockFindings, ["SOC2", "ISO27001"], "/test/path");
            const markdown = formatMultiFrameworkReportAsMarkdown(report);
            expect(markdown).toContain("# Multi-Framework Compliance Report");
            expect(markdown).toContain("## Framework Summary");
            expect(markdown).toContain("SOC2");
            expect(markdown).toContain("ISO27001");
        });
        it("includes framework summary table", () => {
            const report = generateMultiFrameworkReport(mockFindings, ["SOC2", "ISO27001"], "/test/path");
            const markdown = formatMultiFrameworkReportAsMarkdown(report);
            expect(markdown).toContain("| Framework | Compliance | Risk |");
        });
        it("includes prioritized recommendations", () => {
            const report = generateMultiFrameworkReport(mockFindings, ["SOC2", "ISO27001"], "/test/path");
            const markdown = formatMultiFrameworkReportAsMarkdown(report);
            expect(markdown).toContain("## Prioritized Recommendations");
        });
    });
    describe("formatComplianceReportAsJson", () => {
        it("returns valid JSON", () => {
            const report = generateComplianceReport(mockFindings, "SOC2", "/test/path");
            const json = formatComplianceReportAsJson(report);
            expect(() => JSON.parse(json)).not.toThrow();
        });
        it("contains all report fields", () => {
            const report = generateComplianceReport(mockFindings, "SOC2", "/test/path");
            const json = formatComplianceReportAsJson(report);
            const parsed = JSON.parse(json);
            expect(parsed.id).toBeDefined();
            expect(parsed.framework).toBe("SOC2");
            expect(parsed.status).toBeDefined();
            expect(parsed.controls).toBeDefined();
            expect(parsed.recommendations).toBeDefined();
        });
    });
    describe("generateCompactComplianceSummary", () => {
        it("generates single-line summary", () => {
            const report = generateComplianceReport(mockFindings, "SOC2", "/test/path");
            const summary = generateCompactComplianceSummary(report);
            expect(summary).toContain("SOC2 Compliance:");
            expect(summary).toContain("Score:");
            expect(summary).toContain("Risk:");
        });
        it("shows correct status based on score", () => {
            // With critical findings, should not be compliant
            const report = generateComplianceReport(mockFindings, "SOC2", "/test/path");
            const summary = generateCompactComplianceSummary(report);
            // Score should be less than 100 due to findings
            expect(summary).not.toContain("100%");
        });
        it("shows COMPLIANT for perfect score", () => {
            const report = generateComplianceReport([], "SOC2", "/test/path");
            const summary = generateCompactComplianceSummary(report);
            expect(summary).toContain("COMPLIANT");
        });
    });
});
//# sourceMappingURL=report.test.js.map