Skip to content

Commit

Permalink
fix(test): test for & depend on new curlify output
Browse files Browse the repository at this point in the history
Signed-off-by: mathis-m <mathis.michel@outlook.de>
  • Loading branch information
mathis-m committed Mar 2, 2021
1 parent 16e8a46 commit 62a9551
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 102 deletions.
20 changes: 10 additions & 10 deletions test/e2e-cypress/helpers/multiple-examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ function RequestBodyPrimitiveTestCases({
// Assert on the curl body
// TODO: use an interceptor instead of curl
.get(".curl")
.contains(`-d "${exampleA.serializedValue || exampleA.value}"`)
.contains(`-d '${exampleA.serializedValue || exampleA.value}'`)
})

it("should set default static and Try-It-Out values based on choosing the second member in static mode", () => {
Expand All @@ -234,7 +234,7 @@ function RequestBodyPrimitiveTestCases({
// Assert on the request URL
// TODO: use an interceptor instead of curl
.get(".curl")
.contains(`-d "${exampleB.serializedValue || exampleB.value}"`)
.contains(`-d '${exampleB.serializedValue || exampleB.value}'`)
})

it("should set default static and Try-It-Out values based on choosing the second member in Try-It-Out mode", () => {
Expand All @@ -257,7 +257,7 @@ function RequestBodyPrimitiveTestCases({
// Assert on the request URL
// TODO: use an interceptor instead of curl
.get(".curl")
.contains(`-d "${exampleB.serializedValue || exampleB.value}"`)
.contains(`-d '${exampleB.serializedValue || exampleB.value}'`)
// Switch to static docs
.get(".try-out__btn")
.click()
Expand Down Expand Up @@ -323,7 +323,7 @@ function RequestBodyPrimitiveTestCases({
// Assert on the request URL
// TODO: use an interceptor instead of curl
.get(".curl")
.contains(`-d "${exampleB.serializedValue || exampleB.value}"`)
.contains(`-d '${exampleB.serializedValue || exampleB.value}'`)
})

it("should use the first example for the media type when changing the media type without prior interactions with the value", () => {
Expand All @@ -349,7 +349,7 @@ function RequestBodyPrimitiveTestCases({
// Assert on the request URL
// TODO: use an interceptor instead of curl
.get(".curl")
.contains(`-d "${exampleA.serializedValue || exampleA.value}"`)
.contains(`-d '${exampleA.serializedValue || exampleA.value}'`)
})

it("static mode toggling: mediaType -> example -> mediaType -> example", () => {
Expand Down Expand Up @@ -489,7 +489,7 @@ function RequestBodyPrimitiveTestCases({
// TODO: use an interceptor instead of curl
.get(".curl")
.contains(
`-d "${customUserInputExpectedCurlSubstring || customUserInput}"`
`-d '${customUserInputExpectedCurlSubstring || customUserInput}'`
)

// Choose exampleB
Expand All @@ -508,7 +508,7 @@ function RequestBodyPrimitiveTestCases({
// Assert on the curl body
// TODO: use an interceptor instead of curl
.get(".curl")
.contains(`-d "${exampleB.serializedValue || exampleB.value}"`)
.contains(`-d '${exampleB.serializedValue || exampleB.value}'`)

// Ensure the modified value is still accessible
.get(".opblock-section-request-body .examples-select > select")
Expand All @@ -530,7 +530,7 @@ function RequestBodyPrimitiveTestCases({
// Assert on the curl body
// TODO: use an interceptor instead of curl
.get(".curl")
.contains(`-d "${exampleB.serializedValue || exampleB.value}"`)
.contains(`-d '${exampleB.serializedValue || exampleB.value}'`)

// Ensure the modified value is still accessible
.get(".opblock-section-request-body .examples-select > select")
Expand All @@ -552,7 +552,7 @@ function RequestBodyPrimitiveTestCases({
// Assert on the curl body
// TODO: use an interceptor instead of curl
.get(".curl")
.contains(`-d "${exampleA.serializedValue || exampleA.value}"`)
.contains(`-d '${exampleA.serializedValue || exampleA.value}'`)

// Ensure the modified value is still the same value
.get(".opblock-section-request-body .examples-select > select")
Expand All @@ -571,7 +571,7 @@ function RequestBodyPrimitiveTestCases({
// TODO: use an interceptor instead of curl
.get(".curl")
.contains(
`-d "${customUserInputExpectedCurlSubstring || customUserInput}"`
`-d '${customUserInputExpectedCurlSubstring || customUserInput}'`
)
})

Expand Down
60 changes: 31 additions & 29 deletions test/e2e-cypress/tests/features/multiple-examples-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @prettier
*/

const {
const {
ParameterPrimitiveTestCases,
RequestBodyPrimitiveTestCases,
ResponsePrimitiveTestCases,
Expand Down Expand Up @@ -256,7 +256,7 @@ describe("OpenAPI 3.0 Multiple Examples - core features", () => {
.get("#operations-default-post_Array")
.click()
.get(".json-schema-form-item > input")
.then(inputs => {
.then((inputs) => {
expect(inputs.map((i, el) => el.value).toArray()).to.deep.equal([
"a",
"b",
Expand All @@ -276,7 +276,7 @@ describe("OpenAPI 3.0 Multiple Examples - core features", () => {
.get(".parameters-col_description .examples-select > select")
.select("ArrayExampleB")
.get(".json-schema-form-item > input")
.then(inputs => {
.then((inputs) => {
expect(inputs.map((i, el) => el.value).toArray()).to.deep.equal([
"1",
"2",
Expand Down Expand Up @@ -317,7 +317,7 @@ describe("OpenAPI 3.0 Multiple Examples - core features", () => {
.type("5")
// Assert against the input fields
.get(".json-schema-form-item > input")
.then(inputs => {
.then((inputs) => {
expect(inputs.map((i, el) => el.value).toArray()).to.deep.equal([
"1",
"2",
Expand Down Expand Up @@ -351,7 +351,7 @@ describe("OpenAPI 3.0 Multiple Examples - core features", () => {
.select("ArrayExampleB")
// Assert against the input fields
.get(".json-schema-form-item > input")
.then(inputs => {
.then((inputs) => {
expect(inputs.map((i, el) => el.value).toArray()).to.deep.equal([
"1",
"2",
Expand All @@ -367,7 +367,7 @@ describe("OpenAPI 3.0 Multiple Examples - core features", () => {
.select("__MODIFIED__VALUE__")
// Assert that our modified value is back
.get(".json-schema-form-item > input")
.then(inputs => {
.then((inputs) => {
expect(inputs.map((i, el) => el.value).toArray()).to.deep.equal([
"1",
"2",
Expand Down Expand Up @@ -566,41 +566,43 @@ describe("OpenAPI 3.0 Multiple Examples - core features", () => {
})
})
describe("in a Request Body", () => {
const exampleA = JSON.stringify(
{
firstName: "Kyle",
lastName: "Shockey",
email: "kyle.shockey@smartbear.com",
},
null,
2
)
const exampleB = JSON.stringify(
{
name: "Abbey",
type: "kitten",
color: "calico",
gender: "female",
age: "11 weeks",
},
null,
2
)
RequestBodyPrimitiveTestCases({
operationDomId: "#operations-default-post_Object",
primaryMediaType: "application/json",
// ↓ not a typo, Cypress requires escaping { when using `cy.type`
customUserInput: `{{} "openapiIsCool": true }`,
customExpectedUrlSubstring: "?openapiIsCool=true",
customUserInputExpectedCurlSubstring: `{\\"openapiIsCool\\":true}`,
customUserInputExpectedCurlSubstring: `{ "openapiIsCool": true }`,
exampleA: {
key: "ObjectExampleA",
serializedValue: `{\\"firstName\\":\\"Kyle\\",\\"lastName\\":\\"Shockey\\",\\"email\\":\\"kyle.shockey@smartbear.com\\"}`,
value: JSON.stringify(
{
firstName: "Kyle",
lastName: "Shockey",
email: "kyle.shockey@smartbear.com",
},
null,
2
),
serializedValue: exampleA,
value: exampleA,
summary: "A user's contact info",
},
exampleB: {
key: "ObjectExampleB",
serializedValue: `{\\"name\\":\\"Abbey\\",\\"type\\":\\"kitten\\",\\"color\\":\\"calico\\",\\"gender\\":\\"female\\",\\"age\\":\\"11 weeks\\"}`,
value: JSON.stringify(
{
name: "Abbey",
type: "kitten",
color: "calico",
gender: "female",
age: "11 weeks",
},
null,
2
),
serializedValue: exampleB,
value: exampleB,
summary: "A wonderful kitten's info",
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe("OpenAPI 3.0 Validation for Required Request Body and Request Body Fiel
.get(".responses-wrapper .curl-command")
.should("exist")
.get(".responses-wrapper .curl-command span")
.should("contains.text", "\" \"")
.should("contains.text", "' '")
})
})

Expand Down
12 changes: 6 additions & 6 deletions test/mocha/components/live-response.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import React from "react"
import { fromJSOrdered } from "core/utils"
import expect, { createSpy } from "expect"
import { shallow } from "enzyme"
import Curl from "components/curl"
import LiveResponse from "components/live-response"
import ResponseBody from "components/response-body"
import { RequestSnippets } from "core/plugins/request-snippets/request-snippets"

describe("<LiveResponse/>", function () {
let request = fromJSOrdered({
Expand Down Expand Up @@ -36,7 +36,7 @@ describe("<LiveResponse/>", function () {
]

tests.forEach(function (test) {
it("passes " + test.expected.request + " to Curl when showMutatedRequest = " + test.showMutatedRequest, function () {
it("passes " + test.expected.request + " to RequestSnippets when showMutatedRequest = " + test.showMutatedRequest, function () {

// Given

Expand All @@ -54,7 +54,7 @@ describe("<LiveResponse/>", function () {
let requestForSpy = createSpy().andReturn(request)

let components = {
curl: Curl,
RequestSnippets: RequestSnippets,
responseBody: ResponseBody
}

Expand All @@ -79,9 +79,9 @@ describe("<LiveResponse/>", function () {
expect(mutatedRequestForSpy.calls.length).toEqual(test.expected.mutatedRequestForCalls)
expect(requestForSpy.calls.length).toEqual(test.expected.requestForCalls)

const curl = wrapper.find(Curl)
expect(curl.length).toEqual(1)
expect(curl.props().request).toBe(requests[test.expected.request])
const snippets = wrapper.find("RequestSnippets")
expect(snippets.length).toEqual(1)
expect(snippets.props().request).toBe(requests[test.expected.request])

const expectedUrl = requests[test.expected.request].get("url")
expect(wrapper.find("div.request-url pre.microlight").text()).toEqual(expectedUrl)
Expand Down
Loading

0 comments on commit 62a9551

Please sign in to comment.