Skip to content

Commit

Permalink
feat(request): content-type accept more json formats
Browse files Browse the repository at this point in the history
  • Loading branch information
sonicoder86 committed Feb 28, 2016
1 parent 57aef66 commit 04ef5d5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion request.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ SuiteRequest.prototype = {
},

_getPayload: function(data) {
if (this._options.getHeader('content-type') !== 'application/json') {
if (this._options.getHeader('content-type').indexOf('application/json') === -1) {
return data;
}

Expand Down
16 changes: 16 additions & 0 deletions request.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,22 @@ describe('SuiteRequest', function() {
return suiteRequest.post('/path', { name: 'Almanach' });
});

it('should encode payload when content type is utf8 json', function() {
var suiteRequest = SuiteRequest.create('key-id', 'secret', requestOptions);
requestOptions.setHeader(['content-type', 'application/json;charset=utf-8']);

this.sandbox.stub(request, 'post', function(options, callback) {
try {
expect(options.body).to.eql('{"name":"Almanach"}');
callback(null, createDummyResponse());
} catch (e) {
callback(e, createDummyResponse());
}
});

return suiteRequest.post('/path', { name: 'Almanach' });
});

it('should skip encoding of payload when content type is not json', function() {
var suiteRequest = SuiteRequest.create('key-id', 'secret', requestOptions);
requestOptions.setHeader(['content-type', 'text/csv']);
Expand Down

0 comments on commit 04ef5d5

Please sign in to comment.