Skip to content

Commit

Permalink
Updating tests for browser id and logging changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jonsu authored and jonsu committed Jan 17, 2015
1 parent 5e9de9a commit d96c9ec
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 6 deletions.
2 changes: 0 additions & 2 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@ var Router = {
page = this._getPage(request),
controllerParts = this._parseControllerName(request, url),
controllerName = this._getControllerName(controllerParts);

request.minorjs = {
page : page,
controller : {
Expand All @@ -298,7 +297,6 @@ var Router = {
requestToken : Indentifier.generate(),
browserId : request.get('Browser-Context-Id') ? request.get('Browser-Context-Id') : 'browser.' + uuid.v4().replace(/-/g, '')
};

Logger.info('Request for ' + controllerName + '#' + route.handler, request);

Filter.run(filters, request, response, next)
Expand Down
2 changes: 1 addition & 1 deletion test/unit/lib/logger_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('lib/logger.js', function () {
start = 12345;

Module = require('../../../lib/logger');
Module._log = sinon.spy(function (level, request, message) {
Module._log = sinon.spy(function (level, message, request) {
level.should.eql('debug');
message.should.match(/Performance: some name took [0-9]*ms/);
});
Expand Down
69 changes: 66 additions & 3 deletions test/unit/lib/router_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,10 @@ describe('lib/router.js', function () {
url : 'some url',
route : {
path : 'some path'
}
},
get : sinon.spy()
},

response = {},
next = {},
Filter = {
Expand Down Expand Up @@ -328,7 +330,6 @@ describe('lib/router.js', function () {

done();
});

Module._handleRequest(url, route, startTime, controller, request, response, next);
});

Expand All @@ -350,7 +351,8 @@ describe('lib/router.js', function () {
url : 'some url',
route : {
path : 'some path'
}
},
get : sinon.spy()
},
response = {},
next = {},
Expand Down Expand Up @@ -386,6 +388,67 @@ describe('lib/router.js', function () {

Module._handleRequest(url, route, startTime, controller, request, response, next);
});

it('should handle browser id generation', function (done) {
var url = 'some/url',
filters = [ 'some filters' ],
controller = {
getFilters : sinon.spy(function () {
return filters;
})
},
route = {
handler : 'some handler'
},
req_w_id = {
url : 'some url',
route : {
path : 'some path'
},
'Browser-Context-Id' : 'some browser id',
get : sinon.spy(function(key){
return this[key];
})
},
req_no_id = {
url : 'some url',
route : {
path : 'some path'
},
get : sinon.spy(function(key){
return this[key];
})
},

response = {},
next = {},
Filter = {
run : sinon.spy(function () {
return Q(true);
})
},
Logger = {
info : sinon.spy()
},
startTime = Date.now();

Backhoe.mock(require.resolve('../../../lib/logger'), Logger);

Module = require('../../../lib/router');

Module._runController = sinon.spy();
Module._handleError = sinon.spy();

Module._handleRequest(url, route, startTime, controller, req_w_id, response, next);
req_w_id.get.calledWith('Browser-Context-Id');
req_w_id.minorjs.browserId.should.eql('some browser id');

Module._handleRequest(url, route, startTime, controller, req_no_id, response, next);
req_no_id.get.calledWith('Browser-Context-Id');
req_no_id.minorjs.browserId.indexOf('browser').should.eql(0);

done();
});
});

describe('_handleDevelopmentRequest', function () {
Expand Down

0 comments on commit d96c9ec

Please sign in to comment.