From f2ee53c1377e3147b2ef93a3872ff46b3d09d7f3 Mon Sep 17 00:00:00 2001 From: John Szwaronek Date: Sun, 11 Mar 2018 09:40:00 -0400 Subject: [PATCH 1/4] Revert ajv from 6.1.1 to 5.5.2. Errors testing schemas in existing ajv instances. --- package-lock.json | 164 ++++++--------------------------- package.json | 2 +- tests/services/discard.test.js | 27 ++++++ 3 files changed, 56 insertions(+), 137 deletions(-) diff --git a/package-lock.json b/package-lock.json index baa54667..a30f7148 100644 --- a/package-lock.json +++ b/package-lock.json @@ -358,9 +358,9 @@ } }, "browser-stdout": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.0.tgz", - "integrity": "sha1-81HTKWnTL6XXpVZxVCY9korjvR8=", + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.1.tgz", + "integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==", "dev": true }, "bson": { @@ -740,9 +740,9 @@ } }, "diff": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/diff/-/diff-3.2.0.tgz", - "integrity": "sha1-yc45Okt8vQsFinJck98pkCeGj/k=", + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz", + "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==", "dev": true }, "ecc-jsbn": { @@ -1183,16 +1183,10 @@ "integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg=", "dev": true }, - "graceful-readlink": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/graceful-readlink/-/graceful-readlink-1.0.1.tgz", - "integrity": "sha1-TK+tdrxi8C+gObL5Tpo906ORpyU=", - "dev": true - }, "growl": { - "version": "1.9.2", - "resolved": "https://registry.npmjs.org/growl/-/growl-1.9.2.tgz", - "integrity": "sha1-Dqd0NxXbjY3ixe3hd14bRayFwC8=", + "version": "1.10.3", + "resolved": "https://registry.npmjs.org/growl/-/growl-1.10.3.tgz", + "integrity": "sha512-hKlsbA5Vu3xsh1Cg3J7jSmX/WaW6A5oBeqzM88oNbCRQFz+zUaXm6yxS4RVytp1scBoJzSYl4YAEOQIt6O8V1Q==", "dev": true }, "handlebars": { @@ -1725,12 +1719,6 @@ "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=", "dev": true }, - "json3": { - "version": "3.3.2", - "resolved": "https://registry.npmjs.org/json3/-/json3-3.3.2.tgz", - "integrity": "sha1-PAQ0dD35Pi9cQq7nsZvLSDV19OE=", - "dev": true - }, "jsonpointer": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/jsonpointer/-/jsonpointer-4.0.1.tgz", @@ -1833,80 +1821,12 @@ "integrity": "sha1-eCA6TRwyiuHYbcpkYONptX9AVa4=", "dev": true }, - "lodash._baseassign": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/lodash._baseassign/-/lodash._baseassign-3.2.0.tgz", - "integrity": "sha1-jDigmVAPIVrQnlnxci/QxSv+Ck4=", - "dev": true, - "requires": { - "lodash._basecopy": "3.0.1", - "lodash.keys": "3.1.2" - } - }, - "lodash._basecopy": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/lodash._basecopy/-/lodash._basecopy-3.0.1.tgz", - "integrity": "sha1-jaDmqHbPNEwK2KVIghEd08XHyjY=", - "dev": true - }, - "lodash._basecreate": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/lodash._basecreate/-/lodash._basecreate-3.0.3.tgz", - "integrity": "sha1-G8ZhYU2qf8MRt9A78WgGoCE8+CE=", - "dev": true - }, - "lodash._getnative": { - "version": "3.9.1", - "resolved": "https://registry.npmjs.org/lodash._getnative/-/lodash._getnative-3.9.1.tgz", - "integrity": "sha1-VwvH3t5G1hzc3mh9ZdPuy6o6r/U=", - "dev": true - }, - "lodash._isiterateecall": { - "version": "3.0.9", - "resolved": "https://registry.npmjs.org/lodash._isiterateecall/-/lodash._isiterateecall-3.0.9.tgz", - "integrity": "sha1-UgOte6Ql+uhCRg5pbbnPPmqsBXw=", - "dev": true - }, "lodash.cond": { "version": "4.5.2", "resolved": "https://registry.npmjs.org/lodash.cond/-/lodash.cond-4.5.2.tgz", "integrity": "sha1-9HGh2khr5g9quVXRcRVSPdHSVdU=", "dev": true }, - "lodash.create": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/lodash.create/-/lodash.create-3.1.1.tgz", - "integrity": "sha1-1/KEnw29p+BGgruM1yqwIkYd6+c=", - "dev": true, - "requires": { - "lodash._baseassign": "3.2.0", - "lodash._basecreate": "3.0.3", - "lodash._isiterateecall": "3.0.9" - } - }, - "lodash.isarguments": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/lodash.isarguments/-/lodash.isarguments-3.1.0.tgz", - "integrity": "sha1-L1c9hcaiQon/AGY7SRwdM4/zRYo=", - "dev": true - }, - "lodash.isarray": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/lodash.isarray/-/lodash.isarray-3.0.4.tgz", - "integrity": "sha1-eeTriMNqgSKvhvhEqpvNhRtfu1U=", - "dev": true - }, - "lodash.keys": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/lodash.keys/-/lodash.keys-3.1.2.tgz", - "integrity": "sha1-TbwEcrFWvlCgsoaFXRvQsMZWCYo=", - "dev": true, - "requires": { - "lodash._getnative": "3.9.1", - "lodash.isarguments": "3.1.0", - "lodash.isarray": "3.0.4" - } - }, "log-driver": { "version": "1.2.5", "resolved": "https://registry.npmjs.org/log-driver/-/log-driver-1.2.5.tgz", @@ -2002,64 +1922,36 @@ } }, "mocha": { - "version": "3.5.3", - "resolved": "https://registry.npmjs.org/mocha/-/mocha-3.5.3.tgz", - "integrity": "sha512-/6na001MJWEtYxHOV1WLfsmR4YIynkUEhBwzsb+fk2qmQ3iqsi258l/Q2MWHJMImAcNpZ8DEdYAK72NHoIQ9Eg==", + "version": "5.0.4", + "resolved": "https://registry.npmjs.org/mocha/-/mocha-5.0.4.tgz", + "integrity": "sha512-nMOpAPFosU1B4Ix1jdhx5e3q7XO55ic5a8cgYvW27CequcEY+BabS0kUVL1Cw1V5PuVHZWeNRWFLmEPexo79VA==", "dev": true, "requires": { - "browser-stdout": "1.3.0", - "commander": "2.9.0", - "debug": "2.6.8", - "diff": "3.2.0", + "browser-stdout": "1.3.1", + "commander": "2.11.0", + "debug": "3.1.0", + "diff": "3.5.0", "escape-string-regexp": "1.0.5", - "glob": "7.1.1", - "growl": "1.9.2", + "glob": "7.1.2", + "growl": "1.10.3", "he": "1.1.1", - "json3": "3.3.2", - "lodash.create": "3.1.1", "mkdirp": "0.5.1", - "supports-color": "3.1.2" + "supports-color": "4.4.0" }, "dependencies": { - "commander": { - "version": "2.9.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.9.0.tgz", - "integrity": "sha1-nJkJQXbhIkDLItbFFGCYQA/g99Q=", - "dev": true, - "requires": { - "graceful-readlink": "1.0.1" - } - }, - "debug": { - "version": "2.6.8", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.8.tgz", - "integrity": "sha1-5zFTHKLt4n0YgiJCfaF4IdaP9Pw=", - "dev": true, - "requires": { - "ms": "2.0.0" - } - }, - "glob": { - "version": "7.1.1", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.1.tgz", - "integrity": "sha1-gFIR3wT6rxxjo2ADBs31reULLsg=", - "dev": true, - "requires": { - "fs.realpath": "1.0.0", - "inflight": "1.0.6", - "inherits": "2.0.3", - "minimatch": "3.0.4", - "once": "1.4.0", - "path-is-absolute": "1.0.1" - } + "has-flag": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-2.0.0.tgz", + "integrity": "sha1-6CB68cx7MNRGzHC3NLXovhj4jVE=", + "dev": true }, "supports-color": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-3.1.2.tgz", - "integrity": "sha1-cqJiiU2dQIuVbKBf83su2KbiotU=", + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.4.0.tgz", + "integrity": "sha512-rKC3+DyXWgK0ZLKwmRsrkyHVZAjNkfzeehuFWdGGcqGDTZFH73+RH6S/RDAAxl9GusSjZSUWYLmT9N5pzXFOXQ==", "dev": true, "requires": { - "has-flag": "1.0.0" + "has-flag": "2.0.0" } } } diff --git a/package.json b/package.json index ff0edc28..af51a708 100755 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "@feathersjs/commons": "^1.4.0", "@feathersjs/errors": "^3.3.0", "@feathersjs/feathers": "^3.1.3", - "ajv": "^6.1.1", + "ajv": "^5.5.2", "debug": "^3.1.0", "process": "0.11.10", "traverse": "^0.6.6" diff --git a/tests/services/discard.test.js b/tests/services/discard.test.js index babc9c9b..4dec2db0 100755 --- a/tests/services/discard.test.js +++ b/tests/services/discard.test.js @@ -152,5 +152,32 @@ describe('services discard', () => { { empl: { name: { first: 'John', last: 'Doe' }, status: 'AA' }, dept: 'Acct' } ); }); + + it('discards multiple fields', () => { + let hook = { + type: 'after', + method: 'get', + result: { + roles: [ 'super' ], + _id: 'a', + email: 'foo', + password: 'bar', + name: 'Rafael', + id: 'b', + }, + query: {}, + }; + + hooks.discard('email', 'password')(hook); + + assert.deepEqual(hook.result, { + roles: [ 'super' ], + _id: 'a', + //email: 'foo', + //password: 'bar', + name: 'Rafael', + id: 'b', + }); + }); }); }); From 07b4f9b08f4923fc4f64ac18f8cc74a3c19fc079 Mon Sep 17 00:00:00 2001 From: John Szwaronek Date: Sun, 11 Mar 2018 09:49:14 -0400 Subject: [PATCH 2/4] Disable act-on-dispatch.test on node v6 --- tests-async/act-on-dispatch.test.js | 92 +++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100755 tests-async/act-on-dispatch.test.js diff --git a/tests-async/act-on-dispatch.test.js b/tests-async/act-on-dispatch.test.js new file mode 100755 index 00000000..74751ed4 --- /dev/null +++ b/tests-async/act-on-dispatch.test.js @@ -0,0 +1,92 @@ + +const { assert } = require('chai'); +const { actOnDefault, actOnDispatch, combine, getItems, replaceItems } = require('../../lib'); + +let hookBefore; + +function testHook(what, code) { + return context => { + if (context.params._actOn !== what) throw new Error( + `Hook code ${code} expected ${what} found ${context.params._actOn}` + ); + + context.params._actOnCodes.push(code); + }; +} + +describe('services actOn', () => { + describe('Call hooks which do not call other hooks', () => { + beforeEach(() => { + hookBefore = { type: 'before', method: 'get', params: { _actOnCodes: [] } }; + }); + + it('actOnDefault', async () => { + const result = await actOnDefault( + testHook(undefined, 1), testHook(undefined, 2), testHook(undefined, 3) + )(hookBefore); + + assert.deepEqual(result.params._actOnCodes, [1, 2, 3]) + }); + + it('actOnDispatch', async () => { + const result = await actOnDispatch( + testHook('dispatch', 10), testHook('dispatch', 20), testHook('dispatch', 30) + )(hookBefore); + + assert.deepEqual(result.params._actOnCodes, [10, 20, 30]) + }); + + }); + + describe('Call hooks calling others same actOn', () => { + beforeEach(() => { + hookBefore = { type: 'before', method: 'get', params: { _actOnCodes: [] } }; + }); + + it('actOnDefault calling actOnDefault', async () => { + const result = await actOnDefault( + combine(testHook(undefined, 11), testHook(undefined, 12)), + combine(testHook(undefined, 21), testHook(undefined, 22)), + )(hookBefore); + + assert.deepEqual(result.params._actOnCodes, [11, 12, 21, 22]) + }); + + it('actOnDefault calling actOnDispatch', async () => { + const result = await actOnDefault( + actOnDispatch(combine(testHook('dispatch', 11), testHook('dispatch', 12))), + combine(testHook(undefined, 21), testHook(undefined, 22)), + )(hookBefore); + + assert.deepEqual(result.params._actOnCodes, [11, 12, 21, 22]) + }); + + it('actOnDispatch calling actOnDefault', async () => { + const result = await actOnDispatch( + actOnDefault(combine(testHook(undefined, 11), testHook(undefined, 12))), + combine(testHook('dispatch', 21), testHook('dispatch', 22)), + )(hookBefore); + + assert.deepEqual(result.params._actOnCodes, [11, 12, 21, 22]) + }); + }); + + describe('getItems & replaceItems', () => { + beforeEach(() => { + hookBefore = { + type: 'before', method: 'get', data: { a: 1 }, result: { b: 2 }, dispatch: { c: 3 }, + params: { _actOn: 'dispatch' } + }; + }); + + it('Gets dispatch data', () => { + assert.deepEqual(getItems(hookBefore), hookBefore.dispatch) + }); + + it('Returns dispatch data', () => { + replaceItems(hookBefore, { foo: 'bar' }); + + assert.deepEqual(hookBefore.dispatch, { foo: 'bar' }) + }); + }); +}); From 4f925cbf2c1a085e731ddcec08bedf308efe1db3 Mon Sep 17 00:00:00 2001 From: John Szwaronek Date: Sun, 11 Mar 2018 09:53:14 -0400 Subject: [PATCH 3/4] Fixed actOnDispatch for node v6 --- tests/services/act-on-dispatch-stub.test.js | 7 ++ tests/services/act-on-dispatch.test.js | 92 --------------------- 2 files changed, 7 insertions(+), 92 deletions(-) create mode 100755 tests/services/act-on-dispatch-stub.test.js delete mode 100755 tests/services/act-on-dispatch.test.js diff --git a/tests/services/act-on-dispatch-stub.test.js b/tests/services/act-on-dispatch-stub.test.js new file mode 100755 index 00000000..fc59f962 --- /dev/null +++ b/tests/services/act-on-dispatch-stub.test.js @@ -0,0 +1,7 @@ + + +if (process.version.substr(0, 2) >= 'v8') { + require('../../tests-async/act-on-dispatch.test'); +} else { + console.log('\n...act-on-dispatch test ignored. Node version is prior to v8.'); +} diff --git a/tests/services/act-on-dispatch.test.js b/tests/services/act-on-dispatch.test.js deleted file mode 100755 index 74751ed4..00000000 --- a/tests/services/act-on-dispatch.test.js +++ /dev/null @@ -1,92 +0,0 @@ - -const { assert } = require('chai'); -const { actOnDefault, actOnDispatch, combine, getItems, replaceItems } = require('../../lib'); - -let hookBefore; - -function testHook(what, code) { - return context => { - if (context.params._actOn !== what) throw new Error( - `Hook code ${code} expected ${what} found ${context.params._actOn}` - ); - - context.params._actOnCodes.push(code); - }; -} - -describe('services actOn', () => { - describe('Call hooks which do not call other hooks', () => { - beforeEach(() => { - hookBefore = { type: 'before', method: 'get', params: { _actOnCodes: [] } }; - }); - - it('actOnDefault', async () => { - const result = await actOnDefault( - testHook(undefined, 1), testHook(undefined, 2), testHook(undefined, 3) - )(hookBefore); - - assert.deepEqual(result.params._actOnCodes, [1, 2, 3]) - }); - - it('actOnDispatch', async () => { - const result = await actOnDispatch( - testHook('dispatch', 10), testHook('dispatch', 20), testHook('dispatch', 30) - )(hookBefore); - - assert.deepEqual(result.params._actOnCodes, [10, 20, 30]) - }); - - }); - - describe('Call hooks calling others same actOn', () => { - beforeEach(() => { - hookBefore = { type: 'before', method: 'get', params: { _actOnCodes: [] } }; - }); - - it('actOnDefault calling actOnDefault', async () => { - const result = await actOnDefault( - combine(testHook(undefined, 11), testHook(undefined, 12)), - combine(testHook(undefined, 21), testHook(undefined, 22)), - )(hookBefore); - - assert.deepEqual(result.params._actOnCodes, [11, 12, 21, 22]) - }); - - it('actOnDefault calling actOnDispatch', async () => { - const result = await actOnDefault( - actOnDispatch(combine(testHook('dispatch', 11), testHook('dispatch', 12))), - combine(testHook(undefined, 21), testHook(undefined, 22)), - )(hookBefore); - - assert.deepEqual(result.params._actOnCodes, [11, 12, 21, 22]) - }); - - it('actOnDispatch calling actOnDefault', async () => { - const result = await actOnDispatch( - actOnDefault(combine(testHook(undefined, 11), testHook(undefined, 12))), - combine(testHook('dispatch', 21), testHook('dispatch', 22)), - )(hookBefore); - - assert.deepEqual(result.params._actOnCodes, [11, 12, 21, 22]) - }); - }); - - describe('getItems & replaceItems', () => { - beforeEach(() => { - hookBefore = { - type: 'before', method: 'get', data: { a: 1 }, result: { b: 2 }, dispatch: { c: 3 }, - params: { _actOn: 'dispatch' } - }; - }); - - it('Gets dispatch data', () => { - assert.deepEqual(getItems(hookBefore), hookBefore.dispatch) - }); - - it('Returns dispatch data', () => { - replaceItems(hookBefore, { foo: 'bar' }); - - assert.deepEqual(hookBefore.dispatch, { foo: 'bar' }) - }); - }); -}); From 7a636b8e38cd52d252318344c6de39028e5c52c7 Mon Sep 17 00:00:00 2001 From: John Szwaronek Date: Sun, 11 Mar 2018 10:03:16 -0400 Subject: [PATCH 4/4] Fixed actOnDispatch for node v6 --- tests-async/act-on-dispatch.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests-async/act-on-dispatch.test.js b/tests-async/act-on-dispatch.test.js index 74751ed4..7498535b 100755 --- a/tests-async/act-on-dispatch.test.js +++ b/tests-async/act-on-dispatch.test.js @@ -1,6 +1,6 @@ const { assert } = require('chai'); -const { actOnDefault, actOnDispatch, combine, getItems, replaceItems } = require('../../lib'); +const { actOnDefault, actOnDispatch, combine, getItems, replaceItems } = require('../lib'); let hookBefore;