feat: request snippets plugin (#6910)

This commit is contained in:
Mahtis Michel
2021-03-10 20:02:34 +01:00
committed by GitHub
parent 15b8c0c929
commit 8405fa0101
18 changed files with 537 additions and 210 deletions

View File

@@ -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", () => {
@@ -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", () => {
@@ -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()
@@ -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", () => {
@@ -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", () => {
@@ -489,7 +489,7 @@ function RequestBodyPrimitiveTestCases({
// TODO: use an interceptor instead of curl
.get(".curl")
.contains(
`-d "${customUserInputExpectedCurlSubstring || customUserInput}"`
`-d '${customUserInputExpectedCurlSubstring || customUserInput}'`
)
// Choose exampleB
@@ -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")
@@ -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")
@@ -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")
@@ -571,7 +571,7 @@ function RequestBodyPrimitiveTestCases({
// TODO: use an interceptor instead of curl
.get(".curl")
.contains(
`-d "${customUserInputExpectedCurlSubstring || customUserInput}"`
`-d '${customUserInputExpectedCurlSubstring || customUserInput}'`
)
})

View File

@@ -2,7 +2,7 @@
* @prettier
*/
const {
const {
ParameterPrimitiveTestCases,
RequestBodyPrimitiveTestCases,
ResponsePrimitiveTestCases,
@@ -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",
@@ -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",
@@ -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",
@@ -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",
@@ -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",
@@ -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",
},
})

View File

@@ -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", "' '")
})
})