From 66b41a6ae70dca4f4de3b2822e168cb0cfea9900 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Tue, 5 Dec 2017 12:09:31 +0100 Subject: [PATCH] Now .getLayergroup() in test client accepts params to perform custom instantiations --- test/acceptance/aggregation.js | 4 +- test/acceptance/analysis/analysis-layers.js | 4 +- test/acceptance/analysis/error-cases.js | 16 +++--- test/acceptance/dataviews/error-cases.js | 4 +- .../ported/multilayer_error_cases.js | 2 +- test/acceptance/regressions.js | 2 +- test/acceptance/turbo-carto/error-cases.js | 12 ++--- test/acceptance/turbo-carto/regressions.js | 2 +- .../acceptance/user-database-timeout-limit.js | 28 +++++----- test/acceptance/user-render-timeout-limit.js | 5 +- test/acceptance/vector-layergroup.js | 2 +- test/support/test-client.js | 53 ++++++++++++++----- 12 files changed, 82 insertions(+), 52 deletions(-) diff --git a/test/acceptance/aggregation.js b/test/acceptance/aggregation.js index 3638ff0b..c278918a 100644 --- a/test/acceptance/aggregation.js +++ b/test/acceptance/aggregation.js @@ -146,7 +146,7 @@ describe('aggregation', function () { ]); this.testClient = new TestClient(this.mapConfig); - this.testClient.getLayergroup(response, (err, body) => { + this.testClient.getLayergroup({ response }, (err, body) => { if (err) { return done(err); } @@ -187,7 +187,7 @@ describe('aggregation', function () { ]); this.testClient = new TestClient(this.mapConfig); - this.testClient.getLayergroup(response, (err, body) => { + this.testClient.getLayergroup({ response }, (err, body) => { if (err) { return done(err); } diff --git a/test/acceptance/analysis/analysis-layers.js b/test/acceptance/analysis/analysis-layers.js index a745fb97..1eb3d4e6 100644 --- a/test/acceptance/analysis/analysis-layers.js +++ b/test/acceptance/analysis/analysis-layers.js @@ -174,7 +174,9 @@ describe('analysis-layers', function() { } }; - testClient.getLayergroup(PERMISSION_DENIED_RESPONSE, function(err, layergroupResult) { + + + testClient.getLayergroup({ response: PERMISSION_DENIED_RESPONSE }, function(err, layergroupResult) { assert.ok(!err, err); assert.deepEqual( layergroupResult.errors, diff --git a/test/acceptance/analysis/error-cases.js b/test/acceptance/analysis/error-cases.js index b79e1046..376d7606 100644 --- a/test/acceptance/analysis/error-cases.js +++ b/test/acceptance/analysis/error-cases.js @@ -62,7 +62,7 @@ describe('analysis-layers error cases', function() { var testClient = new TestClient(mapConfig, 1234); - testClient.getLayergroup(ERROR_RESPONSE, function(err, layergroupResult) { + testClient.getLayergroup({ response: ERROR_RESPONSE }, function(err, layergroupResult) { assert.ok(!err, err); assert.equal(layergroupResult.errors.length, 1); @@ -97,7 +97,7 @@ describe('analysis-layers error cases', function() { var testClient = new TestClient(mapConfig, 1234); - testClient.getLayergroup(ERROR_RESPONSE, function(err, layergroupResult) { + testClient.getLayergroup({ response: ERROR_RESPONSE }, function(err, layergroupResult) { assert.ok(!err, err); assert.equal(layergroupResult.errors.length, 1); @@ -144,7 +144,7 @@ describe('analysis-layers error cases', function() { var testClient = new TestClient(mapConfig, 1234); - testClient.getLayergroup(ERROR_RESPONSE, function(err, layergroupResult) { + testClient.getLayergroup({ response: ERROR_RESPONSE }, function(err, layergroupResult) { assert.ok(!err, err); assert.equal(layergroupResult.errors.length, 1); @@ -190,7 +190,7 @@ describe('analysis-layers error cases', function() { var testClient = new TestClient(mapConfig, 11111); - testClient.getLayergroup(AUTH_ERROR_RESPONSE, function(err, layergroupResult) { + testClient.getLayergroup({ response: AUTH_ERROR_RESPONSE }, function(err, layergroupResult) { assert.ok(!err, err); assert.equal(layergroupResult.errors.length, 1); @@ -246,7 +246,7 @@ describe('analysis-layers error cases', function() { var testClient = new TestClient(mapConfig, 1234); - testClient.getLayergroup(ERROR_RESPONSE, function(err, layergroupResult) { + testClient.getLayergroup({ response: ERROR_RESPONSE }, function(err, layergroupResult) { assert.ok(!err, err); assert.equal(layergroupResult.errors.length, 1); @@ -298,7 +298,7 @@ describe('analysis-layers error cases', function() { var testClient = new TestClient(mapConfig, 1234); - testClient.getLayergroup(ERROR_RESPONSE, function(err, layergroupResult) { + testClient.getLayergroup({ response: ERROR_RESPONSE }, function(err, layergroupResult) { assert.ok(!err, err); assert.equal(layergroupResult.errors.length, 1); @@ -351,7 +351,7 @@ describe('analysis-layers error cases', function() { var testClient = new TestClient(mapConfig, 1234); - testClient.getLayergroup(ERROR_RESPONSE, function(err, layergroupResult) { + testClient.getLayergroup({ response: ERROR_RESPONSE }, function(err, layergroupResult) { assert.ok(!err, err); assert.equal(layergroupResult.errors.length, 1); @@ -415,7 +415,7 @@ describe('analysis-layers error cases', function() { var testClient = new TestClient(mapConfig, 1234); - testClient.getLayergroup(ERROR_RESPONSE, function(err, layergroupResult) { + testClient.getLayergroup({ response: ERROR_RESPONSE }, function(err, layergroupResult) { assert.ok(!err, err); assert.equal(layergroupResult.errors.length, 1); diff --git a/test/acceptance/dataviews/error-cases.js b/test/acceptance/dataviews/error-cases.js index 7e37e8ee..3e6cc2a8 100644 --- a/test/acceptance/dataviews/error-cases.js +++ b/test/acceptance/dataviews/error-cases.js @@ -51,7 +51,7 @@ describe('histogram-dataview', function() { it('should fail when invalid dataviews object is provided, string case', function(done) { var mapConfig = createMapConfig("wadus-string"); this.testClient = new TestClient(mapConfig, 1234); - this.testClient.getLayergroup(ERROR_RESPONSE, function(err, errObj) { + this.testClient.getLayergroup({ response: ERROR_RESPONSE }, function(err, errObj) { assert.ok(!err, err); assert.deepEqual(errObj.errors, [ '"dataviews" must be a valid JSON object: "string" type found' ]); @@ -63,7 +63,7 @@ describe('histogram-dataview', function() { it('should fail when invalid dataviews object is provided, array case', function(done) { var mapConfig = createMapConfig([]); this.testClient = new TestClient(mapConfig, 1234); - this.testClient.getLayergroup(ERROR_RESPONSE, function(err, errObj) { + this.testClient.getLayergroup({ response: ERROR_RESPONSE }, function(err, errObj) { assert.ok(!err, err); assert.deepEqual(errObj.errors, [ '"dataviews" must be a valid JSON object: "array" type found' ]); diff --git a/test/acceptance/ported/multilayer_error_cases.js b/test/acceptance/ported/multilayer_error_cases.js index 9efd7c7b..6e7f5964 100644 --- a/test/acceptance/ported/multilayer_error_cases.js +++ b/test/acceptance/ported/multilayer_error_cases.js @@ -151,7 +151,7 @@ describe('multilayer error cases', function() { }; ServerOptions.afterLayergroupCreateCalls = 0; this.client = new TestClient(layergroup); - this.client.getLayergroup({status: 400}, function(err, parsed) { + this.client.getLayergroup({ response: { status: 400 } }, function(err, parsed) { assert.ok(!err, err); // See http://github.com/CartoDB/Windshaft/issues/159 assert.equal(ServerOptions.afterLayergroupCreateCalls, 0); diff --git a/test/acceptance/regressions.js b/test/acceptance/regressions.js index 43dad070..421df02f 100644 --- a/test/acceptance/regressions.js +++ b/test/acceptance/regressions.js @@ -28,7 +28,7 @@ describe('regressions', function() { var testClient = new TestClient(mapConfig, 1234); - testClient.getLayergroup(ERROR_RESPONSE, function(err, layergroupResult) { + testClient.getLayergroup({ response: ERROR_RESPONSE }, function(err, layergroupResult) { assert.ok(!err, err); assert.equal(layergroupResult.errors.length, 1); diff --git a/test/acceptance/turbo-carto/error-cases.js b/test/acceptance/turbo-carto/error-cases.js index 0d25ae93..b6424c72 100644 --- a/test/acceptance/turbo-carto/error-cases.js +++ b/test/acceptance/turbo-carto/error-cases.js @@ -51,7 +51,7 @@ describe('turbo-carto error cases', function() { it('should return invalid number of ramp error', function(done) { this.testClient = new TestClient(makeMapconfig('ramp([pop_max], 8, 96, 3, (8,24,96,128))')); - this.testClient.getLayergroup(ERROR_RESPONSE, function(err, layergroup) { + this.testClient.getLayergroup({ response: ERROR_RESPONSE }, function(err, layergroup) { assert.ok(!err, err); assert.ok(layergroup.hasOwnProperty('errors')); @@ -65,7 +65,7 @@ describe('turbo-carto error cases', function() { it('should return invalid column from datasource', function(done) { this.testClient = new TestClient(makeMapconfig(null, 'ramp([wadus_column], (red, green, blue))')); - this.testClient.getLayergroup(ERROR_RESPONSE, function(err, layergroup) { + this.testClient.getLayergroup({ response: ERROR_RESPONSE }, function(err, layergroup) { assert.ok(!err, err); assert.ok(layergroup.hasOwnProperty('errors')); @@ -80,7 +80,7 @@ describe('turbo-carto error cases', function() { it('should return invalid method from datasource', function(done) { this.testClient = new TestClient(makeMapconfig(null, 'ramp([wadus_column], (red, green, blue), wadusmethod)')); - this.testClient.getLayergroup(ERROR_RESPONSE, function(err, layergroup) { + this.testClient.getLayergroup({ response: ERROR_RESPONSE }, function(err, layergroup) { assert.ok(!err, err); assert.ok(layergroup.hasOwnProperty('errors')); @@ -95,7 +95,7 @@ describe('turbo-carto error cases', function() { it('should fail by falling back to normal carto parser', function(done) { this.testClient = new TestClient(makeMapconfig('ramp([price], (8,24,96), (8,24,96));//(red, green, blue))')); - this.testClient.getLayergroup(ERROR_RESPONSE, function(err, layergroup) { + this.testClient.getLayergroup({ response: ERROR_RESPONSE }, function(err, layergroup) { assert.ok(!err, err); assert.ok(layergroup.hasOwnProperty('errors')); @@ -109,7 +109,7 @@ describe('turbo-carto error cases', function() { it('turbo-carto: should return error invalid column from datasource with some context', function(done) { this.testClient = new TestClient(makeMapconfig(null, 'ramp([wadus_column], (red, green, blue))')); - this.testClient.getLayergroup(ERROR_RESPONSE, function(err, layergroup) { + this.testClient.getLayergroup({ response: ERROR_RESPONSE }, function(err, layergroup) { assert.ok(!err, err); assert.ok(layergroup.hasOwnProperty('errors')); @@ -164,7 +164,7 @@ describe('turbo-carto error cases', function() { }; this.testClient = new TestClient(multipleErrorsMapConfig); - this.testClient.getLayergroup(ERROR_RESPONSE, function(err, layergroup) { + this.testClient.getLayergroup({ response: ERROR_RESPONSE }, function(err, layergroup) { assert.ok(!err, err); assert.ok(layergroup.hasOwnProperty('errors')); diff --git a/test/acceptance/turbo-carto/regressions.js b/test/acceptance/turbo-carto/regressions.js index f7f39ccb..9e2d377f 100644 --- a/test/acceptance/turbo-carto/regressions.js +++ b/test/acceptance/turbo-carto/regressions.js @@ -79,7 +79,7 @@ describe('turbo-carto regressions', function() { ].join('\n'); this.testClient = new TestClient(makeMapconfig('SELECT * FROM test_table_private_1', cartocss)); - this.testClient.getLayergroup(TestClient.RESPONSE.ERROR, function(err, layergroup) { + this.testClient.getLayergroup({ response: TestClient.RESPONSE.ERROR }, function(err, layergroup) { assert.ok(!err, err); assert.ok(!layergroup.hasOwnProperty('layergroupid')); diff --git a/test/acceptance/user-database-timeout-limit.js b/test/acceptance/user-database-timeout-limit.js index 9893f00a..52ead026 100644 --- a/test/acceptance/user-database-timeout-limit.js +++ b/test/acceptance/user-database-timeout-limit.js @@ -138,7 +138,7 @@ describe('user database timeout limit', function () { } }; - this.testClient.getLayergroup(expectedResponse, (err, timeoutError) => { + this.testClient.getLayergroup({ response: expectedResponse }, (err, timeoutError) => { assert.deepEqual(timeoutError, { errors: [ 'You are over platform\'s limits. Please contact us to know more details' ], errors_with_context: [{ @@ -177,7 +177,7 @@ describe('user database timeout limit', function () { return done(err); } - this.testClient.getLayergroup(expectedResponse, (err, res) => { + this.testClient.getLayergroup({ response: expectedResponse }, (err, res) => { if (err) { return done(err); } @@ -259,7 +259,7 @@ describe('user database timeout limit', function () { return done(err); } - this.testClient.getLayergroup(expectedResponse, (err, res) => { + this.testClient.getLayergroup({ response: expectedResponse }, (err, res) => { if (err) { return done(err); } @@ -360,7 +360,7 @@ describe('user database timeout limit', function () { } }; - this.testClient.getLayergroup(expectedResponse, (err, timeoutError) => { + this.testClient.getLayergroup({ response: expectedResponse }, (err, timeoutError) => { assert.deepEqual(timeoutError, { errors: [ 'You are over platform\'s limits. Please contact us to know more details' ], errors_with_context: [{ @@ -387,7 +387,7 @@ describe('user database timeout limit', function () { } }; - this.testClient.getLayergroup(expectedResponse, (err, res) => { + this.testClient.getLayergroup({ response: expectedResponse }, (err, res) => { if (err) { return done(err); } @@ -426,16 +426,16 @@ describe('user database timeout limit', function () { this.testClient.getTile(0, 0, 0, params, (err, res, tile) => { assert.ifError(err); - + var tileJSON = tile.toJSON(); assert.equal(Array.isArray(tileJSON), true); assert.equal(tileJSON.length, 2); assert.equal(tileJSON[0].name, 'errorTileSquareLayer'); assert.equal(tileJSON[1].name, 'errorTileStripesLayer'); - + done(); }); - + }); }); }); @@ -467,7 +467,7 @@ describe('user database timeout limit', function () { } }; - this.testClient.getLayergroup(expectedResponse, (err, timeoutError) => { + this.testClient.getLayergroup({ response: expectedResponse }, (err, timeoutError) => { assert.deepEqual(timeoutError, { errors: [ 'You are over platform\'s limits. Please contact us to know more details' ], errors_with_context: [{ @@ -494,7 +494,7 @@ describe('user database timeout limit', function () { } }; - this.testClient.getLayergroup(expectedResponse, (err, res) => { + this.testClient.getLayergroup({ response: expectedResponse }, (err, res) => { if (err) { return done(err); } @@ -571,7 +571,7 @@ describe('user database timeout limit', function () { } }; - this.testClient.getLayergroup(expectedResponse, (err, timeoutError) => { + this.testClient.getLayergroup({ response: expectedResponse }, (err, timeoutError) => { assert.deepEqual(timeoutError, { errors: [ 'You are over platform\'s limits. Please contact us to know more details' ], errors_with_context: [{ @@ -601,7 +601,7 @@ describe('user database timeout limit', function () { } }; - this.testClient.getLayergroup(expectedResponse, (err, res) => { + this.testClient.getLayergroup({ response: expectedResponse }, (err, res) => { if (err) { return done(err); } @@ -702,7 +702,7 @@ describe('user database timeout limit', function () { } }; - this.testClient.getLayergroup(expectedResponse, (err, timeoutError) => { + this.testClient.getLayergroup({ response: expectedResponse }, (err, timeoutError) => { assert.deepEqual(timeoutError, { errors: [ 'You are over platform\'s limits. Please contact us to know more details' ], errors_with_context: [{ @@ -740,7 +740,7 @@ describe('user database timeout limit', function () { } }; - this.testClient.getLayergroup(expectedResponse, (err, res) => { + this.testClient.getLayergroup({ response: expectedResponse }, (err, res) => { if (err) { return done(err); } diff --git a/test/acceptance/user-render-timeout-limit.js b/test/acceptance/user-render-timeout-limit.js index 5942d045..93770080 100644 --- a/test/acceptance/user-render-timeout-limit.js +++ b/test/acceptance/user-render-timeout-limit.js @@ -92,7 +92,7 @@ describe('user render timeout limit', function () { } }; - this.testClient.getLayergroup(expectedResponse, (err, timeoutError) => { + this.testClient.getLayergroup({ response: expectedResponse }, (err, timeoutError) => { assert.ifError(err); assert.deepEqual(timeoutError, { @@ -245,7 +245,7 @@ describe('user render timeout limit', function () { assert.equal(tileJSON.length, 2); assert.equal(tileJSON[0].name, 'errorTileSquareLayer'); assert.equal(tileJSON[1].name, 'errorTileStripesLayer'); - + done(); }); }); @@ -399,4 +399,3 @@ describe('user render timeout limit', function () { }); }); }); - diff --git a/test/acceptance/vector-layergroup.js b/test/acceptance/vector-layergroup.js index 54ec29ef..0778453e 100644 --- a/test/acceptance/vector-layergroup.js +++ b/test/acceptance/vector-layergroup.js @@ -206,7 +206,7 @@ suites.forEach((suite) => { this.testClient.mapConfig.layers[0].options.cartocss = cartocss; this.testClient.mapConfig.layers[0].options.cartocss_version = cartocssVersion; - this.testClient.getLayergroup(response, (err, body) => { + this.testClient.getLayergroup({ response }, (err, body) => { if (err) { return done(err); } diff --git a/test/support/test-client.js b/test/support/test-client.js index 3188d0fc..cda5287a 100644 --- a/test/support/test-client.js +++ b/test/support/test-client.js @@ -618,8 +618,19 @@ TestClient.prototype.getTile = function(z, x, y, params, callback) { } var data = templateId ? params.placeholders : self.mapConfig; + + const queryParams = {}; + + if (self.apiKey) { + queryParams.api_key = self.apiKey; + } + + if (typeof params.aggregation === 'boolean') { + queryParams.aggregation = params.aggregation; + } + var path = templateId ? - urlNamed + '/' + templateId + '?' + qs.stringify({api_key: self.apiKey}) : + urlNamed + '/' + templateId + '?' + qs.stringify(queryParams) : url; assert.response(self.server, @@ -647,7 +658,7 @@ TestClient.prototype.getTile = function(z, x, y, params, callback) { ); }, function getTileResult(err, layergroupId) { - // jshint maxcomplexity:12 + // jshint maxcomplexity:13 assert.ifError(err); self.keysToDelete['map_cfg|' + LayergroupToken.parse(layergroupId).token] = 0; @@ -671,8 +682,14 @@ TestClient.prototype.getTile = function(z, x, y, params, callback) { url += [z,x,y].join('/'); url += '.' + format; + const queryParams = {}; + if (self.apiKey) { - url += '?' + qs.stringify({api_key: self.apiKey}); + queryParams.api_key = self.apiKey; + } + + if (Object.keys(queryParams).length) { + url += '?' + qs.stringify(queryParams); } var request = { @@ -754,23 +771,35 @@ TestClient.prototype.getTile = function(z, x, y, params, callback) { ); }; -TestClient.prototype.getLayergroup = function(expectedResponse, callback) { +TestClient.prototype.getLayergroup = function(params, callback) { var self = this; if (!callback) { - callback = expectedResponse; - expectedResponse = { - status: 200, - headers: { - 'Content-Type': 'application/json; charset=utf-8' + callback = params; + params = { + response: { + status: 200, + headers: { + 'Content-Type': 'application/json; charset=utf-8' + } } }; } var url = '/api/v1/map'; - if (this.apiKey) { - url += '?' + qs.stringify({api_key: this.apiKey}); + const queryParams = {}; + + if (self.apiKey) { + queryParams.api_key = self.apiKey; + } + + if (typeof params.aggregation === 'boolean') { + queryParams.aggregation = params.aggregation; + } + + if (Object.keys(queryParams).length) { + url += '?' + qs.stringify(queryParams); } assert.response(self.server, @@ -783,7 +812,7 @@ TestClient.prototype.getLayergroup = function(expectedResponse, callback) { }, data: JSON.stringify(self.mapConfig) }, - expectedResponse, + params.response, function(res, err) { var parsedBody; // If there is a response, we are still interested in catching the created keys