Skip to content

Commit

Permalink
Merge pull request #7 from brave-intl/prestringify
Browse files Browse the repository at this point in the history
Allow for passing body that is already stringified
  • Loading branch information
ruipenso authored Sep 20, 2017
2 parents 633869b + fd5338a commit 84a1f50
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/core/sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ export default class SDK {
let request;

if (body) {
body = JSON.stringify(body);
if (typeof body === 'object') {
body = JSON.stringify(body);
}
headers['content-type'] = 'application/json';
}

Expand Down
10 changes: 10 additions & 0 deletions test/core/sdk.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,16 @@ describe('SDK', () => {
});
});

it('should pass a stringified body without modification', () => {
const newCard = JSON.stringify({ currency: 'foo', label: 'bar' });

return sdk.api('/biz', { body: newCard, method: 'post' })
.then(() => {
expect(sdk.client.request.mock.calls.length).toBe(1);
expect(sdk.client.request.mock.calls[0][2]).toBe(newCard);
});
});

it('should return the full response if `raw` option is provided', () => {
sdk.client.request.mockReturnValue(Promise.resolve('foo'));

Expand Down

0 comments on commit 84a1f50

Please sign in to comment.