2018-10-24 00:39:02 +08:00
|
|
|
'use strict';
|
|
|
|
|
2019-10-07 16:44:45 +08:00
|
|
|
require('../../support/test-helper');
|
2016-05-13 18:10:05 +08:00
|
|
|
|
|
|
|
var assert = require('../../support/assert');
|
|
|
|
var TestClient = require('../../support/test-client');
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
function makeMapconfig (markerWidth, markerFill) {
|
2016-05-13 18:10:05 +08:00
|
|
|
return {
|
2019-10-22 01:07:24 +08:00
|
|
|
version: '1.4.0',
|
|
|
|
layers: [
|
2016-05-13 18:10:05 +08:00
|
|
|
{
|
2019-10-22 01:07:24 +08:00
|
|
|
type: 'mapnik',
|
|
|
|
options: {
|
|
|
|
cartocss_version: '2.3.0',
|
|
|
|
sql: 'SELECT * FROM populated_places_simple_reduced',
|
|
|
|
cartocss: createCartocss(markerWidth, markerFill)
|
2016-05-13 18:10:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
function createCartocss (markerWidth, markerFill) {
|
2016-05-13 18:10:05 +08:00
|
|
|
return [
|
2019-10-22 01:07:24 +08:00
|
|
|
'#populated_places_simple_reduced {',
|
|
|
|
' marker-fill-opacity: 0.9;',
|
|
|
|
' marker-line-color: #FFF;',
|
|
|
|
' marker-line-width: 1;',
|
|
|
|
' marker-line-opacity: 1;',
|
|
|
|
' marker-placement: point;',
|
|
|
|
' marker-type: ellipse;',
|
|
|
|
' marker-allow-overlap: true;',
|
|
|
|
' marker-width: ' + (markerWidth || '10') + ';',
|
|
|
|
' marker-fill: ' + (markerFill || 'red') + ';',
|
|
|
|
'}'
|
2016-05-13 18:10:05 +08:00
|
|
|
].join('\n');
|
|
|
|
}
|
|
|
|
|
|
|
|
var ERROR_RESPONSE = {
|
|
|
|
status: 400,
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json; charset=utf-8'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('turbo-carto error cases', function () {
|
2016-05-13 18:10:05 +08:00
|
|
|
afterEach(function (done) {
|
|
|
|
if (this.testClient) {
|
|
|
|
this.testClient.drain(done);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should return invalid number of ramp error', function (done) {
|
2016-07-18 17:13:01 +08:00
|
|
|
this.testClient = new TestClient(makeMapconfig('ramp([pop_max], 8, 96, 3, (8,24,96,128))'));
|
2019-10-22 01:07:24 +08:00
|
|
|
this.testClient.getLayergroup({ response: ERROR_RESPONSE }, function (err, layergroup) {
|
2016-05-13 18:10:05 +08:00
|
|
|
assert.ok(!err, err);
|
|
|
|
|
2019-10-22 05:33:27 +08:00
|
|
|
assert.ok(Object.prototype.hasOwnProperty.call(layergroup, 'errors'));
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(layergroup.errors.length, 1);
|
2016-07-18 17:13:37 +08:00
|
|
|
assert.ok(layergroup.errors[0].match(/^Failed\sto\sprocess/), layergroup.errors[0]);
|
|
|
|
assert.ok(layergroup.errors[0].match(/invalid\sramp\slength/i), layergroup.errors[0]);
|
2016-05-13 18:10:05 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should return invalid column from datasource', function (done) {
|
2016-05-13 18:10:05 +08:00
|
|
|
this.testClient = new TestClient(makeMapconfig(null, 'ramp([wadus_column], (red, green, blue))'));
|
2019-10-22 01:07:24 +08:00
|
|
|
this.testClient.getLayergroup({ response: ERROR_RESPONSE }, function (err, layergroup) {
|
2016-05-13 18:10:05 +08:00
|
|
|
assert.ok(!err, err);
|
|
|
|
|
2019-10-22 05:33:27 +08:00
|
|
|
assert.ok(Object.prototype.hasOwnProperty.call(layergroup, 'errors'));
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(layergroup.errors.length, 1);
|
2016-07-06 18:34:09 +08:00
|
|
|
assert.ok(layergroup.errors[0].match(/^Failed\sto\sprocess/));
|
2016-05-13 18:42:18 +08:00
|
|
|
assert.ok(layergroup.errors[0].match(/unable\sto\scompute\sramp/i));
|
2016-05-13 18:10:05 +08:00
|
|
|
assert.ok(layergroup.errors[0].match(/wadus_column/));
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should return invalid method from datasource', function (done) {
|
2016-05-19 21:54:58 +08:00
|
|
|
this.testClient = new TestClient(makeMapconfig(null, 'ramp([wadus_column], (red, green, blue), wadusmethod)'));
|
2019-10-22 01:07:24 +08:00
|
|
|
this.testClient.getLayergroup({ response: ERROR_RESPONSE }, function (err, layergroup) {
|
2016-05-19 21:54:58 +08:00
|
|
|
assert.ok(!err, err);
|
|
|
|
|
2019-10-22 05:33:27 +08:00
|
|
|
assert.ok(Object.prototype.hasOwnProperty.call(layergroup, 'errors'));
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(layergroup.errors.length, 1);
|
2016-07-06 18:34:09 +08:00
|
|
|
assert.ok(layergroup.errors[0].match(/^Failed\sto\sprocess/));
|
2016-05-19 21:54:58 +08:00
|
|
|
assert.ok(layergroup.errors[0].match(/unable\sto\scompute\sramp/i));
|
2019-10-25 01:18:47 +08:00
|
|
|
assert.ok(layergroup.errors[0].match(/invalid\smethod\s"wadusmethod"/i));
|
2016-05-19 21:54:58 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should fail by falling back to normal carto parser', function (done) {
|
2016-05-13 18:10:05 +08:00
|
|
|
this.testClient = new TestClient(makeMapconfig('ramp([price], (8,24,96), (8,24,96));//(red, green, blue))'));
|
2019-10-22 01:07:24 +08:00
|
|
|
this.testClient.getLayergroup({ response: ERROR_RESPONSE }, function (err, layergroup) {
|
2016-05-13 18:10:05 +08:00
|
|
|
assert.ok(!err, err);
|
|
|
|
|
2019-10-22 05:33:27 +08:00
|
|
|
assert.ok(Object.prototype.hasOwnProperty.call(layergroup, 'errors'));
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(layergroup.errors.length, 1);
|
2016-07-06 18:34:09 +08:00
|
|
|
assert.ok(!layergroup.errors[0].match(/^Failed\sto\sprocess/));
|
2016-05-13 18:10:05 +08:00
|
|
|
assert.ok(layergroup.errors[0].match(/invalid\scode/i));
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2016-06-13 18:20:56 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('turbo-carto: should return error invalid column from datasource with some context', function (done) {
|
2016-06-13 18:20:56 +08:00
|
|
|
this.testClient = new TestClient(makeMapconfig(null, 'ramp([wadus_column], (red, green, blue))'));
|
2019-10-22 01:07:24 +08:00
|
|
|
this.testClient.getLayergroup({ response: ERROR_RESPONSE }, function (err, layergroup) {
|
2016-06-13 18:20:56 +08:00
|
|
|
assert.ok(!err, err);
|
|
|
|
|
2019-10-22 05:33:27 +08:00
|
|
|
assert.ok(Object.prototype.hasOwnProperty.call(layergroup, 'errors'));
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(layergroup.errors_with_context.length, 1);
|
|
|
|
assert.strictEqual(layergroup.errors_with_context[0].type, 'layer');
|
|
|
|
assert.strictEqual(layergroup.errors_with_context[0].subtype, 'turbo-carto');
|
2016-07-06 18:34:09 +08:00
|
|
|
assert.ok(layergroup.errors_with_context[0].message.match(/^Failed\sto\sprocess/));
|
2016-06-13 18:20:56 +08:00
|
|
|
assert.ok(layergroup.errors_with_context[0].message.match(/unable\sto\scompute\sramp/i));
|
|
|
|
assert.ok(layergroup.errors_with_context[0].message.match(/wadus_column/));
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(layergroup.errors_with_context[0].layer.id, 'layer0');
|
|
|
|
assert.strictEqual(layergroup.errors_with_context[0].layer.index, 0);
|
|
|
|
assert.strictEqual(layergroup.errors_with_context[0].layer.type, 'mapnik');
|
2016-06-13 18:20:56 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(layergroup.errors_with_context[0].layer.context.selector, '#populated_places_simple_reduced');
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(layergroup.errors_with_context[0].layer.context.source, {
|
2016-06-13 22:14:01 +08:00
|
|
|
start: {
|
|
|
|
line: 10,
|
|
|
|
column: 3
|
|
|
|
},
|
|
|
|
end: {
|
|
|
|
line: 10,
|
|
|
|
column: 56
|
|
|
|
}
|
|
|
|
});
|
2016-06-13 18:20:56 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2016-07-06 06:32:30 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should return multiple errors', function (done) {
|
2016-07-06 06:32:30 +08:00
|
|
|
var multipleErrorsMapConfig = {
|
2019-10-22 01:07:24 +08:00
|
|
|
version: '1.4.0',
|
|
|
|
layers: [
|
2016-07-06 06:32:30 +08:00
|
|
|
{
|
2019-10-22 01:07:24 +08:00
|
|
|
type: 'mapnik',
|
|
|
|
options: {
|
|
|
|
cartocss_version: '2.3.0',
|
|
|
|
sql: 'SELECT * FROM populated_places_simple_reduced',
|
|
|
|
cartocss: createCartocss(null, 'ramp([wadus_column], (red, green, blue))')
|
2016-07-06 06:32:30 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2019-10-22 01:07:24 +08:00
|
|
|
type: 'mapnik',
|
|
|
|
options: {
|
|
|
|
cartocss_version: '2.3.0',
|
|
|
|
sql: 'SELECT * FROM populated_places_simple_reduced',
|
|
|
|
cartocss: createCartocss('ramp([invalid_column], (red, green, blue))')
|
2016-07-06 06:32:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
this.testClient = new TestClient(multipleErrorsMapConfig);
|
2019-10-22 01:07:24 +08:00
|
|
|
this.testClient.getLayergroup({ response: ERROR_RESPONSE }, function (err, layergroup) {
|
2016-07-06 06:32:30 +08:00
|
|
|
assert.ok(!err, err);
|
|
|
|
|
2019-10-22 05:33:27 +08:00
|
|
|
assert.ok(Object.prototype.hasOwnProperty.call(layergroup, 'errors'));
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(layergroup.errors_with_context.length, 2);
|
2016-07-06 06:32:30 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(layergroup.errors_with_context[0].type, 'layer');
|
|
|
|
assert.strictEqual(layergroup.errors_with_context[0].subtype, 'turbo-carto');
|
2016-07-06 18:34:09 +08:00
|
|
|
assert.ok(layergroup.errors_with_context[0].message.match(/^Failed\sto\sprocess/));
|
2016-07-06 06:32:30 +08:00
|
|
|
assert.ok(layergroup.errors_with_context[0].message.match(/unable\sto\scompute\sramp/i));
|
|
|
|
assert.ok(layergroup.errors_with_context[0].message.match(/wadus_column/));
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(layergroup.errors_with_context[0].layer.id, 'layer0');
|
2016-07-06 06:32:30 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(layergroup.errors_with_context[1].type, 'layer');
|
|
|
|
assert.strictEqual(layergroup.errors_with_context[1].subtype, 'turbo-carto');
|
2016-07-06 18:34:09 +08:00
|
|
|
assert.ok(layergroup.errors_with_context[1].message.match(/^Failed\sto\sprocess/));
|
2016-07-06 06:32:30 +08:00
|
|
|
assert.ok(layergroup.errors_with_context[1].message.match(/unable\sto\scompute\sramp/i));
|
|
|
|
assert.ok(layergroup.errors_with_context[1].message.match(/invalid_column/));
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(layergroup.errors_with_context[1].layer.id, 'layer1');
|
2016-07-06 06:32:30 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2016-05-13 18:10:05 +08:00
|
|
|
});
|