mirror of https://github.com/Seich/Beau.git
Fixed issue where an empty payload was changed to an empty object.
This commit is contained in:
parent
e140778393
commit
124d55d1ae
|
|
@ -24,9 +24,9 @@ exports[`Request should execute a request 2`] = `
|
|||
Object {
|
||||
"body": "{\\"hello\\": \\"world\\"}",
|
||||
"request": Object {
|
||||
"body": Object {},
|
||||
"body": undefined,
|
||||
"endpoint": "http://martianwabbit.com/user",
|
||||
"headers": Object {},
|
||||
"headers": undefined,
|
||||
},
|
||||
"response": Object {
|
||||
"body": "{\\"hello\\": \\"world\\"}",
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ Object {
|
|||
"name": "Sergio",
|
||||
},
|
||||
"endpoint": "http://martianwabbit.com/user",
|
||||
"headers": Object {},
|
||||
"headers": undefined,
|
||||
},
|
||||
"response": Object {
|
||||
"body": "{\\"hello\\": \\"world\\"}",
|
||||
|
|
|
|||
|
|
@ -3,7 +3,8 @@ const {
|
|||
httpVerbs,
|
||||
requestRegex,
|
||||
replacementRegex,
|
||||
UpperCaseKeys
|
||||
UpperCaseKeys,
|
||||
removeOptionalKeys
|
||||
} = require('./shared');
|
||||
const RequestList = require('./requestList');
|
||||
const RequestCache = require('./requestCache');
|
||||
|
|
@ -81,9 +82,12 @@ class Request {
|
|||
});
|
||||
|
||||
try {
|
||||
const response = await request({
|
||||
const response = await request(
|
||||
removeOptionalKeys(
|
||||
{
|
||||
url: settings.endpoint,
|
||||
method: settings.method,
|
||||
|
||||
headers: settings.headers,
|
||||
qs: settings.query,
|
||||
body: settings.payload,
|
||||
|
|
@ -91,7 +95,10 @@ class Request {
|
|||
json: true,
|
||||
simple: false,
|
||||
resolveWithFullResponse: true
|
||||
});
|
||||
},
|
||||
['headers', 'qs', 'body']
|
||||
)
|
||||
);
|
||||
|
||||
const results = {
|
||||
request: {
|
||||
|
|
|
|||
|
|
@ -19,9 +19,28 @@ const UpperCaseKeys = function(obj) {
|
|||
return result;
|
||||
};
|
||||
|
||||
const removeOptionalKeys = function(obj, optionalValues) {
|
||||
let result = {};
|
||||
|
||||
Object.keys(obj).forEach(key => {
|
||||
if (
|
||||
optionalValues.includes(key) &&
|
||||
(Object.keys(obj[key]).length === 0 &&
|
||||
obj[key].constructor === Object)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
result[key] = obj[key];
|
||||
});
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
httpVerbs,
|
||||
requestRegex,
|
||||
replacementRegex,
|
||||
UpperCaseKeys
|
||||
UpperCaseKeys,
|
||||
removeOptionalKeys
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue