/**
 * Tests for evaluation fixtures
 */
import { describe, it, expect } from "vitest";
import { ALL_FIXTURES, sqlInjectionFixtures, xssFixtures, secretsFixtures, typeSafetyFixtures, authFixtures, pathTraversalFixtures, getFixturesByCategory, getFixturesByTag, getFixtureById, getFixtureStats, } from "./fixtures.js";
describe("fixtures", () => {
    describe("ALL_FIXTURES", () => {
        it("contains all fixture categories", () => {
            expect(ALL_FIXTURES.length).toBeGreaterThan(0);
            const categories = new Set(ALL_FIXTURES.map((f) => f.category));
            expect(categories.has("sql-injection")).toBe(true);
            expect(categories.has("xss")).toBe(true);
            expect(categories.has("secrets")).toBe(true);
            expect(categories.has("type-safety")).toBe(true);
            expect(categories.has("auth-bypass")).toBe(true);
            expect(categories.has("path-traversal")).toBe(true);
        });
        it("has unique fixture IDs", () => {
            const ids = ALL_FIXTURES.map((f) => f.id);
            const uniqueIds = new Set(ids);
            expect(uniqueIds.size).toBe(ids.length);
        });
        it("all fixtures have required fields", () => {
            for (const fixture of ALL_FIXTURES) {
                expect(fixture.id).toBeDefined();
                expect(fixture.name).toBeDefined();
                expect(fixture.description).toBeDefined();
                expect(fixture.category).toBeDefined();
                expect(fixture.files).toBeDefined();
                expect(fixture.files.length).toBeGreaterThan(0);
                expect(fixture.expectedFindings).toBeDefined();
            }
        });
        it("all expected findings have required fields", () => {
            for (const fixture of ALL_FIXTURES) {
                for (const finding of fixture.expectedFindings) {
                    expect(finding.file).toBeDefined();
                    expect(finding.line).toBeDefined();
                    expect(finding.line).toBeGreaterThan(0);
                    expect(finding.severity).toBeDefined();
                    expect(finding.category).toBeDefined();
                    expect(finding.description).toBeDefined();
                    expect(typeof finding.isVulnerable).toBe("boolean");
                }
            }
        });
    });
    describe("sqlInjectionFixtures", () => {
        it("contains SQL injection test cases", () => {
            expect(sqlInjectionFixtures.length).toBeGreaterThan(0);
            expect(sqlInjectionFixtures.every((f) => f.category === "sql-injection")).toBe(true);
        });
        it("includes string concatenation test case", () => {
            const concatFixture = sqlInjectionFixtures.find((f) => f.id === "sql-001");
            expect(concatFixture).toBeDefined();
            expect(concatFixture.name).toContain("String Concatenation");
        });
        it("includes template literal test case", () => {
            const templateFixture = sqlInjectionFixtures.find((f) => f.id === "sql-002");
            expect(templateFixture).toBeDefined();
            expect(templateFixture.name).toContain("Template Literal");
        });
    });
    describe("xssFixtures", () => {
        it("contains XSS test cases", () => {
            expect(xssFixtures.length).toBeGreaterThan(0);
            expect(xssFixtures.every((f) => f.category === "xss")).toBe(true);
        });
        it("includes React dangerouslySetInnerHTML test case", () => {
            const reactFixture = xssFixtures.find((f) => f.id === "xss-001");
            expect(reactFixture).toBeDefined();
            expect(reactFixture.files[0].language).toBe("tsx");
        });
        it("includes DOM manipulation test case", () => {
            const domFixture = xssFixtures.find((f) => f.id === "xss-002");
            expect(domFixture).toBeDefined();
            expect(domFixture.files[0].content).toContain("innerHTML");
        });
    });
    describe("secretsFixtures", () => {
        it("contains secrets test cases", () => {
            expect(secretsFixtures.length).toBeGreaterThan(0);
            expect(secretsFixtures.every((f) => f.category === "secrets")).toBe(true);
        });
        it("includes API key test case", () => {
            const apiKeyFixture = secretsFixtures.find((f) => f.id === "secrets-001");
            expect(apiKeyFixture).toBeDefined();
            expect(apiKeyFixture.files[0].content).toContain("AWS_ACCESS_KEY");
        });
        it("includes private key test case", () => {
            const pkFixture = secretsFixtures.find((f) => f.id === "secrets-002");
            expect(pkFixture).toBeDefined();
            expect(pkFixture.files[0].content).toContain("PRIVATE_KEY");
        });
    });
    describe("typeSafetyFixtures", () => {
        it("contains type safety test cases", () => {
            expect(typeSafetyFixtures.length).toBeGreaterThan(0);
            expect(typeSafetyFixtures.every((f) => f.category === "type-safety")).toBe(true);
        });
        it("includes explicit any test case", () => {
            const anyFixture = typeSafetyFixtures.find((f) => f.id === "type-001");
            expect(anyFixture).toBeDefined();
            expect(anyFixture.files[0].content).toContain(": any");
        });
        it("includes suppressions test case", () => {
            const suppressFixture = typeSafetyFixtures.find((f) => f.id === "type-002");
            expect(suppressFixture).toBeDefined();
            expect(suppressFixture.files[0].content).toContain("@ts-ignore");
        });
    });
    describe("authFixtures", () => {
        it("contains auth bypass test cases", () => {
            expect(authFixtures.length).toBeGreaterThan(0);
            expect(authFixtures.every((f) => f.category === "auth-bypass")).toBe(true);
        });
        it("includes missing auth check test case", () => {
            const authFixture = authFixtures.find((f) => f.id === "auth-001");
            expect(authFixture).toBeDefined();
            expect(authFixture.expectedFindings.length).toBeGreaterThan(0);
        });
    });
    describe("pathTraversalFixtures", () => {
        it("contains path traversal test cases", () => {
            expect(pathTraversalFixtures.length).toBeGreaterThan(0);
            expect(pathTraversalFixtures.every((f) => f.category === "path-traversal")).toBe(true);
        });
        it("includes file read test case", () => {
            const pathFixture = pathTraversalFixtures.find((f) => f.id === "path-001");
            expect(pathFixture).toBeDefined();
            expect(pathFixture.files[0].content).toContain("readFile");
        });
    });
    describe("getFixturesByCategory", () => {
        it("returns fixtures for valid category", () => {
            const sqlFixtures = getFixturesByCategory("sql-injection");
            expect(sqlFixtures.length).toBeGreaterThan(0);
            expect(sqlFixtures.every((f) => f.category === "sql-injection")).toBe(true);
        });
        it("returns empty array for invalid category", () => {
            const fixtures = getFixturesByCategory("invalid-category");
            expect(fixtures).toEqual([]);
        });
        it("returns all xss fixtures", () => {
            const fixtures = getFixturesByCategory("xss");
            expect(fixtures.length).toBe(xssFixtures.length);
        });
    });
    describe("getFixturesByTag", () => {
        it("returns fixtures with matching tag", () => {
            const owaspFixtures = getFixturesByTag("owasp-top-10");
            expect(owaspFixtures.length).toBeGreaterThan(0);
            expect(owaspFixtures.every((f) => f.tags?.includes("owasp-top-10"))).toBe(true);
        });
        it("returns empty array for non-existent tag", () => {
            const fixtures = getFixturesByTag("non-existent-tag");
            expect(fixtures).toEqual([]);
        });
        it("returns injection tagged fixtures", () => {
            const injectionFixtures = getFixturesByTag("injection");
            expect(injectionFixtures.length).toBeGreaterThan(0);
        });
    });
    describe("getFixtureById", () => {
        it("returns fixture for valid ID", () => {
            const fixture = getFixtureById("sql-001");
            expect(fixture).toBeDefined();
            expect(fixture.id).toBe("sql-001");
        });
        it("returns undefined for invalid ID", () => {
            const fixture = getFixtureById("invalid-id");
            expect(fixture).toBeUndefined();
        });
    });
    describe("getFixtureStats", () => {
        it("returns total fixture count", () => {
            const stats = getFixtureStats();
            expect(stats.total).toBe(ALL_FIXTURES.length);
        });
        it("returns count by category", () => {
            const stats = getFixtureStats();
            expect(stats.byCategory["sql-injection"]).toBe(sqlInjectionFixtures.length);
            expect(stats.byCategory["xss"]).toBe(xssFixtures.length);
            expect(stats.byCategory["secrets"]).toBe(secretsFixtures.length);
        });
        it("returns total expected findings", () => {
            const stats = getFixtureStats();
            const expectedCount = ALL_FIXTURES.reduce((sum, f) => sum + f.expectedFindings.length, 0);
            expect(stats.totalExpected).toBe(expectedCount);
        });
    });
});
//# sourceMappingURL=fixtures.test.js.map