oas3-request-body-required.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /**
  2. * @prettier
  3. */
  4. describe("OpenAPI 3.0 Validation for Required Request Body and Request Body Fields", () => {
  5. describe("Request Body required bug/5181", () => {
  6. it("on execute, if empty value, SHOULD render class 'invalid' and should NOT render cURL component", () => {
  7. cy.visit(
  8. "/?url=/documents/bugs/5181.yaml"
  9. )
  10. .get("#operations-default-post_foos")
  11. .click()
  12. // Expand Try It Out
  13. .get(".try-out__btn")
  14. .click()
  15. // get input
  16. .get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(1) > .parameters-col_description input")
  17. .should("not.have.class", "invalid")
  18. // Execute
  19. .get(".execute.opblock-control__btn")
  20. .click()
  21. // class "invalid" should now exist (and render red, which we won't check)
  22. .get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(1) > .parameters-col_description input")
  23. .should("have.class", "invalid")
  24. // cURL component should not exist
  25. .get(".responses-wrapper .curl-command")
  26. .should("not.exist")
  27. })
  28. it("on execute, if value exists, should NOT render class 'invalid' and SHOULD render cURL component", () => {
  29. cy.visit(
  30. "/?url=/documents/bugs/5181.yaml"
  31. )
  32. .get("#operations-default-post_foos")
  33. .click()
  34. // Expand Try It Out
  35. .get(".try-out__btn")
  36. .click()
  37. // get input
  38. .get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(1) > .parameters-col_description input")
  39. .type("abc")
  40. // Execute
  41. .get(".execute.opblock-control__btn")
  42. .click()
  43. .get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(1) > .parameters-col_description input")
  44. .should("not.have.class", "invalid")
  45. // cURL component should exist
  46. .get(".responses-wrapper .curl-command")
  47. .should("exist")
  48. })
  49. })
  50. describe("Request Body required fields - application/json", () => {
  51. it("on execute, if empty value, SHOULD render class 'invalid' and should NOT render cURL component", () => {
  52. cy.visit(
  53. "/?url=/documents/features/petstore-only-pet.openapi.yaml"
  54. )
  55. .get("#operations-pet-addPet")
  56. .click()
  57. // Expand Try It Out
  58. .get(".try-out__btn")
  59. .click()
  60. // get and clear textarea
  61. .get(".opblock-body .opblock-section .opblock-section-request-body .body-param textarea")
  62. .should("not.have.class", "invalid")
  63. .clear()
  64. // Execute
  65. .get(".execute.opblock-control__btn")
  66. .click()
  67. // class "invalid" should now exist (and render red, which we won't check)
  68. .get(".opblock-body .opblock-section .opblock-section-request-body .body-param textarea")
  69. .should("have.class", "invalid")
  70. // cURL component should not exist
  71. .get(".responses-wrapper .curl-command")
  72. .should("not.exist")
  73. })
  74. it("on execute, if value exists, even if just single space, should NOT render class 'invalid' and SHOULD render cURL component that contains the single space", () => {
  75. cy.visit(
  76. "/?url=/documents/features/petstore-only-pet.openapi.yaml"
  77. )
  78. .get("#operations-pet-addPet")
  79. .click()
  80. // Expand Try It Out
  81. .get(".try-out__btn")
  82. .click()
  83. // get, clear, then modify textarea
  84. .get(".opblock-body .opblock-section .opblock-section-request-body .body-param textarea")
  85. .clear()
  86. .type(" ")
  87. // Execute
  88. .get(".execute.opblock-control__btn")
  89. .click()
  90. .get(".opblock-body .opblock-section .opblock-section-request-body .body-param textarea")
  91. .should("not.have.class", "invalid")
  92. // cURL component should exist
  93. .get(".responses-wrapper .curl-command")
  94. .should("exist")
  95. .get(".responses-wrapper .curl-command span")
  96. .should("contains.text", "\" \"")
  97. })
  98. })
  99. /*
  100. petstore ux notes:
  101. - required field, but if example value exists, will populate the field. So this test will clear the example value.
  102. - "add item" will insert an empty array, and display an input text box. This establishes a value for the field.
  103. */
  104. describe("Request Body required fields - application/x-www-form-urlencoded", () => {
  105. it("on execute, if empty value, SHOULD render class 'invalid' and should NOT render cURL component", () => {
  106. cy.visit(
  107. "/?url=/documents/features/petstore-only-pet.openapi.yaml"
  108. )
  109. .get("#operations-pet-addPet")
  110. .click()
  111. .get(".opblock-section .opblock-section-request-body .body-param-content-type > select")
  112. .select("application/x-www-form-urlencoded")
  113. // Expand Try It Out
  114. .get(".try-out__btn")
  115. .click()
  116. // get and clear input populated from example value
  117. .get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(2) > .parameters-col_description input")
  118. .clear()
  119. // Execute
  120. .get(".execute.opblock-control__btn")
  121. .click()
  122. // class "invalid" should now exist (and render red, which we won't check)
  123. .get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(2) > .parameters-col_description input")
  124. .should("have.class", "invalid")
  125. // cURL component should not exist
  126. .get(".responses-wrapper .curl-command")
  127. .should("not.exist")
  128. })
  129. it("on execute, if all values exist, even if array exists but is empty, should NOT render class 'invalid' and SHOULD render cURL component", () => {
  130. cy.visit(
  131. "/?url=/documents/features/petstore-only-pet.openapi.yaml"
  132. )
  133. .get("#operations-pet-addPet")
  134. .click()
  135. .get(".opblock-section .opblock-section-request-body .body-param-content-type > select")
  136. .select("application/x-www-form-urlencoded")
  137. // Expand Try It Out
  138. .get(".try-out__btn")
  139. .click()
  140. // add item to get input
  141. .get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(4) > .parameters-col_description button")
  142. .click()
  143. // Execute
  144. .get(".execute.opblock-control__btn")
  145. .click()
  146. .get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(2) > .parameters-col_description input")
  147. .should("have.value", "doggie")
  148. .should("not.have.class", "invalid")
  149. .get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(4) > .parameters-col_description input")
  150. .should("have.value", "string")
  151. .should("not.have.class", "invalid")
  152. // cURL component should exist
  153. .get(".responses-wrapper .curl-command")
  154. .should("exist")
  155. })
  156. })
  157. describe("Request Body: switching between Content Types", () => {
  158. it("after application/json 'invalid' error, on switch content type to application/x-www-form-urlencoded, SHOULD be free of errors", () => {
  159. cy.visit(
  160. "/?url=/documents/features/petstore-only-pet.openapi.yaml"
  161. )
  162. .get("#operations-pet-addPet")
  163. .click()
  164. // Expand Try It Out
  165. .get(".try-out__btn")
  166. .click()
  167. // get and clear textarea
  168. .get(".opblock-body .opblock-section .opblock-section-request-body .body-param textarea")
  169. .should("not.have.class", "invalid")
  170. .clear()
  171. // Execute
  172. .get(".execute.opblock-control__btn")
  173. .click()
  174. .get(".opblock-body .opblock-section .opblock-section-request-body .body-param textarea")
  175. .should("have.class", "invalid")
  176. // switch content type
  177. .get(".opblock-section .opblock-section-request-body .body-param-content-type > select")
  178. .select("application/x-www-form-urlencoded")
  179. .get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(2) > .parameters-col_description input")
  180. .should("not.have.class", "invalid")
  181. .get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(4) > .parameters-col_description input")
  182. .should("not.have.class", "invalid")
  183. })
  184. it("after application/x-www-form-urlencoded 'invalid' error, on switch content type to application/json, SHOULD be free of errors", () => {
  185. cy.visit(
  186. "/?url=/documents/features/petstore-only-pet.openapi.yaml"
  187. )
  188. .get("#operations-pet-addPet")
  189. .click()
  190. .get(".opblock-section .opblock-section-request-body .body-param-content-type > select")
  191. .select("application/x-www-form-urlencoded")
  192. // Expand Try It Out
  193. .get(".try-out__btn")
  194. .click()
  195. // get and clear input
  196. .get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(2) > .parameters-col_description input")
  197. .clear()
  198. // Execute
  199. .get(".execute.opblock-control__btn")
  200. .click()
  201. // class "invalid" should now exist (and render red, which we won't check)
  202. .get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(2) > .parameters-col_description input")
  203. .should("have.class", "invalid")
  204. // switch content type
  205. .get(".opblock-section .opblock-section-request-body .body-param-content-type > select")
  206. .select("application/json")
  207. .get(".opblock-body .opblock-section .opblock-section-request-body .body-param textarea")
  208. .should("not.have.class", "invalid")
  209. })
  210. })
  211. })