Skip to content

Commit 4e27a29

Browse files
author
Fabian Hoffmann
committed
renamings
1 parent df48c13 commit 4e27a29

File tree

2 files changed

+38
-39
lines changed

2 files changed

+38
-39
lines changed

index.js

+18-19
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ var utils = function() {
2222
}
2323
};
2424

25-
var healthCheckBody = function(customCallback) {
25+
var healthCheckAction = function(customAction) {
2626
// provide the health check function which is used from nodejs health check endpoint
27-
// and add custom callback to it
27+
// and add custom action to it
2828
return function(req, res) {
29-
if (customCallback) {
30-
customCallback(req, res);
29+
if (customAction) {
30+
customAction(req, res);
3131
}
3232
res.send("UP");
3333
};
@@ -37,19 +37,18 @@ var utils = function() {
3737
* Adds a health check to a nodejs application object.
3838
*
3939
* @param app nodejs application.
40-
* @param customCallback optional callback which will be executed if
41-
* the health check is called.
40+
* @param customAction optional callback which will be executed if
41+
* the health check is called.
4242
*/
43-
var addHealthCheck = function(app, customCallback) {
44-
app.get("/health", healthCheckBody(customCallback));
43+
var registerHealthCheckEndpoint = function(app, customAction) {
44+
app.get("/health", healthCheckAction(customAction));
4545
};
4646

47-
var notifyBody = function(customCallback) {
48-
// enhance the notification api with a custom
49-
// callback
47+
var notificationAction = function(customAction) {
48+
// enhance the notification api with a custom action
5049
return function(req, res) {
51-
if (customCallback) {
52-
customCallback(req, res);
50+
if (customAction) {
51+
customAction(req, res);
5352
}
5453
res.send("OK");
5554
};
@@ -59,17 +58,17 @@ var utils = function() {
5958
* Adds a notification endpoint.
6059
*
6160
* @param app nodejs application.
62-
* @param customCallback optional callback which will be executed if
63-
* the notification is received.
61+
* @param customAction optional callback which will be executed if
62+
* the notification is received.
6463
*/
65-
var addNotifyEndpoint = function(app, customCallback) {
66-
app.post("/notify", notifyBody(customCallback));
64+
var registerNotificationEndpoint = function(app, customAction) {
65+
app.post("/notify", notificationAction(customAction));
6766
};
6867

6968
return {
7069
currentAddress: currentAddress,
71-
addHealthCheck: addHealthCheck,
72-
addNotifyEndpoint: addNotifyEndpoint
70+
registerHealthCheckEndpoint: registerHealthCheckEndpoint,
71+
registerNotificationEndpoint: registerNotificationEndpoint
7372
};
7473
};
7574

test/index.js

+20-20
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ describe("utils", function(){
5353
var appSpy = sinon.spy(app, "get");
5454

5555
// when
56-
utils.addHealthCheck(app);
56+
utils.registerHealthCheckEndpoint(app);
5757

5858
// then
5959
assert(appSpy.withArgs("/health", sinon.match.func).calledOnce);
6060
});
6161

62-
it("should set up health check body and call custom callback", function() {
62+
it("should set up health check body and call custom action", function() {
6363
// given
64-
var customCallbackSpy = sinon.spy();
64+
var customActionSpy = sinon.spy();
6565
var res = {send: function() {}};
6666
var resSpy = sinon.spy(res, "send");
6767
var app = {
@@ -71,23 +71,23 @@ describe("utils", function(){
7171
};
7272

7373
// when
74-
utils.addHealthCheck(app, customCallbackSpy);
74+
utils.registerHealthCheckEndpoint(app, customActionSpy);
7575

7676
// then
77-
assert(customCallbackSpy.calledOnce);
77+
assert(customActionSpy.calledOnce);
7878
assert(resSpy.withArgs("UP").calledOnce);
7979
});
8080

81-
it("should set up health check body and don't call custom callback if undefined", function() {
81+
it("should set up health check body and don't call custom action if undefined", function() {
8282
// given
8383
var app = {
84-
get: function(path, healthCheckBody) {
85-
healthCheckBody({}, {send: function() {}});
84+
get: function(path, healthCheckAction) {
85+
healthCheckAction({}, {send: function() {}});
8686
}
8787
};
8888

8989
// when
90-
utils.addHealthCheck(app, undefined);
90+
utils.registerHealthCheckEndpoint(app, undefined);
9191

9292
// then
9393
// nothing to check, will fail if undefined would be executed
@@ -103,41 +103,41 @@ describe("utils", function(){
103103
var appSpy = sinon.spy(app, "post");
104104

105105
// when
106-
utils.addNotifyEndpoint(app);
106+
utils.registerNotificationEndpoint(app);
107107

108108
// then
109109
assert(appSpy.withArgs("/notify", sinon.match.func).calledOnce);
110110
});
111111

112-
it("should set up notify body and call custom callback", function() {
112+
it("should set up notify body and call custom action", function() {
113113
// given
114-
var customCallbackSpy = sinon.spy();
114+
var customActionSpy = sinon.spy();
115115
var res = {send: function() {}};
116116
var resSpy = sinon.spy(res, "send");
117117
var app = {
118-
post: function(path, notifyBody) {
119-
notifyBody({}, res);
118+
post: function(path, notifyAction) {
119+
notifyAction({}, res);
120120
}
121121
};
122122

123123
// when
124-
utils.addNotifyEndpoint(app, customCallbackSpy);
124+
utils.registerNotificationEndpoint(app, customActionSpy);
125125

126126
// then
127-
assert(customCallbackSpy.calledOnce);
127+
assert(customActionSpy.calledOnce);
128128
assert(resSpy.withArgs("OK").calledOnce);
129129
});
130130

131-
it("should set up notify body and don't call custom callback if undefined", function() {
131+
it("should set up notify body and don't call custom action if undefined", function() {
132132
// given
133133
var app = {
134-
post: function(path, notifyBody) {
135-
notifyBody({}, {send: function() {}});
134+
post: function(path, notificationAction) {
135+
notificationAction({}, {send: function() {}});
136136
}
137137
};
138138

139139
// when
140-
utils.addNotifyEndpoint(app, undefined);
140+
utils.registerNotificationEndpoint(app, undefined);
141141

142142
// then
143143
// nothing to check, will fail if undefined would be executed

0 commit comments

Comments
 (0)