Skip to content

Commit

Permalink
test service.js
Browse files Browse the repository at this point in the history
  • Loading branch information
domenkozar committed Dec 7, 2013
1 parent c64333e commit 4b96555
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ Service.prototype = {
//console.debug("Configuration for %s: %s", service_name, global_config);
},

execute: function(config, directory) {
var service_path = path.resolve(__dirname, '../services/' + this.name + '.js'),
service = require(service_path);
execute: function() {
var service = this._load_service();
return service(this);
},

_load_service: function() {
var service_path = path.resolve(__dirname, 'services/' + this.name + '.js');
return require(service_path);
}
};

Expand Down
24 changes: 24 additions & 0 deletions test/service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
var sinon = require('sinon'),
Service = require('../lib/service.js'),
expect = require('chai').expect;

describe('service.js', function() {
it('Correctly load the service', function() {
var trello = require('../lib/services/trello.js');
service = new Service("trello", {"services": {"trello": {}}}, "foobar")._load_service();
expect(service).to.equal(trello);
});

it('Correctly execute the service', function() {
var service = new Service("trello", {"services": {"trello": {}}}, "foobar"),
obj = sinon.spy();

sinon.stub(service, "_load_service", function() {
return function(){return obj;};
});

expect(service.execute()).to.equal(obj);

service._load_service.restore();
});
});

0 comments on commit 4b96555

Please sign in to comment.