From 2342864c6b83cc197c643d3a2b89aa82ebcdca8c Mon Sep 17 00:00:00 2001 From: scott-wyatt Date: Wed, 10 Apr 2019 14:11:43 -0500 Subject: [PATCH] [fix] coverage --- lib/utils.ts | 9 ++++----- package-lock.json | 2 +- package.json | 2 +- test/unit/lib/util.test.js | 21 +++++++++++++++++++++ 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/lib/utils.ts b/lib/utils.ts index 1157782..d45331c 100755 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -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 @@ -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 diff --git a/package-lock.json b/package-lock.json index 5e87a7a..323fc67 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@fabrix/spool-router", - "version": "1.6.1", + "version": "1.6.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index cd82ffa..71a8d2e 100755 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/unit/lib/util.test.js b/test/unit/lib/util.test.js index 8d40db0..de1b337 100755 --- a/test/unit/lib/util.test.js +++ b/test/unit/lib/util.test.js @@ -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)