25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

175 lines
5.6 KiB

  1. import expect from "expect"
  2. import Im from "immutable"
  3. import curl from "core/curlify"
  4. describe("curlify", function() {
  5. it("prints a curl statement with custom content-type", function() {
  6. var req = {
  7. url: "http://example.com",
  8. method: "POST",
  9. body: {
  10. id: 0,
  11. name: "doggie",
  12. status: "available"
  13. },
  14. headers: {
  15. Accept: "application/json",
  16. "content-type": "application/json"
  17. }
  18. }
  19. let curlified = curl(Im.fromJS(req))
  20. expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"Accept: application/json\" -H \"content-type: application/json\" -d {\"id\":0,\"name\":\"doggie\",\"status\":\"available\"}")
  21. })
  22. it("does not change the case of header in curl", function() {
  23. var req = {
  24. url: "http://example.com",
  25. method: "POST",
  26. headers: {
  27. "conTenT Type": "application/Moar"
  28. }
  29. }
  30. let curlified = curl(Im.fromJS(req))
  31. expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"conTenT Type: application/Moar\"")
  32. })
  33. it("prints a curl statement with an array of query params", function() {
  34. var req = {
  35. url: "http://swaggerhub.com/v1/one?name=john|smith",
  36. method: "GET"
  37. }
  38. let curlified = curl(Im.fromJS(req))
  39. expect(curlified).toEqual("curl -X GET \"http://swaggerhub.com/v1/one?name=john|smith\"")
  40. })
  41. it("prints a curl statement with an array of query params and auth", function() {
  42. var req = {
  43. url: "http://swaggerhub.com/v1/one?name=john|smith",
  44. method: "GET",
  45. headers: {
  46. authorization: "Basic Zm9vOmJhcg=="
  47. }
  48. }
  49. let curlified = curl(Im.fromJS(req))
  50. expect(curlified).toEqual("curl -X GET \"http://swaggerhub.com/v1/one?name=john|smith\" -H \"authorization: Basic Zm9vOmJhcg==\"")
  51. })
  52. it("prints a curl statement with html", function() {
  53. var req = {
  54. url: "http://swaggerhub.com/v1/one?name=john|smith",
  55. method: "GET",
  56. headers: {
  57. accept: "application/json"
  58. },
  59. body: {
  60. description: "<b>Test</b>"
  61. }
  62. }
  63. let curlified = curl(Im.fromJS(req))
  64. expect(curlified).toEqual("curl -X GET \"http://swaggerhub.com/v1/one?name=john|smith\" -H \"accept: application/json\" -d {\"description\":\"<b>Test</b>\"}")
  65. })
  66. it("handles post body with html", function() {
  67. var req = {
  68. url: "http://swaggerhub.com/v1/one?name=john|smith",
  69. method: "POST",
  70. headers: {
  71. accept: "application/json"
  72. },
  73. body: {
  74. description: "<b>Test</b>"
  75. }
  76. }
  77. let curlified = curl(Im.fromJS(req))
  78. expect(curlified).toEqual("curl -X POST \"http://swaggerhub.com/v1/one?name=john|smith\" -H \"accept: application/json\" -d {\"description\":\"<b>Test</b>\"}")
  79. })
  80. it("handles post body with special chars", function() {
  81. var req = {
  82. url: "http://swaggerhub.com/v1/one?name=john|smith",
  83. method: "POST",
  84. body: {
  85. description: "@prefix nif:<http://persistence.uni-leipzig.org/nlp2rdf/ontologies/nif-core#> .\n" +
  86. "@prefix itsrdf: <http://www.w3.org/2005/11/its/rdf#> ."
  87. }
  88. }
  89. let curlified = curl(Im.fromJS(req))
  90. expect(curlified).toEqual("curl -X POST \"http://swaggerhub.com/v1/one?name=john|smith\" -d {\"description\":\"@prefix nif:<http://persistence.uni-leipzig.org/nlp2rdf/ontologies/nif-core#> .@prefix itsrdf: <http://www.w3.org/2005/11/its/rdf#> .\"}")
  91. })
  92. it("handles delete form with parameters", function() {
  93. var req = {
  94. url: "http://example.com",
  95. method: "DELETE",
  96. headers: {
  97. accept: "application/x-www-form-urlencoded"
  98. }
  99. }
  100. let curlified = curl(Im.fromJS(req))
  101. expect(curlified).toEqual("curl -X DELETE \"http://example.com\" -H \"accept: application/x-www-form-urlencoded\"")
  102. })
  103. it("should print a curl with formData", function() {
  104. var req = {
  105. url: "http://example.com",
  106. method: "POST",
  107. headers: { "content-type": "multipart/form-data" },
  108. body: "id=123&name=Sahar"
  109. }
  110. let curlified = curl(Im.fromJS(req))
  111. expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"content-type: multipart/form-data\" -F id=123 -F name=Sahar")
  112. })
  113. it("prints a curl post statement from an object", function() {
  114. var req = {
  115. url: "http://example.com",
  116. method: "POST",
  117. headers: {
  118. accept: "application/json"
  119. },
  120. body: {
  121. id: 10101
  122. }
  123. }
  124. let curlified = curl(Im.fromJS(req))
  125. expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"accept: application/json\" -d {\"id\":10101}")
  126. })
  127. it("prints a curl post statement from a string containing a single quote", function() {
  128. var req = {
  129. url: "http://example.com",
  130. method: "POST",
  131. headers: {
  132. accept: "application/json"
  133. },
  134. body: "{\"id\":\"foo'bar\"}"
  135. }
  136. let curlified = curl(Im.fromJS(req))
  137. expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"accept: application/json\" -d \"{\\\"id\\\":\\\"foo'bar\\\"}\"")
  138. })
  139. })