2016-04-26 21:59:41 +08:00
|
|
|
require('../../support/test_helper');
|
2016-03-09 03:06:43 +08:00
|
|
|
|
2016-04-26 21:59:41 +08:00
|
|
|
var assert = require('../../support/assert');
|
|
|
|
var TestClient = require('../../support/test-client');
|
2016-03-09 03:06:43 +08:00
|
|
|
|
2016-05-17 20:54:44 +08:00
|
|
|
function makeMapconfig(sql, cartocss) {
|
2016-03-09 03:06:43 +08:00
|
|
|
return {
|
|
|
|
"version": "1.4.0",
|
|
|
|
"layers": [
|
|
|
|
{
|
|
|
|
"type": 'mapnik',
|
|
|
|
"options": {
|
|
|
|
"cartocss_version": '2.3.0',
|
2016-05-17 20:54:44 +08:00
|
|
|
"sql": sql,
|
2016-03-09 03:06:43 +08:00
|
|
|
"cartocss": cartocss
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-04-26 21:59:41 +08:00
|
|
|
describe('turbo-carto regressions', function() {
|
2016-03-09 18:48:07 +08:00
|
|
|
|
|
|
|
afterEach(function (done) {
|
2016-05-17 20:54:44 +08:00
|
|
|
if (this.testClient) {
|
|
|
|
this.testClient.drain(done);
|
2016-06-20 19:09:01 +08:00
|
|
|
} else {
|
|
|
|
done();
|
2016-05-17 20:54:44 +08:00
|
|
|
}
|
2016-03-09 18:48:07 +08:00
|
|
|
});
|
2016-03-09 03:06:43 +08:00
|
|
|
|
|
|
|
it('should accept // comments', function(done) {
|
2016-05-17 20:54:44 +08:00
|
|
|
var cartocss = [
|
|
|
|
"/** simple visualization */",
|
|
|
|
"",
|
|
|
|
"Map {",
|
|
|
|
" buffer-size: 256;",
|
|
|
|
"}",
|
|
|
|
"",
|
|
|
|
"#county_points_with_population{",
|
|
|
|
" marker-fill-opacity: 0.1;",
|
|
|
|
" marker-line-color:#FFFFFF;//#CF1C90;",
|
|
|
|
" marker-line-width: 0;",
|
|
|
|
" marker-line-opacity: 0.3;",
|
|
|
|
" marker-placement: point;",
|
|
|
|
" marker-type: ellipse;",
|
|
|
|
" //marker-comp-op: overlay;",
|
|
|
|
" marker-width: [cartodb_id];",
|
|
|
|
" [zoom=5]{marker-width: [cartodb_id]*2;}",
|
|
|
|
" [zoom=6]{marker-width: [cartodb_id]*4;}",
|
|
|
|
" marker-fill: #000000;",
|
|
|
|
" marker-allow-overlap: true;",
|
|
|
|
" ",
|
|
|
|
"",
|
|
|
|
"}"
|
|
|
|
].join('\n');
|
|
|
|
|
|
|
|
this.testClient = new TestClient(makeMapconfig('SELECT * FROM populated_places_simple_reduced', cartocss));
|
|
|
|
this.testClient.getLayergroup(function(err, layergroup) {
|
|
|
|
assert.ok(!err, err);
|
|
|
|
|
|
|
|
assert.ok(layergroup.hasOwnProperty('layergroupid'));
|
|
|
|
assert.ok(!layergroup.hasOwnProperty('errors'));
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-06-21 18:08:40 +08:00
|
|
|
it('should fail for private tables', function(done) {
|
|
|
|
var cartocss = [
|
|
|
|
"#private_table {",
|
|
|
|
" marker-placement: point;",
|
|
|
|
" marker-allow-overlap: true;",
|
|
|
|
" marker-line-width: 0;",
|
|
|
|
" marker-fill-opacity: 1.0;",
|
|
|
|
" marker-width: ramp([cartodb_id], 10, 20);",
|
|
|
|
" marker-fill: red;",
|
|
|
|
"}"
|
|
|
|
].join('\n');
|
|
|
|
|
|
|
|
this.testClient = new TestClient(makeMapconfig('SELECT * FROM test_table_private_1', cartocss));
|
|
|
|
this.testClient.getLayergroup(TestClient.RESPONSE.ERROR, function(err, layergroup) {
|
|
|
|
assert.ok(!err, err);
|
|
|
|
|
|
|
|
assert.ok(!layergroup.hasOwnProperty('layergroupid'));
|
|
|
|
assert.ok(layergroup.hasOwnProperty('errors'));
|
|
|
|
|
|
|
|
var turboCartoError = layergroup.errors_with_context[0];
|
|
|
|
assert.ok(turboCartoError);
|
2016-06-27 00:43:04 +08:00
|
|
|
assert.equal(turboCartoError.type, 'layer');
|
2016-06-21 18:08:40 +08:00
|
|
|
assert.ok(turboCartoError.message.match(/permission\sdenied\sfor\srelation\stest_table_private_1/));
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should work for private tables with api key', function(done) {
|
|
|
|
var cartocss = [
|
|
|
|
"#private_table {",
|
|
|
|
" marker-placement: point;",
|
|
|
|
" marker-allow-overlap: true;",
|
|
|
|
" marker-line-width: 0;",
|
|
|
|
" marker-fill-opacity: 1.0;",
|
|
|
|
" marker-width: ramp([cartodb_id], 10, 20);",
|
|
|
|
" marker-fill: red;",
|
|
|
|
"}"
|
|
|
|
].join('\n');
|
|
|
|
|
|
|
|
this.testClient = new TestClient(makeMapconfig('SELECT * FROM test_table_private_1', cartocss), 1234);
|
|
|
|
this.testClient.getLayergroup(function(err, layergroup) {
|
|
|
|
assert.ok(!err, err);
|
|
|
|
|
|
|
|
assert.ok(layergroup.hasOwnProperty('layergroupid'));
|
|
|
|
assert.ok(!layergroup.hasOwnProperty('errors'));
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-05-17 20:54:44 +08:00
|
|
|
it('should work with mapnik substitution tokens', function(done) {
|
|
|
|
var cartocss = [
|
|
|
|
"#layer {",
|
|
|
|
" line-width: 2;",
|
|
|
|
" line-color: #3B3B58;",
|
|
|
|
" line-opacity: 1;",
|
|
|
|
" polygon-opacity: 0.7;",
|
|
|
|
" polygon-fill: ramp([points_count], (#E5F5F9,#99D8C9,#2CA25F))",
|
|
|
|
"}"
|
|
|
|
].join('\n');
|
|
|
|
|
|
|
|
var sql = [
|
|
|
|
'WITH hgrid AS (',
|
|
|
|
' SELECT CDB_HexagonGrid(',
|
|
|
|
' ST_Expand(!bbox!, greatest(!pixel_width!,!pixel_height!) * 100),',
|
|
|
|
' greatest(!pixel_width!,!pixel_height!) * 100',
|
|
|
|
' ) as cell',
|
|
|
|
')',
|
|
|
|
'SELECT',
|
|
|
|
' hgrid.cell as the_geom_webmercator,',
|
|
|
|
' count(1) as points_count,',
|
|
|
|
' count(1)/power(100 * CDB_XYZ_Resolution(CDB_ZoomFromScale(!scale_denominator!)), 2) as points_density,',
|
|
|
|
' 1 as cartodb_id',
|
|
|
|
'FROM hgrid, (SELECT * FROM populated_places_simple_reduced) i',
|
|
|
|
'where ST_Intersects(i.the_geom_webmercator, hgrid.cell)',
|
|
|
|
'GROUP BY hgrid.cell'
|
|
|
|
].join('\n');
|
|
|
|
|
|
|
|
this.testClient = new TestClient(makeMapconfig(sql, cartocss));
|
2016-05-13 06:49:09 +08:00
|
|
|
this.testClient.getLayergroup(function(err, layergroup) {
|
2016-03-09 03:06:43 +08:00
|
|
|
assert.ok(!err, err);
|
2016-05-13 06:49:09 +08:00
|
|
|
|
|
|
|
assert.ok(layergroup.hasOwnProperty('layergroupid'));
|
|
|
|
assert.ok(!layergroup.hasOwnProperty('errors'));
|
|
|
|
|
2016-03-09 03:06:43 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2016-05-19 17:42:28 +08:00
|
|
|
|
|
|
|
it('should work with mapnik substitution tokens and analyses', function(done) {
|
|
|
|
var cartocss = [
|
|
|
|
"#layer {",
|
|
|
|
" line-width: 2;",
|
|
|
|
" line-color: #3B3B58;",
|
|
|
|
" line-opacity: 1;",
|
|
|
|
" polygon-opacity: 0.7;",
|
|
|
|
" polygon-fill: ramp([points_count], (#E5F5F9,#99D8C9,#2CA25F))",
|
|
|
|
"}"
|
|
|
|
].join('\n');
|
|
|
|
|
|
|
|
var sqlWrap = [
|
|
|
|
'WITH hgrid AS (',
|
|
|
|
' SELECT CDB_HexagonGrid(',
|
|
|
|
' ST_Expand(!bbox!, greatest(!pixel_width!,!pixel_height!) * 100),',
|
|
|
|
' greatest(!pixel_width!,!pixel_height!) * 100',
|
|
|
|
' ) as cell',
|
|
|
|
')',
|
|
|
|
'SELECT',
|
|
|
|
' hgrid.cell as the_geom_webmercator,',
|
|
|
|
' count(1) as points_count,',
|
|
|
|
' count(1)/power(100 * CDB_XYZ_Resolution(CDB_ZoomFromScale(!scale_denominator!)), 2) as points_density,',
|
|
|
|
' 1 as cartodb_id',
|
|
|
|
'FROM hgrid, (<%= sql %>) i',
|
|
|
|
'where ST_Intersects(i.the_geom_webmercator, hgrid.cell)',
|
|
|
|
'GROUP BY hgrid.cell'
|
|
|
|
].join('\n');
|
|
|
|
|
|
|
|
var mapConfig = {
|
|
|
|
"version": "1.5.0",
|
|
|
|
"layers": [
|
|
|
|
{
|
|
|
|
"type": 'mapnik',
|
|
|
|
"options": {
|
|
|
|
"cartocss_version": '2.3.0',
|
|
|
|
"source": {
|
|
|
|
"id": "head"
|
|
|
|
},
|
|
|
|
sql_wrap: sqlWrap,
|
|
|
|
"cartocss": cartocss
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"analyses": [
|
|
|
|
{
|
|
|
|
"id": "head",
|
|
|
|
"type": "source",
|
|
|
|
"params": {
|
2016-05-19 18:13:37 +08:00
|
|
|
"query": "SELECT * FROM populated_places_simple_reduced"
|
2016-05-19 17:42:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
this.testClient = new TestClient(mapConfig, 1234);
|
|
|
|
this.testClient.getLayergroup(function(err, layergroup) {
|
|
|
|
assert.ok(!err, err);
|
|
|
|
|
|
|
|
assert.ok(layergroup.hasOwnProperty('layergroupid'));
|
|
|
|
assert.ok(!layergroup.hasOwnProperty('errors'));
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2016-06-20 19:09:01 +08:00
|
|
|
|
|
|
|
describe('empty datasource results', function() {
|
|
|
|
|
|
|
|
afterEach(function (done) {
|
|
|
|
if (this.testClient) {
|
|
|
|
this.testClient.drain(done);
|
|
|
|
} else {
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
function emptyResultMapConfig(markerFillRule) {
|
|
|
|
var cartocss = [
|
|
|
|
"#county_points_with_population {",
|
|
|
|
" marker-placement: point;",
|
|
|
|
" marker-allow-overlap: true;",
|
|
|
|
" marker-fill-opacity: 1.0;",
|
|
|
|
" marker-fill: " + markerFillRule + ';',
|
|
|
|
" marker-line-width: 0;",
|
|
|
|
"}"
|
|
|
|
].join('\n');
|
|
|
|
|
|
|
|
return {
|
|
|
|
"version": "1.5.0",
|
|
|
|
"layers": [
|
|
|
|
{
|
|
|
|
"type": 'mapnik',
|
|
|
|
"options": {
|
|
|
|
"cartocss_version": '2.3.0',
|
|
|
|
"source": {
|
|
|
|
"id": "head"
|
|
|
|
},
|
|
|
|
"cartocss": cartocss
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"analyses": [
|
|
|
|
{
|
|
|
|
"id": "head",
|
|
|
|
"type": "source",
|
|
|
|
"params": {
|
|
|
|
"query": "SELECT * FROM populated_places_simple_reduced limit 0"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-07-04 08:11:52 +08:00
|
|
|
var methods = ['quantiles', 'equal', 'jenks', 'headtails', 'category'];
|
2016-06-20 19:09:01 +08:00
|
|
|
|
2016-07-04 08:11:52 +08:00
|
|
|
methods.forEach(function(method) {
|
|
|
|
it('should work for "' + method+ '" method', function(done) {
|
|
|
|
var makerFillRule = 'ramp([pop_max], (#E5F5F9,#99D8C9,#2CA25F), ' + method + ')';
|
2016-06-20 19:09:01 +08:00
|
|
|
|
2016-07-04 08:11:52 +08:00
|
|
|
this.testClient = new TestClient(emptyResultMapConfig(makerFillRule), 1234);
|
|
|
|
this.testClient.getLayergroup(function(err, layergroup) {
|
|
|
|
assert.ok(!err, err);
|
2016-06-20 19:09:01 +08:00
|
|
|
|
2016-07-04 08:11:52 +08:00
|
|
|
assert.ok(layergroup.hasOwnProperty('layergroupid'));
|
|
|
|
assert.ok(!layergroup.hasOwnProperty('errors'));
|
2016-06-20 19:09:01 +08:00
|
|
|
|
2016-07-04 08:11:52 +08:00
|
|
|
done();
|
|
|
|
});
|
2016-06-20 19:09:01 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-03-09 03:06:43 +08:00
|
|
|
});
|