oas3-request-body-allow-empty-values.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /**
  2. * @prettier
  3. */
  4. describe("OpenAPI 3.0 Allow Empty Values in Request Body", () => {
  5. it("should not apply or render to required fields", () => {
  6. cy.visit(
  7. "/?url=/documents/features/petstore-only-pet.openapi.yaml"
  8. )
  9. .get("#operations-pet-addPet")
  10. .click()
  11. .get(".opblock-section .opblock-section-request-body .body-param-content-type > select")
  12. .select("application/x-www-form-urlencoded")
  13. // Expand Try It Out
  14. .get(".try-out__btn")
  15. .click()
  16. // Request Body
  17. .get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(2) > .parameters-col_description .parameter__empty_value_toggle input")
  18. .should("not.exist")
  19. })
  20. it("by default, should be checked for all non-required fields", () => {
  21. cy.visit(
  22. "/?url=/documents/features/petstore-only-pet.openapi.yaml"
  23. )
  24. .get("#operations-pet-addPet")
  25. .click()
  26. .get(".opblock-section .opblock-section-request-body .body-param-content-type > select")
  27. .select("application/x-www-form-urlencoded")
  28. // Expand Try It Out
  29. .get(".try-out__btn")
  30. .click()
  31. // Request Body
  32. .get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(5) > .parameters-col_description .parameter__empty_value_toggle input")
  33. .should("be.checked")
  34. .get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(6) > .parameters-col_description .parameter__empty_value_toggle input")
  35. .should("be.checked")
  36. })
  37. it("checkbox should be toggle-able", () => {
  38. cy.visit(
  39. "/?url=/documents/features/petstore-only-pet.openapi.yaml"
  40. )
  41. .get("#operations-pet-addPet")
  42. .click()
  43. .get(".opblock-section .opblock-section-request-body .body-param-content-type > select")
  44. .select("application/x-www-form-urlencoded")
  45. // Expand Try It Out
  46. .get(".try-out__btn")
  47. .click()
  48. // Request Body
  49. .get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(5) > .parameters-col_description .parameter__empty_value_toggle input")
  50. .should("be.checked")
  51. .uncheck()
  52. .get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(5) > .parameters-col_description .parameter__empty_value_toggle input")
  53. .should("not.be.checked")
  54. })
  55. it("on execute, should allow send with all empty values", () => {
  56. cy.visit(
  57. "/?url=/documents/features/petstore-only-pet.openapi.yaml"
  58. )
  59. .get("#operations-pet-addPet")
  60. .click()
  61. .get(".opblock-section .opblock-section-request-body .body-param-content-type > select")
  62. .select("application/x-www-form-urlencoded")
  63. // Expand Try It Out
  64. .get(".try-out__btn")
  65. .click()
  66. // add item to pass required validation
  67. .get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(4) > .parameters-col_description button")
  68. .click()
  69. // Execute
  70. .get(".execute.opblock-control__btn")
  71. .click()
  72. // cURL component
  73. .get(".responses-wrapper .curl-command")
  74. .should("exist")
  75. .get(".responses-wrapper .curl-command span")
  76. .should("contains.text", "tags=&status=")
  77. })
  78. it("on execute, should allow send with some empty values", () => {
  79. cy.visit(
  80. "/?url=/documents/features/petstore-only-pet.openapi.yaml"
  81. )
  82. .get("#operations-pet-addPet")
  83. .click()
  84. .get(".opblock-section .opblock-section-request-body .body-param-content-type > select")
  85. .select("application/x-www-form-urlencoded")
  86. // Expand Try It Out
  87. .get(".try-out__btn")
  88. .click()
  89. // Request Body
  90. .get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(5) > .parameters-col_description .parameter__empty_value_toggle input")
  91. .uncheck()
  92. // add item to pass required validation
  93. .get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(4) > .parameters-col_description button")
  94. .click()
  95. .get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(4) input")
  96. .clear()
  97. // Execute
  98. .get(".execute.opblock-control__btn")
  99. .click()
  100. // cURL component
  101. .get(".responses-wrapper .curl-command")
  102. .should("exist")
  103. .get(".responses-wrapper .curl-command span")
  104. .should("contains.text", "&status=")
  105. .should("not.contains.text", "tags=")
  106. })
  107. it("on execute, should allow send with skip all empty values", () => {
  108. cy.visit(
  109. "/?url=/documents/features/petstore-only-pet.openapi.yaml"
  110. )
  111. .get("#operations-pet-addPet")
  112. .click()
  113. .get(".opblock-section .opblock-section-request-body .body-param-content-type > select")
  114. .select("application/x-www-form-urlencoded")
  115. // Expand Try It Out
  116. .get(".try-out__btn")
  117. .click()
  118. // Request Body
  119. .get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(5) > .parameters-col_description .parameter__empty_value_toggle input")
  120. .uncheck()
  121. .get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(6) > .parameters-col_description .parameter__empty_value_toggle input")
  122. .uncheck()
  123. // add item to pass required validation
  124. .get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(4) > .parameters-col_description button")
  125. .click()
  126. .get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(4) input")
  127. .clear()
  128. // Execute
  129. .get(".execute.opblock-control__btn")
  130. .click()
  131. // cURL component
  132. .get(".responses-wrapper .curl-command")
  133. .should("exist")
  134. .get(".responses-wrapper .curl-command span")
  135. .should("not.contains.text", "tags=")
  136. .should("not.contains.text", "status=")
  137. })
  138. })