Skip to content

Commit c96fc94

Browse files
SouravSourav
authored andcommitted
handle circular body, add test cases for utils.formatRequest
1 parent 0b9e87d commit c96fc94

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

bin/helpers/utils.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const getmac = require('getmac').default;
77
const { v4: uuidv4 } = require('uuid');
88
const browserstack = require('browserstack-local');
99
const crypto = require('crypto');
10+
const util = require('util');
1011

1112
const usageReporting = require("./usageReporting"),
1213
logger = require("./logger").winstonLogger,
@@ -973,7 +974,7 @@ exports.formatRequest = (err, resp, body) => {
973974
return {
974975
err,
975976
status: resp ? resp.statusCode : null,
976-
body: body ? JSON.stringify(body) : null
977+
body: body ? util.format('%j', body) : null
977978
}
978979
}
979980

test/unit/bin/helpers/utils.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2919,4 +2919,15 @@ describe('utils', () => {
29192919
expect(utils.getVideoConfig({video: false, videoUploadOnPasses: false})).to.be.eql({video: false, videoUploadOnPasses: false});
29202920
});
29212921
});
2922+
2923+
describe('formatRequest', () => {
2924+
it('should return correct JSON', () => {
2925+
expect(utils.formatRequest('Something went wrong.', undefined, undefined)).to.be.eql({err: 'Something went wrong.', status: null, body: null});
2926+
const body = {message: "Something went wrong"};
2927+
expect(utils.formatRequest(null, {statusCode: 400}, body)).to.be.eql({err: null, status: 400, body: JSON.stringify(body)});
2928+
const cricularBody = {message: "Something went wrong"};
2929+
cricularBody.body = cricularBody;
2930+
expect(utils.formatRequest(null, {statusCode: 500}, cricularBody)).to.be.eql({err: null, status: 500, body: '[Circular]'});
2931+
});
2932+
});
29222933
});

test/unit/bin/helpers/zipUpload.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ describe("zipUpload", () => {
4949
formatRequest,
5050
};
5151
loggerStub = {
52-
info: sandbox.stub().returns(null)
52+
info: sandbox.stub().returns(null),
53+
error: sandbox.stub().returns(null),
5354
};
5455
sinon.stub(fs, 'lstatSync').returns({ size: 123 });
5556
});

0 commit comments

Comments
 (0)