switched out assertion library with should.js... I really should have written my own baby util library since that was the third time I've done that...
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
describe('Http Connector', function () {
|
||||
|
||||
var should = require('should');
|
||||
var expect = require('expect.js');
|
||||
var Host = require('../../src/lib/host');
|
||||
var errors = require('../../src/lib/errors');
|
||||
var HttpConnection = require('../../src/lib/connectors/http');
|
||||
@ -41,13 +41,13 @@ describe('Http Connector', function () {
|
||||
describe('Constructor', function () {
|
||||
it('creates an object that extends ConnectionAbstract', function () {
|
||||
var con = new HttpConnection(new Host());
|
||||
con.should.be.an.instanceOf(ConnectionAbstract);
|
||||
expect(con).to.be.a(ConnectionAbstract);
|
||||
});
|
||||
|
||||
it('sets certain defaults', function () {
|
||||
var con = new HttpConnection(new Host());
|
||||
|
||||
con.hand.should.be.exactly(require('http'));
|
||||
expect(con.hand).to.be(require('http'));
|
||||
// con.requestTimeout
|
||||
// maxSockets
|
||||
// maxFreeSockets
|
||||
@ -56,9 +56,9 @@ describe('Http Connector', function () {
|
||||
});
|
||||
|
||||
it('expects one the host to have a protocol of http or https', function () {
|
||||
(function () {
|
||||
expect(function () {
|
||||
var con = new HttpConnection(new Host('thrifty://es.com/stuff'));
|
||||
}).should.throw(/invalid protocol/i);
|
||||
}).to.throwError(/invalid protocol/i);
|
||||
});
|
||||
});
|
||||
|
||||
@ -68,7 +68,7 @@ describe('Http Connector', function () {
|
||||
var con = new HttpConnection(host, {});
|
||||
var reqParams = con.makeReqParams();
|
||||
|
||||
reqParams.should.eql({
|
||||
expect(reqParams).to.eql({
|
||||
method: 'GET',
|
||||
protocol: 'http:',
|
||||
auth: 'john:dude',
|
||||
@ -93,9 +93,7 @@ describe('Http Connector', function () {
|
||||
}
|
||||
});
|
||||
|
||||
reqParams.should.include({
|
||||
path: '/?user_id=123&jvm=yes'
|
||||
});
|
||||
expect(reqParams.path).to.eql('/?user_id=123&jvm=yes');
|
||||
});
|
||||
|
||||
it('merges the path prefex', function () {
|
||||
@ -108,7 +106,7 @@ describe('Http Connector', function () {
|
||||
}
|
||||
});
|
||||
|
||||
reqParams.should.eql({
|
||||
expect(reqParams).to.eql({
|
||||
method: 'GET',
|
||||
protocol: 'https:',
|
||||
auth: null,
|
||||
@ -131,7 +129,7 @@ describe('Http Connector', function () {
|
||||
}
|
||||
});
|
||||
|
||||
reqParams.should.eql({
|
||||
expect(reqParams).to.eql({
|
||||
method: 'PUT',
|
||||
protocol: 'http:',
|
||||
auth: null,
|
||||
@ -151,7 +149,7 @@ describe('Http Connector', function () {
|
||||
path: '/stuff'
|
||||
});
|
||||
|
||||
reqParams.should.eql({
|
||||
expect(reqParams).to.eql({
|
||||
method: 'PUT',
|
||||
protocol: 'http:',
|
||||
auth: null,
|
||||
@ -173,8 +171,8 @@ describe('Http Connector', function () {
|
||||
it('calls http based on the host', function (done) {
|
||||
var con = new HttpConnection(new Host('http://google.com'));
|
||||
con.request({}, function () {
|
||||
http.request.callCount.should.eql(1);
|
||||
https.request.callCount.should.eql(0);
|
||||
expect(http.request.callCount).to.eql(1);
|
||||
expect(https.request.callCount).to.eql(0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@ -182,8 +180,8 @@ describe('Http Connector', function () {
|
||||
it('calls https based on the host', function (done) {
|
||||
var con = new HttpConnection(new Host('https://google.com'));
|
||||
con.request({}, function () {
|
||||
http.request.callCount.should.eql(0);
|
||||
https.request.callCount.should.eql(1);
|
||||
expect(http.request.callCount).to.eql(0);
|
||||
expect(https.request.callCount).to.eql(1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@ -202,14 +200,14 @@ describe('Http Connector', function () {
|
||||
|
||||
con.request({}, function (err) {
|
||||
// error should have been sent to the
|
||||
err.message.should.eql('actual error');
|
||||
expect(err.message).to.eql('actual error');
|
||||
|
||||
// logged the error and the trace log
|
||||
con.log.trace.callCount.should.eql(1);
|
||||
con.log.error.callCount.should.eql(0);
|
||||
con.log.info.callCount.should.eql(0);
|
||||
con.log.warning.callCount.should.eql(0);
|
||||
con.log.debug.callCount.should.eql(0);
|
||||
expect(con.log.trace.callCount).to.eql(1);
|
||||
expect(con.log.error.callCount).to.eql(0);
|
||||
expect(con.log.info.callCount).to.eql(0);
|
||||
expect(con.log.warning.callCount).to.eql(0);
|
||||
expect(con.log.debug.callCount).to.eql(0);
|
||||
|
||||
done();
|
||||
});
|
||||
@ -224,10 +222,10 @@ describe('Http Connector', function () {
|
||||
|
||||
con.request({}, function (err) {
|
||||
// error should have been sent to the
|
||||
err.message.should.eql('actual error');
|
||||
expect(err.message).to.eql('actual error');
|
||||
|
||||
// logged the error
|
||||
con.log.error.callCount.should.eql(0);
|
||||
expect(con.log.error.callCount).to.eql(0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@ -254,7 +252,7 @@ describe('Http Connector', function () {
|
||||
stub(https, 'request', makeStubReqWithMsgWhichErrorsMidBody());
|
||||
|
||||
con.request({}, function (err, resp, status) {
|
||||
con.log.error.callCount.should.eql(0);
|
||||
expect(con.log.error.callCount).to.eql(0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@ -264,8 +262,8 @@ describe('Http Connector', function () {
|
||||
stub(https, 'request', makeStubReqWithMsgWhichErrorsMidBody(new Error('no more message :(')));
|
||||
|
||||
con.request({}, function (err, resp, status) {
|
||||
should.exist(err);
|
||||
err.message.should.eql('no more message :(');
|
||||
expect(err).to.be.an(Error);
|
||||
expect(err.message).to.eql('no more message :(');
|
||||
done();
|
||||
});
|
||||
});
|
||||
@ -275,7 +273,7 @@ describe('Http Connector', function () {
|
||||
stub(https, 'request', makeStubReqWithMsgWhichErrorsMidBody());
|
||||
|
||||
con.request({}, function (err, resp, status) {
|
||||
should.not.exist(resp);
|
||||
expect(resp).to.be(undefined);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@ -285,7 +283,7 @@ describe('Http Connector', function () {
|
||||
stub(https, 'request', makeStubReqWithMsgWhichErrorsMidBody());
|
||||
|
||||
con.request({}, function (err, resp, status) {
|
||||
should.not.exist(status);
|
||||
expect(status).to.be(undefined);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@ -305,9 +303,9 @@ describe('Http Connector', function () {
|
||||
method: 'GET',
|
||||
path: '/users/1'
|
||||
}, function (err, resp, status) {
|
||||
should.not.exist(err);
|
||||
resp.should.eql(body);
|
||||
status.should.eql(200);
|
||||
expect(err).to.be(undefined);
|
||||
expect(resp).to.eql(body);
|
||||
expect(status).to.eql(200);
|
||||
server.done();
|
||||
done();
|
||||
});
|
||||
@ -327,9 +325,9 @@ describe('Http Connector', function () {
|
||||
method: 'GET',
|
||||
path: '/users/1'
|
||||
}, function (err, resp, status) {
|
||||
should.not.exist(err);
|
||||
resp.should.eql(body);
|
||||
status.should.eql(200);
|
||||
expect(err).to.be(undefined);
|
||||
expect(resp).to.eql(body);
|
||||
expect(status).to.eql(200);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@ -342,8 +340,8 @@ describe('Http Connector', function () {
|
||||
var server = nock('http://localhost').get('/').reply(200);
|
||||
|
||||
con.request({}, function (err, resp, status) {
|
||||
http.ClientRequest.prototype.setNoDelay.callCount.should.eql(1);
|
||||
http.ClientRequest.prototype.setNoDelay.lastCall.args[0].should.eql(true);
|
||||
expect(http.ClientRequest.prototype.setNoDelay.callCount).to.eql(1);
|
||||
expect(http.ClientRequest.prototype.setNoDelay.lastCall.args[0]).to.eql(true);
|
||||
server.done();
|
||||
done();
|
||||
});
|
||||
@ -355,13 +353,13 @@ describe('Http Connector', function () {
|
||||
var server = nock('http://localhost').get('/').reply(200);
|
||||
|
||||
var body = 'pasta and 𝄞';
|
||||
body.length.should.eql(12); // nope
|
||||
Buffer.byteLength(body, 'utf8').should.eql(14); // yep
|
||||
expect(body.length).to.eql(12); // nope
|
||||
expect(Buffer.byteLength(body, 'utf8')).to.eql(14); // yep
|
||||
|
||||
con.request({
|
||||
body: body
|
||||
}, function (err, resp, status) {
|
||||
http.ClientRequest.prototype.setHeader.lastCall.args.should.eql(['Content-Length', 14]);
|
||||
expect(http.ClientRequest.prototype.setHeader.lastCall.args).to.eql(['Content-Length', 14]);
|
||||
server.done();
|
||||
done();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user