From 4653577e2052d551449c8674088e912b901787dd Mon Sep 17 00:00:00 2001 From: joelchu Date: Wed, 4 Mar 2020 09:36:44 +0800 Subject: [PATCH 1/6] small update and mark the todos --- packages/resolver/package.json | 33 +++--- .../src/client/validate-client-config.js | 8 +- packages/resolver/src/handle-auth-methods.js | 15 +-- packages/resolver/src/search-resolvers.js | 14 +-- packages/resolver/src/validate-and-call.js | 4 +- .../fixtures/contract/another/contract.json | 104 ----------------- .../contract/another/public-contract.json | 108 ------------------ .../tests/fixtures/contract/contract.json | 104 ----------------- .../tests/fixtures/contract/es/contract.json | 48 -------- packages/ws-server-core/package.json | 6 +- 10 files changed, 35 insertions(+), 409 deletions(-) delete mode 100644 packages/resolver/tests/fixtures/contract/another/contract.json delete mode 100644 packages/resolver/tests/fixtures/contract/another/public-contract.json delete mode 100644 packages/resolver/tests/fixtures/contract/contract.json delete mode 100644 packages/resolver/tests/fixtures/contract/es/contract.json diff --git a/packages/resolver/package.json b/packages/resolver/package.json index f32d102d..a72a33e9 100644 --- a/packages/resolver/package.json +++ b/packages/resolver/package.json @@ -1,6 +1,6 @@ { "name": "jsonql-resolver", - "version": "1.0.9", + "version": "1.1.0", "description": "This is NOT for general use, please do not install it directly. This module is part of the jsonql tools supporting modules.", "main": "index.js", "files": [ @@ -8,12 +8,12 @@ "index.js" ], "scripts": { - "test": "ava --verbose", + "test": "ava", "prepare": "npm run test", - "test:base": "DEBUG=jsonql* ava --verbose ./tests/base.test.js", - "test:clients": "DEBUG=jsonql* ava --verbose ./tests/clients.test.js", - "test:throw": "DEBUG=jsonql-resolver* ava --verbose ./tests/throw.test.js", - "test:es": "DEBUG=jsonql-resolver* ava --verbose ./tests/es.test.js", + "test:base": "DEBUG=jsonql* ava ./tests/base.test.js", + "test:clients": "DEBUG=jsonql* ava ./tests/clients.test.js", + "test:throw": "DEBUG=jsonql-resolver* ava ./tests/throw.test.js", + "test:es": "DEBUG=jsonql-resolver* ava ./tests/es.test.js", "contract": "DEBUG=jsonql-contract* jsonql-contract create ./tests/fixtures/resolvers ./tests/fixtures/contract" }, "keywords": [ @@ -31,33 +31,30 @@ "jsonql-constants": "^1.8.14", "jsonql-errors": "^1.1.10", "jsonql-jwt": "^1.3.8", - "jsonql-node-client": "^1.2.10", + "jsonql-node-client": "^1.3.0", "jsonql-params-validator": "^1.5.2", "jsonql-utils": "^0.9.7", "lodash.merge": "^4.6.2" }, "devDependencies": { - "ava": "^2.4.0", - "jsonql-contract": "^1.8.6", - "jsonql-koa": "^1.5.6", - "server-io-core": "^1.2.0" + "ava": "^3.5.0", + "jsonql-contract": "^1.8.7", + "jsonql-koa": "^1.6.2", + "server-io-core": "^1.3.1" }, "ava": { "files": [ - "tests/**/*.test.js", - "!tests/fixtures/**/*.*" + "tests/**/*.test.js" ], - "sources": [ - "**/*.{js,jsx}", - "!dist/**/*" + "ignoredByWatcher": [ + "tests/fixtures/**/*.*" ], "cache": true, "concurrency": 5, "failFast": true, "failWithoutAssertions": false, "tap": false, - "verbose": true, - "compileEnhancements": false + "verbose": true }, "engine": { "node": ">=8" diff --git a/packages/resolver/src/client/validate-client-config.js b/packages/resolver/src/client/validate-client-config.js index 1558d217..7328431e 100644 --- a/packages/resolver/src/client/validate-client-config.js +++ b/packages/resolver/src/client/validate-client-config.js @@ -9,9 +9,9 @@ const debug = getDebug('validate-client-config') * @return {object|boolean} false when there is none, with additional properties */ const validateClientConfig = function(config) { - const ctn = config.clientConfig ? config.clientConfig.length : 0; + const ctn = config.clientConfig ? config.clientConfig.length : 0 // take the contractDir from the main - const contractDir = config.contractDir; + const contractDir = config.contractDir if (ctn) { let names = [] let clients = [] @@ -33,9 +33,9 @@ const validateClientConfig = function(config) { // push it back to the config clients.push(client) } - return clients; + return clients } - return false; + return false } module.exports = { validateClientConfig } diff --git a/packages/resolver/src/handle-auth-methods.js b/packages/resolver/src/handle-auth-methods.js index a451ac43..b897a9e5 100644 --- a/packages/resolver/src/handle-auth-methods.js +++ b/packages/resolver/src/handle-auth-methods.js @@ -1,16 +1,11 @@ // Auth methods handler const { - QUERY_NAME, - MUTATION_NAME, AUTH_TYPE, - LOGOUT_NAME, - ISSUER_NAME, QUERY_ARG_NAME, UNAUTHORIZED_STATUS } = require('jsonql-constants') const { JsonqlResolverNotFoundError, - JsonqlResolverAppError, JsonqlValidationError, JsonqlAuthorisationError, getErrorNameByInstance, @@ -31,10 +26,10 @@ const debug = getDebug('public-method-middleware') * @return {function} the correct handler */ const getLocalValidator = (config, contract) => { - const { validatorHandlerName } = config; + const { validatorHandlerName } = config // if you explicitly set it to false then it will be ignore if (!validatorHandlerName) { - return false; + return false } // @BUG when this searchResolvers throw error the next call can not use instanceof to check the Error? // @TODO there is no need to pass the type here, it will always be the AUTH_TYPE @@ -46,14 +41,16 @@ const getLocalValidator = (config, contract) => { * This is move from the auth middleware to handle the ISSUER_NAME and LOGOUT_NAME * They both are always publicly available * @param {object} ctx koa context - * @param {string} resolverName to call + * @param {string} resolverName to call --> TODO remove this? * @param {object} payload it send * @param {object} opts configuration * @param {object} contract to match against */ const handleAuthMethods = async function(ctx, resolverName, payload, opts, contract) { try { - const { loginHandlerName } = opts; + const { loginHandlerName } = opts + // @1.1.0 @TODO the resolverName can overwrite the stock name ? + // @TODO look at how to deal with the OAuth validation // @TODO here we intercept the result and add extra output if the useJwt is enabled const issuerFnPath = searchResolvers(loginHandlerName, AUTH_TYPE, opts, contract) const issuerFn = require(issuerFnPath) diff --git a/packages/resolver/src/search-resolvers.js b/packages/resolver/src/search-resolvers.js index 8f1221dd..777bfe37 100644 --- a/packages/resolver/src/search-resolvers.js +++ b/packages/resolver/src/search-resolvers.js @@ -8,7 +8,7 @@ const { DEFAULT_RESOLVER_IMPORT_FILE_NAME } = require('jsonql-constants') const { getDebug } = require('./utils') const debug = getDebug('search-resolvers') -const prod = process.env.NODE_ENV === 'production'; +const prod = process.env.NODE_ENV === 'production' /** * @TODO we might have to change to the contract folder instead @@ -42,14 +42,14 @@ function requireEsModule(pathToResolver) { if (typeof obj === 'function') { return obj; } else if (obj.default && typeof obj.default === 'function') { - return obj.default; + return obj.default } throw new JsonqlError(`Unable to import ES module!`) } catch (e) { throw new JsonqlError(e) } finally { - // reset the require here? - require = oldRequire; // reset + // reset the require here + require = oldRequire } } @@ -66,18 +66,18 @@ function requireEsModule(pathToResolver) { */ function searchResolvers(name, type, opts, contract) { try { - const json = typeof contract === 'string' ? JSON.parse(contract) : contract; + const json = typeof contract === 'string' ? JSON.parse(contract) : contract let pathToResolver; pathToResolver = findFromContract(type, name, json) if (pathToResolver !== false) { - return pathToResolver; + return pathToResolver } debug(`pathToResolver not found in contract`, type, name, json) // search by running pathToResolver = getPathToFn(name, type, opts) if (pathToResolver) { - return pathToResolver; + return pathToResolver } const debugMsg = `${name} not found! [${opts.name}]` diff --git a/packages/resolver/src/validate-and-call.js b/packages/resolver/src/validate-and-call.js index 32b7f155..69172a98 100644 --- a/packages/resolver/src/validate-and-call.js +++ b/packages/resolver/src/validate-and-call.js @@ -22,8 +22,8 @@ const getEncodeJwtMethod = opts => { if (resultMethod && typeof resultMethod === 'function') { return resultMethod; } - let key = isString(opts.useJwt) ? opts.useJwt : opts.privateKey; - let alg = isString(opts.useJwt) ? HSA_ALGO : RSA_ALGO; + let key = isString(opts.useJwt) ? opts.useJwt : opts.privateKey + let alg = isString(opts.useJwt) ? HSA_ALGO : RSA_ALGO // add jwtTokenOption for the extra configuration for generate token return loginResultToJwt(key, opts.jwtTokenOption, alg) } diff --git a/packages/resolver/tests/fixtures/contract/another/contract.json b/packages/resolver/tests/fixtures/contract/another/contract.json deleted file mode 100644 index f5c77d02..00000000 --- a/packages/resolver/tests/fixtures/contract/another/contract.json +++ /dev/null @@ -1,104 +0,0 @@ -{ - "query": { - "anotherService": { - "file": "/home/joel/projects/open-source/jsonql/packages/resolver/tests/fixtures/resolvers/query/another-service.js", - "description": false, - "params": [ - { - "type": [ - "string" - ], - "name": "msg", - "description": "input" - } - ], - "returns": [ - { - "type": [ - "string" - ], - "description": "msg output" - } - ] - }, - "callMsService": { - "file": "/home/joel/projects/open-source/jsonql/packages/resolver/tests/fixtures/resolvers/query/call-ms-service.js", - "description": "pass a txt value then process else where", - "params": [ - { - "type": [ - "string" - ], - "name": "txt" - } - ], - "returns": [ - { - "type": [ - "string" - ], - "description": "transformted txt" - } - ] - }, - "fakeLogin": { - "file": "/home/joel/projects/open-source/jsonql/packages/resolver/tests/fixtures/resolvers/query/fake-login.js", - "description": "Fake the login and throw a JsonqlAuthorisationError error to see if it catches it", - "params": [ - { - "type": [ - "string" - ], - "name": "name", - "description": "username" - } - ], - "returns": [ - { - "type": [ - "object" - ], - "description": "userdata" - } - ] - }, - "getSomething": { - "file": "/home/joel/projects/open-source/jsonql/packages/resolver/tests/fixtures/resolvers/query/get-something.js", - "description": false, - "params": [ - { - "type": [ - "string" - ], - "name": "name", - "description": "pass a name" - } - ], - "returns": [ - { - "type": [ - "string" - ], - "description": "name with prefix" - } - ] - }, - "toFail": { - "file": "/home/joel/projects/open-source/jsonql/packages/resolver/tests/fixtures/resolvers/query/to-fail.js", - "description": "This resolver will fail and throw an error", - "params": [], - "returns": [ - { - "type": [ - "any" - ], - "description": "a variable that didn't exist" - } - ] - } - }, - "mutation": {}, - "auth": {}, - "timestamp": 1576129069, - "sourceType": "script" -} diff --git a/packages/resolver/tests/fixtures/contract/another/public-contract.json b/packages/resolver/tests/fixtures/contract/another/public-contract.json deleted file mode 100644 index baace634..00000000 --- a/packages/resolver/tests/fixtures/contract/another/public-contract.json +++ /dev/null @@ -1,108 +0,0 @@ -{ - "query": { - "helloWorld": { - "description": "This is the stock resolver for testing purpose", - "params": [], - "returns": [ - { - "type": "string", - "description": "stock message" - } - ] - }, - "anotherService": { - "description": false, - "params": [ - { - "type": [ - "string" - ], - "name": "msg", - "description": "input" - } - ], - "returns": [ - { - "type": [ - "string" - ], - "description": "msg output" - } - ] - }, - "callMsService": { - "description": "pass a txt value then process else where", - "params": [ - { - "type": [ - "string" - ], - "name": "txt" - } - ], - "returns": [ - { - "type": [ - "string" - ], - "description": "transformted txt" - } - ] - }, - "fakeLogin": { - "description": "Fake the login and throw a JsonqlAuthorisationError error to see if it catches it", - "params": [ - { - "type": [ - "string" - ], - "name": "name", - "description": "username" - } - ], - "returns": [ - { - "type": [ - "object" - ], - "description": "userdata" - } - ] - }, - "getSomething": { - "description": false, - "params": [ - { - "type": [ - "string" - ], - "name": "name", - "description": "pass a name" - } - ], - "returns": [ - { - "type": [ - "string" - ], - "description": "name with prefix" - } - ] - }, - "toFail": { - "description": "This resolver will fail and throw an error", - "params": [], - "returns": [ - { - "type": [ - "any" - ], - "description": "a variable that didn't exist" - } - ] - } - }, - "mutation": {}, - "auth": {}, - "timestamp": 1576129069 -} diff --git a/packages/resolver/tests/fixtures/contract/contract.json b/packages/resolver/tests/fixtures/contract/contract.json deleted file mode 100644 index 83a1e58a..00000000 --- a/packages/resolver/tests/fixtures/contract/contract.json +++ /dev/null @@ -1,104 +0,0 @@ -{ - "query": { - "anotherService": { - "file": "/home/joel/projects/open-source/jsonql/packages/resolver/tests/fixtures/resolvers/query/another-service.js", - "description": false, - "params": [ - { - "type": [ - "string" - ], - "name": "msg", - "description": "input" - } - ], - "returns": [ - { - "type": [ - "string" - ], - "description": "msg output" - } - ] - }, - "callMsService": { - "file": "/home/joel/projects/open-source/jsonql/packages/resolver/tests/fixtures/resolvers/query/call-ms-service.js", - "description": "pass a txt value then process else where", - "params": [ - { - "type": [ - "string" - ], - "name": "txt" - } - ], - "returns": [ - { - "type": [ - "string" - ], - "description": "transformted txt" - } - ] - }, - "fakeLogin": { - "file": "/home/joel/projects/open-source/jsonql/packages/resolver/tests/fixtures/resolvers/query/fake-login.js", - "description": "Fake the login and throw a JsonqlAuthorisationError error to see if it catches it", - "params": [ - { - "type": [ - "string" - ], - "name": "name", - "description": "username" - } - ], - "returns": [ - { - "type": [ - "object" - ], - "description": "userdata" - } - ] - }, - "getSomething": { - "file": "/home/joel/projects/open-source/jsonql/packages/resolver/tests/fixtures/resolvers/query/get-something.js", - "description": false, - "params": [ - { - "type": [ - "string" - ], - "name": "name", - "description": "pass a name" - } - ], - "returns": [ - { - "type": [ - "string" - ], - "description": "name with prefix" - } - ] - }, - "toFail": { - "file": "/home/joel/projects/open-source/jsonql/packages/resolver/tests/fixtures/resolvers/query/to-fail.js", - "description": "This resolver will fail and throw an error", - "params": [], - "returns": [ - { - "type": [ - "any" - ], - "description": "a variable that didn't exist" - } - ] - } - }, - "mutation": {}, - "auth": {}, - "timestamp": 1576128195, - "sourceType": "script" -} diff --git a/packages/resolver/tests/fixtures/contract/es/contract.json b/packages/resolver/tests/fixtures/contract/es/contract.json deleted file mode 100644 index b175add3..00000000 --- a/packages/resolver/tests/fixtures/contract/es/contract.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "query": { - "getSomething": { - "file": "/home/joel/projects/open-source/jsonql/packages/resolver/tests/fixtures/es/query/get-something.js", - "description": false, - "params": [], - "returns": [ - { - "type": [ - "array" - ], - "description": "list of something" - } - ] - } - }, - "mutation": { - "saveSomething": { - "file": "/home/joel/projects/open-source/jsonql/packages/resolver/tests/fixtures/es/mutation/save-something.js", - "description": false, - "params": [ - { - "type": [ - "object" - ], - "name": "payload" - }, - { - "type": [ - "object" - ], - "name": "condition" - } - ], - "returns": [ - { - "type": [ - "boolean" - ], - "description": "true on OK" - } - ] - } - }, - "auth": {}, - "timestamp": 1577247858, - "sourceType": "module" -} diff --git a/packages/ws-server-core/package.json b/packages/ws-server-core/package.json index cd04cd76..9ca73e86 100644 --- a/packages/ws-server-core/package.json +++ b/packages/ws-server-core/package.json @@ -1,6 +1,6 @@ { "name": "jsonql-ws-server-core", - "version": "0.4.1", + "version": "0.4.2", "description": "This is the core module that drive the Jsonql WS Socket server, not for direct use.", "main": "index.js", "files": [ @@ -59,10 +59,6 @@ "engine": { "node": ">=8" }, - "optionalDependencies": { - "bufferutil": "^4.0.1", - "utf-8-validate": "^5.0.2" - }, "repository": { "type": "git", "url": "git+ssh://git@gitee.com:to1source/jsonql.git" -- Gitee From 5593af8f0aebd8aed39d767f01c587eb955748e0 Mon Sep 17 00:00:00 2001 From: joelchu Date: Wed, 4 Mar 2020 09:40:57 +0800 Subject: [PATCH 2/6] start the test again --- packages/resolver/tests/base.test.js | 2 +- packages/resolver/tests/clients.test.js | 4 +- .../resolver/tests/fixtures/another-server.js | 2 +- .../fixtures/contract/another/contract.json | 104 +++++++++++++++++ .../contract/another/public-contract.json | 108 ++++++++++++++++++ .../tests/fixtures/contract/es/contract.json | 48 ++++++++ packages/resolver/tests/fixtures/rm.js | 6 +- packages/resolver/tests/throw.test.js | 4 +- 8 files changed, 269 insertions(+), 9 deletions(-) create mode 100644 packages/resolver/tests/fixtures/contract/another/contract.json create mode 100644 packages/resolver/tests/fixtures/contract/another/public-contract.json create mode 100644 packages/resolver/tests/fixtures/contract/es/contract.json diff --git a/packages/resolver/tests/base.test.js b/packages/resolver/tests/base.test.js index f48d1842..6b0757b7 100644 --- a/packages/resolver/tests/base.test.js +++ b/packages/resolver/tests/base.test.js @@ -16,7 +16,7 @@ test.before(async t => { }) test(`It should able to call a resolver`, async t => { - const resolverName = 'getSomething'; + const resolverName = 'getSomething' const payload = createQuery(resolverName, ['Joel']) const result = await executeResolver( diff --git a/packages/resolver/tests/clients.test.js b/packages/resolver/tests/clients.test.js index d5c8d675..0be5b949 100644 --- a/packages/resolver/tests/clients.test.js +++ b/packages/resolver/tests/clients.test.js @@ -1,8 +1,8 @@ // this is for testing the inject client const test = require('ava') const { join } = require('path') -const nodeClient = require('jsonql-node-client') -const debug = require('debug')('jsonql-resolver:test:clients') +// const nodeClient = require('jsonql-node-client') +// const debug = require('debug')('jsonql-resolver:test:clients') const anotherServer = require('./fixtures/another-server') const { executeResolver } = require('../') const readJson = require('./fixtures/read-json') diff --git a/packages/resolver/tests/fixtures/another-server.js b/packages/resolver/tests/fixtures/another-server.js index 13b109c8..cc08309f 100644 --- a/packages/resolver/tests/fixtures/another-server.js +++ b/packages/resolver/tests/fixtures/another-server.js @@ -1,7 +1,7 @@ // this is the ms run on 8001 const serverIoCore = require('server-io-core') -const { jsonqlKoa } = require('../../../koa') +const { jsonqlKoa } = require('jsonql-koa') const { join } = require('path') // export the return for use later module.exports = () => serverIoCore({ diff --git a/packages/resolver/tests/fixtures/contract/another/contract.json b/packages/resolver/tests/fixtures/contract/another/contract.json new file mode 100644 index 00000000..15710be9 --- /dev/null +++ b/packages/resolver/tests/fixtures/contract/another/contract.json @@ -0,0 +1,104 @@ +{ + "query": { + "anotherService": { + "file": "/home/joel/projects/open-source/jsonql/packages/resolver/tests/fixtures/resolvers/query/another-service.js", + "description": false, + "params": [ + { + "type": [ + "string" + ], + "name": "msg", + "description": "input" + } + ], + "returns": [ + { + "type": [ + "string" + ], + "description": "msg output" + } + ] + }, + "callMsService": { + "file": "/home/joel/projects/open-source/jsonql/packages/resolver/tests/fixtures/resolvers/query/call-ms-service.js", + "description": "pass a txt value then process else where", + "params": [ + { + "type": [ + "string" + ], + "name": "txt" + } + ], + "returns": [ + { + "type": [ + "string" + ], + "description": "transformted txt" + } + ] + }, + "fakeLogin": { + "file": "/home/joel/projects/open-source/jsonql/packages/resolver/tests/fixtures/resolvers/query/fake-login.js", + "description": "Fake the login and throw a JsonqlAuthorisationError error to see if it catches it", + "params": [ + { + "type": [ + "string" + ], + "name": "name", + "description": "username" + } + ], + "returns": [ + { + "type": [ + "object" + ], + "description": "userdata" + } + ] + }, + "getSomething": { + "file": "/home/joel/projects/open-source/jsonql/packages/resolver/tests/fixtures/resolvers/query/get-something.js", + "description": false, + "params": [ + { + "type": [ + "string" + ], + "name": "name", + "description": "pass a name" + } + ], + "returns": [ + { + "type": [ + "string" + ], + "description": "name with prefix" + } + ] + }, + "toFail": { + "file": "/home/joel/projects/open-source/jsonql/packages/resolver/tests/fixtures/resolvers/query/to-fail.js", + "description": "This resolver will fail and throw an error", + "params": [], + "returns": [ + { + "type": [ + "any" + ], + "description": "a variable that didn't exist" + } + ] + } + }, + "mutation": {}, + "auth": {}, + "timestamp": 1583285808, + "sourceType": "script" +} diff --git a/packages/resolver/tests/fixtures/contract/another/public-contract.json b/packages/resolver/tests/fixtures/contract/another/public-contract.json new file mode 100644 index 00000000..41057d67 --- /dev/null +++ b/packages/resolver/tests/fixtures/contract/another/public-contract.json @@ -0,0 +1,108 @@ +{ + "query": { + "helloWorld": { + "description": "This is the stock resolver for testing purpose", + "params": [], + "returns": [ + { + "type": "string", + "description": "stock message" + } + ] + }, + "anotherService": { + "description": false, + "params": [ + { + "type": [ + "string" + ], + "name": "msg", + "description": "input" + } + ], + "returns": [ + { + "type": [ + "string" + ], + "description": "msg output" + } + ] + }, + "callMsService": { + "description": "pass a txt value then process else where", + "params": [ + { + "type": [ + "string" + ], + "name": "txt" + } + ], + "returns": [ + { + "type": [ + "string" + ], + "description": "transformted txt" + } + ] + }, + "fakeLogin": { + "description": "Fake the login and throw a JsonqlAuthorisationError error to see if it catches it", + "params": [ + { + "type": [ + "string" + ], + "name": "name", + "description": "username" + } + ], + "returns": [ + { + "type": [ + "object" + ], + "description": "userdata" + } + ] + }, + "getSomething": { + "description": false, + "params": [ + { + "type": [ + "string" + ], + "name": "name", + "description": "pass a name" + } + ], + "returns": [ + { + "type": [ + "string" + ], + "description": "name with prefix" + } + ] + }, + "toFail": { + "description": "This resolver will fail and throw an error", + "params": [], + "returns": [ + { + "type": [ + "any" + ], + "description": "a variable that didn't exist" + } + ] + } + }, + "mutation": {}, + "auth": {}, + "timestamp": 1583285808 +} diff --git a/packages/resolver/tests/fixtures/contract/es/contract.json b/packages/resolver/tests/fixtures/contract/es/contract.json new file mode 100644 index 00000000..dca962e5 --- /dev/null +++ b/packages/resolver/tests/fixtures/contract/es/contract.json @@ -0,0 +1,48 @@ +{ + "query": { + "getSomething": { + "file": "/home/joel/projects/open-source/jsonql/packages/resolver/tests/fixtures/es/query/get-something.js", + "description": false, + "params": [], + "returns": [ + { + "type": [ + "array" + ], + "description": "list of something" + } + ] + } + }, + "mutation": { + "saveSomething": { + "file": "/home/joel/projects/open-source/jsonql/packages/resolver/tests/fixtures/es/mutation/save-something.js", + "description": false, + "params": [ + { + "type": [ + "object" + ], + "name": "payload" + }, + { + "type": [ + "object" + ], + "name": "condition" + } + ], + "returns": [ + { + "type": [ + "boolean" + ], + "description": "true on OK" + } + ] + } + }, + "auth": {}, + "timestamp": 1583285807, + "sourceType": "module" +} diff --git a/packages/resolver/tests/fixtures/rm.js b/packages/resolver/tests/fixtures/rm.js index f5429816..f94f2b41 100644 --- a/packages/resolver/tests/fixtures/rm.js +++ b/packages/resolver/tests/fixtures/rm.js @@ -20,13 +20,13 @@ exports.rmdirs = async function rmdirs(dir) { exports.rmdirs = async function rmdirs(dir) { let entries = await readdir(dir, { withFileTypes: true }); let results = await Promise.all(entries.map(entry => { - let fullPath = path.join(dir, entry.name); + let fullPath = path.join(dir, entry.name) let task = entry.isDirectory() ? rmdirs(fullPath) : unlink(fullPath) return task.catch(error => ({ error })) })); results.forEach(result => { // Ignore missing files/directories; bail on other errors - if (result && result.error.code !== 'ENOENT') throw result.error; - }); + if (result && result.error.code !== 'ENOENT') throw result.error + }) await rmdir(dir) } diff --git a/packages/resolver/tests/throw.test.js b/packages/resolver/tests/throw.test.js index fa7c26a7..9f0a9ed7 100644 --- a/packages/resolver/tests/throw.test.js +++ b/packages/resolver/tests/throw.test.js @@ -6,8 +6,8 @@ const { JsonqlAuthorisationError, JsonqlValidationError, JsonqlResolverAppError, - getErrorNameByInstance, - UNKNOWN_ERROR + getErrorNameByInstance + // UNKNOWN_ERROR } = require('jsonql-errors') const { join } = require('path') -- Gitee From d9a09e51530a0913afd3462c9da1f425288439bf Mon Sep 17 00:00:00 2001 From: joelchu Date: Wed, 4 Mar 2020 09:49:16 +0800 Subject: [PATCH 3/6] regenerate the contract for test --- .../resolver/tests/fixtures/another-server.js | 1 - .../tests/fixtures/contract/contract.json | 104 ++++++++++++++++++ 2 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 packages/resolver/tests/fixtures/contract/contract.json diff --git a/packages/resolver/tests/fixtures/another-server.js b/packages/resolver/tests/fixtures/another-server.js index cc08309f..82b3e906 100644 --- a/packages/resolver/tests/fixtures/another-server.js +++ b/packages/resolver/tests/fixtures/another-server.js @@ -1,5 +1,4 @@ // this is the ms run on 8001 - const serverIoCore = require('server-io-core') const { jsonqlKoa } = require('jsonql-koa') const { join } = require('path') diff --git a/packages/resolver/tests/fixtures/contract/contract.json b/packages/resolver/tests/fixtures/contract/contract.json new file mode 100644 index 00000000..bcc5f3db --- /dev/null +++ b/packages/resolver/tests/fixtures/contract/contract.json @@ -0,0 +1,104 @@ +{ + "query": { + "anotherService": { + "file": "/home/joel/projects/open-source/jsonql/packages/resolver/tests/fixtures/resolvers/query/another-service.js", + "description": false, + "params": [ + { + "type": [ + "string" + ], + "name": "msg", + "description": "input" + } + ], + "returns": [ + { + "type": [ + "string" + ], + "description": "msg output" + } + ] + }, + "callMsService": { + "file": "/home/joel/projects/open-source/jsonql/packages/resolver/tests/fixtures/resolvers/query/call-ms-service.js", + "description": "pass a txt value then process else where", + "params": [ + { + "type": [ + "string" + ], + "name": "txt" + } + ], + "returns": [ + { + "type": [ + "string" + ], + "description": "transformted txt" + } + ] + }, + "fakeLogin": { + "file": "/home/joel/projects/open-source/jsonql/packages/resolver/tests/fixtures/resolvers/query/fake-login.js", + "description": "Fake the login and throw a JsonqlAuthorisationError error to see if it catches it", + "params": [ + { + "type": [ + "string" + ], + "name": "name", + "description": "username" + } + ], + "returns": [ + { + "type": [ + "object" + ], + "description": "userdata" + } + ] + }, + "getSomething": { + "file": "/home/joel/projects/open-source/jsonql/packages/resolver/tests/fixtures/resolvers/query/get-something.js", + "description": false, + "params": [ + { + "type": [ + "string" + ], + "name": "name", + "description": "pass a name" + } + ], + "returns": [ + { + "type": [ + "string" + ], + "description": "name with prefix" + } + ] + }, + "toFail": { + "file": "/home/joel/projects/open-source/jsonql/packages/resolver/tests/fixtures/resolvers/query/to-fail.js", + "description": "This resolver will fail and throw an error", + "params": [], + "returns": [ + { + "type": [ + "any" + ], + "description": "a variable that didn't exist" + } + ] + } + }, + "mutation": {}, + "auth": {}, + "timestamp": 1583286535, + "sourceType": "script" +} -- Gitee From 693a11551b39efcabb55ec2da55262fb3603c5c6 Mon Sep 17 00:00:00 2001 From: joelchu Date: Wed, 4 Mar 2020 10:01:47 +0800 Subject: [PATCH 4/6] verify all test passed --- packages/resolver/tests/es.test.js | 2 +- .../resolver/tests/fixtures/contract/es/contract.json | 2 +- packages/resolver/tests/fixtures/es/import.js | 2 -- packages/resolver/tests/fixtures/es/resolver.js | 7 ------- .../tests/fixtures/resolvers/query/call-ms-service.js | 2 +- .../resolver/tests/fixtures/resolvers/query/to-fail.js | 2 +- packages/resolver/tests/throw.test.js | 10 +++++----- 7 files changed, 9 insertions(+), 18 deletions(-) delete mode 100644 packages/resolver/tests/fixtures/es/import.js delete mode 100644 packages/resolver/tests/fixtures/es/resolver.js diff --git a/packages/resolver/tests/es.test.js b/packages/resolver/tests/es.test.js index 2602e859..de8da991 100644 --- a/packages/resolver/tests/es.test.js +++ b/packages/resolver/tests/es.test.js @@ -26,7 +26,7 @@ test.after(t => { // start testing test(`It should able to generate a contract for the es module`, t => { - const contract = t.context.contract; + const contract = t.context.contract debug(contract) diff --git a/packages/resolver/tests/fixtures/contract/es/contract.json b/packages/resolver/tests/fixtures/contract/es/contract.json index dca962e5..0aa8c14e 100644 --- a/packages/resolver/tests/fixtures/contract/es/contract.json +++ b/packages/resolver/tests/fixtures/contract/es/contract.json @@ -43,6 +43,6 @@ } }, "auth": {}, - "timestamp": 1583285807, + "timestamp": 1583287286, "sourceType": "module" } diff --git a/packages/resolver/tests/fixtures/es/import.js b/packages/resolver/tests/fixtures/es/import.js deleted file mode 100644 index 6601f782..00000000 --- a/packages/resolver/tests/fixtures/es/import.js +++ /dev/null @@ -1,2 +0,0 @@ -require = require("esm")(module/*, options*/) -module.exports = require("./resolver.js") diff --git a/packages/resolver/tests/fixtures/es/resolver.js b/packages/resolver/tests/fixtures/es/resolver.js deleted file mode 100644 index 9057792d..00000000 --- a/packages/resolver/tests/fixtures/es/resolver.js +++ /dev/null @@ -1,7 +0,0 @@ -import querygetSomething from './query/get-something.js' -import mutationsaveSomething from './mutation/save-something.js' - -export { - querygetSomething, -mutationsaveSomething -} \ No newline at end of file diff --git a/packages/resolver/tests/fixtures/resolvers/query/call-ms-service.js b/packages/resolver/tests/fixtures/resolvers/query/call-ms-service.js index c415c064..f8c9ba62 100644 --- a/packages/resolver/tests/fixtures/resolvers/query/call-ms-service.js +++ b/packages/resolver/tests/fixtures/resolvers/query/call-ms-service.js @@ -11,5 +11,5 @@ module.exports = async function callMsService(txt) { debug(client0) let txt0 = ['callMsService', txt].join(' ') - return await client0.query.anotherService(txt0) + return await client0.anotherService(txt0) } diff --git a/packages/resolver/tests/fixtures/resolvers/query/to-fail.js b/packages/resolver/tests/fixtures/resolvers/query/to-fail.js index 2a681edb..764800dd 100644 --- a/packages/resolver/tests/fixtures/resolvers/query/to-fail.js +++ b/packages/resolver/tests/fixtures/resolvers/query/to-fail.js @@ -3,5 +3,5 @@ * @return {*} a variable that didn't exist */ module.exports = function toFail() { - return varNotExisted; + return varNotExisted } diff --git a/packages/resolver/tests/throw.test.js b/packages/resolver/tests/throw.test.js index 9f0a9ed7..81efd8c0 100644 --- a/packages/resolver/tests/throw.test.js +++ b/packages/resolver/tests/throw.test.js @@ -53,7 +53,7 @@ test.cb(`When the resolver throw certain type of error, it should forward the sa test.cb(`When resolver throw error, it should able to throw back a JsonqlResolverAppError`, t => { t.plan(1) - const resolverName = 'toFail'; + const resolverName = 'toFail' const payload = createQuery(resolverName, []) executeResolver( @@ -85,8 +85,8 @@ test(`The getLocalValidator should throw a JsonqlResolverNotFoundError`, t => { return getLocalValidator({ validatorHandlerName: 'validator' }, t.context.contract) - }, JsonqlResolverNotFoundError, 'There is no validator and should throw error') - - // debug(error) - + }, /* JsonqlResolverNotFoundError*/ null, 'There is no validator and should throw error') + + // debug('', error) + t.is(error.className , 'JsonqlResolverNotFoundError') }) -- Gitee From ccad2c2c9e4f1a6d7570e8b865f01f1191c9d3a0 Mon Sep 17 00:00:00 2001 From: joelchu Date: Wed, 4 Mar 2020 10:02:02 +0800 Subject: [PATCH 5/6] update contract.json --- packages/resolver/tests/fixtures/contract/es/contract.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/resolver/tests/fixtures/contract/es/contract.json b/packages/resolver/tests/fixtures/contract/es/contract.json index 0aa8c14e..0f9bfc60 100644 --- a/packages/resolver/tests/fixtures/contract/es/contract.json +++ b/packages/resolver/tests/fixtures/contract/es/contract.json @@ -43,6 +43,6 @@ } }, "auth": {}, - "timestamp": 1583287286, + "timestamp": 1583287310, "sourceType": "module" } -- Gitee From ae148128e8be46e45e6848f74ee5b93ff2798d47 Mon Sep 17 00:00:00 2001 From: joelchu Date: Wed, 4 Mar 2020 10:02:42 +0800 Subject: [PATCH 6/6] jsonql-resolver to 1.1.0 --- packages/resolver/tests/fixtures/contract/es/contract.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/resolver/tests/fixtures/contract/es/contract.json b/packages/resolver/tests/fixtures/contract/es/contract.json index 0f9bfc60..c56d8ecf 100644 --- a/packages/resolver/tests/fixtures/contract/es/contract.json +++ b/packages/resolver/tests/fixtures/contract/es/contract.json @@ -43,6 +43,6 @@ } }, "auth": {}, - "timestamp": 1583287310, + "timestamp": 1583287348, "sourceType": "module" } -- Gitee