Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
osherx authored and pbojinov committed Jan 27, 2016
1 parent e0b44ee commit ec3bdf8
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,33 @@ test('req.connection.remoteAddress', function(t) {
}
});

test('request-ip.mw -', function(t) {
t.plan(2);

console.log(typeof requestIp.mw)

t.equal(typeof requestIp.mw, 'function', 'requestIp.mw - should be a factory function');
t.equal(requestIp.mw.length, 1, 'requestIp.mw expects 1 argument - options');
});

test('request-ip.mw - used with no arguments', function(t) {
t.plan(2);
var mw = requestIp.mw();
t.ok(typeof mw == 'function' && mw.length == 3, 'returns a middleware');

var mockReq = { headers : { 'x-forwarded-for' : "111.222.111.222"} };
mw( mockReq, null, function() {
t.equal(mockReq.clientIp, "111.222.111.222", "when used - the middleware augments the request object with attribute 'clientIp'" );
});
});

test('request-ip.mw - user code customizes augmented attribute name', function(t) {
t.plan(2);
var mw = requestIp.mw({ attributeName : "realIp" });
t.ok(typeof mw == 'function' && mw.length == 3, 'returns a middleware');

var mockReq = { headers : { 'x-forwarded-for' : "111.222.111.222"} };
mw( mockReq, null, function() {
t.equal(mockReq.realIp, "111.222.111.222", "when used - the middleware augments the request object with attribute name provided by user-code" );
});
});

0 comments on commit ec3bdf8

Please sign in to comment.