diff --git a/test/e2e-cypress/e2e/features/plugins/spec/validation-errors.cy.js b/test/e2e-cypress/e2e/features/plugins/spec/validation-errors.cy.js deleted file mode 100644 index a038cd2f6c0..00000000000 --- a/test/e2e-cypress/e2e/features/plugins/spec/validation-errors.cy.js +++ /dev/null @@ -1,24 +0,0 @@ -/** - * @prettier - */ - -describe("Validation errors", () => { - it("should correctly format validation errors for Map items", () => { - cy.visit("/?url=/documents/petstore.swagger.yaml") - .get("#operations-pet-addPet") - .click() - .get("button.try-out__btn") - .click() - .get("textarea.body-param__text") - .clear() - .type(`{backspace}"id": "test", "name": 1}`) - .get("button.execute") - .click() - .get("div.validation-errors.errors-wrapper") - .contains("id: Value must be an integer") - .should("exist") - .get("div.validation-errors.errors-wrapper") - .contains("name: Value must be a string") - .should("exist") - }) -}) diff --git a/test/unit/core/plugins/spec/selectors.js b/test/unit/core/plugins/spec/selectors.js index 6cbb99cd264..29f6ca25a34 100644 --- a/test/unit/core/plugins/spec/selectors.js +++ b/test/unit/core/plugins/spec/selectors.js @@ -14,7 +14,8 @@ import { parameterInclusionSettingFor, consumesOptionsFor, taggedOperations, - isMediaTypeSchemaPropertiesEqual + isMediaTypeSchemaPropertiesEqual, + validationErrors } from "core/plugins/spec/selectors" import Petstore from "./assets/petstore.json" @@ -1380,3 +1381,55 @@ describe("isMediaTypeSchemaPropertiesEqual", () => { }) }) }) +describe("validationErrors", function() { + const state = fromJS({ + meta: { + paths: { + "/": { + get: { + parameters: { + id: { + errors: [ + "Value must be an integer" + ] + } + } + }, + post: { + parameters: { + body: { + errors: [ + { + error: "Value must be an integer", + propKey: "id" + }, + { + error: "Value must be a string", + propKey: "name" + } + ] + } + } + } + } + } + } + }) + + it("should return validation errors without formatting them", function () { + const result = validationErrors(state, ["/", "get"]) + + expect(result).toEqual([ + "Value must be an integer" + ]) + }) + + it("should return formatted validation errors", function () { + const result = validationErrors(state, ["/", "post"]) + + expect(result).toEqual([ + "id: Value must be an integer", + "name: Value must be a string" + ]) + }) +})