added a few tests checking the headers actually being set

This commit is contained in:
Spencer Alger
2014-09-08 13:11:15 -07:00
parent 6e2c2a8417
commit eb4e0136a6
2 changed files with 35 additions and 3 deletions

View File

@ -63,7 +63,7 @@
"mocha": "^1.21.3", "mocha": "^1.21.3",
"mocha-lcov-reporter": "0.0.1", "mocha-lcov-reporter": "0.0.1",
"moment": "~2.4.0", "moment": "~2.4.0",
"nock": "~0.28.1", "nock": "~0.28.3",
"open": "0.0.4", "open": "0.0.4",
"optimist": "~0.6.0", "optimist": "~0.6.0",
"sinon": "~1.7.3", "sinon": "~1.7.3",
@ -87,4 +87,4 @@
"engines": { "engines": {
"node": ">=0.8 <0.11" "node": ">=0.8 <0.11"
} }
} }

View File

@ -356,7 +356,7 @@ describe('Http Connector', function () {
}); });
}); });
it('Can handle uncompress errors', function (done) { it('Can handle decompression errors', function (done) {
var server = nock('http://esjs.com:9200'); var server = nock('http://esjs.com:9200');
var con = new HttpConnection(new Host('http://esjs.com:9200')); var con = new HttpConnection(new Host('http://esjs.com:9200'));
var body = 'blah'; var body = 'blah';
@ -429,6 +429,38 @@ describe('Http Connector', function () {
done(); done();
}); });
}); });
it('does not set the Accept-Encoding header by default', function (done) {
var con = new HttpConnection(new Host());
var respBody = 'i should not be encoded';
var server = nock('http://localhost:9200')
.matchHeader('accept-encoding', undefined)
.get('/')
.once()
.reply(200, respBody);
con.request({}, function (err, resp, status) {
expect(resp).to.be(respBody);
server.done();
done();
});
});
it('sets the Accept-Encoding header when specified', function (done) {
var con = new HttpConnection(new Host({ suggestCompression: true }));
var respBody = 'i should be encoded';
var server = nock('http://localhost:9200')
.matchHeader('accept-encoding', 'gzip,deflate')
.get('/')
.once()
.reply(200, respBody);
con.request({}, function (err, resp, status) {
expect(resp).to.be(respBody);
server.done();
done();
});
});
}); });
describe('Connection cleanup', function () { describe('Connection cleanup', function () {