import { describe, it, expect } from "vitest";
import { GoldenPathFlowSchema } from "../../../scanners/runtime/types.js";
describe("runtime types", () => {
    describe("GoldenPathFlowSchema", () => {
        it("parses a minimal valid flow", () => {
            const flow = {
                name: "test-flow",
                steps: [
                    { action: "navigate", url: "/" },
                ],
            };
            const result = GoldenPathFlowSchema.parse(flow);
            expect(result.name).toBe("test-flow");
            expect(result.priority).toBe("medium");
            expect(result.steps).toHaveLength(1);
        });
        it("parses a full flow with all options", () => {
            const flow = {
                name: "checkout-flow",
                description: "Test the checkout process",
                priority: "critical",
                tags: ["smoke", "e2e"],
                baseUrl: "http://localhost:3000",
                steps: [
                    { action: "navigate", url: "/", description: "Go home" },
                    { action: "click", selector: "#login", timeout: 5000 },
                    { action: "fill", selector: "#email", value: "test@example.com" },
                    { action: "api", url: "/api/health", method: "GET" },
                    { action: "assert", url: "/dashboard" },
                    { action: "wait", timeout: 1000 },
                    { action: "screenshot", description: "Final state" },
                ],
            };
            const result = GoldenPathFlowSchema.parse(flow);
            expect(result.name).toBe("checkout-flow");
            expect(result.priority).toBe("critical");
            expect(result.tags).toContain("smoke");
            expect(result.steps).toHaveLength(7);
        });
        it("validates action types", () => {
            const validActions = [
                "navigate",
                "click",
                "fill",
                "select",
                "assert",
                "wait",
                "screenshot",
                "api",
            ];
            for (const action of validActions) {
                const flow = {
                    name: "test",
                    steps: [{ action }],
                };
                expect(() => GoldenPathFlowSchema.parse(flow)).not.toThrow();
            }
        });
        it("rejects invalid action types", () => {
            const flow = {
                name: "test",
                steps: [{ action: "invalid-action" }],
            };
            expect(() => GoldenPathFlowSchema.parse(flow)).toThrow();
        });
        it("validates priority values", () => {
            const priorities = ["critical", "high", "medium", "low"];
            for (const priority of priorities) {
                const flow = {
                    name: "test",
                    priority,
                    steps: [{ action: "navigate", url: "/" }],
                };
                expect(() => GoldenPathFlowSchema.parse(flow)).not.toThrow();
            }
        });
        it("rejects invalid priority", () => {
            const flow = {
                name: "test",
                priority: "urgent",
                steps: [{ action: "navigate", url: "/" }],
            };
            expect(() => GoldenPathFlowSchema.parse(flow)).toThrow();
        });
        it("validates HTTP methods for API action", () => {
            const methods = ["GET", "POST", "PUT", "DELETE", "PATCH"];
            for (const method of methods) {
                const flow = {
                    name: "test",
                    steps: [{ action: "api", url: "/api/test", method }],
                };
                expect(() => GoldenPathFlowSchema.parse(flow)).not.toThrow();
            }
        });
        it("allows body and headers for API action", () => {
            const flow = {
                name: "test",
                steps: [
                    {
                        action: "api",
                        url: "/api/create",
                        method: "POST",
                        body: { name: "test", value: 123 },
                        headers: { "X-Custom": "header" },
                    },
                ],
            };
            const result = GoldenPathFlowSchema.parse(flow);
            expect(result.steps[0].body).toEqual({ name: "test", value: 123 });
            expect(result.steps[0].headers).toEqual({ "X-Custom": "header" });
        });
        it("requires name field", () => {
            const flow = {
                steps: [{ action: "navigate", url: "/" }],
            };
            expect(() => GoldenPathFlowSchema.parse(flow)).toThrow();
        });
        it("requires steps array", () => {
            const flow = {
                name: "test",
            };
            expect(() => GoldenPathFlowSchema.parse(flow)).toThrow();
        });
    });
});
//# sourceMappingURL=types.test.js.map