Merge pull request #940 from CartoDB/regression-test-named-map-dataview-filter

Regression test named map dataview filter
This commit is contained in:
Daniel G. Aubert 2018-04-13 12:45:34 +02:00 committed by GitHub
commit 1b8e37a62c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 135 additions and 3 deletions

View File

@ -90,4 +90,78 @@ describe('regressions', function() {
});
});
});
it('should create and instantiate a named map with filters', function (done) {
const apikeyToken = '1234';
const template = {
version: '0.0.1',
name: 'regression-dataview-filter-template',
placeholders: {
buffersize: {
type: 'number',
default: 0
}
},
layergroup: {
version: '1.6.0',
layers: [
{
type: 'cartodb',
options: {
source: {
id: 'a1'
},
cartocss: TestClient.CARTOCSS.POINTS,
cartocss_version: '2.3.0'
}
}
],
dataviews: {
country_places_count: {
source: {
id: 'a1'
},
type: 'aggregation',
options: {
column: 'adm0_a3',
aggregation: 'count'
}
}
},
analyses: [
{
id: 'a1',
type: 'source',
params: {
query: 'select * from populated_places_simple_reduced'
}
}
]
}
};
const testClient = new TestClient(template, apikeyToken);
const params = {
own_filter: 1,
filters: {
dataviews: {
country_places_count: {
accept: ['CAN']
}
}
}
};
testClient.getDataview('country_places_count', params, (err, dataview) => {
assert.ifError(err);
assert.equal(dataview.type, 'aggregation');
assert.equal(dataview.categories.length, 1);
assert.deepEqual(dataview.categories[0], { value: 256, category: 'CAN', agg: false });
testClient.drain(done);
});
});
});

View File

@ -358,6 +358,8 @@ TestClient.prototype.getDataview = function(dataviewName, params, callback) {
}
var url = '/api/v1/map';
var urlNamed = url + '/named';
if (Object.keys(extraParams).length > 0) {
url += '?' + qs.stringify(extraParams);
}
@ -370,17 +372,73 @@ TestClient.prototype.getDataview = function(dataviewName, params, callback) {
};
step(
function createLayergroup() {
function createTemplate () {
var next = this;
if (!self.template) {
return next();
}
if (!self.apiKey) {
return next(new Error('apiKey param is mandatory to create a new template'));
}
params.placeholders = params.placeholders || {};
assert.response(self.server,
{
url: url,
url: urlNamed + '?' + qs.stringify({ api_key: self.apiKey }),
method: 'POST',
headers: {
host: 'localhost',
'Content-Type': 'application/json'
},
data: JSON.stringify(self.mapConfig)
data: JSON.stringify(self.template)
},
{
status: 200,
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
},
function (res, err) {
if (err) {
return next(err);
}
return next(null, JSON.parse(res.body).template_id);
}
);
},
function createLayergroup(err, templateId) {
assert.ifError(err);
var next = this;
var data = templateId ? params.placeholders : self.mapConfig;
const queryParams = {};
if (self.apiKey) {
queryParams.api_key = self.apiKey;
}
if (params.filters !== undefined) {
queryParams.filters = JSON.stringify(params.filters);
}
var path = templateId ?
urlNamed + '/' + templateId + '?' + qs.stringify(queryParams) :
url;
assert.response(self.server,
{
url: path,
method: 'POST',
headers: {
host: 'localhost',
'Content-Type': 'application/json'
},
data: JSON.stringify(data)
},
{
status: 200,