Skip to content

Commit

Permalink
fix: smapi - pass {} by default when non of the in body params specified
Browse files Browse the repository at this point in the history
  • Loading branch information
kakha urigashvili authored and RonWang committed Oct 16, 2020
1 parent fdee176 commit 97fe277
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
7 changes: 4 additions & 3 deletions lib/commands/smapi/smapi-command-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ const _loadValue = (param, value) => {

const _mapToParams = (optionsValues, flatParamsMap, commanderToApiCustomizationMap) => {
const res = {};
const bodyParam = Array.from(flatParamsMap.values()).find(p => p.rootName);
if (bodyParam) {
res[bodyParam.rootName] = {};
}
Object.keys(optionsValues).forEach(key => {
const apiName = commanderToApiCustomizationMap.get(key) || key;
const param = flatParamsMap.get(standardize(apiName));
Expand All @@ -57,9 +61,6 @@ const _mapToParams = (optionsValues, flatParamsMap, commanderToApiCustomizationM
value = param.isNumber ? Number(value) : value;
value = param.isBoolean ? Boolean(value) : value;
if (param.rootName) {
if (!res[param.rootName]) {
res[param.rootName] = {};
}
let mergeObject = {};
mergeObject[param.bodyPath] = _loadValue(param, value);
mergeObject = unflatten(mergeObject, BODY_PATH_DELIMITER);
Expand Down
4 changes: 4 additions & 0 deletions lib/view/json-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ module.exports = {
*/
function toString(jsonObject) {
try {
// handle issue when Error object serialized to {}
if (jsonObject instanceof Error) {
jsonObject = { message: jsonObject.message, stack: jsonObject.stack };
}
return JSON.stringify(jsonObject, null, CONSTANTS.CONFIGURATION.JSON_DISPLAY_INDENT);
} catch (e) {
return e.toString();
Expand Down
2 changes: 1 addition & 1 deletion test/unit/commands/smapi/smapi-command-handler-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ describe('Smapi test - smapiCommandHandler function', () => {
skillId,
someNonPopulatedProperty: null,
someArray: null,
simulationsApiRequest: null })}\n`]);
simulationsApiRequest: {} })}\n`]);
expect(messengerStub.args[3]).eql(['INFO', 'Response:']);
expect(messengerStub.args[4]).eql(['INFO', jsonView.toString(fakeResponse)]);
});
Expand Down

0 comments on commit 97fe277

Please sign in to comment.