Skip to content

Commit

Permalink
extract web application functionality out of utils
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabian Hoffmann committed May 20, 2015
1 parent 4e27a29 commit caf8c8c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
11 changes: 9 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ var utils = function() {
}
};

return {
currentAddress: currentAddress
};
};

var webApp = function() {

var healthCheckAction = function(customAction) {
// provide the health check function which is used from nodejs health check endpoint
// and add custom action to it
Expand Down Expand Up @@ -66,7 +73,6 @@ var utils = function() {
};

return {
currentAddress: currentAddress,
registerHealthCheckEndpoint: registerHealthCheckEndpoint,
registerNotificationEndpoint: registerNotificationEndpoint
};
Expand Down Expand Up @@ -141,5 +147,6 @@ var master = function(masterUrl) {

module.exports = {
utils: utils,
master: master
master: master,
webApp: webApp
};
18 changes: 11 additions & 7 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ describe("utils", function(){
assert.equal(utils.currentAddress(), undefined);
});
});
});

describe("webApp", function(){
var webApp = testee.webApp();

describe("health check registration", function() {
describe("health check endpoint registration", function() {
it("should add application endpoint /health", function() {
// given
var app = {
Expand All @@ -53,7 +57,7 @@ describe("utils", function(){
var appSpy = sinon.spy(app, "get");

// when
utils.registerHealthCheckEndpoint(app);
webApp.registerHealthCheckEndpoint(app);

// then
assert(appSpy.withArgs("/health", sinon.match.func).calledOnce);
Expand All @@ -71,7 +75,7 @@ describe("utils", function(){
};

// when
utils.registerHealthCheckEndpoint(app, customActionSpy);
webApp.registerHealthCheckEndpoint(app, customActionSpy);

// then
assert(customActionSpy.calledOnce);
Expand All @@ -87,7 +91,7 @@ describe("utils", function(){
};

// when
utils.registerHealthCheckEndpoint(app, undefined);
webApp.registerHealthCheckEndpoint(app, undefined);

// then
// nothing to check, will fail if undefined would be executed
Expand All @@ -103,7 +107,7 @@ describe("utils", function(){
var appSpy = sinon.spy(app, "post");

// when
utils.registerNotificationEndpoint(app);
webApp.registerNotificationEndpoint(app);

// then
assert(appSpy.withArgs("/notify", sinon.match.func).calledOnce);
Expand All @@ -121,7 +125,7 @@ describe("utils", function(){
};

// when
utils.registerNotificationEndpoint(app, customActionSpy);
webApp.registerNotificationEndpoint(app, customActionSpy);

// then
assert(customActionSpy.calledOnce);
Expand All @@ -137,7 +141,7 @@ describe("utils", function(){
};

// when
utils.registerNotificationEndpoint(app, undefined);
webApp.registerNotificationEndpoint(app, undefined);

// then
// nothing to check, will fail if undefined would be executed
Expand Down

0 comments on commit caf8c8c

Please sign in to comment.