fixed tests for host that were too specific to begin with
This commit is contained in:
@ -2,19 +2,23 @@ var Host = require('../../../src/lib/host');
|
||||
var _ = require('lodash-node');
|
||||
var expect = require('expect.js');
|
||||
var url = require('url');
|
||||
var expectSubObject = require('../../utils/expect_sub_object');
|
||||
|
||||
var hostDefaults = {
|
||||
protocol: 'http',
|
||||
host: 'localhost',
|
||||
port: 9200,
|
||||
path: '',
|
||||
auth: null,
|
||||
query: {},
|
||||
headers: null
|
||||
};
|
||||
|
||||
describe('Host class', function () {
|
||||
describe('construction', function () {
|
||||
it('properly sets the defaults', function () {
|
||||
var host = new Host();
|
||||
expect(host).to.eql({
|
||||
protocol: 'http',
|
||||
host: 'localhost',
|
||||
port: 9200,
|
||||
path: '',
|
||||
auth: null,
|
||||
query: {}
|
||||
});
|
||||
expect(host).to.eql(hostDefaults);
|
||||
});
|
||||
|
||||
it('accepts a string for query', function () {
|
||||
@ -36,7 +40,7 @@ describe('Host class', function () {
|
||||
it('accepts a string for the entire url', function () {
|
||||
var host = new Host('john:dude@pizza.com:420/pizza/cheese?shrooms=true');
|
||||
|
||||
expect(host).to.eql({
|
||||
expectSubObject(host, {
|
||||
protocol: 'http',
|
||||
host: 'pizza.com',
|
||||
port: 420,
|
||||
@ -95,14 +99,7 @@ describe('Host class', function () {
|
||||
it('ignores anything that\'s not a string or object-y', function () {
|
||||
var host = new Host(1234);
|
||||
|
||||
expect(host).to.eql({
|
||||
protocol: 'http',
|
||||
host: 'localhost',
|
||||
port: 9200,
|
||||
path: '',
|
||||
auth: null,
|
||||
query: {}
|
||||
});
|
||||
expect(host).to.eql(hostDefaults);
|
||||
});
|
||||
});
|
||||
|
||||
@ -121,7 +118,7 @@ describe('Host class', function () {
|
||||
param: 1
|
||||
},
|
||||
auth: 'user:pass'
|
||||
})).to.be('http://user:pass@localhost:9200/prefix/this and that?param=1&user_id=123');
|
||||
})).to.be('http://user:pass@localhost:9200/prefix/this and that?user_id=123¶m=1');
|
||||
});
|
||||
|
||||
it('ensures that path starts with a forward-slash', function () {
|
||||
|
||||
@ -1,18 +1,19 @@
|
||||
describe('Http Connector', function () {
|
||||
|
||||
var expect = require('expect.js');
|
||||
var Host = require('../../../src/lib/host');
|
||||
var errors = require('../../../src/lib/errors');
|
||||
var HttpConnection = require('../../../src/lib/connectors/http');
|
||||
var ConnectionAbstract = require('../../../src/lib/connection');
|
||||
var nock = require('nock');
|
||||
var sinon = require('sinon');
|
||||
var util = require('util');
|
||||
var ForeverAgent = require('forever-agent');
|
||||
|
||||
var http = require('http');
|
||||
var https = require('https');
|
||||
|
||||
var Host = require('../../../src/lib/host');
|
||||
var errors = require('../../../src/lib/errors');
|
||||
var HttpConnection = require('../../../src/lib/connectors/http');
|
||||
var ConnectionAbstract = require('../../../src/lib/connection');
|
||||
|
||||
var expectSubObject = require('../../utils/expect_sub_object');
|
||||
var MockRequest = require('../../mocks/request');
|
||||
var MockIncommingMessage = require('../../mocks/incomming_message');
|
||||
|
||||
@ -97,7 +98,7 @@ describe('Http Connector', function () {
|
||||
expect(reqParams.path).to.eql('/?user_id=123&jvm=yes');
|
||||
});
|
||||
|
||||
it('merges the path prefex', function () {
|
||||
it('merges the path prefix', function () {
|
||||
var con = new HttpConnection(new Host('https://google.com/path/prefix/for/user/1'));
|
||||
var reqParams = con.makeReqParams({
|
||||
method: 'GET',
|
||||
@ -107,15 +108,8 @@ describe('Http Connector', function () {
|
||||
}
|
||||
});
|
||||
|
||||
expect(reqParams).to.eql({
|
||||
method: 'GET',
|
||||
protocol: 'https:',
|
||||
auth: null,
|
||||
hostname: 'google.com',
|
||||
port: 443,
|
||||
expectSubObject(reqParams, {
|
||||
path: '/path/prefix/for/user/1/items?q=pizza',
|
||||
headers: undefined,
|
||||
agent: con.agent
|
||||
});
|
||||
});
|
||||
|
||||
@ -130,15 +124,8 @@ describe('Http Connector', function () {
|
||||
}
|
||||
});
|
||||
|
||||
expect(reqParams).to.eql({
|
||||
method: 'PUT',
|
||||
protocol: 'http:',
|
||||
auth: null,
|
||||
hostname: 'google.com',
|
||||
port: 80,
|
||||
expectSubObject(reqParams, {
|
||||
path: '/pref-x/stuff?userId=12345&token=42069&q=pizza',
|
||||
headers: undefined,
|
||||
agent: con.agent
|
||||
});
|
||||
});
|
||||
|
||||
@ -157,7 +144,7 @@ describe('Http Connector', function () {
|
||||
hostname: 'google.com',
|
||||
port: 80,
|
||||
path: '/stuff',
|
||||
headers: undefined,
|
||||
headers: null,
|
||||
agent: con.agent
|
||||
});
|
||||
});
|
||||
|
||||
12
test/utils/expect_sub_object.js
Normal file
12
test/utils/expect_sub_object.js
Normal file
@ -0,0 +1,12 @@
|
||||
var _ = require('lodash-node');
|
||||
var expect = require('expect.js');
|
||||
module.exports = function expectSubObject(obj, subObj) {
|
||||
_.forOwn(subObj, function (val, prop) {
|
||||
if (typeof obj[prop] === 'object') {
|
||||
// non-strict equals
|
||||
expect(obj[prop]).to.eql(val, 'Expected property' + prop + ' of object to equal ' + val);
|
||||
} else {
|
||||
expect(obj).property(prop, val);
|
||||
}
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user