Comparing version 2.6.1 to 2.6.2
@@ -5,3 +5,3 @@ { | ||
"homepage": "https://homer0.github.io/wootils/", | ||
"version": "2.6.1", | ||
"version": "2.6.2", | ||
"repository": "homer0/wootils", | ||
@@ -8,0 +8,0 @@ "author": "Leonardo Apiwan (@homer0) <me@homer0.com>", |
@@ -314,5 +314,8 @@ const statuses = require('statuses'); | ||
if (typeof opts.body === 'object') { | ||
// ...encode it. | ||
opts.body = JSON.stringify(opts.body); | ||
// And if no `Content-Type` was defined, let's assume is a JSON request. | ||
// ...and if it's an object literal... | ||
if (Object.getPrototypeOf(opts.body).constructor.name === 'Object') { | ||
// ...encode it. | ||
opts.body = JSON.stringify(opts.body); | ||
} | ||
// If no `Content-Type` was defined, let's assume is a JSON request. | ||
if (!hasContentType) { | ||
@@ -319,0 +322,0 @@ opts.headers['Content-Type'] = 'application/json'; |
@@ -597,2 +597,36 @@ jest.unmock('/shared/objectUtils'); | ||
it('shouldn\'t encode the body if is not an object literal', () => { | ||
// Given | ||
const requestURL = 'http://example.com'; | ||
const requestMethod = 'post'; | ||
class CustomFormData {} | ||
const requestBody = new CustomFormData(); | ||
const requestResponseData = { | ||
message: 'hello-world', | ||
}; | ||
const requestResponse = { | ||
status: 200, | ||
json: jest.fn(() => Promise.resolve(requestResponseData)), | ||
}; | ||
const fetchClient = jest.fn(() => Promise.resolve(requestResponse)); | ||
const headers = { | ||
'Content-Type': 'application/custom-form-data', | ||
}; | ||
let sut = null; | ||
// When | ||
sut = new APIClient('', '', fetchClient); | ||
return sut.post(requestURL, requestBody, { headers }) | ||
.then((response) => { | ||
// Then | ||
expect(response).toEqual(requestResponseData); | ||
expect(requestResponse.json).toHaveBeenCalledTimes(1); | ||
expect(fetchClient).toHaveBeenCalledTimes(1); | ||
expect(fetchClient).toHaveBeenCalledWith(requestURL, { | ||
headers, | ||
method: requestMethod.toUpperCase(), | ||
body: requestBody, | ||
}); | ||
}); | ||
}); | ||
it('should make a successfully PUT request using the shortcut method', () => { | ||
@@ -599,0 +633,0 @@ // Given |
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
611426
8407