UNPKG

@kubb/plugin-cypress

Version:

Cypress test generator plugin for Kubb, creating end-to-end tests from OpenAPI specifications for automated API testing.

108 lines (106 loc) 4 kB
const require_index = require('./index.cjs'); let _kubb_plugin_oas_utils = require("@kubb/plugin-oas/utils"); let _kubb_react_fabric = require("@kubb/react-fabric"); let _kubb_core_utils = require("@kubb/core/utils"); let _kubb_oas = require("@kubb/oas"); let _kubb_react_fabric_jsx_runtime = require("@kubb/react-fabric/jsx-runtime"); //#region src/components/Request.tsx function getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas }) { if (paramsType === "object") { const pathParams = (0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, { typed: true, casing: paramsCasing }); return _kubb_react_fabric.FunctionParams.factory({ data: { mode: "object", children: { ...pathParams, data: typeSchemas.request?.name ? { type: typeSchemas.request?.name, optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema) } : void 0, params: typeSchemas.queryParams?.name ? { type: typeSchemas.queryParams?.name, optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema) } : void 0, headers: typeSchemas.headerParams?.name ? { type: typeSchemas.headerParams?.name, optional: (0, _kubb_oas.isOptional)(typeSchemas.headerParams?.schema) } : void 0 } }, options: { type: "Partial<Cypress.RequestOptions>", default: "{}" } }); } return _kubb_react_fabric.FunctionParams.factory({ pathParams: typeSchemas.pathParams?.name ? { mode: pathParamsType === "object" ? "object" : "inlineSpread", children: (0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, { typed: true, casing: paramsCasing }), default: (0, _kubb_oas.isAllOptional)(typeSchemas.pathParams?.schema) ? "{}" : void 0 } : void 0, data: typeSchemas.request?.name ? { type: typeSchemas.request?.name, optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema) } : void 0, params: typeSchemas.queryParams?.name ? { type: typeSchemas.queryParams?.name, optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema) } : void 0, headers: typeSchemas.headerParams?.name ? { type: typeSchemas.headerParams?.name, optional: (0, _kubb_oas.isOptional)(typeSchemas.headerParams?.schema) } : void 0, options: { type: "Partial<Cypress.RequestOptions>", default: "{}" } }); } function Request({ baseURL = "", name, dataReturnType, typeSchemas, url, method, paramsType, paramsCasing, pathParamsType }) { const path = new _kubb_core_utils.URLPath(url, { casing: paramsCasing }); const params = getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas }); const returnType = dataReturnType === "data" ? `Cypress.Chainable<${typeSchemas.response.name}>` : `Cypress.Chainable<Cypress.Response<${typeSchemas.response.name}>>`; const urlTemplate = path.toTemplateString({ prefix: baseURL }); const requestOptions = [`method: '${method}'`, `url: ${urlTemplate}`]; if (typeSchemas.queryParams?.name) requestOptions.push("qs: params"); if (typeSchemas.headerParams?.name) requestOptions.push("headers"); if (typeSchemas.request?.name) requestOptions.push("body: data"); requestOptions.push("...options"); return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, { name, isIndexable: true, isExportable: true, children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Function, { name, export: true, params: params.toConstructor(), returnType, children: dataReturnType === "data" ? `return cy.request<${typeSchemas.response.name}>({ ${requestOptions.join(",\n ")} }).then((res) => res.body)` : `return cy.request<${typeSchemas.response.name}>({ ${requestOptions.join(",\n ")} })` }) }); } Request.getParams = getParams; //#endregion Object.defineProperty(exports, 'Request', { enumerable: true, get: function () { return Request; } }); //# sourceMappingURL=components-CEpexuad.cjs.map