Skip to content

Commit

Permalink
Merge 0437fcb into 359a479
Browse files Browse the repository at this point in the history
  • Loading branch information
ewandennis committed Feb 23, 2016
2 parents 359a479 + 0437fcb commit df65cd7
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 3 deletions.
8 changes: 6 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,15 @@ module.exports = function(grunt) {
}
},
shell: {
test: {
coverage: {
command : '<%= config.binPath %>/istanbul cover --report lcov --dir test/reports/ <%= config.binPath %>/_mocha test/spec -- --reporter ' + reporter,
options : {
stdout : true,
failOnError : true
}
},
test: {
command: '<%= config.binPath %>/_mocha test/spec'
}
},
coveralls: {
Expand All @@ -69,7 +72,8 @@ module.exports = function(grunt) {
// grunt test - runs linting and then our unit tests
grunt.registerTask('test', [
'lint',
'shell:test'
'shell:test',
'shell:coverage'
]);

// register default grunt command as grunt test
Expand Down
5 changes: 5 additions & 0 deletions lib/sparkpost.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ SparkPost.prototype.request = function( options, callback ) {
// set Strict SSL (Always true)
options.strictSSL = true;

// default to accepting gzipped responses
if (typeof options.gzip === 'undefined') {
options.gzip = true;
}

request(options, function(err, res, body) {
var invalidCodeRegex = /(5|4)[0-9]{2}/;
if(err) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"jshint-stylish": "0.4.0",
"matchdep": "0.3.0",
"mocha": "1.21.4",
"nock": "^1.6.1",
"nock": "^7.2.2",
"proxyquire": "1.0.1",
"sinon": "^1.14.1",
"sinon-chai": "2.5.0",
Expand Down
59 changes: 59 additions & 0 deletions test/spec/sparkpost.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var chai = require('chai')
, expect = chai.expect
, sinon = require('sinon')
, sinonChai = require('sinon-chai')
, zlib = require('zlib')
, nock = require('nock')
, SparkPost = require('../../lib/sparkpost');

Expand Down Expand Up @@ -165,6 +166,64 @@ describe('SparkPost Library', function() {
done();
});
});

it('should accept gzipped responses', function(done) {
var TEST_MESSAGE = 'This is a compressible test and it is full of compressible test stuff.'
, compressedMsg
, gzipNock
, options = {
method: 'GET'
, uri: 'https://test.sparkpost.com/test'
};

zlib.gzip(TEST_MESSAGE+TEST_MESSAGE, function(err, gzipped) {
expect(err).to.be.null;
compressedMsg = gzipped;
gzipNock = nock('https://test.sparkpost.com', {
reqheaders: {
'accept-encoding': 'gzip'
}
})
.get('/test')
.reply(200, compressedMsg, {
'X-Transfer-Length': String(compressedMsg.length)
, 'Content-Length': undefined
, 'Content-Encoding': 'gzip'
});
client.request(options, function(err, data) {
expect(err).to.be.null;
expect(data.statusCode).to.equal(200);
expect(data.body).to.equal(TEST_MESSAGE + TEST_MESSAGE);

// finish async test
done();
});
});
});

it('should support explicitly disabled gzip option', function(done) {
var TEST_MESSAGE = 'This is an uncompressed test message';

nock('https://test.sparkpost.com')
.get('/test')
.reply(200, TEST_MESSAGE);

var options = {
method: 'GET'
, uri: 'https://test.sparkpost.com/test'
, gzip: false
};

client.request(options, function(err, data) {
expect(err).to.be.null;
expect(data.statusCode).to.equal(200);
expect(data.body).to.equal(TEST_MESSAGE);
expect(data.headers).not.to.have.property('content-encoding');

// finish async test
done();
});
});
});

describe('get method', function() {
Expand Down

0 comments on commit df65cd7

Please sign in to comment.