Comparing version 0.3.0 to 0.4.0
@@ -78,3 +78,4 @@ "use strict"; | ||
this.headers.forEach(function (value, key) { | ||
result[key] = value; | ||
result[key] = | ||
value instanceof Array && value.length == 1 ? value[0] : value; | ||
}); | ||
@@ -130,3 +131,4 @@ return result; | ||
this.parameters.forEach(function (value, key) { | ||
result[key] = value; | ||
result[key] = | ||
value instanceof Array && value.length == 1 ? value[0] : value; | ||
}); | ||
@@ -133,0 +135,0 @@ return result; |
{ | ||
"name": "http-types", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "Library for JSON serialisation of HTTP exchanges", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -80,3 +80,4 @@ /** HTTP request method to indicate the desired action to be performed for a given resource. */ | ||
this.headers.forEach(function(value, key) { | ||
result[key] = value; | ||
result[key] = | ||
value instanceof Array && value.length == 1 ? value[0] : value; | ||
}); | ||
@@ -138,3 +139,4 @@ return result; | ||
this.parameters.forEach(function(value, key) { | ||
result[key] = value; | ||
result[key] = | ||
value instanceof Array && value.length == 1 ? value[0] : value; | ||
}); | ||
@@ -141,0 +143,0 @@ return result; |
@@ -185,1 +185,35 @@ import { | ||
}); | ||
test("Http exchanges from JSON with pathname and single query parameter as array", () => { | ||
const json = `{ | ||
"request": { | ||
"protocol": "https", | ||
"host": "example.com", | ||
"timestamp": "2018-11-13T20:20:39+02:00", | ||
"method": "post", | ||
"headers": { | ||
"accept": "*/*", | ||
"multi-value": ["value1", "value2"] | ||
}, | ||
"pathname": "/a/path", | ||
"query": {"a": ["b"]}, | ||
"body": "a request body" | ||
}, | ||
"response": { | ||
"timestamp": "2019-11-13T20:20:39+02:00", | ||
"statusCode": 404, | ||
"headers": { | ||
"content-length": "15", | ||
"Upper-Case": "yes" | ||
}, | ||
"body": "a response body" | ||
} | ||
}`; | ||
const exchange = HttpExchangeReader.fromJson(json); | ||
expect(exchange.request.pathname).toBe("/a/path"); | ||
expect(exchange.request.query.get("a")).toBe("b"); | ||
console.log("AAAA " + JSON.stringify(exchange)); | ||
expect(JSON.parse(JSON.stringify(exchange))["request"]["query"]["a"]).toBe( | ||
"b" | ||
); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
47210
1054