import { describe, it, expect } from "vitest";
import { LoadProfileSchema, EndpointSchema, ScenarioSchema, } from "../../../scanners/scale/types.js";
describe("scale types", () => {
    describe("EndpointSchema", () => {
        it("parses minimal endpoint", () => {
            const endpoint = { path: "/api/health" };
            const result = EndpointSchema.parse(endpoint);
            expect(result.path).toBe("/api/health");
            expect(result.method).toBe("GET");
            expect(result.weight).toBe(100);
        });
        it("parses full endpoint with thresholds", () => {
            const endpoint = {
                path: "/api/checkout",
                method: "POST",
                weight: 30,
                headers: { "X-Custom": "value" },
                body: { items: [{ id: 1 }] },
                thresholds: {
                    p95: 200,
                    p99: 500,
                    errorRate: 0.005,
                },
            };
            const result = EndpointSchema.parse(endpoint);
            expect(result.method).toBe("POST");
            expect(result.weight).toBe(30);
            expect(result.thresholds?.p95).toBe(200);
        });
        it("validates method enum", () => {
            const validMethods = ["GET", "POST", "PUT", "DELETE", "PATCH"];
            for (const method of validMethods) {
                expect(() => EndpointSchema.parse({ path: "/", method })).not.toThrow();
            }
        });
        it("rejects invalid method", () => {
            expect(() => EndpointSchema.parse({ path: "/", method: "INVALID" })).toThrow();
        });
    });
    describe("ScenarioSchema", () => {
        it("parses fixed VUs scenario", () => {
            const scenario = {
                name: "Steady State",
                duration: "5m",
                vus: 50,
            };
            const result = ScenarioSchema.parse(scenario);
            expect(result.name).toBe("Steady State");
            expect(result.type).toBe("ramp");
            expect(result.vus).toBe(50);
        });
        it("parses ramping VUs scenario", () => {
            const scenario = {
                name: "Ramp Up",
                type: "ramp",
                duration: "2m",
                vus: { start: 1, end: 100 },
            };
            const result = ScenarioSchema.parse(scenario);
            expect(result.vus).toEqual({ start: 1, end: 100 });
        });
        it("validates scenario types", () => {
            const types = ["ramp", "spike", "soak", "stress", "breakpoint"];
            for (const type of types) {
                expect(() => ScenarioSchema.parse({ name: "test", type, duration: "1m", vus: 10 })).not.toThrow();
            }
        });
    });
    describe("LoadProfileSchema", () => {
        it("parses minimal profile", () => {
            const profile = {
                name: "test",
                scenarios: [
                    { name: "Basic", duration: "1m", vus: 10 },
                ],
            };
            const result = LoadProfileSchema.parse(profile);
            expect(result.name).toBe("test");
            expect(result.tool).toBe("k6");
            expect(result.scenarios).toHaveLength(1);
        });
        it("parses full profile", () => {
            const profile = {
                name: "production",
                description: "Production load test",
                baseUrl: "http://localhost:3000",
                tool: "k6",
                thresholds: {
                    p95: 500,
                    p99: 1000,
                    errorRate: 0.01,
                    throughput: 100,
                },
                endpoints: [
                    { path: "/", weight: 50 },
                    { path: "/api/products", weight: 30 },
                ],
                scenarios: [
                    { name: "Ramp", type: "ramp", duration: "2m", vus: { start: 1, end: 50 } },
                    { name: "Steady", duration: "5m", vus: 50 },
                ],
            };
            const result = LoadProfileSchema.parse(profile);
            expect(result.tool).toBe("k6");
            expect(result.thresholds?.p95).toBe(500);
            expect(result.endpoints).toHaveLength(2);
            expect(result.scenarios).toHaveLength(2);
        });
        it("validates tool enum", () => {
            const tools = ["k6", "artillery", "autocannon", "wrk"];
            for (const tool of tools) {
                expect(() => LoadProfileSchema.parse({
                    name: "test",
                    tool,
                    scenarios: [{ name: "s", duration: "1m", vus: 1 }],
                })).not.toThrow();
            }
        });
        it("requires name", () => {
            expect(() => LoadProfileSchema.parse({
                scenarios: [{ name: "s", duration: "1m", vus: 1 }],
            })).toThrow();
        });
        it("requires scenarios", () => {
            expect(() => LoadProfileSchema.parse({ name: "test" })).toThrow();
        });
    });
});
//# sourceMappingURL=types.test.js.map