Skip to content

Commit

Permalink
Tests are green
Browse files Browse the repository at this point in the history
  • Loading branch information
floatdrop committed Jan 26, 2014
1 parent 8c5f791 commit cdebb26
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
5 changes: 1 addition & 4 deletions index.js
Expand Up @@ -2,9 +2,6 @@

'use strict';

var argv = require('optimist').argv;
var cocaine = require('cocaine');

var connectOnce = require('connect-once');

var slice = [].slice;
Expand All @@ -15,7 +12,7 @@ module.exports = function () {
var options = {};
if (typeof args[0] === 'object') { options = args.shift(); }

options.client = options.client || new cocaine.Client(argv.locator);
options.client = options.client || new (require('cocaine')).Client(require('optimist').argv.locator);

var services = args,
modules = new connectOnce(options, options.client.getServices.bind(options.client), services);
Expand Down
27 changes: 13 additions & 14 deletions test/cocaine-service-test.js
Expand Up @@ -7,23 +7,21 @@ var ces = require('..'),
should = require('should');

describe('express-cocaine-service', function () {
beforeEach(function () {
this.req = {};
});

it('should request services before request', function (done) {
var client = { getServices: function (services, cb) {
setTimeout(cb.apply.bind(cb), 1000, cb, [null].concat(services));
setTimeout(function () {
cb.apply(cb, [null].concat(services));
}, 1000);
}};

var mw = ces({ client: client }, 'one');
setTimeout(function () {
var requestTime = (new Date()).getTime();
mw(this.req, {}, function () {
mw({}, {}, function () {
var responseTime = (new Date()).getTime();
(responseTime - requestTime).should.be.below(400);
done();
}.bind(this));
});
}, 700);
});

Expand All @@ -33,13 +31,14 @@ describe('express-cocaine-service', function () {
}};

var mw = ces({ client: client }, 'one', 'two');
mw(this.req, {}, function () {
should.exist(this.req.services);
should.exist(this.req.services.one);
this.req.services.one.equal('one');
should.exist(this.req.services.two);
this.req.services.two.equal('two');
var req = {};
mw(req, {}, function () {
should.exist(req.services);
should.exist(req.services.one);
should.equal(req.services.one, 'one');
should.exist(req.services.two);
should.equal(req.services.two, 'two');
done();
}.bind(this));
});
});
});

0 comments on commit cdebb26

Please sign in to comment.