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,12 +1,13 @@
|
||||
var Host = require('../../src/lib/host');
|
||||
var _ = require('lodash');
|
||||
var expect = require('expect.js');
|
||||
var url = require('url');
|
||||
|
||||
describe('Host class', function () {
|
||||
describe('construction', function () {
|
||||
it('properly sets the defaults', function () {
|
||||
var host = new Host();
|
||||
host.should.eql({
|
||||
expect(host).to.eql({
|
||||
protocol: 'http',
|
||||
host: 'localhost',
|
||||
port: 9200,
|
||||
@ -19,7 +20,7 @@ describe('Host class', function () {
|
||||
it('accepts a string for query', function () {
|
||||
var host = new Host({ query: 'beep=boop'});
|
||||
|
||||
host.query.should.eql({
|
||||
expect(host.query).to.eql({
|
||||
beep: 'boop'
|
||||
});
|
||||
});
|
||||
@ -28,14 +29,14 @@ describe('Host class', function () {
|
||||
var headers = { 'X-Special-Routing-Header': 'pie' };
|
||||
var host = new Host({ headers: headers });
|
||||
|
||||
host.headers.should.be.exactly(headers);
|
||||
expect(host.headers).to.be(headers);
|
||||
});
|
||||
|
||||
describe('from a string', function () {
|
||||
it('accepts a string for the entire url', function () {
|
||||
var host = new Host('john:dude@pizza.com:420/pizza/cheese?shrooms=true');
|
||||
|
||||
host.should.eql({
|
||||
expect(host).to.eql({
|
||||
protocol: 'http',
|
||||
host: 'pizza.com',
|
||||
port: 420,
|
||||
@ -51,14 +52,14 @@ describe('Host class', function () {
|
||||
var host;
|
||||
|
||||
host = new Host('https://google.com');
|
||||
host.port.should.eql(443);
|
||||
expect(host.port).to.be(443);
|
||||
|
||||
host = new Host('http://google.com');
|
||||
host.port.should.eql(80);
|
||||
expect(host.port).to.be(80);
|
||||
|
||||
Host.defaultPorts.trift = 9300;
|
||||
host = new Host('thrift://google.com');
|
||||
host.port.should.eql(9200);
|
||||
expect(host.port).to.be(9200);
|
||||
delete Host.defaultPorts.trift;
|
||||
});
|
||||
});
|
||||
@ -68,37 +69,33 @@ describe('Host class', function () {
|
||||
var parsedUrl = url.parse('pizza.com:888');
|
||||
|
||||
// I imagine most people don't expect
|
||||
parsedUrl.should.include({
|
||||
protocol: 'pizza.com:',
|
||||
host: '888',
|
||||
});
|
||||
expect(parsedUrl.protocol).to.eql('pizza.com:');
|
||||
expect(parsedUrl.host).to.eql('888');
|
||||
|
||||
var host = new Host(parsedUrl);
|
||||
host.protocol.should.eql('pizza.com');
|
||||
host.host.should.eql('888');
|
||||
expect(host.protocol).to.eql('pizza.com');
|
||||
expect(host.host).to.eql('888');
|
||||
});
|
||||
|
||||
it('will cause extra properties', function () {
|
||||
var host = new Host(url.parse('https://joe:diner@pizza.com:888/path?query=yes'));
|
||||
host.should.include({
|
||||
protocol: 'https',
|
||||
host: 'pizza.com',
|
||||
port: 888,
|
||||
path: '/path',
|
||||
auth: 'joe:diner',
|
||||
query: {
|
||||
query: 'yes'
|
||||
}
|
||||
expect(host.protocol).to.eql('https');
|
||||
expect(host.host).to.eql('pizza.com');
|
||||
expect(host.port).to.eql(888);
|
||||
expect(host.path).to.eql('/path');
|
||||
expect(host.auth).to.eql('joe:diner');
|
||||
expect(host.query).to.eql({
|
||||
query: 'yes'
|
||||
});
|
||||
|
||||
_.keys(host).should.include('slashes', 'hash', 'href', 'search');
|
||||
expect(host).to.include.keys('slashes', 'hash', 'href', 'search');
|
||||
});
|
||||
});
|
||||
|
||||
it('ignores anything that\'s not a string or object-y', function () {
|
||||
var host = new Host(1234);
|
||||
|
||||
host.should.eql({
|
||||
expect(host).to.eql({
|
||||
protocol: 'http',
|
||||
host: 'localhost',
|
||||
port: 9200,
|
||||
@ -118,39 +115,39 @@ describe('Host class', function () {
|
||||
}
|
||||
});
|
||||
|
||||
host.makeUrl({
|
||||
expect(host.makeUrl({
|
||||
path: '/this and that',
|
||||
query: {
|
||||
param: 1
|
||||
},
|
||||
auth: 'user:pass'
|
||||
}).should.eql('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?param=1&user_id=123');
|
||||
});
|
||||
|
||||
it('ensures that path starts with a forward-slash', function () {
|
||||
var host = new Host();
|
||||
host.path = 'prefix';
|
||||
|
||||
host.makeUrl({ path: '/this and that'})
|
||||
.should.eql('http://localhost:9200/prefix/this and that');
|
||||
expect(host.makeUrl({ path: '/this and that'}))
|
||||
.to.be('http://localhost:9200/prefix/this and that');
|
||||
});
|
||||
|
||||
it('does not try to prevent double forward-slashes', function () {
|
||||
var host = new Host({ path: 'prefix/' });
|
||||
|
||||
host.makeUrl({ path: '/this and that'})
|
||||
.should.eql('http://localhost:9200/prefix//this and that');
|
||||
expect(host.makeUrl({ path: '/this and that'}))
|
||||
.to.be('http://localhost:9200/prefix//this and that');
|
||||
});
|
||||
|
||||
it('creates proper url without any params', function () {
|
||||
var host = new Host({});
|
||||
host.makeUrl().should.eql('http://localhost:9200/');
|
||||
expect(host.makeUrl()).to.be('http://localhost:9200/');
|
||||
|
||||
host = new Host({ host: 'john', port: 80 });
|
||||
host.makeUrl().should.eql('http://john/');
|
||||
expect(host.makeUrl()).to.be('http://john/');
|
||||
|
||||
host = new Host({ host: 'italy', path: '/pie', auth: 'user:pass'});
|
||||
host.makeUrl().should.eql('http://user:pass@italy:9200/pie');
|
||||
expect(host.makeUrl()).to.be('http://user:pass@italy:9200/pie');
|
||||
});
|
||||
});
|
||||
|
||||
@ -161,7 +158,7 @@ describe('Host class', function () {
|
||||
host: 'google.com'
|
||||
});
|
||||
|
||||
host.toString().should.eql(host.makeUrl());
|
||||
expect(host.toString()).to.eql(host.makeUrl());
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user