import { describe, it } from "node:test";
import { expect } from "chai";
import { convertRoutes } from "../convert/engine.js";
describe("Routes.json Conversion Engine", () => {
    it("should handle simple route conversion (no version)", () => {
        const routesConfig = {
            versions: [
                {
                    name: "v1",
                    pathPrefix: "/v1",
                },
                {
                    name: "none",
                    pathPrefix: "",
                },
            ],
            routes: [
                {
                    methods: ["GET"],
                    path: "/test",
                    summary: "Test route",
                    version: "none",
                    corsPolicy: "anything-goes",
                    description: "This is a test route",
                    operationId: "random",
                    handler: {
                        export: "urlRewriteHandler",
                        module: "$import(@zuplo/runtime)",
                        options: {
                            rewritePattern: "https://jsonplaceholder.typicode.com/todos",
                            forwardSearch: true,
                        },
                    },
                },
            ],
        };
        const expected = {
            openapi: "3.1.0",
            info: {
                title: "Converted from config/routes.json",
                version: "1.0.0",
            },
            paths: {
                "/test": {
                    get: {
                        summary: "Test route",
                        description: "This is a test route",
                        operationId: "random",
                        "x-zuplo-route": {
                            corsPolicy: "anything-goes",
                            handler: {
                                export: "urlRewriteHandler",
                                module: "$import(@zuplo/runtime)",
                                options: {
                                    rewritePattern: "https://jsonplaceholder.typicode.com/todos",
                                    forwardSearch: true,
                                },
                            },
                        },
                    },
                    "x-zuplo-path": {
                        pathMode: "url-pattern",
                    },
                },
            },
        };
        const actual = convertRoutes(routesConfig);
        expect(actual).to.deep.equal(expected);
    });
    it("should handle simple route conversion (with version)", () => {
        const routesConfig = {
            versions: [
                {
                    name: "v1",
                    pathPrefix: "/v1",
                },
                {
                    name: "none",
                    pathPrefix: "",
                },
            ],
            routes: [
                {
                    methods: ["GET"],
                    path: "/test",
                    summary: "Test route",
                    version: "v1",
                    corsPolicy: "anything-goes",
                    description: "This is a test route",
                    operationId: "random",
                    handler: {
                        export: "urlRewriteHandler",
                        module: "$import(@zuplo/runtime)",
                        options: {
                            rewritePattern: "https://jsonplaceholder.typicode.com/todos",
                            forwardSearch: true,
                        },
                    },
                },
            ],
        };
        const expected = {
            openapi: "3.1.0",
            info: {
                title: "Converted from config/routes.json",
                version: "1.0.0",
            },
            paths: {
                "/v1/test": {
                    get: {
                        summary: "Test route",
                        description: "This is a test route",
                        operationId: "random",
                        "x-zuplo-route": {
                            corsPolicy: "anything-goes",
                            handler: {
                                export: "urlRewriteHandler",
                                module: "$import(@zuplo/runtime)",
                                options: {
                                    rewritePattern: "https://jsonplaceholder.typicode.com/todos",
                                    forwardSearch: true,
                                },
                            },
                        },
                    },
                    "x-zuplo-path": {
                        pathMode: "url-pattern",
                    },
                },
            },
        };
        const actual = convertRoutes(routesConfig);
        expect(actual).to.deep.equal(expected);
    });
    it("should handle single route with multiple methods", () => {
        const routesConfig = {
            versions: [
                {
                    name: "v1",
                    pathPrefix: "/v1",
                },
                {
                    name: "none",
                    pathPrefix: "",
                },
            ],
            routes: [
                {
                    methods: ["GET", "POST", "HEAD"],
                    path: "/test",
                    summary: "Test route",
                    version: "v1",
                    corsPolicy: "anything-goes",
                    description: "This is a test route",
                    operationId: "random",
                    handler: {
                        export: "urlRewriteHandler",
                        module: "$import(@zuplo/runtime)",
                        options: {
                            rewritePattern: "https://jsonplaceholder.typicode.com/todos",
                            forwardSearch: true,
                        },
                    },
                },
            ],
        };
        const expected = {
            openapi: "3.1.0",
            info: {
                title: "Converted from config/routes.json",
                version: "1.0.0",
            },
            paths: {
                "/v1/test": {
                    "get,post,head": {
                        summary: "Test route",
                        description: "This is a test route",
                        operationId: "random",
                        "x-zuplo-route": {
                            corsPolicy: "anything-goes",
                            handler: {
                                export: "urlRewriteHandler",
                                module: "$import(@zuplo/runtime)",
                                options: {
                                    rewritePattern: "https://jsonplaceholder.typicode.com/todos",
                                    forwardSearch: true,
                                },
                            },
                        },
                    },
                    "x-zuplo-path": {
                        pathMode: "url-pattern",
                    },
                },
            },
        };
        const actual = convertRoutes(routesConfig);
        expect(actual).to.deep.equal(expected);
    });
    it("should handle single route with different methods", () => {
        const routesConfig = {
            versions: [
                {
                    name: "v1",
                    pathPrefix: "/v1",
                },
                {
                    name: "none",
                    pathPrefix: "",
                },
            ],
            routes: [
                {
                    methods: ["GET"],
                    path: "/test",
                    summary: "Test route",
                    description: "This is a test route",
                    version: "v1",
                    corsPolicy: "anything-goes",
                    handler: {
                        export: "urlRewriteHandler",
                        module: "$import(@zuplo/runtime)",
                        options: {
                            rewritePattern: "https://welcome.zuplo.io/",
                            forwardSearch: true,
                        },
                    },
                    operationId: "random1",
                },
                {
                    methods: ["POST"],
                    path: "/test",
                    summary: "Test route",
                    description: "This is a test route",
                    version: "v1",
                    corsPolicy: "anything-goes",
                    handler: {
                        export: "urlRewriteHandler",
                        module: "$import(@zuplo/runtime)",
                        options: {
                            rewritePattern: "https://welcome.zuplo.io/",
                            forwardSearch: true,
                        },
                    },
                    operationId: "random2",
                },
            ],
        };
        const expected = {
            openapi: "3.1.0",
            info: {
                title: "Converted from config/routes.json",
                version: "1.0.0",
            },
            paths: {
                "/v1/test": {
                    get: {
                        summary: "Test route",
                        description: "This is a test route",
                        operationId: "random1",
                        "x-zuplo-route": {
                            corsPolicy: "anything-goes",
                            handler: {
                                export: "urlRewriteHandler",
                                module: "$import(@zuplo/runtime)",
                                options: {
                                    rewritePattern: "https://welcome.zuplo.io/",
                                    forwardSearch: true,
                                },
                            },
                        },
                    },
                    post: {
                        summary: "Test route",
                        description: "This is a test route",
                        operationId: "random2",
                        "x-zuplo-route": {
                            corsPolicy: "anything-goes",
                            handler: {
                                export: "urlRewriteHandler",
                                module: "$import(@zuplo/runtime)",
                                options: {
                                    rewritePattern: "https://welcome.zuplo.io/",
                                    forwardSearch: true,
                                },
                            },
                        },
                    },
                    "x-zuplo-path": {
                        pathMode: "url-pattern",
                    },
                },
            },
        };
        const actual = convertRoutes(routesConfig);
        expect(actual).to.deep.equal(expected);
    });
});
//# sourceMappingURL=engine.test.js.map