2018-10-24 00:39:02 +08:00
|
|
|
'use strict';
|
|
|
|
|
2019-10-07 16:44:45 +08:00
|
|
|
require('../../support/test-helper');
|
2016-04-21 23:24:25 +08:00
|
|
|
|
|
|
|
var assert = require('../../support/assert');
|
|
|
|
var TestClient = require('../../support/test-client');
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('analysis-layers error cases', function () {
|
|
|
|
function createMapConfig (layers, dataviews, analysis) {
|
2016-04-21 23:24:25 +08:00
|
|
|
return {
|
|
|
|
version: '1.5.0',
|
|
|
|
layers: layers,
|
|
|
|
dataviews: dataviews || {},
|
|
|
|
analyses: analysis || []
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
var ERROR_RESPONSE = {
|
|
|
|
status: 400,
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json; charset=utf-8'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-06-13 18:20:56 +08:00
|
|
|
var AUTH_ERROR_RESPONSE = {
|
|
|
|
status: 403,
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json; charset=utf-8'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should handle missing analysis nodes for layers', function (done) {
|
2016-04-21 23:27:20 +08:00
|
|
|
var mapConfig = createMapConfig(
|
|
|
|
[
|
|
|
|
{
|
2019-10-22 01:07:24 +08:00
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
source: {
|
|
|
|
id: 'INVALID-SOURCE-ID'
|
2016-04-21 23:27:20 +08:00
|
|
|
},
|
2019-10-22 01:07:24 +08:00
|
|
|
cartocss: '#polygons { polygon-fill: red; }',
|
|
|
|
cartocss_version: '2.3.0'
|
2016-04-21 23:27:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
{},
|
|
|
|
[
|
|
|
|
{
|
2019-10-22 01:07:24 +08:00
|
|
|
id: 'HEAD',
|
|
|
|
type: 'buffer',
|
|
|
|
params: {
|
|
|
|
source: {
|
|
|
|
id: '2570e105-7b37-40d2-bdf4-1af889598745',
|
|
|
|
type: 'source',
|
|
|
|
params: {
|
|
|
|
query: 'select * from populated_places_simple_reduced'
|
2016-04-21 23:27:20 +08:00
|
|
|
}
|
|
|
|
},
|
2019-10-22 01:07:24 +08:00
|
|
|
radius: 50000
|
2016-04-21 23:27:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
);
|
2016-04-21 23:24:25 +08:00
|
|
|
|
2016-04-21 23:27:20 +08:00
|
|
|
var testClient = new TestClient(mapConfig, 1234);
|
2016-04-21 23:24:25 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
testClient.getLayergroup({ response: ERROR_RESPONSE }, function (err, layergroupResult) {
|
2016-04-21 23:27:20 +08:00
|
|
|
assert.ok(!err, err);
|
2016-04-21 23:24:25 +08:00
|
|
|
|
2016-04-21 23:27:20 +08:00
|
|
|
assert.equal(layergroupResult.errors.length, 1);
|
|
|
|
assert.equal(layergroupResult.errors[0], 'Missing analysis node.id="INVALID-SOURCE-ID" for layer=0');
|
2016-04-21 23:24:25 +08:00
|
|
|
|
2016-04-21 23:27:20 +08:00
|
|
|
testClient.drain(done);
|
2016-04-21 23:24:25 +08:00
|
|
|
});
|
|
|
|
});
|
2016-06-13 18:20:56 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should handle missing analyses when layers point to nonexistent one', function (done) {
|
2016-06-21 23:25:28 +08:00
|
|
|
var mapConfig = createMapConfig(
|
|
|
|
[
|
|
|
|
{
|
2019-10-22 01:07:24 +08:00
|
|
|
type: 'http',
|
|
|
|
options: {
|
|
|
|
urlTemplate: 'http://{s}.basemaps.cartocdn.com/light_only_labels/{z}/{x}/{y}.png',
|
|
|
|
subdomains: 'abcd'
|
2016-06-21 23:25:28 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2019-10-22 01:07:24 +08:00
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
source: {
|
|
|
|
id: 'ID-FOR-NONEXISTENT-ANALYSIS'
|
2016-06-21 23:25:28 +08:00
|
|
|
},
|
2019-10-22 01:07:24 +08:00
|
|
|
cartocss: '#polygons { polygon-fill: red; }',
|
|
|
|
cartocss_version: '2.3.0'
|
2016-06-21 23:25:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
var testClient = new TestClient(mapConfig, 1234);
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
testClient.getLayergroup({ response: ERROR_RESPONSE }, function (err, layergroupResult) {
|
2016-06-21 23:25:28 +08:00
|
|
|
assert.ok(!err, err);
|
|
|
|
|
|
|
|
assert.equal(layergroupResult.errors.length, 1);
|
|
|
|
assert.equal(
|
|
|
|
layergroupResult.errors[0],
|
|
|
|
'Missing analysis node.id="ID-FOR-NONEXISTENT-ANALYSIS" for layer=1'
|
|
|
|
);
|
|
|
|
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should handle missing analyses when dataviews point to nonexistent one', function (done) {
|
2016-06-21 23:25:28 +08:00
|
|
|
var mapConfig = createMapConfig(
|
|
|
|
[
|
|
|
|
{
|
2019-10-22 01:07:24 +08:00
|
|
|
type: 'http',
|
|
|
|
options: {
|
|
|
|
urlTemplate: 'http://{s}.basemaps.cartocdn.com/light_only_labels/{z}/{x}/{y}.png',
|
|
|
|
subdomains: 'abcd'
|
2016-06-21 23:25:28 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2019-10-22 01:07:24 +08:00
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: 'select * from populated_places_simple_reduced',
|
|
|
|
cartocss: '#polygons { polygon-fill: red; }',
|
|
|
|
cartocss_version: '2.3.0'
|
2016-06-21 23:25:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
{
|
|
|
|
pop_max_histogram: {
|
|
|
|
source: {
|
|
|
|
id: 'ID-FOR-NONEXISTENT-ANALYSIS'
|
|
|
|
},
|
|
|
|
type: 'histogram',
|
|
|
|
options: {
|
|
|
|
column: 'pop_max'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
var testClient = new TestClient(mapConfig, 1234);
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
testClient.getLayergroup({ response: ERROR_RESPONSE }, function (err, layergroupResult) {
|
2016-06-21 23:25:28 +08:00
|
|
|
assert.ok(!err, err);
|
|
|
|
|
|
|
|
assert.equal(layergroupResult.errors.length, 1);
|
|
|
|
assert.equal(layergroupResult.errors[0], 'Node with `source.id="ID-FOR-NONEXISTENT-ANALYSIS"`' +
|
|
|
|
' not found in analyses for dataview "pop_max_histogram"');
|
|
|
|
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('camshaft: should return error missing analysis nodes for layers with some context', function (done) {
|
2016-06-13 18:20:56 +08:00
|
|
|
var mapConfig = createMapConfig(
|
|
|
|
[
|
|
|
|
{
|
2019-10-22 01:07:24 +08:00
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
source: {
|
|
|
|
id: 'HEAD'
|
2016-06-13 18:20:56 +08:00
|
|
|
},
|
2019-10-22 01:07:24 +08:00
|
|
|
cartocss: '#polygons { polygon-fill: red; }',
|
|
|
|
cartocss_version: '2.3.0'
|
2016-06-13 18:20:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
{},
|
|
|
|
[
|
|
|
|
{
|
2019-10-22 01:07:24 +08:00
|
|
|
id: 'HEAD',
|
|
|
|
type: 'buffer',
|
|
|
|
params: {
|
|
|
|
source: {
|
|
|
|
id: 'HEAD',
|
|
|
|
type: 'source',
|
|
|
|
params: {
|
|
|
|
query: 'select * from populated_places_simple_reduced'
|
2016-06-13 18:20:56 +08:00
|
|
|
}
|
|
|
|
},
|
2019-10-22 01:07:24 +08:00
|
|
|
radius: 50000
|
2016-06-13 18:20:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
var testClient = new TestClient(mapConfig); // No apikey provided -> using default public apikey
|
2016-06-13 18:20:56 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
testClient.getLayergroup({ response: AUTH_ERROR_RESPONSE }, function (err, layergroupResult) {
|
2016-06-13 18:20:56 +08:00
|
|
|
assert.ok(!err, err);
|
|
|
|
|
|
|
|
assert.equal(layergroupResult.errors.length, 1);
|
|
|
|
assert.equal(
|
|
|
|
layergroupResult.errors[0],
|
|
|
|
'Analysis requires authentication with API key: permission denied.'
|
|
|
|
);
|
|
|
|
|
2016-06-22 00:26:10 +08:00
|
|
|
assert.equal(layergroupResult.errors_with_context[0].type, 'analysis');
|
|
|
|
assert.equal(
|
|
|
|
layergroupResult.errors_with_context[0].message,
|
|
|
|
'Analysis requires authentication with API key: permission denied.'
|
|
|
|
);
|
2016-06-27 00:43:04 +08:00
|
|
|
assert.equal(layergroupResult.errors_with_context[0].analysis.id, 'HEAD');
|
|
|
|
assert.equal(layergroupResult.errors_with_context[0].analysis.type, 'buffer');
|
2016-06-13 18:20:56 +08:00
|
|
|
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('camshaft: should return error: Missing required param "radius"; with context', function (done) {
|
2016-06-13 18:20:56 +08:00
|
|
|
var mapConfig = createMapConfig(
|
|
|
|
[
|
|
|
|
{
|
2019-10-22 01:07:24 +08:00
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
source: {
|
|
|
|
id: 'HEAD'
|
2016-06-13 18:20:56 +08:00
|
|
|
},
|
2019-10-22 01:07:24 +08:00
|
|
|
cartocss: '#polygons { polygon-fill: red; }',
|
|
|
|
cartocss_version: '2.3.0'
|
2016-06-13 18:20:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
{},
|
|
|
|
[
|
|
|
|
{
|
2019-10-22 01:07:24 +08:00
|
|
|
id: 'HEAD',
|
|
|
|
type: 'buffer',
|
|
|
|
params: {
|
|
|
|
source: {
|
|
|
|
id: 'HEAD2',
|
|
|
|
type: 'source',
|
|
|
|
params: {
|
|
|
|
query: 'select * from populated_places_simple_reduced'
|
2016-06-13 18:20:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
var testClient = new TestClient(mapConfig, 1234);
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
testClient.getLayergroup({ response: ERROR_RESPONSE }, function (err, layergroupResult) {
|
2016-06-13 18:20:56 +08:00
|
|
|
assert.ok(!err, err);
|
|
|
|
|
|
|
|
assert.equal(layergroupResult.errors.length, 1);
|
|
|
|
assert.equal(
|
|
|
|
layergroupResult.errors[0],
|
|
|
|
'Missing required param "radius"'
|
|
|
|
);
|
|
|
|
|
2016-06-22 00:26:10 +08:00
|
|
|
assert.equal(layergroupResult.errors_with_context[0].type, 'analysis');
|
|
|
|
assert.equal(layergroupResult.errors_with_context[0].message, 'Missing required param "radius"');
|
2016-06-27 00:43:04 +08:00
|
|
|
assert.equal(layergroupResult.errors_with_context[0].analysis.id, 'HEAD');
|
|
|
|
assert.equal(layergroupResult.errors_with_context[0].analysis.type, 'buffer');
|
2016-06-13 18:20:56 +08:00
|
|
|
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should return missing param error of outer node indicating the node_id and context', function (done) {
|
2016-07-11 21:48:26 +08:00
|
|
|
var mapConfig = createMapConfig([{
|
2019-10-22 01:07:24 +08:00
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
source: {
|
|
|
|
id: 'HEAD'
|
2016-07-11 21:48:26 +08:00
|
|
|
},
|
2019-10-22 01:07:24 +08:00
|
|
|
cartocss: '#polygons { polygon-fill: red; }',
|
|
|
|
cartocss_version: '2.3.0'
|
2016-07-11 21:48:26 +08:00
|
|
|
}
|
|
|
|
}], {}, [{
|
2019-10-22 01:07:24 +08:00
|
|
|
id: 'HEAD',
|
|
|
|
type: 'buffer',
|
|
|
|
params: {
|
|
|
|
source: {
|
|
|
|
id: 'HEAD2',
|
|
|
|
type: 'buffer',
|
|
|
|
params: {
|
|
|
|
source: {
|
|
|
|
id: 'HEAD3',
|
|
|
|
type: 'source',
|
|
|
|
params: {
|
|
|
|
query: 'select * from populated_places_simple_reduced'
|
2016-07-11 21:48:26 +08:00
|
|
|
}
|
|
|
|
},
|
2019-10-22 01:07:24 +08:00
|
|
|
radius: 10
|
2016-07-11 21:48:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// radius: 'missing'
|
|
|
|
}]);
|
|
|
|
|
|
|
|
var testClient = new TestClient(mapConfig, 1234);
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
testClient.getLayergroup({ response: ERROR_RESPONSE }, function (err, layergroupResult) {
|
2016-07-11 21:48:26 +08:00
|
|
|
assert.ok(!err, err);
|
|
|
|
|
|
|
|
assert.equal(layergroupResult.errors.length, 1);
|
|
|
|
assert.equal(
|
|
|
|
layergroupResult.errors[0],
|
|
|
|
'Missing required param "radius"'
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(layergroupResult.errors_with_context[0].type, 'analysis');
|
|
|
|
assert.equal(layergroupResult.errors_with_context[0].message, 'Missing required param "radius"');
|
|
|
|
assert.equal(layergroupResult.errors_with_context[0].analysis.id, 'HEAD');
|
|
|
|
assert.equal(layergroupResult.errors_with_context[0].analysis.type, 'buffer');
|
|
|
|
assert.equal(layergroupResult.errors_with_context[0].analysis.node_id, 'HEAD');
|
|
|
|
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should return invalid param type error of inner node indicating the node_id and context', function (done) {
|
2016-07-11 21:48:26 +08:00
|
|
|
var mapConfig = createMapConfig([{
|
2019-10-22 01:07:24 +08:00
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
source: {
|
|
|
|
id: 'HEAD'
|
2016-07-11 21:48:26 +08:00
|
|
|
},
|
2019-10-22 01:07:24 +08:00
|
|
|
cartocss: '#polygons { polygon-fill: red; }',
|
|
|
|
cartocss_version: '2.3.0'
|
2016-07-11 21:48:26 +08:00
|
|
|
}
|
|
|
|
}], {}, [{
|
2019-10-22 01:07:24 +08:00
|
|
|
id: 'HEAD',
|
|
|
|
type: 'buffer',
|
|
|
|
params: {
|
|
|
|
source: {
|
|
|
|
id: 'HEAD2',
|
|
|
|
type: 'buffer',
|
|
|
|
params: {
|
|
|
|
source: {
|
|
|
|
id: 'HEAD3',
|
|
|
|
type: 'source',
|
|
|
|
params: {
|
|
|
|
query: 'select * from populated_places_simple_reduced'
|
2016-07-11 21:48:26 +08:00
|
|
|
}
|
|
|
|
},
|
2019-10-22 01:07:24 +08:00
|
|
|
radius: 'invalid_radius'
|
2016-07-11 21:48:26 +08:00
|
|
|
}
|
|
|
|
},
|
2019-10-22 01:07:24 +08:00
|
|
|
radius: 10
|
2016-07-11 21:48:26 +08:00
|
|
|
}
|
|
|
|
}]);
|
|
|
|
|
|
|
|
var testClient = new TestClient(mapConfig, 1234);
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
testClient.getLayergroup({ response: ERROR_RESPONSE }, function (err, layergroupResult) {
|
2016-07-11 21:48:26 +08:00
|
|
|
assert.ok(!err, err);
|
|
|
|
|
|
|
|
assert.equal(layergroupResult.errors.length, 1);
|
|
|
|
assert.equal(
|
|
|
|
layergroupResult.errors[0],
|
|
|
|
'Invalid type for param "radius", expects "number" type, got `"invalid_radius"`'
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(layergroupResult.errors_with_context[0].type, 'analysis');
|
|
|
|
assert.equal(
|
|
|
|
layergroupResult.errors_with_context[0].message,
|
|
|
|
'Invalid type for param "radius", expects "number" type, got `"invalid_radius"`'
|
|
|
|
);
|
|
|
|
assert.equal(layergroupResult.errors_with_context[0].analysis.id, 'HEAD');
|
|
|
|
assert.equal(layergroupResult.errors_with_context[0].analysis.type, 'buffer');
|
|
|
|
assert.equal(layergroupResult.errors_with_context[0].analysis.node_id, 'HEAD2');
|
|
|
|
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should return "function does not exist" indicating the node_id and context', function (done) {
|
2017-05-11 18:55:53 +08:00
|
|
|
var mapConfig = createMapConfig([{
|
2019-10-22 01:07:24 +08:00
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
source: {
|
|
|
|
id: 'HEAD'
|
2017-05-11 18:55:53 +08:00
|
|
|
},
|
2019-10-22 01:07:24 +08:00
|
|
|
cartocss: '#polygons { polygon-fill: red; }',
|
|
|
|
cartocss_version: '2.3.0'
|
2017-05-11 18:55:53 +08:00
|
|
|
}
|
|
|
|
}], {}, [{
|
2019-10-22 01:07:24 +08:00
|
|
|
id: 'HEAD',
|
|
|
|
type: 'buffer',
|
|
|
|
params: {
|
|
|
|
source: {
|
|
|
|
id: 'HEAD2',
|
|
|
|
type: 'buffer',
|
|
|
|
params: {
|
|
|
|
source: {
|
|
|
|
id: 'HEAD3',
|
|
|
|
type: 'deprecated-sql-function',
|
|
|
|
params: {
|
|
|
|
id: 'HEAD4',
|
|
|
|
function_name: 'DEP_EXT_does_not_exist_fn',
|
|
|
|
primary_source: {
|
|
|
|
type: 'source',
|
|
|
|
params: {
|
|
|
|
query: 'select * from populated_places_simple_reduced'
|
2017-05-11 18:55:53 +08:00
|
|
|
}
|
|
|
|
},
|
2019-10-22 01:07:24 +08:00
|
|
|
function_args: ['wadus']
|
2017-05-11 18:55:53 +08:00
|
|
|
}
|
|
|
|
},
|
2019-10-22 01:07:24 +08:00
|
|
|
radius: 10
|
2017-05-11 18:55:53 +08:00
|
|
|
}
|
|
|
|
},
|
2019-10-22 01:07:24 +08:00
|
|
|
radius: 10
|
2017-05-11 18:55:53 +08:00
|
|
|
}
|
|
|
|
}]);
|
|
|
|
|
|
|
|
var testClient = new TestClient(mapConfig, 1234);
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
testClient.getLayergroup({ response: ERROR_RESPONSE }, function (err, layergroupResult) {
|
2017-05-11 18:55:53 +08:00
|
|
|
assert.ok(!err, err);
|
|
|
|
|
|
|
|
assert.equal(layergroupResult.errors.length, 1);
|
|
|
|
assert.equal(
|
|
|
|
layergroupResult.errors[0],
|
|
|
|
'function dep_ext_does_not_exist_fn(unknown, unknown, unknown, text[], unknown) does not exist'
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(layergroupResult.errors_with_context[0].type, 'analysis');
|
|
|
|
assert.equal(
|
|
|
|
layergroupResult.errors_with_context[0].message,
|
|
|
|
'function dep_ext_does_not_exist_fn(unknown, unknown, unknown, text[], unknown) does not exist'
|
|
|
|
);
|
|
|
|
assert.equal(layergroupResult.errors_with_context[0].analysis.id, 'HEAD');
|
|
|
|
assert.equal(layergroupResult.errors_with_context[0].analysis.type, 'buffer');
|
|
|
|
assert.equal(layergroupResult.errors_with_context[0].analysis.node_id, 'HEAD3');
|
|
|
|
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
2016-04-21 23:24:25 +08:00
|
|
|
});
|