diff --git a/.codeclimate.yml b/.codeclimate.yml index 3bc1b9848a..7b0da69409 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -37,7 +37,7 @@ plugins: count_threshold: 3 exclude_patterns: - "**/test/*" - - "**/tests/*" + - "**/adapter-tests/lib/*" - "**/dist/*" - "**/*.dist.js" - "**/templates/*" \ No newline at end of file diff --git a/packages/adapter-commons/README.md b/packages/adapter-commons/README.md index e68f3dcc0c..f797e4658a 100644 --- a/packages/adapter-commons/README.md +++ b/packages/adapter-commons/README.md @@ -1,7 +1,7 @@ # Feathers Adapter Commons [![Build Status](https://travis-ci.org/feathersjs/feathers.png?branch=master)](https://travis-ci.org/feathersjs/feathers) -[![Dependency Status](https://img.shields.io/david/feathersjs/feathers.svg?style=flat-square&path=packages/commons)](https://david-dm.org/feathersjs/feathers?path=packages/commons) +[![Dependency Status](https://img.shields.io/david/feathersjs/feathers.svg?style=flat-square&path=packages/adapter-commons)](https://david-dm.org/feathersjs/feathers?path=packages/adapter-commons) [![Download Status](https://img.shields.io/npm/dm/@feathersjs/adapter-commons.svg?style=flat-square)](https://www.npmjs.com/package/@feathersjs/adapter-commons) > Shared utility functions for Feathers adatabase adapters @@ -13,7 +13,7 @@ This is a repository for handling Feathers common database syntax. ## Authors -[Feathers contributors](https://github.com/feathersjs/commons/graphs/contributors) +[Feathers contributors](https://github.com/feathersjs/adapter-commons/graphs/contributors) ## License diff --git a/packages/adapter-commons/tests.js b/packages/adapter-commons/tests.js deleted file mode 100644 index 1a6002e056..0000000000 --- a/packages/adapter-commons/tests.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require('./lib/tests'); diff --git a/packages/adapter-tests/.npmignore b/packages/adapter-tests/.npmignore new file mode 100644 index 0000000000..65e3ba2eda --- /dev/null +++ b/packages/adapter-tests/.npmignore @@ -0,0 +1 @@ +test/ diff --git a/packages/adapter-tests/CHANGELOG.md b/packages/adapter-tests/CHANGELOG.md new file mode 100644 index 0000000000..767840ada8 --- /dev/null +++ b/packages/adapter-tests/CHANGELOG.md @@ -0,0 +1,5 @@ +# Change Log + +All notable changes to this project will be documented in this file. +See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + diff --git a/packages/adapter-tests/LICENSE b/packages/adapter-tests/LICENSE new file mode 100644 index 0000000000..dcd8248aa9 --- /dev/null +++ b/packages/adapter-tests/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2019 Feathers + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/packages/adapter-tests/README.md b/packages/adapter-tests/README.md new file mode 100644 index 0000000000..6d096346ad --- /dev/null +++ b/packages/adapter-tests/README.md @@ -0,0 +1,22 @@ +# Feathers Adapter Tests + +[![Build Status](https://travis-ci.org/feathersjs/feathers.png?branch=master)](https://travis-ci.org/feathersjs/feathers) +[![Dependency Status](https://img.shields.io/david/feathersjs/feathers.svg?style=flat-square&path=packages/adapter-tests)](https://david-dm.org/feathersjs/feathers?path=packages/adapter-tests) +[![Download Status](https://img.shields.io/npm/dm/@feathersjs/adapter-commons.svg?style=flat-square)](https://www.npmjs.com/package/@feathersjs/adapter-commons) + +> Feathers shared database adapter test suite + +## About + +This is a repository that contains the test suite for the common database adapter syntax. + + +## Authors + +[Feathers contributors](https://github.com/feathersjs/adapter-tests/graphs/contributors) + +## License + +Copyright (c) 2018 Feathers contributors + +Licensed under the [MIT license](LICENSE). diff --git a/packages/adapter-commons/lib/tests/basic.js b/packages/adapter-tests/lib/basic.js similarity index 100% rename from packages/adapter-commons/lib/tests/basic.js rename to packages/adapter-tests/lib/basic.js diff --git a/packages/adapter-commons/lib/tests/index.js b/packages/adapter-tests/lib/index.js similarity index 100% rename from packages/adapter-commons/lib/tests/index.js rename to packages/adapter-tests/lib/index.js diff --git a/packages/adapter-commons/lib/tests/methods.js b/packages/adapter-tests/lib/methods.js similarity index 90% rename from packages/adapter-commons/lib/tests/methods.js rename to packages/adapter-tests/lib/methods.js index 7e5c73c72b..402c2acf9b 100644 --- a/packages/adapter-commons/lib/tests/methods.js +++ b/packages/adapter-tests/lib/methods.js @@ -52,6 +52,17 @@ module.exports = (test, app, errors, serviceName, idProp) => { 'Got a NotFound Feathers error' ); } + + try { + await service.get(doug[idProp], { + query: { [idProp]: '568225fbfe21222432e836ff' } + }); + throw new Error('Should never get here'); + } catch (error) { + assert.ok(error instanceof errors.NotFound, + 'Got a NotFound Feathers error' + ); + } }); test('.get + NotFound', async () => { @@ -102,6 +113,17 @@ module.exports = (test, app, errors, serviceName, idProp) => { 'Got a NotFound Feathers error' ); } + + try { + await service.remove(doug[idProp], { + query: { [idProp]: '568225fbfe21222432e836ff' } + }); + throw new Error('Should never get here'); + } catch (error) { + assert.ok(error instanceof errors.NotFound, + 'Got a NotFound Feathers error' + ); + } }); test('.remove + multi', async () => { @@ -181,6 +203,19 @@ module.exports = (test, app, errors, serviceName, idProp) => { 'Got a NotFound Feathers error' ); } + + try { + await service.update(doug[idProp], { + name: 'Dougler' + }, { + query: { [idProp]: '568225fbfe21222432e836ff' } + }); + throw new Error('Should never get here'); + } catch (error) { + assert.ok(error instanceof errors.NotFound, + 'Got a NotFound Feathers error' + ); + } }); test('.update + NotFound', async () => { @@ -234,6 +269,19 @@ module.exports = (test, app, errors, serviceName, idProp) => { 'Got a NotFound Feathers error' ); } + + try { + await service.patch(doug[idProp], { + name: 'id patched doug' + }, { + query: { [idProp]: '568225fbfe21222432e836ff' } + }); + throw new Error('Should never get here'); + } catch (error) { + assert.ok(error instanceof errors.NotFound, + 'Got a NotFound Feathers error' + ); + } }); test('.patch multiple', async () => { diff --git a/packages/adapter-commons/lib/tests/syntax.js b/packages/adapter-tests/lib/syntax.js similarity index 100% rename from packages/adapter-commons/lib/tests/syntax.js rename to packages/adapter-tests/lib/syntax.js diff --git a/packages/adapter-tests/package-lock.json b/packages/adapter-tests/package-lock.json new file mode 100644 index 0000000000..6ce7644c6b --- /dev/null +++ b/packages/adapter-tests/package-lock.json @@ -0,0 +1,256 @@ +{ + "name": "@feathersjs/adapter-tests", + "version": "0.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "@feathersjs/adapter-commons": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/@feathersjs/adapter-commons/-/adapter-commons-1.0.7.tgz", + "integrity": "sha512-VZLbos2840xUfEe+CYqKAKLpSm7l+26T2wWz2OLlnYy5UkCjosfsd/coJPtSwAn3dsTNUpQU2Gcb6xdOfZCy1w==", + "dev": true, + "requires": { + "@feathersjs/commons": "^4.0.0", + "@feathersjs/errors": "^3.3.6" + } + }, + "@feathersjs/commons": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/@feathersjs/commons/-/commons-4.0.0.tgz", + "integrity": "sha512-hyCLse4RiNt7WLPQ0KSudjoVnwiRykhYzIZdtDon9i2usPaoYkFw/fEYZrkE5HVB+sUTwphZoZ1oOntRk1MShg==", + "dev": true + }, + "@feathersjs/errors": { + "version": "3.3.6", + "resolved": "https://registry.npmjs.org/@feathersjs/errors/-/errors-3.3.6.tgz", + "integrity": "sha512-VCohY/AQU13xYyZGl6rfdUgE+2bjaI76a4aEb6reIphHKgb4mnjYlg2PzS1/hcU1qUNi515kY9yQa5HsE7J1dQ==", + "dev": true, + "requires": { + "debug": "^4.0.0" + }, + "dependencies": { + "debug": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", + "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", + "dev": true, + "requires": { + "ms": "^2.1.1" + } + }, + "ms": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", + "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==", + "dev": true + } + } + }, + "balanced-match": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", + "dev": true + }, + "brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dev": true, + "requires": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "browser-stdout": { + "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 + }, + "commander": { + "version": "2.15.1", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.15.1.tgz", + "integrity": "sha512-VlfT9F3V0v+jr4yxPc5gg9s62/fIVWsd2Bk2iD435um1NlGMYdVCq+MjcXnhYq2icNOizHr1kK+5TI6H0Hy0ag==", + "dev": true + }, + "concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", + "dev": true + }, + "debug": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", + "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", + "dev": true, + "requires": { + "ms": "2.0.0" + } + }, + "diff": { + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz", + "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==", + "dev": true + }, + "escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", + "dev": true + }, + "feathers-memory": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/feathers-memory/-/feathers-memory-3.0.1.tgz", + "integrity": "sha512-Z3AodnPKXWWhstzQn/EYJ+/aZCGH+//AdSHiVV1jrP+RR2oT+TCjGwWoQl8nZd7oMEJOkgEuFcjzXx5IB1kNjg==", + "dev": true, + "requires": { + "@feathersjs/adapter-commons": "^1.0.2", + "@feathersjs/commons": "^4.0.0", + "@feathersjs/errors": "^3.3.4", + "sift": "^7.0.1" + } + }, + "fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", + "dev": true + }, + "glob": { + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", + "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", + "dev": true, + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, + "growl": { + "version": "1.10.5", + "resolved": "https://registry.npmjs.org/growl/-/growl-1.10.5.tgz", + "integrity": "sha512-qBr4OuELkhPenW6goKVXiv47US3clb3/IbuWF9KNKEijAy9oeHxU9IgzjvJhHkUzhaj7rOUD7+YGWqUjLp5oSA==", + "dev": true + }, + "has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", + "dev": true + }, + "he": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/he/-/he-1.1.1.tgz", + "integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0=", + "dev": true + }, + "inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "dev": true, + "requires": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", + "dev": true + }, + "minimatch": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "dev": true, + "requires": { + "brace-expansion": "^1.1.7" + } + }, + "minimist": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", + "dev": true + }, + "mkdirp": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", + "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "dev": true, + "requires": { + "minimist": "0.0.8" + } + }, + "mocha": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/mocha/-/mocha-5.2.0.tgz", + "integrity": "sha512-2IUgKDhc3J7Uug+FxMXuqIyYzH7gJjXECKe/w43IGgQHTSj3InJi+yAA7T24L9bQMRKiUEHxEX37G5JpVUGLcQ==", + "dev": true, + "requires": { + "browser-stdout": "1.3.1", + "commander": "2.15.1", + "debug": "3.1.0", + "diff": "3.5.0", + "escape-string-regexp": "1.0.5", + "glob": "7.1.2", + "growl": "1.10.5", + "he": "1.1.1", + "minimatch": "3.0.4", + "mkdirp": "0.5.1", + "supports-color": "5.4.0" + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", + "dev": true + }, + "once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "dev": true, + "requires": { + "wrappy": "1" + } + }, + "path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", + "dev": true + }, + "sift": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/sift/-/sift-7.0.1.tgz", + "integrity": "sha512-oqD7PMJ+uO6jV9EQCl0LrRw1OwsiPsiFQR5AR30heR+4Dl7jBBbDLnNvWiak20tzZlSE1H7RB30SX/1j/YYT7g==", + "dev": true + }, + "supports-color": { + "version": "5.4.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.4.0.tgz", + "integrity": "sha512-zjaXglF5nnWpsq470jSv6P9DwPvgLkuapYmfDm3JWOm0vkNTVF2tI4UrN2r6jH1qM/uc/WtxYY1hYoA2dOKj5w==", + "dev": true, + "requires": { + "has-flag": "^3.0.0" + } + }, + "wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", + "dev": true + } + } +} diff --git a/packages/adapter-tests/package.json b/packages/adapter-tests/package.json new file mode 100644 index 0000000000..dcbf90eeed --- /dev/null +++ b/packages/adapter-tests/package.json @@ -0,0 +1,42 @@ +{ + "name": "@feathersjs/adapter-tests", + "version": "0.0.0", + "description": "Feathers shared database adapter test suite", + "homepage": "https://feathersjs.com", + "keywords": [ + "feathers" + ], + "license": "MIT", + "repository": { + "type": "git", + "url": "git://github.com/feathersjs/feathers.git" + }, + "author": { + "name": "Feathers contributor", + "email": "hello@feathersjs.com", + "url": "https://feathersjs.com" + }, + "contributors": [], + "bugs": { + "url": "https://github.com/feathersjs/feathers/issues" + }, + "engines": { + "node": ">= 8" + }, + "main": "lib/index.js", + "scripts": { + "test": "mocha --opts ../../mocha.opts" + }, + "directories": { + "lib": "lib" + }, + "publishConfig": { + "access": "public" + }, + "devDependencies": { + "@feathersjs/feathers": "^3.3.1", + "@feathersjs/errors": "^3.3.6", + "feathers-memory": "^3.0.1", + "mocha": "^5.2.0" + } +} diff --git a/packages/adapter-tests/test/index.test.js b/packages/adapter-tests/test/index.test.js new file mode 100644 index 0000000000..df5aa7f56b --- /dev/null +++ b/packages/adapter-tests/test/index.test.js @@ -0,0 +1,76 @@ +const memory = require('feathers-memory'); +const errors = require('@feathersjs/errors'); +const feathers = require('@feathersjs/feathers'); + +const adapterTests = require('../lib'); +const testSuite = adapterTests([ + '.events', + '._get', + '._find', + '._create', + '._update', + '._patch', + '._remove', + '.get', + '.get + $select', + '.get + id + query', + '.get + NotFound', + '.find', + '.remove', + '.remove + $select', + '.remove + id + query', + '.remove + multi', + '.update', + '.update + $select', + '.update + id + query', + '.update + NotFound', + '.patch', + '.patch + $select', + '.patch + id + query', + '.patch multiple', + '.patch multi query', + '.patch + NotFound', + '.create', + '.create + $select', + '.create multi', + 'internal .find', + 'internal .get', + 'internal .create', + 'internal .update', + 'internal .patch', + 'internal .remove', + '.find + equal', + '.find + equal multiple', + '.find + $sort', + '.find + $sort + string', + '.find + $limit', + '.find + $limit 0', + '.find + $skip', + '.find + $select', + '.find + $or', + '.find + $in', + '.find + $nin', + '.find + $lt', + '.find + $lte', + '.find + $gt', + '.find + $gte', + '.find + $ne', + '.find + $gt + $lt + $sort', + '.find + $or nested + $sort', + '.find + paginate', + '.find + paginate + $limit + $skip', + '.find + paginate + $limit 0', + '.find + paginate + params' +]); + +describe('Feathers Memory Service', () => { + const events = [ 'testing' ]; + const app = feathers() + .use('/people', memory({ events })) + .use('/people-customid', memory({ + id: 'customid', events + })); + + testSuite(app, errors, 'people'); + testSuite(app, errors, 'people-customid', 'customid'); +});