import { z } from "zod";
import { loadTestSchema, numericString } from "./loadTestSchema.js";
describe("generateLoadRestTool schema validation", () => {
    describe("numericString helper", () => {
        const testSchema = numericString("testParam");
        it("should accept empty string", () => {
            const result = testSchema.safeParse("");
            expect(result.success).toBe(true);
        });
        it("should accept valid positive integers", () => {
            expect(testSchema.safeParse("0").success).toBe(true);
            expect(testSchema.safeParse("1").success).toBe(true);
            expect(testSchema.safeParse("100").success).toBe(true);
            expect(testSchema.safeParse("9999").success).toBe(true);
        });
        it("should reject decimal numbers", () => {
            const result = testSchema.safeParse("1.5");
            expect(result.success).toBe(false);
            if (!result.success) {
                expect(result.error.issues[0].message).toContain("non-negative integer");
            }
        });
        it("should reject negative numbers", () => {
            const result = testSchema.safeParse("-1");
            expect(result.success).toBe(false);
            if (!result.success) {
                expect(result.error.issues[0].message).toContain("non-negative integer");
            }
        });
        it("should reject non-numeric strings", () => {
            const result = testSchema.safeParse("abc");
            expect(result.success).toBe(false);
            if (!result.success) {
                expect(result.error.issues[0].message).toContain("non-negative integer");
            }
        });
        it("should reject strings with mixed alphanumeric", () => {
            const result = testSchema.safeParse("123abc");
            expect(result.success).toBe(false);
            if (!result.success) {
                expect(result.error.issues[0].message).toContain("non-negative integer");
            }
        });
        it("should reject strings with spaces", () => {
            const result = testSchema.safeParse("1 0");
            expect(result.success).toBe(false);
        });
        it("should reject floating point notation", () => {
            expect(testSchema.safeParse("1e5").success).toBe(false);
            expect(testSchema.safeParse("1.0").success).toBe(false);
        });
    });
    describe("loadTestSchema validation", () => {
        const schema = z.object(loadTestSchema);
        it("should accept valid load parameters", () => {
            const result = schema.safeParse({
                endpointURL: "https://api.example.com/endpoint",
                method: "GET",
                language: "python",
                framework: "pytest",
                outputDir: "/tmp/tests",
                prompt: "Generate load test",
                loadCount: "1000",
                loadDuration: "60",
                loadNumThreads: "10",
                loadRampupDuration: "30",
                loadRampupInterval: "5",
                loadTargetRPS: "100",
            });
            expect(result.success).toBe(true);
        });
        it("should accept empty load parameters", () => {
            const result = schema.safeParse({
                endpointURL: "https://api.example.com/endpoint",
                method: "POST",
                language: "python",
                framework: "pytest",
                outputDir: "/tmp/tests",
                prompt: "Generate load test",
                loadCount: "",
                loadDuration: "",
                loadNumThreads: "",
            });
            expect(result.success).toBe(true);
        });
        it("should reject invalid loadDuration (decimal)", () => {
            const result = schema.safeParse({
                endpointURL: "https://api.example.com/endpoint",
                method: "GET",
                language: "python",
                framework: "pytest",
                outputDir: "/tmp/tests",
                prompt: "Generate load test",
                loadDuration: "5.5",
            });
            expect(result.success).toBe(false);
            if (!result.success) {
                expect(result.error.issues[0].message).toContain("non-negative integer");
                expect(result.error.issues[0].path).toContain("loadDuration");
            }
        });
        it("should reject invalid loadNumThreads (negative)", () => {
            const result = schema.safeParse({
                endpointURL: "https://api.example.com/endpoint",
                method: "GET",
                language: "python",
                framework: "pytest",
                outputDir: "/tmp/tests",
                prompt: "Generate load test",
                loadNumThreads: "-5",
            });
            expect(result.success).toBe(false);
            if (!result.success) {
                expect(result.error.issues[0].path).toContain("loadNumThreads");
            }
        });
        it("should reject invalid loadTargetRPS (non-numeric)", () => {
            const result = schema.safeParse({
                endpointURL: "https://api.example.com/endpoint",
                method: "GET",
                language: "python",
                framework: "pytest",
                outputDir: "/tmp/tests",
                prompt: "Generate load test",
                loadTargetRPS: "high",
            });
            expect(result.success).toBe(false);
            if (!result.success) {
                expect(result.error.issues[0].path).toContain("loadTargetRPS");
            }
        });
        it("should reject invalid loadCount (alphanumeric)", () => {
            const result = schema.safeParse({
                endpointURL: "https://api.example.com/endpoint",
                method: "GET",
                language: "python",
                framework: "pytest",
                outputDir: "/tmp/tests",
                prompt: "Generate load test",
                loadCount: "100k",
            });
            expect(result.success).toBe(false);
        });
        it("should reject invalid loadRampupDuration (with spaces)", () => {
            const result = schema.safeParse({
                endpointURL: "https://api.example.com/endpoint",
                method: "GET",
                language: "python",
                framework: "pytest",
                outputDir: "/tmp/tests",
                prompt: "Generate load test",
                loadRampupDuration: "1 0",
            });
            expect(result.success).toBe(false);
        });
        it("should reject invalid loadRampupInterval (scientific notation)", () => {
            const result = schema.safeParse({
                endpointURL: "https://api.example.com/endpoint",
                method: "GET",
                language: "python",
                framework: "pytest",
                outputDir: "/tmp/tests",
                prompt: "Generate load test",
                loadRampupInterval: "1e3",
            });
            expect(result.success).toBe(false);
        });
    });
});
