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

@ -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 con = new HttpConnection(new Host('http://esjs.com:9200'));
var body = 'blah';
@ -429,6 +429,38 @@ describe('Http Connector', function () {
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 () {