@kubb/plugin-cypress
Version:
Cypress test generator plugin for Kubb, creating end-to-end tests from OpenAPI specifications for automated API testing.
24 lines (22 loc) • 1.43 kB
JavaScript
import { FunctionParams, File, Function } from '@kubb/react';
import { isOptional } from '@kubb/oas';
import { URLPath } from '@kubb/core/utils';
import { jsx, jsxs } from '@kubb/react/jsx-runtime';
// src/components/Request.tsx
function Request({ baseURL = "", name, dataReturnType, typeSchemas, url, method }) {
const params = FunctionParams.factory({
data: typeSchemas.request?.name ? {
type: typeSchemas.request?.name,
optional: isOptional(typeSchemas.request?.schema)
} : void 0
});
const returnType = dataReturnType === "data" ? `Cypress.Chainable<${typeSchemas.response.name}>` : `Cypress.Chainable<Cypress.Response<${typeSchemas.response.name}>>`;
const body = typeSchemas.request?.name ? "data" : void 0;
return /* @__PURE__ */ jsx(File.Source, { name, isIndexable: true, isExportable: true, children: /* @__PURE__ */ jsxs(Function, { name, export: true, params: params.toConstructor(), returnType, children: [
dataReturnType === "data" && `return cy.request('${method}', '${baseURL ?? ""}${new URLPath(url).toURLPath().replace(/([^/]):/g, "$1\\\\:")}', ${body}).then((res: Cypress.Response<${typeSchemas.response.name}>) => res.body)`,
dataReturnType === "full" && `return cy.request('${method}', '${new URLPath(`${baseURL ?? ""}${url}`).toURLPath()}', ${body})`
] }) });
}
export { Request };
//# sourceMappingURL=chunk-NEMUYKDD.js.map
//# sourceMappingURL=chunk-NEMUYKDD.js.map