From 993d773b157fe6fbe86fdf69604706ed78d3aa6b Mon Sep 17 00:00:00 2001 From: Yoann Abbes Date: Wed, 20 May 2020 14:05:45 +0200 Subject: [PATCH 1/5] Fix query string construction --- .ci/doc/docker-compose.yml | 6 +++--- package.json | 7 ++++--- src/protocols/Http.js | 2 +- test/protocol/Http.test.js | 24 ++++++++++++++++++++++++ 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/.ci/doc/docker-compose.yml b/.ci/doc/docker-compose.yml index 4c77f6188..86019e68c 100644 --- a/.ci/doc/docker-compose.yml +++ b/.ci/doc/docker-compose.yml @@ -49,7 +49,7 @@ services: ash -c ' mkdir -p /var/snippets/node; apk add --no-cache curl; - npm install -g eslint; + npm install -g eslint@6.8.0; cd /var/snippets/node; npm install \ bluebird \ @@ -76,7 +76,7 @@ services: apt-get update; apt-get install -y curl; npm install -g \ - eslint; + eslint@6.8.0; cd /mnt; npm install; cd /var/snippets/web; @@ -105,7 +105,7 @@ services: apt-get update; apt-get install -y curl; npm install -g \ - eslint; + eslint@6.8.0; cd /var/snippets/webpack; cp /mnt/.ci/doc/puppeteer.js /var/snippets/webpack/; cp /mnt/.ci/doc/webpackBuild.js /var/snippets/webpack/; diff --git a/package.json b/package.json index cafb909b8..81720ea3e 100644 --- a/package.json +++ b/package.json @@ -20,9 +20,9 @@ "scripts": { "prepublishOnly": "npm run build", "test": "npm run --silent lint && npm run unit-testing && npm run functional-testing", - "unit-testing": "nyc --reporter=text-summary --reporter=lcov mocha", - "functional-testing": "cucumber-js --exit --fail-fast", - "lint": "eslint --max-warnings=0 ./src ./test ./features", + "test:unit": "nyc --reporter=text-summary --reporter=lcov mocha", + "test:functional": "cucumber-js --exit --fail-fast", + "test:lint": "eslint --max-warnings=0 ./src ./test ./features", "build": "node build.js", "doc": "docker-compose -f doc/docker-compose.yml up", "doc-testing": "bash .ci/test-docs.sh", @@ -50,6 +50,7 @@ "eslint": "^6.8.0", "eslint-friendly-formatter": "^4.0.1", "eslint-loader": "^4.0.0", + "eslint-plugin-import": "^2.20.2", "kuzdoc": "^1.2.2", "lolex": "^6.0.0", "mocha": "7.1.1", diff --git a/src/protocols/Http.js b/src/protocols/Http.js index b3b40e85a..e90da908b 100644 --- a/src/protocols/Http.js +++ b/src/protocols/Http.js @@ -226,7 +226,7 @@ class HttpProtocol extends BaseProtocol { } } else { - queryString.push(`${key}=${value}`); + queryString.push(`${key}=${typeof value === 'object' ? JSON.stringify(value) : value}`); } } diff --git a/test/protocol/Http.test.js b/test/protocol/Http.test.js index 067a6e8b7..bf91dbd57 100644 --- a/test/protocol/Http.test.js +++ b/test/protocol/Http.test.js @@ -321,6 +321,30 @@ describe('HTTP networking module', () => { protocol.send(data); }); + it('should inject the nested body object as querystring on a GET request', done => { + const data = { + requestId: 'requestId', + action: 'action', + controller: 'getreq', + body: { foo: { foofoo: { barbar: 'bar' } }, baz: ['oh', 'an', 'array'] } + }; + + protocol.on('requestId', () => { + try { + should(protocol._sendHttpRequest).be.calledOnce(); + should(protocol._sendHttpRequest.firstCall.args[0]).be.equal('GET'); + should(protocol._sendHttpRequest.firstCall.args[1]) + .be.equal('/foo?foo={"foofoo":{"barbar":"bar"}}&baz=oh,an,array'); + done(); + } + catch (error) { + done(error); + } + }); + + protocol.send(data); + }); + it('should inject queryString to the HTTP request', done => { const data = { requestId: 'requestId', From 20f22aeaf3065bffd07024a6bbf32e99b0a1bfbb Mon Sep 17 00:00:00 2001 From: Yoann Abbes Date: Wed, 20 May 2020 14:25:27 +0200 Subject: [PATCH 2/5] update .travis.yml --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index c919ddfa9..766269287 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,8 +34,8 @@ jobs: - npm install script: - - npm run lint - - npm run unit-testing + - npm run test:lint + - npm run test:unit after_success: - cat ./coverage/lcov.info | ./node_modules/.bin/codecov @@ -65,7 +65,7 @@ jobs: - npm run build script: - - npm run functional-testing + - npm run test:functional - stage: Tests name: Documentation Tests From 5f36ecb33721ba19df1a4998f641e2585ebf98e5 Mon Sep 17 00:00:00 2001 From: Yoann Abbes Date: Wed, 20 May 2020 17:10:28 +0200 Subject: [PATCH 3/5] revert package.json change --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 81720ea3e..b4542688f 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,6 @@ "eslint": "^6.8.0", "eslint-friendly-formatter": "^4.0.1", "eslint-loader": "^4.0.0", - "eslint-plugin-import": "^2.20.2", "kuzdoc": "^1.2.2", "lolex": "^6.0.0", "mocha": "7.1.1", From d0e4513c2811b91b4fe7d8932f45fa55d02e6c74 Mon Sep 17 00:00:00 2001 From: Yoann Abbes Date: Fri, 22 May 2020 10:37:56 +0200 Subject: [PATCH 4/5] add refresh to deleteByQuery snippet --- .../document/delete-by-query/snippets/delete-by-query.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/7/controllers/document/delete-by-query/snippets/delete-by-query.js b/doc/7/controllers/document/delete-by-query/snippets/delete-by-query.js index ad36861b6..4a105b653 100644 --- a/doc/7/controllers/document/delete-by-query/snippets/delete-by-query.js +++ b/doc/7/controllers/document/delete-by-query/snippets/delete-by-query.js @@ -6,7 +6,8 @@ try { query: { term: { capacity: 7 } } - } + }, + {refresh: 'wait_for'} ); console.log(`Successfully deleted ${deleted.length} documents`); From 68d6ea720f1d6e7a0e468080c4cbfc430f887b33 Mon Sep 17 00:00:00 2001 From: Yoann Abbes Date: Fri, 22 May 2020 10:50:00 +0200 Subject: [PATCH 5/5] refresh collection before deletebyquery --- .../document/delete-by-query/snippets/delete-by-query.js | 3 +-- .../document/delete-by-query/snippets/delete-by-query.test.yml | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/doc/7/controllers/document/delete-by-query/snippets/delete-by-query.js b/doc/7/controllers/document/delete-by-query/snippets/delete-by-query.js index 4a105b653..ad36861b6 100644 --- a/doc/7/controllers/document/delete-by-query/snippets/delete-by-query.js +++ b/doc/7/controllers/document/delete-by-query/snippets/delete-by-query.js @@ -6,8 +6,7 @@ try { query: { term: { capacity: 7 } } - }, - {refresh: 'wait_for'} + } ); console.log(`Successfully deleted ${deleted.length} documents`); diff --git a/doc/7/controllers/document/delete-by-query/snippets/delete-by-query.test.yml b/doc/7/controllers/document/delete-by-query/snippets/delete-by-query.test.yml index 89da56819..a95123d23 100644 --- a/doc/7/controllers/document/delete-by-query/snippets/delete-by-query.test.yml +++ b/doc/7/controllers/document/delete-by-query/snippets/delete-by-query.test.yml @@ -14,7 +14,7 @@ hooks: curl -H "Content-type: application/json" -d '{"capacity": 7}' kuzzle:7512/nyc-open-data/yellow-taxi/_create done - curl -XPOST kuzzle:7512/nyc-open-data/_refresh + curl -XPOST kuzzle:7512/nyc-open-data/yellow-taxi/_refresh after: template: default expected: Successfully deleted 5 documents