Skip to content

Commit

Permalink
Merge pull request #20 from fabrix-app/v1.6
Browse files Browse the repository at this point in the history
[fix] coverage
  • Loading branch information
scott-wyatt authored Apr 10, 2019
2 parents 1954064 + 2342864 commit 28741b8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
9 changes: 4 additions & 5 deletions lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,6 @@ export const Utils = {

Utils.methods.forEach(method => {
if (route[method]) {
console.log('\n')
// Clean copy of config
const config = Object.assign({}, route.config)
// Clean copy of config.pre
Expand All @@ -395,16 +394,16 @@ export const Utils = {
else if (route[method] instanceof Object && route[method].hasOwnProperty('handler')) {
route[method].config = route[method].config || config
route[method].config.pre = route[method].config.pre || config.pre

route[method].config.pre = Utils.getControllerPolicy(app, route[method].handler, method, route[method].config.pre)
if (typeof route[method].handler === 'string') {
route.config.pre = Utils.getControllerPolicy(app, route[method].handler, method, config.pre)

return route[method] = {
...route[method],
handler: Utils.getControllerFromString(app, route[method].handler)
handler: Utils.getControllerFromString(app, route[method].handler),
}
}
else {
// route.config.pre = Utils.getControllerPolicy(app, route[method].handler, method, route.config.pre)
// route.config.pre = Utils.getControllerPolicy(app, route[method].handler, method, config.pre)
return route[method] = {
...route[method],
handler: route[method].handler
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fabrix/spool-router",
"version": "1.6.1",
"version": "1.6.2",
"description": "Spool - Router for Fabrix",
"scripts": {
"build": "tsc -p ./lib/tsconfig.release.json",
Expand Down
21 changes: 21 additions & 0 deletions test/unit/lib/util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,27 @@ describe('lib.Util', () => {
'GET': 'TestController.foo',
'POST': 'TestController.foo'
})
assert.equal(route.GET.config.pre[0], global.app.policies.GlobalPolicy.foo)
assert.equal(route.GET.config.pre[1], global.app.policies.GetPolicy.foo)
assert.equal(route.GET.config.pre[2], global.app.policies.FooWildCardPolicy.foo)
assert.equal(route.GET.config.pre[3], global.app.policies.FooGetPolicy.foo)
assert.equal(route.GET.config.pre.length, 4)

assert.equal(route.POST.config.pre[0], global.app.policies.GlobalPolicy.foo)
assert.equal(route.POST.config.pre[1], global.app.policies.PostPolicy.post)
assert.equal(route.POST.config.pre[2], global.app.policies.FooWildCardPolicy.foo)
assert.equal(route.POST.config.pre[3], global.app.policies.FooPostPolicy.post)
assert.equal(route.POST.config.pre.length, 4)
})
it('should inherit the global policy and the global GET/POST policy and the Controller Specific Get/POST Policy', () => {
const [{ path, route}] = lib.Utils.buildRoute(global.app, '/foo/bar', {
'GET': {
handler: 'TestController.foo'
},
'POST': {
handler: 'TestController.foo'
}
})
console.log('BRK 1', route.GET.config)
assert.equal(route.GET.config.pre[0], global.app.policies.GlobalPolicy.foo)
assert.equal(route.GET.config.pre[1], global.app.policies.GetPolicy.foo)
Expand Down

0 comments on commit 28741b8

Please sign in to comment.