import { describe, it, expect } from "vitest";
import { DeployConfigSchema, SmokeTestSchema, CanaryConfigSchema, } from "../../../scanners/deploy/types.js";
describe("deploy types", () => {
    describe("SmokeTestSchema", () => {
        it("parses minimal smoke test", () => {
            const test = {
                name: "Homepage",
                endpoint: "/",
            };
            const result = SmokeTestSchema.parse(test);
            expect(result.name).toBe("Homepage");
            expect(result.method).toBe("GET");
            expect(result.expectedStatus).toBe(200);
        });
        it("parses full smoke test with assertions", () => {
            const test = {
                name: "API test",
                endpoint: "/api/data",
                method: "POST",
                expectedStatus: 201,
                timeout: 5000,
                headers: { "X-Custom": "value" },
                body: { key: "value" },
                assertions: [
                    { type: "status", operator: "eq", value: 201 },
                    { type: "latency", operator: "lt", value: 500 },
                    { type: "body", path: "success", operator: "eq", value: "true" },
                ],
            };
            const result = SmokeTestSchema.parse(test);
            expect(result.method).toBe("POST");
            expect(result.assertions).toHaveLength(3);
        });
        it("validates assertion types", () => {
            const types = ["status", "body", "header", "latency"];
            for (const type of types) {
                const test = {
                    name: "test",
                    endpoint: "/",
                    assertions: [{ type, operator: "eq", value: "test" }],
                };
                expect(() => SmokeTestSchema.parse(test)).not.toThrow();
            }
        });
        it("validates assertion operators", () => {
            const operators = ["eq", "ne", "gt", "lt", "contains", "matches"];
            for (const operator of operators) {
                const test = {
                    name: "test",
                    endpoint: "/",
                    assertions: [{ type: "status", operator, value: 200 }],
                };
                expect(() => SmokeTestSchema.parse(test)).not.toThrow();
            }
        });
    });
    describe("CanaryConfigSchema", () => {
        it("parses minimal canary config", () => {
            const config = {};
            const result = CanaryConfigSchema.parse(config);
            expect(result.enabled).toBe(true);
            expect(result.trafficPercent).toBe(10);
            expect(result.duration).toBe("10m");
        });
        it("parses full canary config", () => {
            const config = {
                enabled: true,
                trafficPercent: 20,
                duration: "15m",
                thresholds: {
                    errorRate: 0.005,
                    p95Latency: 300,
                    healthCheckFailures: 3,
                },
                rollbackOnFailure: true,
            };
            const result = CanaryConfigSchema.parse(config);
            expect(result.trafficPercent).toBe(20);
            expect(result.thresholds?.errorRate).toBe(0.005);
        });
        it("validates traffic percent range", () => {
            expect(() => CanaryConfigSchema.parse({ trafficPercent: -1 })).toThrow();
            expect(() => CanaryConfigSchema.parse({ trafficPercent: 101 })).toThrow();
            expect(() => CanaryConfigSchema.parse({ trafficPercent: 50 })).not.toThrow();
        });
    });
    describe("DeployConfigSchema", () => {
        it("parses minimal config", () => {
            const config = {};
            const result = DeployConfigSchema.parse(config);
            expect(result.healthEndpoints).toEqual(["/", "/api/health"]);
        });
        it("parses full config", () => {
            const config = {
                provider: "vercel",
                healthEndpoints: ["/health", "/ready"],
                smokeTests: [
                    { name: "test", endpoint: "/" },
                ],
                canary: {
                    enabled: true,
                    trafficPercent: 10,
                },
                rollback: {
                    autoRollback: true,
                    retainVersions: 3,
                },
                notifications: {
                    slack: "https://hooks.slack.com/...",
                    email: ["team@example.com"],
                },
            };
            const result = DeployConfigSchema.parse(config);
            expect(result.provider).toBe("vercel");
            expect(result.smokeTests).toHaveLength(1);
            expect(result.canary?.enabled).toBe(true);
        });
        it("validates provider enum", () => {
            const providers = ["vercel", "aws", "gcp", "railway", "render", "fly"];
            for (const provider of providers) {
                expect(() => DeployConfigSchema.parse({ provider })).not.toThrow();
            }
        });
    });
});
//# sourceMappingURL=types.test.js.map