Skip to content

Commit

Permalink
pencilblue#970 more unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brianhyder committed Nov 29, 2016
1 parent 86593d8 commit e2954f1
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 5 deletions.
6 changes: 3 additions & 3 deletions include/http/middleware/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,14 @@ module.exports = function(pb) {
*/
static deriveRouteTheme (req, res, next) {

//routeTheme describes the site/theme/method combo
// routeTheme describes the site/theme/method combo
var rt = req.handler.routeTheme = req.routeTheme = req.handler.getRouteTheme(req.activeTheme, req.route);
if (rt.theme === null || rt.method === null || rt.site === null) {
return next(ErrorUtils.notFound());
}

//while themeRoute describes the specific route definition based on the theme
//TODO [1.0] super confusing and should be changed
// themeRoute describes the specific route definition based on the theme
// TODO [1.0] super confusing and should be changed
req.handler.themeRoute = req.themeRoute = req.route.themes[rt.site][rt.theme][rt.method];
if (pb.log.isSilly()) {
pb.log.silly("RequestHandler: Settling on theme [%s] and method [%s] for URL=[%s:%s]", rt.theme, rt.method, req.method, req.handler.url.href);
Expand Down
63 changes: 61 additions & 2 deletions test/include/http/middleware/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,67 @@ describe('Middleware', function() {

describe('deriveRouteTheme', function() {

it('', function(done) {
done();
beforeEach(function() {
req.activeTheme = 'some-active-theme';
req.route = {
themes: {
global: {
pencilblue: {
'get': {
hello: 'world'
}
}
}
}
};
});

[
{
theme: null,
method: 'get',
site: 'global'
},
{
theme: 'pencilblue',
method: null,
site: 'global'
},
{
theme: 'pencilblue',
method: 'get',
site: null
}
].forEach(function(routeTheme) {
it('should call back with a not found error when the route theme returns with: ' + JSON.stringify(routeTheme), function(done) {
sandbox.stub(req.handler, 'getRouteTheme')
.withArgs(req.activeTheme, req.route)
.returns(routeTheme);
this.pb.Middleware.deriveRouteTheme(req, res, function(err) {
err.code.should.eql(HttpStatusCodes.NOT_FOUND);
should(req.themeRoute).eql(undefined);
should(req.handler.themeRoute).eql(undefined);

done();
});
});
});

it('should derive the themed route from the route definition', function(done) {
var routeTheme = {
theme: 'pencilblue',
method: 'get',
site: 'global'
};
sandbox.stub(req.handler, 'getRouteTheme')
.withArgs(req.activeTheme, req.route)
.returns(routeTheme);
this.pb.Middleware.deriveRouteTheme(req, res, function(err) {
should(err).eql(undefined);
req.themeRoute.should.eql(req.route.themes.global.pencilblue.get);
req.handler.themeRoute.should.eql(req.route.themes.global.pencilblue.get);
done();
});
});
});

Expand Down

0 comments on commit e2954f1

Please sign in to comment.