/**
 * Unit tests for diff-mode module
 */
import { describe, it, expect } from "vitest";
import { filterScannableFiles, getFilesToScan, hasSecurityRelevantChanges, generateChangeSummary, } from "./diff-mode.js";
describe("filterScannableFiles", () => {
    it("filters out removed files", () => {
        const files = [
            { filename: "src/index.ts", status: "removed", additions: 0, deletions: 10, changes: 10 },
            { filename: "src/utils.ts", status: "modified", additions: 5, deletions: 2, changes: 7 },
        ];
        const filtered = filterScannableFiles(files);
        expect(filtered).toHaveLength(1);
        expect(filtered[0].filename).toBe("src/utils.ts");
    });
    it("filters out node_modules", () => {
        const files = [
            { filename: "node_modules/lodash/index.js", status: "added", additions: 100, deletions: 0, changes: 100 },
            { filename: "src/index.ts", status: "modified", additions: 5, deletions: 2, changes: 7 },
        ];
        const filtered = filterScannableFiles(files);
        expect(filtered).toHaveLength(1);
        expect(filtered[0].filename).toBe("src/index.ts");
    });
    it("filters out dist directory", () => {
        const files = [
            { filename: "dist/index.js", status: "modified", additions: 100, deletions: 0, changes: 100 },
            { filename: "src/index.ts", status: "modified", additions: 5, deletions: 2, changes: 7 },
        ];
        const filtered = filterScannableFiles(files);
        expect(filtered).toHaveLength(1);
        expect(filtered[0].filename).toBe("src/index.ts");
    });
    it("filters out minified files", () => {
        const files = [
            { filename: "public/bundle.min.js", status: "modified", additions: 1, deletions: 1, changes: 2 },
            { filename: "src/index.ts", status: "modified", additions: 5, deletions: 2, changes: 7 },
        ];
        const filtered = filterScannableFiles(files);
        expect(filtered).toHaveLength(1);
        expect(filtered[0].filename).toBe("src/index.ts");
    });
    it("includes TypeScript and JavaScript files", () => {
        const files = [
            { filename: "src/index.ts", status: "modified", additions: 5, deletions: 2, changes: 7 },
            { filename: "src/app.tsx", status: "added", additions: 50, deletions: 0, changes: 50 },
            { filename: "lib/utils.js", status: "modified", additions: 3, deletions: 1, changes: 4 },
            { filename: "lib/helper.jsx", status: "modified", additions: 2, deletions: 1, changes: 3 },
        ];
        const filtered = filterScannableFiles(files);
        expect(filtered).toHaveLength(4);
    });
    it("includes JSON and YAML files", () => {
        const files = [
            { filename: "package.json", status: "modified", additions: 1, deletions: 1, changes: 2 },
            { filename: "config.yaml", status: "added", additions: 10, deletions: 0, changes: 10 },
            { filename: ".github/workflows/ci.yml", status: "modified", additions: 5, deletions: 3, changes: 8 },
        ];
        const filtered = filterScannableFiles(files);
        expect(filtered).toHaveLength(3);
    });
    it("excludes non-code files", () => {
        const files = [
            { filename: "README.md", status: "modified", additions: 10, deletions: 5, changes: 15 },
            { filename: "logo.png", status: "added", additions: 0, deletions: 0, changes: 0 },
            { filename: "docs/guide.pdf", status: "added", additions: 0, deletions: 0, changes: 0 },
        ];
        const filtered = filterScannableFiles(files);
        expect(filtered).toHaveLength(0);
    });
});
describe("getFilesToScan", () => {
    it("returns array of filenames", () => {
        const files = [
            { filename: "src/index.ts", status: "modified", additions: 5, deletions: 2, changes: 7 },
            { filename: "src/utils.ts", status: "added", additions: 50, deletions: 0, changes: 50 },
        ];
        const toScan = getFilesToScan(files);
        expect(toScan).toEqual(["src/index.ts", "src/utils.ts"]);
    });
    it("filters and returns only scannable files", () => {
        const files = [
            { filename: "src/index.ts", status: "modified", additions: 5, deletions: 2, changes: 7 },
            { filename: "README.md", status: "modified", additions: 10, deletions: 5, changes: 15 },
            { filename: "dist/bundle.js", status: "modified", additions: 100, deletions: 100, changes: 200 },
        ];
        const toScan = getFilesToScan(files);
        expect(toScan).toEqual(["src/index.ts"]);
    });
});
describe("hasSecurityRelevantChanges", () => {
    it("detects package.json changes", () => {
        const files = [
            { filename: "package.json", status: "modified", additions: 1, deletions: 1, changes: 2 },
        ];
        expect(hasSecurityRelevantChanges(files)).toBe(true);
    });
    it("detects package-lock.json changes", () => {
        const files = [
            { filename: "package-lock.json", status: "modified", additions: 100, deletions: 50, changes: 150 },
        ];
        expect(hasSecurityRelevantChanges(files)).toBe(true);
    });
    it("detects .env changes", () => {
        const files = [
            { filename: ".env", status: "modified", additions: 1, deletions: 0, changes: 1 },
        ];
        expect(hasSecurityRelevantChanges(files)).toBe(true);
    });
    it("detects auth directory changes", () => {
        const files = [
            { filename: "src/auth/login.ts", status: "modified", additions: 10, deletions: 5, changes: 15 },
        ];
        expect(hasSecurityRelevantChanges(files)).toBe(true);
    });
    it("detects api directory changes", () => {
        const files = [
            { filename: "api/users.ts", status: "added", additions: 50, deletions: 0, changes: 50 },
        ];
        expect(hasSecurityRelevantChanges(files)).toBe(true);
    });
    it("returns false for non-security files", () => {
        const files = [
            { filename: "src/components/Button.tsx", status: "modified", additions: 5, deletions: 2, changes: 7 },
            { filename: "README.md", status: "modified", additions: 10, deletions: 5, changes: 15 },
        ];
        expect(hasSecurityRelevantChanges(files)).toBe(false);
    });
});
describe("generateChangeSummary", () => {
    it("generates markdown summary", () => {
        const files = [
            { filename: "src/index.ts", status: "modified", additions: 5, deletions: 2, changes: 7 },
            { filename: "src/utils.ts", status: "added", additions: 50, deletions: 0, changes: 50 },
            { filename: "src/old.ts", status: "removed", additions: 0, deletions: 30, changes: 30 },
        ];
        const summary = generateChangeSummary(files);
        expect(summary).toContain("**Changed Files**: 3");
        expect(summary).toContain("| Status | Count |");
        expect(summary).toContain("modified |");
        expect(summary).toContain("added |");
        expect(summary).toContain("removed |");
        expect(summary).toContain("| Extension | Count |");
        expect(summary).toContain("| .ts |");
    });
    it("handles empty file list", () => {
        const summary = generateChangeSummary([]);
        expect(summary).toContain("**Changed Files**: 0");
    });
    it("groups by extension", () => {
        const files = [
            { filename: "src/a.ts", status: "modified", additions: 1, deletions: 1, changes: 2 },
            { filename: "src/b.ts", status: "modified", additions: 1, deletions: 1, changes: 2 },
            { filename: "src/c.ts", status: "modified", additions: 1, deletions: 1, changes: 2 },
            { filename: "src/x.js", status: "modified", additions: 1, deletions: 1, changes: 2 },
        ];
        const summary = generateChangeSummary(files);
        expect(summary).toContain("| .ts | 3 |");
        expect(summary).toContain("| .js | 1 |");
    });
});
//# sourceMappingURL=diff-mode.test.js.map