Now .getLayergroup() in test client accepts params to perform custom instantiations

This commit is contained in:
Daniel García Aubert 2017-12-05 12:09:31 +01:00
parent 499e9de75d
commit 66b41a6ae7
12 changed files with 82 additions and 52 deletions

View File

@ -146,7 +146,7 @@ describe('aggregation', function () {
]); ]);
this.testClient = new TestClient(this.mapConfig); this.testClient = new TestClient(this.mapConfig);
this.testClient.getLayergroup(response, (err, body) => { this.testClient.getLayergroup({ response }, (err, body) => {
if (err) { if (err) {
return done(err); return done(err);
} }
@ -187,7 +187,7 @@ describe('aggregation', function () {
]); ]);
this.testClient = new TestClient(this.mapConfig); this.testClient = new TestClient(this.mapConfig);
this.testClient.getLayergroup(response, (err, body) => { this.testClient.getLayergroup({ response }, (err, body) => {
if (err) { if (err) {
return done(err); return done(err);
} }

View File

@ -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.ok(!err, err);
assert.deepEqual( assert.deepEqual(
layergroupResult.errors, layergroupResult.errors,

View File

@ -62,7 +62,7 @@ describe('analysis-layers error cases', function() {
var testClient = new TestClient(mapConfig, 1234); 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.ok(!err, err);
assert.equal(layergroupResult.errors.length, 1); assert.equal(layergroupResult.errors.length, 1);
@ -97,7 +97,7 @@ describe('analysis-layers error cases', function() {
var testClient = new TestClient(mapConfig, 1234); 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.ok(!err, err);
assert.equal(layergroupResult.errors.length, 1); assert.equal(layergroupResult.errors.length, 1);
@ -144,7 +144,7 @@ describe('analysis-layers error cases', function() {
var testClient = new TestClient(mapConfig, 1234); 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.ok(!err, err);
assert.equal(layergroupResult.errors.length, 1); assert.equal(layergroupResult.errors.length, 1);
@ -190,7 +190,7 @@ describe('analysis-layers error cases', function() {
var testClient = new TestClient(mapConfig, 11111); 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.ok(!err, err);
assert.equal(layergroupResult.errors.length, 1); assert.equal(layergroupResult.errors.length, 1);
@ -246,7 +246,7 @@ describe('analysis-layers error cases', function() {
var testClient = new TestClient(mapConfig, 1234); 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.ok(!err, err);
assert.equal(layergroupResult.errors.length, 1); assert.equal(layergroupResult.errors.length, 1);
@ -298,7 +298,7 @@ describe('analysis-layers error cases', function() {
var testClient = new TestClient(mapConfig, 1234); 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.ok(!err, err);
assert.equal(layergroupResult.errors.length, 1); assert.equal(layergroupResult.errors.length, 1);
@ -351,7 +351,7 @@ describe('analysis-layers error cases', function() {
var testClient = new TestClient(mapConfig, 1234); 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.ok(!err, err);
assert.equal(layergroupResult.errors.length, 1); assert.equal(layergroupResult.errors.length, 1);
@ -415,7 +415,7 @@ describe('analysis-layers error cases', function() {
var testClient = new TestClient(mapConfig, 1234); 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.ok(!err, err);
assert.equal(layergroupResult.errors.length, 1); assert.equal(layergroupResult.errors.length, 1);

View File

@ -51,7 +51,7 @@ describe('histogram-dataview', function() {
it('should fail when invalid dataviews object is provided, string case', function(done) { it('should fail when invalid dataviews object is provided, string case', function(done) {
var mapConfig = createMapConfig("wadus-string"); var mapConfig = createMapConfig("wadus-string");
this.testClient = new TestClient(mapConfig, 1234); 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.ok(!err, err);
assert.deepEqual(errObj.errors, [ '"dataviews" must be a valid JSON object: "string" type found' ]); 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) { it('should fail when invalid dataviews object is provided, array case', function(done) {
var mapConfig = createMapConfig([]); var mapConfig = createMapConfig([]);
this.testClient = new TestClient(mapConfig, 1234); 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.ok(!err, err);
assert.deepEqual(errObj.errors, [ '"dataviews" must be a valid JSON object: "array" type found' ]); assert.deepEqual(errObj.errors, [ '"dataviews" must be a valid JSON object: "array" type found' ]);

View File

@ -151,7 +151,7 @@ describe('multilayer error cases', function() {
}; };
ServerOptions.afterLayergroupCreateCalls = 0; ServerOptions.afterLayergroupCreateCalls = 0;
this.client = new TestClient(layergroup); 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); assert.ok(!err, err);
// See http://github.com/CartoDB/Windshaft/issues/159 // See http://github.com/CartoDB/Windshaft/issues/159
assert.equal(ServerOptions.afterLayergroupCreateCalls, 0); assert.equal(ServerOptions.afterLayergroupCreateCalls, 0);

View File

@ -28,7 +28,7 @@ describe('regressions', function() {
var testClient = new TestClient(mapConfig, 1234); 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.ok(!err, err);
assert.equal(layergroupResult.errors.length, 1); assert.equal(layergroupResult.errors.length, 1);

View File

@ -51,7 +51,7 @@ describe('turbo-carto error cases', function() {
it('should return invalid number of ramp error', function(done) { 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 = 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(!err, err);
assert.ok(layergroup.hasOwnProperty('errors')); assert.ok(layergroup.hasOwnProperty('errors'));
@ -65,7 +65,7 @@ describe('turbo-carto error cases', function() {
it('should return invalid column from datasource', function(done) { it('should return invalid column from datasource', function(done) {
this.testClient = new TestClient(makeMapconfig(null, 'ramp([wadus_column], (red, green, blue))')); 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(!err, err);
assert.ok(layergroup.hasOwnProperty('errors')); assert.ok(layergroup.hasOwnProperty('errors'));
@ -80,7 +80,7 @@ describe('turbo-carto error cases', function() {
it('should return invalid method from datasource', function(done) { it('should return invalid method from datasource', function(done) {
this.testClient = new TestClient(makeMapconfig(null, 'ramp([wadus_column], (red, green, blue), wadusmethod)')); 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(!err, err);
assert.ok(layergroup.hasOwnProperty('errors')); 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) { 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 = 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(!err, err);
assert.ok(layergroup.hasOwnProperty('errors')); 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) { 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 = 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(!err, err);
assert.ok(layergroup.hasOwnProperty('errors')); assert.ok(layergroup.hasOwnProperty('errors'));
@ -164,7 +164,7 @@ describe('turbo-carto error cases', function() {
}; };
this.testClient = new TestClient(multipleErrorsMapConfig); 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(!err, err);
assert.ok(layergroup.hasOwnProperty('errors')); assert.ok(layergroup.hasOwnProperty('errors'));

View File

@ -79,7 +79,7 @@ describe('turbo-carto regressions', function() {
].join('\n'); ].join('\n');
this.testClient = new TestClient(makeMapconfig('SELECT * FROM test_table_private_1', cartocss)); 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(!err, err);
assert.ok(!layergroup.hasOwnProperty('layergroupid')); assert.ok(!layergroup.hasOwnProperty('layergroupid'));

View File

@ -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, { assert.deepEqual(timeoutError, {
errors: [ 'You are over platform\'s limits. Please contact us to know more details' ], errors: [ 'You are over platform\'s limits. Please contact us to know more details' ],
errors_with_context: [{ errors_with_context: [{
@ -177,7 +177,7 @@ describe('user database timeout limit', function () {
return done(err); return done(err);
} }
this.testClient.getLayergroup(expectedResponse, (err, res) => { this.testClient.getLayergroup({ response: expectedResponse }, (err, res) => {
if (err) { if (err) {
return done(err); return done(err);
} }
@ -259,7 +259,7 @@ describe('user database timeout limit', function () {
return done(err); return done(err);
} }
this.testClient.getLayergroup(expectedResponse, (err, res) => { this.testClient.getLayergroup({ response: expectedResponse }, (err, res) => {
if (err) { if (err) {
return done(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, { assert.deepEqual(timeoutError, {
errors: [ 'You are over platform\'s limits. Please contact us to know more details' ], errors: [ 'You are over platform\'s limits. Please contact us to know more details' ],
errors_with_context: [{ 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) { if (err) {
return done(err); return done(err);
} }
@ -426,16 +426,16 @@ describe('user database timeout limit', function () {
this.testClient.getTile(0, 0, 0, params, (err, res, tile) => { this.testClient.getTile(0, 0, 0, params, (err, res, tile) => {
assert.ifError(err); assert.ifError(err);
var tileJSON = tile.toJSON(); var tileJSON = tile.toJSON();
assert.equal(Array.isArray(tileJSON), true); assert.equal(Array.isArray(tileJSON), true);
assert.equal(tileJSON.length, 2); assert.equal(tileJSON.length, 2);
assert.equal(tileJSON[0].name, 'errorTileSquareLayer'); assert.equal(tileJSON[0].name, 'errorTileSquareLayer');
assert.equal(tileJSON[1].name, 'errorTileStripesLayer'); assert.equal(tileJSON[1].name, 'errorTileStripesLayer');
done(); 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, { assert.deepEqual(timeoutError, {
errors: [ 'You are over platform\'s limits. Please contact us to know more details' ], errors: [ 'You are over platform\'s limits. Please contact us to know more details' ],
errors_with_context: [{ 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) { if (err) {
return done(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, { assert.deepEqual(timeoutError, {
errors: [ 'You are over platform\'s limits. Please contact us to know more details' ], errors: [ 'You are over platform\'s limits. Please contact us to know more details' ],
errors_with_context: [{ 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) { if (err) {
return done(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, { assert.deepEqual(timeoutError, {
errors: [ 'You are over platform\'s limits. Please contact us to know more details' ], errors: [ 'You are over platform\'s limits. Please contact us to know more details' ],
errors_with_context: [{ 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) { if (err) {
return done(err); return done(err);
} }

View File

@ -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.ifError(err);
assert.deepEqual(timeoutError, { assert.deepEqual(timeoutError, {
@ -245,7 +245,7 @@ describe('user render timeout limit', function () {
assert.equal(tileJSON.length, 2); assert.equal(tileJSON.length, 2);
assert.equal(tileJSON[0].name, 'errorTileSquareLayer'); assert.equal(tileJSON[0].name, 'errorTileSquareLayer');
assert.equal(tileJSON[1].name, 'errorTileStripesLayer'); assert.equal(tileJSON[1].name, 'errorTileStripesLayer');
done(); done();
}); });
}); });
@ -399,4 +399,3 @@ describe('user render timeout limit', function () {
}); });
}); });
}); });

View File

@ -206,7 +206,7 @@ suites.forEach((suite) => {
this.testClient.mapConfig.layers[0].options.cartocss = cartocss; this.testClient.mapConfig.layers[0].options.cartocss = cartocss;
this.testClient.mapConfig.layers[0].options.cartocss_version = cartocssVersion; this.testClient.mapConfig.layers[0].options.cartocss_version = cartocssVersion;
this.testClient.getLayergroup(response, (err, body) => { this.testClient.getLayergroup({ response }, (err, body) => {
if (err) { if (err) {
return done(err); return done(err);
} }

View File

@ -618,8 +618,19 @@ TestClient.prototype.getTile = function(z, x, y, params, callback) {
} }
var data = templateId ? params.placeholders : self.mapConfig; 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 ? var path = templateId ?
urlNamed + '/' + templateId + '?' + qs.stringify({api_key: self.apiKey}) : urlNamed + '/' + templateId + '?' + qs.stringify(queryParams) :
url; url;
assert.response(self.server, assert.response(self.server,
@ -647,7 +658,7 @@ TestClient.prototype.getTile = function(z, x, y, params, callback) {
); );
}, },
function getTileResult(err, layergroupId) { function getTileResult(err, layergroupId) {
// jshint maxcomplexity:12 // jshint maxcomplexity:13
assert.ifError(err); assert.ifError(err);
self.keysToDelete['map_cfg|' + LayergroupToken.parse(layergroupId).token] = 0; 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 += [z,x,y].join('/');
url += '.' + format; url += '.' + format;
const queryParams = {};
if (self.apiKey) { 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 = { 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; var self = this;
if (!callback) { if (!callback) {
callback = expectedResponse; callback = params;
expectedResponse = { params = {
status: 200, response: {
headers: { status: 200,
'Content-Type': 'application/json; charset=utf-8' headers: {
'Content-Type': 'application/json; charset=utf-8'
}
} }
}; };
} }
var url = '/api/v1/map'; var url = '/api/v1/map';
if (this.apiKey) { const queryParams = {};
url += '?' + qs.stringify({api_key: this.apiKey});
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, assert.response(self.server,
@ -783,7 +812,7 @@ TestClient.prototype.getLayergroup = function(expectedResponse, callback) {
}, },
data: JSON.stringify(self.mapConfig) data: JSON.stringify(self.mapConfig)
}, },
expectedResponse, params.response,
function(res, err) { function(res, err) {
var parsedBody; var parsedBody;
// If there is a response, we are still interested in catching the created keys // If there is a response, we are still interested in catching the created keys