From 7a2275294f3b7e9148137edf767192cd49566138 Mon Sep 17 00:00:00 2001 From: Timothy Lai Date: Tue, 16 Jun 2020 14:46:43 -0700 Subject: [PATCH 01/10] fix: curlify agnostic to order of header values Refs #6082 * use curlify flag isMultipartFormDataRequest * curlify test updated --- src/core/curlify.js | 11 +- test/mocha/core/curlify.js | 447 +++++++++++++++++++++---------------- 2 files changed, 267 insertions(+), 191 deletions(-) diff --git a/src/core/curlify.js b/src/core/curlify.js index 70c5ad1a34c..17fa31b8cb7 100644 --- a/src/core/curlify.js +++ b/src/core/curlify.js @@ -16,7 +16,7 @@ const extractKey = (k) => { export default function curl( request ){ let curlified = [] - let type = "" + let isMultipartFormDataRequest = false let headers = request.get("headers") curlified.push( "curl" ) curlified.push( "-X", request.get("method") ) @@ -25,15 +25,18 @@ export default function curl( request ){ if ( headers && headers.size ) { for( let p of request.get("headers").entries() ){ let [ h,v ] = p - type = v curlified.push( "-H " ) curlified.push( `"${h}: ${v}"` ) + if (isMultipartFormDataRequest) { + break + } else { + isMultipartFormDataRequest = /^content-type$/i.test(h) && /^multipart\/form-data$/i.test(v) + } } } if ( request.get("body") ){ - - if(type === "multipart/form-data" && ["POST", "PUT", "PATCH"].includes(request.get("method"))) { + if (isMultipartFormDataRequest && ["POST", "PUT", "PATCH"].includes(request.get("method"))) { for( let [ k,v ] of request.get("body").entrySeq()) { let extractedKey = extractKey(k) curlified.push( "-F" ) diff --git a/test/mocha/core/curlify.js b/test/mocha/core/curlify.js index 44ee88b143b..7bf4f7931e8 100644 --- a/test/mocha/core/curlify.js +++ b/test/mocha/core/curlify.js @@ -3,247 +3,320 @@ import Im from "immutable" import curl from "core/curlify" import win from "core/window" -describe("curlify", function() { - - it("prints a curl statement with custom content-type", function() { - var req = { - url: "http://example.com", - method: "POST", - body: { - id: 0, - name: "doggie", - status: "available" - }, - headers: { - Accept: "application/json", - "content-type": "application/json" - } - } +describe("curlify", function () { + + it("prints a curl statement with custom content-type", function () { + let req = { + url: "http://example.com", + method: "POST", + body: { + id: 0, + name: "doggie", + status: "available" + }, + headers: { + Accept: "application/json", + "content-type": "application/json" + } + } - let curlified = curl(Im.fromJS(req)) + let curlified = curl(Im.fromJS(req)) - 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\"}") - }) + 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\"}") + }) - it("does add a empty data param if no request body given", function() { - var req = { - url: "http://example.com", - method: "POST", + it("does add a empty data param if no request body given", function () { + let req = { + url: "http://example.com", + method: "POST", + } + + let curlified = curl(Im.fromJS(req)) + + expect(curlified).toEqual("curl -X POST \"http://example.com\" -d \"\"") + }) + + it("does not change the case of header in curl", function () { + let req = { + url: "http://example.com", + method: "POST", + headers: { + "conTenT Type": "application/Moar" } + } - let curlified = curl(Im.fromJS(req)) + let curlified = curl(Im.fromJS(req)) - expect(curlified).toEqual("curl -X POST \"http://example.com\" -d \"\"") - }) + expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"conTenT Type: application/Moar\" -d \"\"") + }) - it("does not change the case of header in curl", function() { - var req = { - url: "http://example.com", - method: "POST", - headers: { - "conTenT Type": "application/Moar" - } - } + it("prints a curl statement with an array of query params", function () { + let req = { + url: "http://swaggerhub.com/v1/one?name=john|smith", + method: "GET" + } - let curlified = curl(Im.fromJS(req)) + let curlified = curl(Im.fromJS(req)) - expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"conTenT Type: application/Moar\" -d \"\"") - }) + expect(curlified).toEqual("curl -X GET \"http://swaggerhub.com/v1/one?name=john|smith\"") + }) - it("prints a curl statement with an array of query params", function() { - var req = { - url: "http://swaggerhub.com/v1/one?name=john|smith", - method: "GET" - } + it("prints a curl statement with an array of query params and auth", function () { + let req = { + url: "http://swaggerhub.com/v1/one?name=john|smith", + method: "GET", + headers: { + authorization: "Basic Zm9vOmJhcg==" + } + } + + let curlified = curl(Im.fromJS(req)) + + expect(curlified).toEqual("curl -X GET \"http://swaggerhub.com/v1/one?name=john|smith\" -H \"authorization: Basic Zm9vOmJhcg==\"") + }) + + it("prints a curl statement with html", function () { + let req = { + url: "http://swaggerhub.com/v1/one?name=john|smith", + method: "GET", + headers: { + accept: "application/json" + }, + body: { + description: "Test" + } + } + + let curlified = curl(Im.fromJS(req)) + + expect(curlified).toEqual("curl -X GET \"http://swaggerhub.com/v1/one?name=john|smith\" -H \"accept: application/json\" -d {\"description\":\"Test\"}") + }) + + it("handles post body with html", function () { + let req = { + url: "http://swaggerhub.com/v1/one?name=john|smith", + method: "POST", + headers: { + accept: "application/json" + }, + body: { + description: "Test" + } + } - let curlified = curl(Im.fromJS(req)) + let curlified = curl(Im.fromJS(req)) - expect(curlified).toEqual("curl -X GET \"http://swaggerhub.com/v1/one?name=john|smith\"") - }) + expect(curlified).toEqual("curl -X POST \"http://swaggerhub.com/v1/one?name=john|smith\" -H \"accept: application/json\" -d {\"description\":\"Test\"}") + }) - it("prints a curl statement with an array of query params and auth", function() { - var req = { - url: "http://swaggerhub.com/v1/one?name=john|smith", - method: "GET", - headers: { - authorization: "Basic Zm9vOmJhcg==" - } - } + it("handles post body with special chars", function () { + let req = { + url: "http://swaggerhub.com/v1/one?name=john|smith", + method: "POST", + body: { + description: "@prefix nif: .\n" + + "@prefix itsrdf: ." + } + } - let curlified = curl(Im.fromJS(req)) + let curlified = curl(Im.fromJS(req)) - expect(curlified).toEqual("curl -X GET \"http://swaggerhub.com/v1/one?name=john|smith\" -H \"authorization: Basic Zm9vOmJhcg==\"") - }) + expect(curlified).toEqual("curl -X POST \"http://swaggerhub.com/v1/one?name=john|smith\" -d {\"description\":\"@prefix nif: .@prefix itsrdf: .\"}") + }) - it("prints a curl statement with html", function() { - var req = { - url: "http://swaggerhub.com/v1/one?name=john|smith", - method: "GET", - headers: { - accept: "application/json" - }, - body: { - description: "Test" - } - } + it("handles delete form with parameters", function () { + let req = { + url: "http://example.com", + method: "DELETE", + headers: { + accept: "application/x-www-form-urlencoded" + } + } - let curlified = curl(Im.fromJS(req)) + let curlified = curl(Im.fromJS(req)) - expect(curlified).toEqual("curl -X GET \"http://swaggerhub.com/v1/one?name=john|smith\" -H \"accept: application/json\" -d {\"description\":\"Test\"}") - }) + expect(curlified).toEqual("curl -X DELETE \"http://example.com\" -H \"accept: application/x-www-form-urlencoded\"") + }) - it("handles post body with html", function() { - var req = { - url: "http://swaggerhub.com/v1/one?name=john|smith", - method: "POST", - headers: { - accept: "application/json" - }, - body: { - description: "Test" - } - } + it("should print a curl with formData", function () { + let req = { + url: "http://example.com", + method: "POST", + headers: { "content-type": "multipart/form-data" }, + body: { + id: "123", + name: "Sahar" + } + } + + let curlified = curl(Im.fromJS(req)) + + expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"content-type: multipart/form-data\" -F \"id=123\" -F \"name=Sahar\"") + }) + + it("should print a curl with formData that extracts array representation with hashIdx", function () { + // Note: hashIdx = `_**[]${counter}` + // Usage of hashIdx is an internal SwaggerUI method to convert formData array into something curlify can handle + let req = { + url: "http://example.com", + method: "POST", + headers: { "content-type": "multipart/form-data" }, + body: { + id: "123", + "fruits[]_**[]1": "apple", + "fruits[]_**[]2": "banana", + "fruits[]_**[]3": "grape" + } + } - let curlified = curl(Im.fromJS(req)) + let curlified = curl(Im.fromJS(req)) - expect(curlified).toEqual("curl -X POST \"http://swaggerhub.com/v1/one?name=john|smith\" -H \"accept: application/json\" -d {\"description\":\"Test\"}") - }) + expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"content-type: multipart/form-data\" -F \"id=123\" -F \"fruits[]=apple\" -F \"fruits[]=banana\" -F \"fruits[]=grape\"") + }) - it("handles post body with special chars", function() { - var req = { - url: "http://swaggerhub.com/v1/one?name=john|smith", - method: "POST", - body: { - description: "@prefix nif: .\n" + - "@prefix itsrdf: ." - } - } + it("should print a curl with formData and file", function () { + var file = new win.File() + file.name = "file.txt" + file.type = "text/plain" - let curlified = curl(Im.fromJS(req)) + let req = { + url: "http://example.com", + method: "POST", + headers: { "content-type": "multipart/form-data" }, + body: { + id: "123", + file + } + } - expect(curlified).toEqual("curl -X POST \"http://swaggerhub.com/v1/one?name=john|smith\" -d {\"description\":\"@prefix nif: .@prefix itsrdf: .\"}") - }) + let curlified = curl(Im.fromJS(req)) - it("handles delete form with parameters", function() { - var req = { - url: "http://example.com", - method: "DELETE", - headers: { - accept: "application/x-www-form-urlencoded" - } - } + expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"content-type: multipart/form-data\" -F \"id=123\" -F \"file=@file.txt;type=text/plain\"") + }) - let curlified = curl(Im.fromJS(req)) + it("should print a curl without form data type if type is unknown", function () { + var file = new win.File() + file.name = "file.txt" + file.type = "" - expect(curlified).toEqual("curl -X DELETE \"http://example.com\" -H \"accept: application/x-www-form-urlencoded\"") - }) + let req = { + url: "http://example.com", + method: "POST", + headers: { "content-type": "multipart/form-data" }, + body: { + id: "123", + file + } + } + + let curlified = curl(Im.fromJS(req)) + + expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"content-type: multipart/form-data\" -F \"id=123\" -F \"file=@file.txt\"") + }) + + it("prints a curl post statement from an object", function () { + let req = { + url: "http://example.com", + method: "POST", + headers: { + accept: "application/json" + }, + body: { + id: 10101 + } + } - it("should print a curl with formData", function() { - var req = { - url: "http://example.com", - method: "POST", - headers: { "content-type": "multipart/form-data" }, - body: { - id: "123", - name: "Sahar" - } - } + let curlified = curl(Im.fromJS(req)) - let curlified = curl(Im.fromJS(req)) + expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"accept: application/json\" -d {\"id\":10101}") + }) - expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"content-type: multipart/form-data\" -F \"id=123\" -F \"name=Sahar\"") - }) + it("prints a curl post statement from a string containing a single quote", function () { + let req = { + url: "http://example.com", + method: "POST", + headers: { + accept: "application/json" + }, + body: "{\"id\":\"foo'bar\"}" + } + + let curlified = curl(Im.fromJS(req)) - it("should print a curl with formData that extracts array representation with hashIdx", function() { - // Note: hashIdx = `_**[]${counter}` - // Usage of hashIdx is an internal SwaggerUI method to convert formData array into something curlify can handle - const req = { - url: "http://example.com", - method: "POST", - headers: { "content-type": "multipart/form-data" }, - body: { - id: "123", - "fruits[]_**[]1": "apple", - "fruits[]_**[]2": "banana", - "fruits[]_**[]3": "grape" - } + expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"accept: application/json\" -d \"{\\\"id\\\":\\\"foo'bar\\\"}\"") + }) + + context("given multiple entries with file", function () { + context("and with leading custom header", function () { + it("should print a proper curl -F", function () { + let file = new win.File() + file.name = "file.txt" + file.type = "text/plain" + + let req = { + url: "http://example.com", + method: "POST", + headers: { + "x-custom-name": "multipart/form-data", + "content-type": "multipart/form-data" + }, + body: { + id: "123", + file + } } - let curlified = curl(Im.fromJS(req)) + const curlified = curl(Im.fromJS(req)) - expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"content-type: multipart/form-data\" -F \"id=123\" -F \"fruits[]=apple\" -F \"fruits[]=banana\" -F \"fruits[]=grape\"") + expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"x-custom-name: multipart/form-data\" -H \"content-type: multipart/form-data\" -F \"id=123\" -F \"file=@file.txt;type=text/plain\"") + }) }) - it("should print a curl with formData and file", function() { - var file = new win.File() + context("and with trailing custom header; e.g. from requestInterceptor appending req.headers", function () { + it("should print a proper curl -F", function () { + let file = new win.File() file.name = "file.txt" file.type = "text/plain" - var req = { - url: "http://example.com", - method: "POST", - headers: { "content-type": "multipart/form-data" }, - body: { - id: "123", - file - } + let req = { + url: "http://example.com", + method: "POST", + headers: { + "content-type": "multipart/form-data", + "x-custom-name": "any-value" + }, + body: { + id: "123", + file + } } - let curlified = curl(Im.fromJS(req)) + const curlified = curl(Im.fromJS(req)) - expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"content-type: multipart/form-data\" -F \"id=123\" -F \"file=@file.txt;type=text/plain\"") + expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"content-type: multipart/form-data\" -H \"x-custom-name: any-value\" -F \"id=123\" -F \"file=@file.txt;type=text/plain\"") + }) }) + }) - it("should print a curl without form data type if type is unknown", function() { - var file = new win.File() + context("POST when header value is 'multipart/form-data' but header name is not 'content-type'", function () { + it("shoud print a proper curl as -d ", function () { + let file = new win.File() file.name = "file.txt" - file.type = "" + file.type = "text/plain" - var req = { + let req = { url: "http://example.com", method: "POST", - headers: { "content-type": "multipart/form-data" }, + headers: { "x-custom-name": "multipart/form-data" }, body: { id: "123", file } } - let curlified = curl(Im.fromJS(req)) - - expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"content-type: multipart/form-data\" -F \"id=123\" -F \"file=@file.txt\"") - }) - - it("prints a curl post statement from an object", function() { - var req = { - url: "http://example.com", - method: "POST", - headers: { - accept: "application/json" - }, - body: { - id: 10101 - } - } - - let curlified = curl(Im.fromJS(req)) + const curlified = curl(Im.fromJS(req)) - expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"accept: application/json\" -d {\"id\":10101}") + expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"x-custom-name: multipart/form-data\" -d {\"id\":\"123\",\"file\":{\"name\":\"file.txt\",\"type\":\"text/plain\"}}") }) - - it("prints a curl post statement from a string containing a single quote", function() { - var req = { - url: "http://example.com", - method: "POST", - headers: { - accept: "application/json" - }, - body: "{\"id\":\"foo'bar\"}" - } - - let curlified = curl(Im.fromJS(req)) - - expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"accept: application/json\" -d \"{\\\"id\\\":\\\"foo'bar\\\"}\"") - }) - + }) }) From 7ffcd03d8cf9ef0479ac836af47ba0b1a7c2cf62 Mon Sep 17 00:00:00 2001 From: Timothy Lai Date: Thu, 18 Jun 2020 11:23:47 -0700 Subject: [PATCH 02/10] refactor: curlify isMultipartFormDataRequest without break --- src/core/curlify.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/core/curlify.js b/src/core/curlify.js index 17fa31b8cb7..e707fa26dc3 100644 --- a/src/core/curlify.js +++ b/src/core/curlify.js @@ -27,11 +27,7 @@ export default function curl( request ){ let [ h,v ] = p curlified.push( "-H " ) curlified.push( `"${h}: ${v}"` ) - if (isMultipartFormDataRequest) { - break - } else { - isMultipartFormDataRequest = /^content-type$/i.test(h) && /^multipart\/form-data$/i.test(v) - } + isMultipartFormDataRequest = isMultipartFormDataRequest || /^content-type$/i.test(h) && /^multipart\/form-data$/i.test(v) } } From 10e1f5cd12a9533aa4983b15e9bd3fff820c4d81 Mon Sep 17 00:00:00 2001 From: Timothy Lai Date: Thu, 18 Jun 2020 11:29:49 -0700 Subject: [PATCH 03/10] test: revert curlify style --- test/mocha/core/curlify.js | 588 ++++++++++++++++++------------------- 1 file changed, 294 insertions(+), 294 deletions(-) diff --git a/test/mocha/core/curlify.js b/test/mocha/core/curlify.js index 7bf4f7931e8..971ef681b55 100644 --- a/test/mocha/core/curlify.js +++ b/test/mocha/core/curlify.js @@ -5,318 +5,318 @@ import win from "core/window" describe("curlify", function () { - it("prints a curl statement with custom content-type", function () { - let req = { - url: "http://example.com", - method: "POST", - body: { - id: 0, - name: "doggie", - status: "available" - }, - headers: { - Accept: "application/json", - "content-type": "application/json" - } - } - - let curlified = curl(Im.fromJS(req)) - - 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\"}") - }) - - it("does add a empty data param if no request body given", function () { - let req = { - url: "http://example.com", - method: "POST", - } - - let curlified = curl(Im.fromJS(req)) - - expect(curlified).toEqual("curl -X POST \"http://example.com\" -d \"\"") - }) - - it("does not change the case of header in curl", function () { - let req = { - url: "http://example.com", - method: "POST", - headers: { - "conTenT Type": "application/Moar" - } - } - - let curlified = curl(Im.fromJS(req)) - - expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"conTenT Type: application/Moar\" -d \"\"") - }) - - it("prints a curl statement with an array of query params", function () { - let req = { - url: "http://swaggerhub.com/v1/one?name=john|smith", - method: "GET" - } - - let curlified = curl(Im.fromJS(req)) - - expect(curlified).toEqual("curl -X GET \"http://swaggerhub.com/v1/one?name=john|smith\"") - }) - - it("prints a curl statement with an array of query params and auth", function () { - let req = { - url: "http://swaggerhub.com/v1/one?name=john|smith", - method: "GET", - headers: { - authorization: "Basic Zm9vOmJhcg==" - } - } - - let curlified = curl(Im.fromJS(req)) - - expect(curlified).toEqual("curl -X GET \"http://swaggerhub.com/v1/one?name=john|smith\" -H \"authorization: Basic Zm9vOmJhcg==\"") - }) - - it("prints a curl statement with html", function () { - let req = { - url: "http://swaggerhub.com/v1/one?name=john|smith", - method: "GET", - headers: { - accept: "application/json" - }, - body: { - description: "Test" - } - } - - let curlified = curl(Im.fromJS(req)) - - expect(curlified).toEqual("curl -X GET \"http://swaggerhub.com/v1/one?name=john|smith\" -H \"accept: application/json\" -d {\"description\":\"Test\"}") - }) - - it("handles post body with html", function () { - let req = { - url: "http://swaggerhub.com/v1/one?name=john|smith", - method: "POST", - headers: { - accept: "application/json" - }, - body: { - description: "Test" - } - } - - let curlified = curl(Im.fromJS(req)) - - expect(curlified).toEqual("curl -X POST \"http://swaggerhub.com/v1/one?name=john|smith\" -H \"accept: application/json\" -d {\"description\":\"Test\"}") - }) - - it("handles post body with special chars", function () { - let req = { - url: "http://swaggerhub.com/v1/one?name=john|smith", - method: "POST", - body: { - description: "@prefix nif: .\n" + - "@prefix itsrdf: ." - } - } - - let curlified = curl(Im.fromJS(req)) - - expect(curlified).toEqual("curl -X POST \"http://swaggerhub.com/v1/one?name=john|smith\" -d {\"description\":\"@prefix nif: .@prefix itsrdf: .\"}") - }) - - it("handles delete form with parameters", function () { - let req = { - url: "http://example.com", - method: "DELETE", - headers: { - accept: "application/x-www-form-urlencoded" - } - } - - let curlified = curl(Im.fromJS(req)) - - expect(curlified).toEqual("curl -X DELETE \"http://example.com\" -H \"accept: application/x-www-form-urlencoded\"") - }) - - it("should print a curl with formData", function () { - let req = { - url: "http://example.com", - method: "POST", - headers: { "content-type": "multipart/form-data" }, - body: { - id: "123", - name: "Sahar" - } - } - - let curlified = curl(Im.fromJS(req)) - - expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"content-type: multipart/form-data\" -F \"id=123\" -F \"name=Sahar\"") - }) - - it("should print a curl with formData that extracts array representation with hashIdx", function () { - // Note: hashIdx = `_**[]${counter}` - // Usage of hashIdx is an internal SwaggerUI method to convert formData array into something curlify can handle - let req = { - url: "http://example.com", - method: "POST", - headers: { "content-type": "multipart/form-data" }, - body: { - id: "123", - "fruits[]_**[]1": "apple", - "fruits[]_**[]2": "banana", - "fruits[]_**[]3": "grape" - } - } - - let curlified = curl(Im.fromJS(req)) - - expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"content-type: multipart/form-data\" -F \"id=123\" -F \"fruits[]=apple\" -F \"fruits[]=banana\" -F \"fruits[]=grape\"") - }) - - it("should print a curl with formData and file", function () { - var file = new win.File() - file.name = "file.txt" - file.type = "text/plain" - - let req = { - url: "http://example.com", - method: "POST", - headers: { "content-type": "multipart/form-data" }, - body: { - id: "123", - file - } - } - - let curlified = curl(Im.fromJS(req)) - - expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"content-type: multipart/form-data\" -F \"id=123\" -F \"file=@file.txt;type=text/plain\"") - }) - - it("should print a curl without form data type if type is unknown", function () { - var file = new win.File() - file.name = "file.txt" - file.type = "" - - let req = { - url: "http://example.com", - method: "POST", - headers: { "content-type": "multipart/form-data" }, - body: { - id: "123", - file - } - } - - let curlified = curl(Im.fromJS(req)) - - expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"content-type: multipart/form-data\" -F \"id=123\" -F \"file=@file.txt\"") - }) - - it("prints a curl post statement from an object", function () { - let req = { - url: "http://example.com", - method: "POST", - headers: { - accept: "application/json" - }, - body: { - id: 10101 - } - } - - let curlified = curl(Im.fromJS(req)) - - expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"accept: application/json\" -d {\"id\":10101}") - }) - - it("prints a curl post statement from a string containing a single quote", function () { - let req = { - url: "http://example.com", - method: "POST", - headers: { - accept: "application/json" - }, - body: "{\"id\":\"foo'bar\"}" - } - - let curlified = curl(Im.fromJS(req)) - - expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"accept: application/json\" -d \"{\\\"id\\\":\\\"foo'bar\\\"}\"") - }) - - context("given multiple entries with file", function () { - context("and with leading custom header", function () { - it("should print a proper curl -F", function () { - let file = new win.File() + it("prints a curl statement with custom content-type", function () { + let req = { + url: "http://example.com", + method: "POST", + body: { + id: 0, + name: "doggie", + status: "available" + }, + headers: { + Accept: "application/json", + "content-type": "application/json" + } + } + + let curlified = curl(Im.fromJS(req)) + + 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\"}") + }) + + it("does add a empty data param if no request body given", function () { + let req = { + url: "http://example.com", + method: "POST", + } + + let curlified = curl(Im.fromJS(req)) + + expect(curlified).toEqual("curl -X POST \"http://example.com\" -d \"\"") + }) + + it("does not change the case of header in curl", function () { + let req = { + url: "http://example.com", + method: "POST", + headers: { + "conTenT Type": "application/Moar" + } + } + + let curlified = curl(Im.fromJS(req)) + + expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"conTenT Type: application/Moar\" -d \"\"") + }) + + it("prints a curl statement with an array of query params", function () { + let req = { + url: "http://swaggerhub.com/v1/one?name=john|smith", + method: "GET" + } + + let curlified = curl(Im.fromJS(req)) + + expect(curlified).toEqual("curl -X GET \"http://swaggerhub.com/v1/one?name=john|smith\"") + }) + + it("prints a curl statement with an array of query params and auth", function () { + let req = { + url: "http://swaggerhub.com/v1/one?name=john|smith", + method: "GET", + headers: { + authorization: "Basic Zm9vOmJhcg==" + } + } + + let curlified = curl(Im.fromJS(req)) + + expect(curlified).toEqual("curl -X GET \"http://swaggerhub.com/v1/one?name=john|smith\" -H \"authorization: Basic Zm9vOmJhcg==\"") + }) + + it("prints a curl statement with html", function () { + let req = { + url: "http://swaggerhub.com/v1/one?name=john|smith", + method: "GET", + headers: { + accept: "application/json" + }, + body: { + description: "Test" + } + } + + let curlified = curl(Im.fromJS(req)) + + expect(curlified).toEqual("curl -X GET \"http://swaggerhub.com/v1/one?name=john|smith\" -H \"accept: application/json\" -d {\"description\":\"Test\"}") + }) + + it("handles post body with html", function () { + let req = { + url: "http://swaggerhub.com/v1/one?name=john|smith", + method: "POST", + headers: { + accept: "application/json" + }, + body: { + description: "Test" + } + } + + let curlified = curl(Im.fromJS(req)) + + expect(curlified).toEqual("curl -X POST \"http://swaggerhub.com/v1/one?name=john|smith\" -H \"accept: application/json\" -d {\"description\":\"Test\"}") + }) + + it("handles post body with special chars", function () { + let req = { + url: "http://swaggerhub.com/v1/one?name=john|smith", + method: "POST", + body: { + description: "@prefix nif: .\n" + + "@prefix itsrdf: ." + } + } + + let curlified = curl(Im.fromJS(req)) + + expect(curlified).toEqual("curl -X POST \"http://swaggerhub.com/v1/one?name=john|smith\" -d {\"description\":\"@prefix nif: .@prefix itsrdf: .\"}") + }) + + it("handles delete form with parameters", function () { + let req = { + url: "http://example.com", + method: "DELETE", + headers: { + accept: "application/x-www-form-urlencoded" + } + } + + let curlified = curl(Im.fromJS(req)) + + expect(curlified).toEqual("curl -X DELETE \"http://example.com\" -H \"accept: application/x-www-form-urlencoded\"") + }) + + it("should print a curl with formData", function () { + let req = { + url: "http://example.com", + method: "POST", + headers: { "content-type": "multipart/form-data" }, + body: { + id: "123", + name: "Sahar" + } + } + + let curlified = curl(Im.fromJS(req)) + + expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"content-type: multipart/form-data\" -F \"id=123\" -F \"name=Sahar\"") + }) + + it("should print a curl with formData that extracts array representation with hashIdx", function () { + // Note: hashIdx = `_**[]${counter}` + // Usage of hashIdx is an internal SwaggerUI method to convert formData array into something curlify can handle + let req = { + url: "http://example.com", + method: "POST", + headers: { "content-type": "multipart/form-data" }, + body: { + id: "123", + "fruits[]_**[]1": "apple", + "fruits[]_**[]2": "banana", + "fruits[]_**[]3": "grape" + } + } + + let curlified = curl(Im.fromJS(req)) + + expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"content-type: multipart/form-data\" -F \"id=123\" -F \"fruits[]=apple\" -F \"fruits[]=banana\" -F \"fruits[]=grape\"") + }) + + it("should print a curl with formData and file", function () { + var file = new win.File() file.name = "file.txt" file.type = "text/plain" let req = { - url: "http://example.com", - method: "POST", - headers: { - "x-custom-name": "multipart/form-data", - "content-type": "multipart/form-data" - }, - body: { - id: "123", - file - } + url: "http://example.com", + method: "POST", + headers: { "content-type": "multipart/form-data" }, + body: { + id: "123", + file + } } - const curlified = curl(Im.fromJS(req)) + let curlified = curl(Im.fromJS(req)) - expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"x-custom-name: multipart/form-data\" -H \"content-type: multipart/form-data\" -F \"id=123\" -F \"file=@file.txt;type=text/plain\"") - }) + expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"content-type: multipart/form-data\" -F \"id=123\" -F \"file=@file.txt;type=text/plain\"") }) - context("and with trailing custom header; e.g. from requestInterceptor appending req.headers", function () { - it("should print a proper curl -F", function () { - let file = new win.File() + it("should print a curl without form data type if type is unknown", function () { + var file = new win.File() file.name = "file.txt" - file.type = "text/plain" + file.type = "" let req = { - url: "http://example.com", - method: "POST", - headers: { - "content-type": "multipart/form-data", - "x-custom-name": "any-value" - }, - body: { - id: "123", - file - } + url: "http://example.com", + method: "POST", + headers: { "content-type": "multipart/form-data" }, + body: { + id: "123", + file + } } - const curlified = curl(Im.fromJS(req)) + let curlified = curl(Im.fromJS(req)) - expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"content-type: multipart/form-data\" -H \"x-custom-name: any-value\" -F \"id=123\" -F \"file=@file.txt;type=text/plain\"") - }) + expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"content-type: multipart/form-data\" -F \"id=123\" -F \"file=@file.txt\"") }) - }) - - context("POST when header value is 'multipart/form-data' but header name is not 'content-type'", function () { - it("shoud print a proper curl as -d ", function () { - let file = new win.File() - file.name = "file.txt" - file.type = "text/plain" - - let req = { - url: "http://example.com", - method: "POST", - headers: { "x-custom-name": "multipart/form-data" }, - body: { - id: "123", - file + + it("prints a curl post statement from an object", function () { + let req = { + url: "http://example.com", + method: "POST", + headers: { + accept: "application/json" + }, + body: { + id: 10101 + } } - } - const curlified = curl(Im.fromJS(req)) + let curlified = curl(Im.fromJS(req)) + + expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"accept: application/json\" -d {\"id\":10101}") + }) + + it("prints a curl post statement from a string containing a single quote", function () { + let req = { + url: "http://example.com", + method: "POST", + headers: { + accept: "application/json" + }, + body: "{\"id\":\"foo'bar\"}" + } + + let curlified = curl(Im.fromJS(req)) + + expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"accept: application/json\" -d \"{\\\"id\\\":\\\"foo'bar\\\"}\"") + }) + + context("given multiple entries with file", function () { + context("and with leading custom header", function () { + it("should print a proper curl -F", function () { + let file = new win.File() + file.name = "file.txt" + file.type = "text/plain" + + let req = { + url: "http://example.com", + method: "POST", + headers: { + "x-custom-name": "multipart/form-data", + "content-type": "multipart/form-data" + }, + body: { + id: "123", + file + } + } + + const curlified = curl(Im.fromJS(req)) + + expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"x-custom-name: multipart/form-data\" -H \"content-type: multipart/form-data\" -F \"id=123\" -F \"file=@file.txt;type=text/plain\"") + }) + }) + + context("and with trailing custom header; e.g. from requestInterceptor appending req.headers", function () { + it("should print a proper curl -F", function () { + let file = new win.File() + file.name = "file.txt" + file.type = "text/plain" + + let req = { + url: "http://example.com", + method: "POST", + headers: { + "content-type": "multipart/form-data", + "x-custom-name": "any-value" + }, + body: { + id: "123", + file + } + } + + const curlified = curl(Im.fromJS(req)) + + expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"content-type: multipart/form-data\" -H \"x-custom-name: any-value\" -F \"id=123\" -F \"file=@file.txt;type=text/plain\"") + }) + }) + }) - expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"x-custom-name: multipart/form-data\" -d {\"id\":\"123\",\"file\":{\"name\":\"file.txt\",\"type\":\"text/plain\"}}") + context("POST when header value is 'multipart/form-data' but header name is not 'content-type'", function () { + it("shoud print a proper curl as -d ", function () { + let file = new win.File() + file.name = "file.txt" + file.type = "text/plain" + + let req = { + url: "http://example.com", + method: "POST", + headers: { "x-custom-name": "multipart/form-data" }, + body: { + id: "123", + file + } + } + + const curlified = curl(Im.fromJS(req)) + + expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"x-custom-name: multipart/form-data\" -d {\"id\":\"123\",\"file\":{\"name\":\"file.txt\",\"type\":\"text/plain\"}}") + }) }) - }) }) From 5b3fe50a3625c0422d64d0ff012235cac6e4fd52 Mon Sep 17 00:00:00 2001 From: Timothy Lai Date: Thu, 18 Jun 2020 11:33:36 -0700 Subject: [PATCH 04/10] test: curlify additional style reverts --- test/mocha/core/curlify.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/test/mocha/core/curlify.js b/test/mocha/core/curlify.js index 971ef681b55..70552fc42ee 100644 --- a/test/mocha/core/curlify.js +++ b/test/mocha/core/curlify.js @@ -6,7 +6,7 @@ import win from "core/window" describe("curlify", function () { it("prints a curl statement with custom content-type", function () { - let req = { + var req = { url: "http://example.com", method: "POST", body: { @@ -26,7 +26,7 @@ describe("curlify", function () { }) it("does add a empty data param if no request body given", function () { - let req = { + var req = { url: "http://example.com", method: "POST", } @@ -37,7 +37,7 @@ describe("curlify", function () { }) it("does not change the case of header in curl", function () { - let req = { + var req = { url: "http://example.com", method: "POST", headers: { @@ -51,7 +51,7 @@ describe("curlify", function () { }) it("prints a curl statement with an array of query params", function () { - let req = { + var req = { url: "http://swaggerhub.com/v1/one?name=john|smith", method: "GET" } @@ -62,7 +62,7 @@ describe("curlify", function () { }) it("prints a curl statement with an array of query params and auth", function () { - let req = { + var req = { url: "http://swaggerhub.com/v1/one?name=john|smith", method: "GET", headers: { @@ -76,7 +76,7 @@ describe("curlify", function () { }) it("prints a curl statement with html", function () { - let req = { + var req = { url: "http://swaggerhub.com/v1/one?name=john|smith", method: "GET", headers: { @@ -93,7 +93,7 @@ describe("curlify", function () { }) it("handles post body with html", function () { - let req = { + var req = { url: "http://swaggerhub.com/v1/one?name=john|smith", method: "POST", headers: { @@ -110,7 +110,7 @@ describe("curlify", function () { }) it("handles post body with special chars", function () { - let req = { + var req = { url: "http://swaggerhub.com/v1/one?name=john|smith", method: "POST", body: { @@ -125,7 +125,7 @@ describe("curlify", function () { }) it("handles delete form with parameters", function () { - let req = { + var req = { url: "http://example.com", method: "DELETE", headers: { @@ -139,7 +139,7 @@ describe("curlify", function () { }) it("should print a curl with formData", function () { - let req = { + var req = { url: "http://example.com", method: "POST", headers: { "content-type": "multipart/form-data" }, @@ -154,10 +154,10 @@ describe("curlify", function () { expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"content-type: multipart/form-data\" -F \"id=123\" -F \"name=Sahar\"") }) - it("should print a curl with formData that extracts array representation with hashIdx", function () { + it("should print a curl with formData that extracts array representation with hashIdx", function() { // Note: hashIdx = `_**[]${counter}` // Usage of hashIdx is an internal SwaggerUI method to convert formData array into something curlify can handle - let req = { + var req = { url: "http://example.com", method: "POST", headers: { "content-type": "multipart/form-data" }, @@ -179,7 +179,7 @@ describe("curlify", function () { file.name = "file.txt" file.type = "text/plain" - let req = { + var req = { url: "http://example.com", method: "POST", headers: { "content-type": "multipart/form-data" }, @@ -199,7 +199,7 @@ describe("curlify", function () { file.name = "file.txt" file.type = "" - let req = { + var req = { url: "http://example.com", method: "POST", headers: { "content-type": "multipart/form-data" }, @@ -215,7 +215,7 @@ describe("curlify", function () { }) it("prints a curl post statement from an object", function () { - let req = { + var req = { url: "http://example.com", method: "POST", headers: { @@ -232,7 +232,7 @@ describe("curlify", function () { }) it("prints a curl post statement from a string containing a single quote", function () { - let req = { + var req = { url: "http://example.com", method: "POST", headers: { From d01819a03620d77206f10ba96bf83836340e9a28 Mon Sep 17 00:00:00 2001 From: Timothy Lai Date: Thu, 18 Jun 2020 11:37:03 -0700 Subject: [PATCH 05/10] test: curlify more style reverts --- test/mocha/core/curlify.js | 46 +++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/test/mocha/core/curlify.js b/test/mocha/core/curlify.js index 70552fc42ee..53144d1e856 100644 --- a/test/mocha/core/curlify.js +++ b/test/mocha/core/curlify.js @@ -3,9 +3,9 @@ import Im from "immutable" import curl from "core/curlify" import win from "core/window" -describe("curlify", function () { +describe("curlify", function() { - it("prints a curl statement with custom content-type", function () { + it("prints a curl statement with custom content-type", function() { var req = { url: "http://example.com", method: "POST", @@ -25,7 +25,7 @@ describe("curlify", function () { 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\"}") }) - it("does add a empty data param if no request body given", function () { + it("does add a empty data param if no request body given", function() { var req = { url: "http://example.com", method: "POST", @@ -36,7 +36,7 @@ describe("curlify", function () { expect(curlified).toEqual("curl -X POST \"http://example.com\" -d \"\"") }) - it("does not change the case of header in curl", function () { + it("does not change the case of header in curl", function() { var req = { url: "http://example.com", method: "POST", @@ -50,7 +50,7 @@ describe("curlify", function () { expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"conTenT Type: application/Moar\" -d \"\"") }) - it("prints a curl statement with an array of query params", function () { + it("prints a curl statement with an array of query params", function() { var req = { url: "http://swaggerhub.com/v1/one?name=john|smith", method: "GET" @@ -61,7 +61,7 @@ describe("curlify", function () { expect(curlified).toEqual("curl -X GET \"http://swaggerhub.com/v1/one?name=john|smith\"") }) - it("prints a curl statement with an array of query params and auth", function () { + it("prints a curl statement with an array of query params and auth", function() { var req = { url: "http://swaggerhub.com/v1/one?name=john|smith", method: "GET", @@ -75,7 +75,7 @@ describe("curlify", function () { expect(curlified).toEqual("curl -X GET \"http://swaggerhub.com/v1/one?name=john|smith\" -H \"authorization: Basic Zm9vOmJhcg==\"") }) - it("prints a curl statement with html", function () { + it("prints a curl statement with html", function() { var req = { url: "http://swaggerhub.com/v1/one?name=john|smith", method: "GET", @@ -92,7 +92,7 @@ describe("curlify", function () { expect(curlified).toEqual("curl -X GET \"http://swaggerhub.com/v1/one?name=john|smith\" -H \"accept: application/json\" -d {\"description\":\"Test\"}") }) - it("handles post body with html", function () { + it("handles post body with html", function() { var req = { url: "http://swaggerhub.com/v1/one?name=john|smith", method: "POST", @@ -109,7 +109,7 @@ describe("curlify", function () { expect(curlified).toEqual("curl -X POST \"http://swaggerhub.com/v1/one?name=john|smith\" -H \"accept: application/json\" -d {\"description\":\"Test\"}") }) - it("handles post body with special chars", function () { + it("handles post body with special chars", function() { var req = { url: "http://swaggerhub.com/v1/one?name=john|smith", method: "POST", @@ -124,7 +124,7 @@ describe("curlify", function () { expect(curlified).toEqual("curl -X POST \"http://swaggerhub.com/v1/one?name=john|smith\" -d {\"description\":\"@prefix nif: .@prefix itsrdf: .\"}") }) - it("handles delete form with parameters", function () { + it("handles delete form with parameters", function() { var req = { url: "http://example.com", method: "DELETE", @@ -138,7 +138,7 @@ describe("curlify", function () { expect(curlified).toEqual("curl -X DELETE \"http://example.com\" -H \"accept: application/x-www-form-urlencoded\"") }) - it("should print a curl with formData", function () { + it("should print a curl with formData", function() { var req = { url: "http://example.com", method: "POST", @@ -157,7 +157,7 @@ describe("curlify", function () { it("should print a curl with formData that extracts array representation with hashIdx", function() { // Note: hashIdx = `_**[]${counter}` // Usage of hashIdx is an internal SwaggerUI method to convert formData array into something curlify can handle - var req = { + const req = { url: "http://example.com", method: "POST", headers: { "content-type": "multipart/form-data" }, @@ -174,7 +174,7 @@ describe("curlify", function () { expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"content-type: multipart/form-data\" -F \"id=123\" -F \"fruits[]=apple\" -F \"fruits[]=banana\" -F \"fruits[]=grape\"") }) - it("should print a curl with formData and file", function () { + it("should print a curl with formData and file", function() { var file = new win.File() file.name = "file.txt" file.type = "text/plain" @@ -194,7 +194,7 @@ describe("curlify", function () { expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"content-type: multipart/form-data\" -F \"id=123\" -F \"file=@file.txt;type=text/plain\"") }) - it("should print a curl without form data type if type is unknown", function () { + it("should print a curl without form data type if type is unknown", function() { var file = new win.File() file.name = "file.txt" file.type = "" @@ -214,7 +214,7 @@ describe("curlify", function () { expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"content-type: multipart/form-data\" -F \"id=123\" -F \"file=@file.txt\"") }) - it("prints a curl post statement from an object", function () { + it("prints a curl post statement from an object", function() { var req = { url: "http://example.com", method: "POST", @@ -231,7 +231,7 @@ describe("curlify", function () { expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"accept: application/json\" -d {\"id\":10101}") }) - it("prints a curl post statement from a string containing a single quote", function () { + it("prints a curl post statement from a string containing a single quote", function() { var req = { url: "http://example.com", method: "POST", @@ -246,9 +246,9 @@ describe("curlify", function () { expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"accept: application/json\" -d \"{\\\"id\\\":\\\"foo'bar\\\"}\"") }) - context("given multiple entries with file", function () { - context("and with leading custom header", function () { - it("should print a proper curl -F", function () { + context("given multiple entries with file", function() { + context("and with leading custom header", function() { + it("should print a proper curl -F", function() { let file = new win.File() file.name = "file.txt" file.type = "text/plain" @@ -272,8 +272,8 @@ describe("curlify", function () { }) }) - context("and with trailing custom header; e.g. from requestInterceptor appending req.headers", function () { - it("should print a proper curl -F", function () { + context("and with trailing custom header; e.g. from requestInterceptor appending req.headers", function() { + it("should print a proper curl -F", function() { let file = new win.File() file.name = "file.txt" file.type = "text/plain" @@ -298,8 +298,8 @@ describe("curlify", function () { }) }) - context("POST when header value is 'multipart/form-data' but header name is not 'content-type'", function () { - it("shoud print a proper curl as -d ", function () { + context("POST when header value is 'multipart/form-data' but header name is not 'content-type'", function() { + it("shoud print a proper curl as -d ", function() { let file = new win.File() file.name = "file.txt" file.type = "text/plain" From 716fa5eae7a19624948966c2618fb1acb16d1e03 Mon Sep 17 00:00:00 2001 From: Timothy Lai Date: Thu, 18 Jun 2020 11:45:58 -0700 Subject: [PATCH 06/10] test: curlify more style reverts --- test/mocha/core/curlify.js | 56 +++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/test/mocha/core/curlify.js b/test/mocha/core/curlify.js index 53144d1e856..65be82ef0d9 100644 --- a/test/mocha/core/curlify.js +++ b/test/mocha/core/curlify.js @@ -26,14 +26,14 @@ describe("curlify", function() { }) it("does add a empty data param if no request body given", function() { - var req = { - url: "http://example.com", - method: "POST", - } + var req = { + url: "http://example.com", + method: "POST", + } - let curlified = curl(Im.fromJS(req)) + let curlified = curl(Im.fromJS(req)) - expect(curlified).toEqual("curl -X POST \"http://example.com\" -d \"\"") + expect(curlified).toEqual("curl -X POST \"http://example.com\" -d \"\"") }) it("does not change the case of header in curl", function() { @@ -115,7 +115,7 @@ describe("curlify", function() { method: "POST", body: { description: "@prefix nif: .\n" + - "@prefix itsrdf: ." + "@prefix itsrdf: ." } } @@ -144,8 +144,8 @@ describe("curlify", function() { method: "POST", headers: { "content-type": "multipart/form-data" }, body: { - id: "123", - name: "Sahar" + id: "123", + name: "Sahar" } } @@ -184,8 +184,8 @@ describe("curlify", function() { method: "POST", headers: { "content-type": "multipart/form-data" }, body: { - id: "123", - file + id: "123", + file } } @@ -195,23 +195,23 @@ describe("curlify", function() { }) it("should print a curl without form data type if type is unknown", function() { - var file = new win.File() - file.name = "file.txt" - file.type = "" - - var req = { - url: "http://example.com", - method: "POST", - headers: { "content-type": "multipart/form-data" }, - body: { - id: "123", - file - } - } - - let curlified = curl(Im.fromJS(req)) - - expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"content-type: multipart/form-data\" -F \"id=123\" -F \"file=@file.txt\"") + var file = new win.File() + file.name = "file.txt" + file.type = "" + + var req = { + url: "http://example.com", + method: "POST", + headers: { "content-type": "multipart/form-data" }, + body: { + id: "123", + file + } + } + + let curlified = curl(Im.fromJS(req)) + + expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"content-type: multipart/form-data\" -F \"id=123\" -F \"file=@file.txt\"") }) it("prints a curl post statement from an object", function() { From f9670035b1eead7ec8957cd8aae52c35dbd43bfd Mon Sep 17 00:00:00 2001 From: Timothy Lai Date: Thu, 18 Jun 2020 11:47:51 -0700 Subject: [PATCH 07/10] test: curlify more style reverts --- test/mocha/core/curlify.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/mocha/core/curlify.js b/test/mocha/core/curlify.js index 65be82ef0d9..2acdbba38ff 100644 --- a/test/mocha/core/curlify.js +++ b/test/mocha/core/curlify.js @@ -200,13 +200,13 @@ describe("curlify", function() { file.type = "" var req = { - url: "http://example.com", - method: "POST", - headers: { "content-type": "multipart/form-data" }, - body: { - id: "123", - file - } + url: "http://example.com", + method: "POST", + headers: { "content-type": "multipart/form-data" }, + body: { + id: "123", + file + } } let curlified = curl(Im.fromJS(req)) From 4a6a438764b1a2a899b86aadb6c1554bf6e2ae2d Mon Sep 17 00:00:00 2001 From: Tim Lai Date: Thu, 18 Jun 2020 11:55:37 -0700 Subject: [PATCH 08/10] Update test/mocha/core/curlify.js Co-authored-by: Vladimir Gorej --- test/mocha/core/curlify.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/mocha/core/curlify.js b/test/mocha/core/curlify.js index 2acdbba38ff..629c6c7c543 100644 --- a/test/mocha/core/curlify.js +++ b/test/mocha/core/curlify.js @@ -266,7 +266,7 @@ describe("curlify", function() { } } - const curlified = curl(Im.fromJS(req)) + let curlified = curl(Im.fromJS(req)) expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"x-custom-name: multipart/form-data\" -H \"content-type: multipart/form-data\" -F \"id=123\" -F \"file=@file.txt;type=text/plain\"") }) From b88b10ee11bf3bd1e2012226c6960798e5e2c5ff Mon Sep 17 00:00:00 2001 From: Tim Lai Date: Thu, 18 Jun 2020 11:55:45 -0700 Subject: [PATCH 09/10] Update test/mocha/core/curlify.js Co-authored-by: Vladimir Gorej --- test/mocha/core/curlify.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/mocha/core/curlify.js b/test/mocha/core/curlify.js index 629c6c7c543..9d9f057ed4c 100644 --- a/test/mocha/core/curlify.js +++ b/test/mocha/core/curlify.js @@ -314,7 +314,7 @@ describe("curlify", function() { } } - const curlified = curl(Im.fromJS(req)) + let curlified = curl(Im.fromJS(req)) expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"x-custom-name: multipart/form-data\" -d {\"id\":\"123\",\"file\":{\"name\":\"file.txt\",\"type\":\"text/plain\"}}") }) From 8373b495d9df81f153cd5a56aa39fe4d6d0b803f Mon Sep 17 00:00:00 2001 From: Tim Lai Date: Thu, 18 Jun 2020 11:55:53 -0700 Subject: [PATCH 10/10] Update test/mocha/core/curlify.js Co-authored-by: Vladimir Gorej --- test/mocha/core/curlify.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/mocha/core/curlify.js b/test/mocha/core/curlify.js index 9d9f057ed4c..6506b128976 100644 --- a/test/mocha/core/curlify.js +++ b/test/mocha/core/curlify.js @@ -291,7 +291,7 @@ describe("curlify", function() { } } - const curlified = curl(Im.fromJS(req)) + let curlified = curl(Im.fromJS(req)) expect(curlified).toEqual("curl -X POST \"http://example.com\" -H \"content-type: multipart/form-data\" -H \"x-custom-name: any-value\" -F \"id=123\" -F \"file=@file.txt;type=text/plain\"") })