Camel case
This commit is contained in:
parent
e49cb524a8
commit
734c373f3d
@ -11,14 +11,14 @@ var FILTER_MIN_ROWS = 65536;
|
||||
// Maximum filtered fraction to not apply overviews
|
||||
var FILTER_MAX_FRACTION = 0.2;
|
||||
|
||||
function apply_filters_to_query (query, filters, bbox_filter) {
|
||||
function applyFiltersToQuery (query, filters, bboxFilter) {
|
||||
if (filters && !_.isEmpty(filters)) {
|
||||
var analysisFilter = new AnalysisFilter(filters);
|
||||
query = analysisFilter.sql(query);
|
||||
}
|
||||
if (bbox_filter) {
|
||||
var bboxFilter = new BBoxFilter(bbox_filter.options, bbox_filter.params);
|
||||
query = bboxFilter.sql(query);
|
||||
if (bboxFilter) {
|
||||
var filter = new BBoxFilter(bboxFilter.options, bboxFilter.params);
|
||||
query = filter.sql(query);
|
||||
}
|
||||
return query;
|
||||
}
|
||||
@ -36,72 +36,72 @@ module.exports = OverviewsQueryRewriter;
|
||||
// Build UNION expression to replace table, using overviews metadata
|
||||
// overviews metadata: { 1: 'table_ov1', ... }
|
||||
// assume table and overview names include schema if necessary and are quoted as needed
|
||||
function overviews_view_for_table (table, overviews_metadata, indent) {
|
||||
var condition, i, len, ov_table, overview_layers, selects, z_hi, z_lo;
|
||||
var parsed_table = TableNameParser.parse(table);
|
||||
function overviewsViewForTable (table, overviewsMetadata, indent) {
|
||||
var condition, i, len, ovTable, overviewLayers, selects, zHi, zLo;
|
||||
var parsedTable = TableNameParser.parse(table);
|
||||
|
||||
var sorted_overviews = []; // [[1, 'table_ov1'], ...]
|
||||
var sortedOverviews = []; // [[1, 'table_ov1'], ...]
|
||||
|
||||
indent = indent || ' ';
|
||||
for (var z in overviews_metadata) {
|
||||
if (Object.prototype.hasOwnProperty.call(overviews_metadata, z) && z !== 'schema') {
|
||||
sorted_overviews.push([z, overviews_metadata[z].table]);
|
||||
for (var z in overviewsMetadata) {
|
||||
if (Object.prototype.hasOwnProperty.call(overviewsMetadata, z) && z !== 'schema') {
|
||||
sortedOverviews.push([z, overviewsMetadata[z].table]);
|
||||
}
|
||||
}
|
||||
sorted_overviews.sort(function (a, b) { return a[0] - b[0]; });
|
||||
sortedOverviews.sort(function (a, b) { return a[0] - b[0]; });
|
||||
|
||||
overview_layers = [];
|
||||
z_lo = null;
|
||||
for (i = 0, len = sorted_overviews.length; i < len; i++) {
|
||||
z_hi = parseInt(sorted_overviews[i][0]);
|
||||
ov_table = sorted_overviews[i][1];
|
||||
overview_layers.push([overview_z_condition(z_lo, z_hi), ov_table]);
|
||||
z_lo = z_hi;
|
||||
overviewLayers = [];
|
||||
zLo = null;
|
||||
for (i = 0, len = sortedOverviews.length; i < len; i++) {
|
||||
zHi = parseInt(sortedOverviews[i][0]);
|
||||
ovTable = sortedOverviews[i][1];
|
||||
overviewLayers.push([overviewZCondition(zLo, zHi), ovTable]);
|
||||
zLo = zHi;
|
||||
}
|
||||
overview_layers.push(['_vovw_z > ' + z_lo, table]);
|
||||
overviewLayers.push(['_vovw_z > ' + zLo, table]);
|
||||
|
||||
selects = overview_layers.map(function (condition_table) {
|
||||
condition = condition_table[0];
|
||||
ov_table = TableNameParser.parse(condition_table[1]);
|
||||
ov_table.schema = ov_table.schema || parsed_table.schema;
|
||||
var ov_identifier = TableNameParser.table_identifier(ov_table);
|
||||
return indent + 'SELECT * FROM ' + ov_identifier + ', _vovw_scale WHERE ' + condition;
|
||||
selects = overviewLayers.map(function (conditionTable) {
|
||||
condition = conditionTable[0];
|
||||
ovTable = TableNameParser.parse(conditionTable[1]);
|
||||
ovTable.schema = ovTable.schema || parsedTable.schema;
|
||||
var ovIdentifier = TableNameParser.table_identifier(ovTable);
|
||||
return indent + 'SELECT * FROM ' + ovIdentifier + ', _vovw_scale WHERE ' + condition;
|
||||
});
|
||||
|
||||
return selects.join('\n' + indent + 'UNION ALL\n');
|
||||
}
|
||||
|
||||
function overview_z_condition (z_lo, z_hi) {
|
||||
if (z_lo !== null) {
|
||||
if (z_lo === z_hi - 1) {
|
||||
return '_vovw_z = ' + z_hi;
|
||||
function overviewZCondition (zLo, zHi) {
|
||||
if (zLo !== null) {
|
||||
if (zLo === zHi - 1) {
|
||||
return '_vovw_z = ' + zHi;
|
||||
} else {
|
||||
return '_vovw_z > ' + z_lo + ' AND _vovw_z <= ' + z_hi;
|
||||
return '_vovw_z > ' + zLo + ' AND _vovw_z <= ' + zHi;
|
||||
}
|
||||
} else {
|
||||
if (z_hi === 0) {
|
||||
return '_vovw_z = ' + z_hi;
|
||||
if (zHi === 0) {
|
||||
return '_vovw_z = ' + zHi;
|
||||
} else {
|
||||
return '_vovw_z <= ' + z_hi;
|
||||
return '_vovw_z <= ' + zHi;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// name to be used for the view of the table using overviews
|
||||
function overviews_view_name (table) {
|
||||
var parsed_table = TableNameParser.parse(table);
|
||||
parsed_table.table = '_vovw_' + parsed_table.table;
|
||||
parsed_table.schema = null;
|
||||
return TableNameParser.table_identifier(parsed_table);
|
||||
function overviewsViewName (table) {
|
||||
var parsedTable = TableNameParser.parse(table);
|
||||
parsedTable.table = '_vovw_' + parsedTable.table;
|
||||
parsedTable.schema = null;
|
||||
return TableNameParser.table_identifier(parsedTable);
|
||||
}
|
||||
|
||||
// replace a table name in a query by anoter name
|
||||
function replace_table_in_query (sql, old_table_name, replacement) {
|
||||
var old_table = TableNameParser.parse(old_table_name);
|
||||
var old_table_ident = TableNameParser.table_identifier(old_table);
|
||||
function replaceTableInQuery (sql, oldTableName, replacement) {
|
||||
var oldTable = TableNameParser.parse(oldTableName);
|
||||
var oldTableIdent = TableNameParser.table_identifier(oldTable);
|
||||
|
||||
// regular expression prefix (beginning) to match a table name
|
||||
function pattern_prefix (schema, identifier) {
|
||||
function patternPrefix (schema, identifier) {
|
||||
if (schema) {
|
||||
// to match a table name including schema prefix
|
||||
// name should not be part of another name, so we require
|
||||
@ -123,7 +123,7 @@ function replace_table_in_query (sql, old_table_name, replacement) {
|
||||
}
|
||||
|
||||
// regular expression suffix (ending) to match a table name
|
||||
function pattern_suffix (identifier) {
|
||||
function patternSuffix (identifier) {
|
||||
// name shouldn't be the prefix of a longer name
|
||||
if (identifier[identifier.length - 1] !== '"') {
|
||||
return '\\b';
|
||||
@ -133,23 +133,23 @@ function replace_table_in_query (sql, old_table_name, replacement) {
|
||||
}
|
||||
|
||||
// regular expression to match a table name
|
||||
var regexp = pattern_prefix(old_table.schema, old_table_ident) +
|
||||
old_table_ident +
|
||||
pattern_suffix(old_table_ident);
|
||||
var regexp = patternPrefix(oldTable.schema, oldTableIdent) +
|
||||
oldTableIdent +
|
||||
patternSuffix(oldTableIdent);
|
||||
|
||||
// replace all occurrences of the table pattern
|
||||
return sql.replace(new RegExp(regexp, 'g'), replacement);
|
||||
}
|
||||
|
||||
function replace_table_in_query_with_schema (query, table, schema, replacement) {
|
||||
function replaceTableInQueryWithSchema (query, table, schema, replacement) {
|
||||
if (replacement) {
|
||||
query = replace_table_in_query(query, table, replacement);
|
||||
var parsed_table = TableNameParser.parse(table);
|
||||
if (!parsed_table.schema && schema) {
|
||||
query = replaceTableInQuery(query, table, replacement);
|
||||
var parsedTable = TableNameParser.parse(table);
|
||||
if (!parsedTable.schema && schema) {
|
||||
// replace also the qualified table name, if the table wasn't qualified
|
||||
parsed_table.schema = schema;
|
||||
table = TableNameParser.table_identifier(parsed_table);
|
||||
query = replace_table_in_query(query, table, replacement);
|
||||
parsedTable.schema = schema;
|
||||
table = TableNameParser.table_identifier(parsedTable);
|
||||
query = replaceTableInQuery(query, table, replacement);
|
||||
}
|
||||
}
|
||||
return query;
|
||||
@ -157,20 +157,20 @@ function replace_table_in_query_with_schema (query, table, schema, replacement)
|
||||
|
||||
// Build query to use overviews for a variant zoom level (given by a expression to
|
||||
// be evaluated by the database server)
|
||||
function overviews_query_with_zoom_expression (query, overviews, zoom_level_expression) {
|
||||
var replaced_query = query;
|
||||
var sql = 'WITH\n _vovw_scale AS ( SELECT ' + zoom_level_expression + ' AS _vovw_z )';
|
||||
function overviewsQueryWithZoomExpression (query, overviews, zoomLevelExpression) {
|
||||
var replacedQuery = query;
|
||||
var sql = 'WITH\n _vovw_scale AS ( SELECT ' + zoomLevelExpression + ' AS _vovw_z )';
|
||||
var replacement;
|
||||
_.each(Object.keys(overviews), function (table) {
|
||||
var table_overviews = overviews[table];
|
||||
var table_view = overviews_view_name(table);
|
||||
var schema = table_overviews.schema;
|
||||
replacement = '(\n' + overviews_view_for_table(table, table_overviews) + '\n ) AS ' + table_view;
|
||||
replaced_query = replace_table_in_query_with_schema(replaced_query, table, schema, replacement);
|
||||
var tableOverviews = overviews[table];
|
||||
var tableView = overviewsViewName(table);
|
||||
var schema = tableOverviews.schema;
|
||||
replacement = '(\n' + overviewsViewForTable(table, tableOverviews) + '\n ) AS ' + tableView;
|
||||
replacedQuery = replaceTableInQueryWithSchema(replacedQuery, table, schema, replacement);
|
||||
});
|
||||
if (replaced_query !== query) {
|
||||
if (replacedQuery !== query) {
|
||||
sql += '\n';
|
||||
sql += replaced_query;
|
||||
sql += replacedQuery;
|
||||
} else {
|
||||
sql = query;
|
||||
}
|
||||
@ -178,27 +178,27 @@ function overviews_query_with_zoom_expression (query, overviews, zoom_level_expr
|
||||
}
|
||||
|
||||
// Build query to use overviews for a specific zoom level value
|
||||
function overviews_query_with_definite_zoom (query, overviews, zoom_level) {
|
||||
var replaced_query = query;
|
||||
function overviewsQueryWithDefiniteZoom (query, overviews, zoomLevel) {
|
||||
var replacedQuery = query;
|
||||
var replacement;
|
||||
_.each(Object.keys(overviews), function (table) {
|
||||
var table_overviews = overviews[table];
|
||||
var schema = table_overviews.schema;
|
||||
replacement = overview_table_for_zoom_level(table_overviews, zoom_level);
|
||||
replaced_query = replace_table_in_query_with_schema(replaced_query, table, schema, replacement);
|
||||
var tableOverviews = overviews[table];
|
||||
var schema = tableOverviews.schema;
|
||||
replacement = overviewTableForZoomLevel(tableOverviews, zoomLevel);
|
||||
replacedQuery = replaceTableInQueryWithSchema(replacedQuery, table, schema, replacement);
|
||||
});
|
||||
return replaced_query;
|
||||
return replacedQuery;
|
||||
}
|
||||
|
||||
// Find a suitable overview table for a specific zoom_level
|
||||
function overview_table_for_zoom_level (table_overviews, zoom_level) {
|
||||
var overview_table;
|
||||
if (table_overviews) {
|
||||
overview_table = table_overviews[zoom_level];
|
||||
if (!overview_table) {
|
||||
_.every(Object.keys(table_overviews).sort(function (x, y) { return x - y; }), function (overview_zoom) {
|
||||
if (+overview_zoom > +zoom_level) {
|
||||
overview_table = table_overviews[overview_zoom];
|
||||
// Find a suitable overview table for a specific zoomLevel
|
||||
function overviewTableForZoomLevel (tableOverviews, zoomLevel) {
|
||||
var overviewTable;
|
||||
if (tableOverviews) {
|
||||
overviewTable = tableOverviews[zoomLevel];
|
||||
if (!overviewTable) {
|
||||
_.every(Object.keys(tableOverviews).sort(function (x, y) { return x - y; }), function (overviewZoom) {
|
||||
if (+overviewZoom > +zoomLevel) {
|
||||
overviewTable = tableOverviews[overviewZoom];
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
@ -206,10 +206,10 @@ function overview_table_for_zoom_level (table_overviews, zoom_level) {
|
||||
});
|
||||
}
|
||||
}
|
||||
if (overview_table) {
|
||||
overview_table = overview_table.table;
|
||||
if (overviewTable) {
|
||||
overviewTable = overviewTable.table;
|
||||
}
|
||||
return overview_table;
|
||||
return overviewTable;
|
||||
}
|
||||
|
||||
// Transform an SQL query so that it uses overviews.
|
||||
@ -226,87 +226,87 @@ function overview_table_for_zoom_level (table_overviews, zoom_level) {
|
||||
// {
|
||||
// overviews: // overview tables metadata
|
||||
// { 'table-name': {1: { table: 'overview-table-1' }, ... }, ... },
|
||||
// zoom_level: ..., // optional zoom level
|
||||
// zoomLevel: ..., // optional zoom level
|
||||
// filters: ..., // filters definition
|
||||
// unfiltered_query: ..., // query without the filters
|
||||
// bbox_filter: ... // bounding-box filter
|
||||
// unfilteredQuery: ..., // query without the filters
|
||||
// bboxFilter: ... // bounding-box filter
|
||||
// }
|
||||
OverviewsQueryRewriter.prototype.query = function (query, data, options) {
|
||||
options = options || {};
|
||||
data = data || {};
|
||||
|
||||
var overviews = data.overviews;
|
||||
var unfiltered_query = data.unfiltered_query;
|
||||
var unfilteredQuery = data.unfiltered_query;
|
||||
var filters = data.filters;
|
||||
var bbox_filter = data.bbox_filter;
|
||||
var bboxFilter = data.bbox_filter;
|
||||
|
||||
if (!unfiltered_query) {
|
||||
unfiltered_query = query;
|
||||
if (!unfilteredQuery) {
|
||||
unfilteredQuery = query;
|
||||
}
|
||||
|
||||
if (!should_use_overviews(unfiltered_query, data)) {
|
||||
if (!shouldUseOverviews(unfilteredQuery, data)) {
|
||||
return query;
|
||||
}
|
||||
|
||||
var rewritten_query;
|
||||
var rewrittenQuery;
|
||||
|
||||
var zoom_level_expression = this.options.zoom_level;
|
||||
var zoom_level = zoom_level_for_query(unfiltered_query, zoom_level_expression, options);
|
||||
var zoomLevelExpression = this.options.zoom_level;
|
||||
var zoomLevel = zoomLevelForQuery(unfilteredQuery, zoomLevelExpression, options);
|
||||
|
||||
rewritten_query = overviews_query(unfiltered_query, overviews, zoom_level, zoom_level_expression);
|
||||
rewrittenQuery = overviewsQuery(unfilteredQuery, overviews, zoomLevel, zoomLevelExpression);
|
||||
|
||||
if (rewritten_query === unfiltered_query) {
|
||||
if (rewrittenQuery === unfilteredQuery) {
|
||||
// could not or didn't need to alter the query
|
||||
rewritten_query = query;
|
||||
rewrittenQuery = query;
|
||||
} else {
|
||||
rewritten_query = apply_filters_to_query(rewritten_query, filters, bbox_filter);
|
||||
rewrittenQuery = applyFiltersToQuery(rewrittenQuery, filters, bboxFilter);
|
||||
}
|
||||
|
||||
return rewritten_query;
|
||||
return rewrittenQuery;
|
||||
};
|
||||
|
||||
function zoom_level_for_query (query, zoom_level_expression, options) {
|
||||
var zoom_level = null;
|
||||
function zoomLevelForQuery (query, zoomLevelExpression, options) {
|
||||
var zoomLevel = null;
|
||||
if (_.has(options, 'zoom_level')) {
|
||||
zoom_level = options.zoom_level || '0';
|
||||
zoomLevel = options.zoom_level || '0';
|
||||
}
|
||||
if (zoom_level === null && !zoom_level_expression) {
|
||||
zoom_level = '0';
|
||||
if (zoomLevel === null && !zoomLevelExpression) {
|
||||
zoomLevel = '0';
|
||||
}
|
||||
return zoom_level;
|
||||
return zoomLevel;
|
||||
}
|
||||
|
||||
function overviews_query (query, overviews, zoom_level, zoom_level_expression) {
|
||||
if (zoom_level || zoom_level === '0' || zoom_level === 0) {
|
||||
return overviews_query_with_definite_zoom(query, overviews, zoom_level);
|
||||
function overviewsQuery (query, overviews, zoomLevel, zoomLevelExpression) {
|
||||
if (zoomLevel || zoomLevel === '0' || zoomLevel === 0) {
|
||||
return overviewsQueryWithDefiniteZoom(query, overviews, zoomLevel);
|
||||
} else {
|
||||
return overviews_query_with_zoom_expression(query, overviews, zoom_level_expression);
|
||||
return overviewsQueryWithZoomExpression(query, overviews, zoomLevelExpression);
|
||||
}
|
||||
}
|
||||
|
||||
function should_use_overviews (query, data) {
|
||||
function shouldUseOverviews (query, data) {
|
||||
data = data || {};
|
||||
var use_overviews = data.overviews && is_supported_query(query);
|
||||
if (use_overviews && data.filters && data.filter_stats) {
|
||||
var filtered_rows = data.filter_stats.filtered_rows;
|
||||
var unfiltered_rows = data.filter_stats.unfiltered_rows;
|
||||
if (unfiltered_rows && (filtered_rows || filtered_rows === 0)) {
|
||||
use_overviews = filtered_rows >= FILTER_MIN_ROWS ||
|
||||
(filtered_rows / unfiltered_rows) > FILTER_MAX_FRACTION;
|
||||
var useOverviews = data.overviews && isSupportedQuery(query);
|
||||
if (useOverviews && data.filters && data.filter_stats) {
|
||||
var filteredRows = data.filter_stats.filtered_rows;
|
||||
var unfilteredRows = data.filter_stats.unfiltered_rows;
|
||||
if (unfilteredRows && (filteredRows || filteredRows === 0)) {
|
||||
useOverviews = filteredRows >= FILTER_MIN_ROWS ||
|
||||
(filteredRows / unfilteredRows) > FILTER_MAX_FRACTION;
|
||||
}
|
||||
}
|
||||
return use_overviews;
|
||||
return useOverviews;
|
||||
}
|
||||
|
||||
function is_supported_query (sql) {
|
||||
var basic_query = /\s*SELECT\s+[\*a-z0-9_,\s]+?\s+FROM\s+((\"[^"]+\"|[a-z0-9_]+)\.)?(\"[^"]+\"|[a-z0-9_]+)\s*;?\s*/i; // eslint-disable-line no-useless-escape
|
||||
var unwrapped_query = new RegExp('^' + basic_query.source + '$', 'i');
|
||||
function isSupportedQuery (sql) {
|
||||
var basicQuery = /\s*SELECT\s+[\*a-z0-9_,\s]+?\s+FROM\s+((\"[^"]+\"|[a-z0-9_]+)\.)?(\"[^"]+\"|[a-z0-9_]+)\s*;?\s*/i; // eslint-disable-line no-useless-escape
|
||||
var unwrappedQuery = new RegExp('^' + basicQuery.source + '$', 'i');
|
||||
// queries for named maps are wrapped like this:
|
||||
var wrapped_query = new RegExp(
|
||||
var wrappedQuery = new RegExp(
|
||||
'^\\s*SELECT\\s+\\*\\s+FROM\\s+\\(' +
|
||||
basic_query.source +
|
||||
basicQuery.source +
|
||||
'\\)\\s+AS\\s+wrapped_query\\s+WHERE\\s+\\d+=1\\s*$',
|
||||
'i'
|
||||
);
|
||||
return !!(sql.match(unwrapped_query) || sql.match(wrapped_query));
|
||||
return !!(sql.match(unwrappedQuery) || sql.match(wrappedQuery));
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ var _ = require('underscore');
|
||||
var redis = require('redis');
|
||||
var step = require('step');
|
||||
var strftime = require('strftime');
|
||||
var redis_stats_db = 5;
|
||||
var redisStatsDb = 5;
|
||||
|
||||
var mapnik = require('windshaft').mapnik;
|
||||
var semver = require('semver');
|
||||
@ -14,7 +14,7 @@ var semver = require('semver');
|
||||
var helper = require('../support/test-helper');
|
||||
var LayergroupToken = require('../../lib/models/layergroup-token');
|
||||
|
||||
var windshaft_fixtures = path.join(__dirname, '/../../node_modules/windshaft/test/fixtures');
|
||||
var windshaftFixtures = path.join(__dirname, '/../../node_modules/windshaft/test/fixtures');
|
||||
|
||||
var IMAGE_EQUALS_TOLERANCE_PER_MIL = 20;
|
||||
var IMAGE_EQUALS_HIGHER_TOLERANCE_PER_MIL = 25;
|
||||
@ -24,8 +24,8 @@ var serverOptions = require('../../lib/server-options');
|
||||
|
||||
var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
|
||||
['/api/v1/map', '/user/localhost/api/v1/map'].forEach(function (layergroup_url) {
|
||||
var suiteName = 'multilayer:postgres=layergroup_url=' + layergroup_url;
|
||||
['/api/v1/map', '/user/localhost/api/v1/map'].forEach(function (layergroupUrl) {
|
||||
var suiteName = 'multilayer:postgres=layergroupUrl=' + layergroupUrl;
|
||||
describe(suiteName, function () {
|
||||
var server;
|
||||
|
||||
@ -46,11 +46,11 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
|
||||
var cdbQueryTablesFromPostgresEnabledValue = true;
|
||||
|
||||
var expected_last_updated_epoch = 1234567890123; // this is hard-coded into SQLAPIEmu
|
||||
var expected_last_updated = new Date(expected_last_updated_epoch).toISOString();
|
||||
var expectedLastUpdatedEpoch = 1234567890123; // this is hard-coded into SQLAPIEmu
|
||||
var expectedLastUpdated = new Date(expectedLastUpdatedEpoch).toISOString();
|
||||
|
||||
var test_user = _.template(global.environment.postgres_auth_user, { user_id: 1 });
|
||||
var test_database = test_user + '_db';
|
||||
var testUser = _.template(global.environment.postgres_auth_user, { user_id: 1 });
|
||||
var testDatabase = testUser + '_db';
|
||||
|
||||
it('layergroup with 2 layers, each with its style', function (done) {
|
||||
var layergroup = {
|
||||
@ -77,29 +77,29 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
]
|
||||
};
|
||||
|
||||
var expected_token; // = "e34dd7e235138a062f8ba7ad051aa3a7";
|
||||
var expectedToken; // = "e34dd7e235138a062f8ba7ad051aa3a7";
|
||||
step(
|
||||
function do_post () {
|
||||
function doPost () {
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: layergroup_url,
|
||||
url: layergroupUrl,
|
||||
method: 'POST',
|
||||
headers: { host: 'localhost', 'Content-Type': 'application/json' },
|
||||
data: JSON.stringify(layergroup)
|
||||
}, {}, function (res) {
|
||||
assert.strictEqual(res.statusCode, 200, res.body);
|
||||
var parsedBody = JSON.parse(res.body);
|
||||
assert.strictEqual(parsedBody.last_updated, expected_last_updated);
|
||||
assert.strictEqual(parsedBody.last_updated, expectedLastUpdated);
|
||||
assert.strictEqual(res.headers['x-layergroup-id'], parsedBody.layergroupid);
|
||||
expected_token = parsedBody.layergroupid;
|
||||
expectedToken = parsedBody.layergroupid;
|
||||
next(null, res);
|
||||
});
|
||||
},
|
||||
function do_get_tile (err) {
|
||||
function doGetTile (err) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: layergroup_url + '/' + expected_token + ':cb0/0/0/0.png',
|
||||
url: layergroupUrl + '/' + expectedToken + ':cb0/0/0/0.png',
|
||||
method: 'GET',
|
||||
headers: { host: 'localhost' },
|
||||
encoding: 'binary'
|
||||
@ -114,7 +114,7 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
// Check X-Cache-Channel
|
||||
cc = res.headers['x-cache-channel'];
|
||||
assert.ok(cc);
|
||||
var dbname = test_database;
|
||||
var dbname = testDatabase;
|
||||
assert.strictEqual(cc.substring(0, dbname.length), dbname);
|
||||
if (!cdbQueryTablesFromPostgresEnabledValue) { // only test if it was using the SQL API
|
||||
var jsonquery = cc.substring(dbname.length + 1);
|
||||
@ -139,11 +139,11 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
});
|
||||
},
|
||||
// See https://github.com/CartoDB/Windshaft-cartodb/issues/170
|
||||
function do_get_tile_nosignature (err) {
|
||||
function doGetTileNoSignature (err) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: layergroup_url + '/localhost@' + expected_token + ':cb0/0/0/0.png',
|
||||
url: layergroupUrl + '/localhost@' + expectedToken + ':cb0/0/0/0.png',
|
||||
method: 'GET',
|
||||
headers: { host: 'localhost' },
|
||||
encoding: 'binary'
|
||||
@ -155,11 +155,11 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
next(err);
|
||||
});
|
||||
},
|
||||
function do_get_grid_layer0 (err) {
|
||||
function doGetGridLayer0 (err) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: layergroup_url + '/' + expected_token + '/0/0/0/0.grid.json',
|
||||
url: layergroupUrl + '/' + expectedToken + '/0/0/0/0.grid.json',
|
||||
headers: { host: 'localhost' },
|
||||
method: 'GET'
|
||||
}, {}, function (res) {
|
||||
@ -171,11 +171,11 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
});
|
||||
});
|
||||
},
|
||||
function do_get_grid_layer1 (err) {
|
||||
function doGetGridLayer1 (err) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: layergroup_url + '/' + expected_token + '/1/0/0/0.grid.json',
|
||||
url: layergroupUrl + '/' + expectedToken + '/1/0/0/0.grid.json',
|
||||
headers: { host: 'localhost' },
|
||||
method: 'GET'
|
||||
}, {}, function (res) {
|
||||
@ -188,7 +188,7 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
});
|
||||
},
|
||||
function finish (err) {
|
||||
keysToDelete['map_cfg|' + LayergroupToken.parse(expected_token).token] = 0;
|
||||
keysToDelete['map_cfg|' + LayergroupToken.parse(expectedToken).token] = 0;
|
||||
keysToDelete['user:localhost:mapviews:global'] = 5;
|
||||
done(err);
|
||||
}
|
||||
@ -222,15 +222,15 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
};
|
||||
|
||||
step(
|
||||
function do_create_get () {
|
||||
function doCreateGet () {
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: layergroup_url + '?config=' + encodeURIComponent(JSON.stringify(layergroup)),
|
||||
url: layergroupUrl + '?config=' + encodeURIComponent(JSON.stringify(layergroup)),
|
||||
method: 'GET',
|
||||
headers: { host: 'localhost' }
|
||||
}, {}, function (res, err) { next(err, res); });
|
||||
},
|
||||
function do_check_create (err, res) {
|
||||
function doCheckCreate (err, res) {
|
||||
assert.ifError(err);
|
||||
var parsed = JSON.parse(res.body);
|
||||
keysToDelete['map_cfg|' + LayergroupToken.parse(parsed.layergroupid).token] = 0;
|
||||
@ -265,28 +265,28 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
]
|
||||
};
|
||||
|
||||
var expected_token;
|
||||
var expectedToken;
|
||||
step(
|
||||
function do_create_get () {
|
||||
function doCreateGet () {
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: layergroup_url + '?config=' + encodeURIComponent(JSON.stringify(layergroup)),
|
||||
url: layergroupUrl + '?config=' + encodeURIComponent(JSON.stringify(layergroup)),
|
||||
method: 'GET',
|
||||
headers: { host: 'localhost' }
|
||||
}, {}, function (res, err) { next(err, res); });
|
||||
},
|
||||
function do_check_create (err, res) {
|
||||
function doCheckCreate (err, res) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(res.statusCode, 200, res.body);
|
||||
var parsedBody = JSON.parse(res.body);
|
||||
expected_token = parsedBody.layergroupid.split(':')[0];
|
||||
expectedToken = parsedBody.layergroupid.split(':')[0];
|
||||
helper.checkCache(res);
|
||||
helper.checkSurrogateKey(res, new QueryTables.QueryMetadata([
|
||||
{ dbname: 'test_windshaft_cartodb_user_1_db', table_name: 'test_table', schema_name: 'public' },
|
||||
{ dbname: 'test_windshaft_cartodb_user_1_db', table_name: 'test_table_2', schema_name: 'public' }
|
||||
]).key().join(' '));
|
||||
|
||||
keysToDelete['map_cfg|' + expected_token] = 0;
|
||||
keysToDelete['map_cfg|' + expectedToken] = 0;
|
||||
keysToDelete['user:localhost:mapviews:global'] = 5;
|
||||
|
||||
done();
|
||||
@ -308,7 +308,7 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
]
|
||||
};
|
||||
assert.response(server, {
|
||||
url: layergroup_url + '?config=' + encodeURIComponent(JSON.stringify(layergroup)),
|
||||
url: layergroupUrl + '?config=' + encodeURIComponent(JSON.stringify(layergroup)),
|
||||
method: 'GET',
|
||||
headers: { host: 'localhost' }
|
||||
}, {}, function (res) {
|
||||
@ -333,7 +333,7 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
]
|
||||
};
|
||||
assert.response(server, {
|
||||
url: layergroup_url + '?config=' + encodeURIComponent(JSON.stringify(layergroup)),
|
||||
url: layergroupUrl + '?config=' + encodeURIComponent(JSON.stringify(layergroup)),
|
||||
method: 'GET',
|
||||
headers: { host: 'localhost' }
|
||||
}, {}, function (res) {
|
||||
@ -359,32 +359,32 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
]
|
||||
};
|
||||
|
||||
var expected_token; // = "6d8e4ad5458e2d25cf0eef38e38717a6";
|
||||
var expectedToken; // = "6d8e4ad5458e2d25cf0eef38e38717a6";
|
||||
step(
|
||||
function do_post () {
|
||||
function doPost () {
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: layergroup_url,
|
||||
url: layergroupUrl,
|
||||
method: 'POST',
|
||||
headers: { host: 'localhost', 'Content-Type': 'application/json' },
|
||||
data: JSON.stringify(layergroup)
|
||||
}, {}, function (res) {
|
||||
assert.strictEqual(res.statusCode, 200, res.body);
|
||||
var parsedBody = JSON.parse(res.body);
|
||||
assert.strictEqual(parsedBody.last_updated, expected_last_updated);
|
||||
if (expected_token) {
|
||||
assert.strictEqual(parsedBody.layergroupid, expected_token + ':' + expected_last_updated_epoch);
|
||||
assert.strictEqual(parsedBody.last_updated, expectedLastUpdated);
|
||||
if (expectedToken) {
|
||||
assert.strictEqual(parsedBody.layergroupid, expectedToken + ':' + expectedLastUpdatedEpoch);
|
||||
} else {
|
||||
expected_token = parsedBody.layergroupid.split(':')[0];
|
||||
expectedToken = parsedBody.layergroupid.split(':')[0];
|
||||
}
|
||||
next(null, res);
|
||||
});
|
||||
},
|
||||
function do_get_tile1 (err) {
|
||||
function doGetTile1 (err) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: layergroup_url + '/' + expected_token + ':cb10/1/0/0.png',
|
||||
url: layergroupUrl + '/' + expectedToken + ':cb10/1/0/0.png',
|
||||
method: 'GET',
|
||||
headers: { host: 'localhost' },
|
||||
encoding: 'binary'
|
||||
@ -395,7 +395,7 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
// Check X-Cache-Channel
|
||||
var cc = res.headers['x-cache-channel'];
|
||||
assert.ok(cc);
|
||||
var dbname = test_database;
|
||||
var dbname = testDatabase;
|
||||
assert.strictEqual(cc.substring(0, dbname.length), dbname);
|
||||
if (!cdbQueryTablesFromPostgresEnabledValue) { // only test if it was using the SQL API
|
||||
var jsonquery = cc.substring(dbname.length + 1);
|
||||
@ -419,11 +419,11 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
});
|
||||
});
|
||||
},
|
||||
function do_get_tile4 (err) {
|
||||
function doGetTile4 (err) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: layergroup_url + '/' + expected_token + ':cb11/4/0/0.png',
|
||||
url: layergroupUrl + '/' + expectedToken + ':cb11/4/0/0.png',
|
||||
method: 'GET',
|
||||
headers: { host: 'localhost' },
|
||||
encoding: 'binary'
|
||||
@ -434,7 +434,7 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
// Check X-Cache-Channel
|
||||
var cc = res.headers['x-cache-channel'];
|
||||
assert.ok(cc);
|
||||
var dbname = test_database;
|
||||
var dbname = testDatabase;
|
||||
assert.strictEqual(cc.substring(0, dbname.length), dbname);
|
||||
if (!cdbQueryTablesFromPostgresEnabledValue) { // only test if it was using the SQL API
|
||||
var jsonquery = cc.substring(dbname.length + 1);
|
||||
@ -458,11 +458,11 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
});
|
||||
});
|
||||
},
|
||||
function do_get_grid1 (err) {
|
||||
function doGetGrid1 (err) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: layergroup_url + '/' + expected_token + '/0/1/0/0.grid.json',
|
||||
url: layergroupUrl + '/' + expectedToken + '/0/1/0/0.grid.json',
|
||||
headers: { host: 'localhost' },
|
||||
method: 'GET'
|
||||
}, {}, function (res) {
|
||||
@ -474,11 +474,11 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
});
|
||||
});
|
||||
},
|
||||
function do_get_grid4 (err) {
|
||||
function doGetGrid4 (err) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: layergroup_url + '/' + expected_token + '/0/4/0/0.grid.json',
|
||||
url: layergroupUrl + '/' + expectedToken + '/0/4/0/0.grid.json',
|
||||
headers: { host: 'localhost' },
|
||||
method: 'GET'
|
||||
}, {}, function (res) {
|
||||
@ -488,7 +488,7 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
});
|
||||
},
|
||||
function finish (err) {
|
||||
keysToDelete['map_cfg|' + expected_token] = 0;
|
||||
keysToDelete['map_cfg|' + expectedToken] = 0;
|
||||
keysToDelete['user:localhost:mapviews:global'] = 5;
|
||||
|
||||
done(err);
|
||||
@ -512,61 +512,61 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
]
|
||||
};
|
||||
var statskey = 'user:localhost:mapviews';
|
||||
var redis_stats_client = redis.createClient(global.environment.redis.port);
|
||||
var expected_token; // will be set on first post and checked on second
|
||||
var redisStatsClient = redis.createClient(global.environment.redis.port);
|
||||
var expectedToken; // will be set on first post and checked on second
|
||||
var now = strftime('%Y%m%d', new Date());
|
||||
step(
|
||||
function clean_stats () {
|
||||
function cleanStats () {
|
||||
var next = this;
|
||||
redis_stats_client.select(redis_stats_db, function (err) {
|
||||
redisStatsClient.select(redisStatsDb, function (err) {
|
||||
if (err) {
|
||||
next(err);
|
||||
} else {
|
||||
redis_stats_client.del(statskey + ':global', next);
|
||||
redisStatsClient.del(statskey + ':global', next);
|
||||
}
|
||||
});
|
||||
},
|
||||
function do_post_1 (err) {
|
||||
function doPost1 (err) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: layergroup_url,
|
||||
url: layergroupUrl,
|
||||
method: 'POST',
|
||||
headers: { host: 'localhost', 'Content-Type': 'application/json' },
|
||||
data: JSON.stringify(layergroup)
|
||||
}, {}, function (res) {
|
||||
assert.strictEqual(res.statusCode, 200, res.body);
|
||||
expected_token = JSON.parse(res.body).layergroupid;
|
||||
redis_stats_client.zscore(statskey + ':global', now, next);
|
||||
expectedToken = JSON.parse(res.body).layergroupid;
|
||||
redisStatsClient.zscore(statskey + ':global', now, next);
|
||||
});
|
||||
},
|
||||
function check_global_stats_1 (err, val) {
|
||||
function checkGlobalStats1 (err, val) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(val, '1', 'Expected score of ' + now + ' in ' + statskey + ':global to be 1, got ' + val);
|
||||
redis_stats_client.zscore(statskey + ':stat_tag:random_tag', now, this);
|
||||
redisStatsClient.zscore(statskey + ':stat_tag:random_tag', now, this);
|
||||
},
|
||||
function check_tag_stats_1_do_post_2 (err, val) {
|
||||
function checkTagStats1DoPost2 (err, val) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(val, '1', 'Expected score of ' + now + ' in ' + statskey + ':stat_tag:' + layergroup.stat_tag +
|
||||
' to be 1, got ' + val);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: layergroup_url,
|
||||
url: layergroupUrl,
|
||||
method: 'POST',
|
||||
headers: { host: 'localhost', 'Content-Type': 'application/json' },
|
||||
data: JSON.stringify(layergroup)
|
||||
}, {}, function (res) {
|
||||
assert.strictEqual(res.statusCode, 200, res.body);
|
||||
assert.strictEqual(JSON.parse(res.body).layergroupid, expected_token);
|
||||
redis_stats_client.zscore(statskey + ':global', now, next);
|
||||
assert.strictEqual(JSON.parse(res.body).layergroupid, expectedToken);
|
||||
redisStatsClient.zscore(statskey + ':global', now, next);
|
||||
});
|
||||
},
|
||||
function check_global_stats_2 (err, val) {
|
||||
function checkGlobalStats2 (err, val) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(val, '2', 'Expected score of ' + now + ' in ' + statskey + ':global to be 2, got ' + val);
|
||||
redis_stats_client.zscore(statskey + ':stat_tag:' + layergroup.stat_tag, now, this);
|
||||
redisStatsClient.zscore(statskey + ':stat_tag:' + layergroup.stat_tag, now, this);
|
||||
},
|
||||
function check_tag_stats_2 (err, val) {
|
||||
function checkTagStats2 (err, val) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(val, '2', 'Expected score of ' + now + ' in ' + statskey + ':stat_tag:' + layergroup.stat_tag +
|
||||
' to be 2, got ' + val);
|
||||
@ -577,8 +577,8 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
return done(err);
|
||||
}
|
||||
// strip epoch
|
||||
expected_token = expected_token.split(':')[0];
|
||||
keysToDelete['map_cfg|' + expected_token] = 0;
|
||||
expectedToken = expectedToken.split(':')[0];
|
||||
keysToDelete['map_cfg|' + expectedToken] = 0;
|
||||
keysToDelete['user:localhost:mapviews:global'] = 5;
|
||||
keysToDelete[statskey + ':stat_tag:' + layergroup.stat_tag] = 5;
|
||||
done();
|
||||
@ -602,7 +602,7 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
]
|
||||
};
|
||||
assert.response(server, {
|
||||
url: layergroup_url,
|
||||
url: layergroupUrl,
|
||||
method: 'POST',
|
||||
headers: { host: 'localhost', 'Content-Type': 'application/json' },
|
||||
data: JSON.stringify(layergroup)
|
||||
@ -632,7 +632,7 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
]
|
||||
};
|
||||
assert.response(server, {
|
||||
url: layergroup_url,
|
||||
url: layergroupUrl,
|
||||
method: 'POST',
|
||||
headers: { host: 'localhost', 'Content-Type': 'application/json' },
|
||||
data: JSON.stringify(layergroup)
|
||||
@ -669,32 +669,32 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
]
|
||||
};
|
||||
|
||||
var expected_token; // = "b4ed64d93a411a59f330ab3d798e4009";
|
||||
var expectedToken; // = "b4ed64d93a411a59f330ab3d798e4009";
|
||||
step(
|
||||
function do_post () {
|
||||
function doPost () {
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: layergroup_url + '?map_key=1234',
|
||||
url: layergroupUrl + '?map_key=1234',
|
||||
method: 'POST',
|
||||
headers: { host: 'localhost', 'Content-Type': 'application/json' },
|
||||
data: JSON.stringify(layergroup)
|
||||
}, {}, function (res) {
|
||||
assert.strictEqual(res.statusCode, 200, res.body);
|
||||
var parsedBody = JSON.parse(res.body);
|
||||
assert.strictEqual(parsedBody.last_updated, expected_last_updated);
|
||||
if (expected_token) {
|
||||
assert.strictEqual(parsedBody.layergroupid, expected_token + ':' + expected_last_updated_epoch);
|
||||
assert.strictEqual(parsedBody.last_updated, expectedLastUpdated);
|
||||
if (expectedToken) {
|
||||
assert.strictEqual(parsedBody.layergroupid, expectedToken + ':' + expectedLastUpdatedEpoch);
|
||||
} else {
|
||||
expected_token = parsedBody.layergroupid.split(':')[0];
|
||||
expectedToken = parsedBody.layergroupid.split(':')[0];
|
||||
}
|
||||
next(null, res);
|
||||
});
|
||||
},
|
||||
function do_get_tile (err) {
|
||||
function doGetTile (err) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: layergroup_url + '/' + expected_token + ':cb0/0/0/0.png?map_key=1234',
|
||||
url: layergroupUrl + '/' + expectedToken + ':cb0/0/0/0.png?map_key=1234',
|
||||
method: 'GET',
|
||||
headers: { host: 'localhost' },
|
||||
encoding: 'binary'
|
||||
@ -705,16 +705,16 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
// Check X-Cache-Channel
|
||||
var cc = res.headers['x-cache-channel'];
|
||||
assert.ok(cc);
|
||||
var dbname = test_database;
|
||||
var dbname = testDatabase;
|
||||
assert.strictEqual(cc.substring(0, dbname.length), dbname);
|
||||
next(err);
|
||||
});
|
||||
},
|
||||
function do_get_grid_layer0 (err) {
|
||||
function doGetGridLayer0 (err) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: layergroup_url + '/' + expected_token + '/0/0/0/0.grid.json?map_key=1234',
|
||||
url: layergroupUrl + '/' + expectedToken + '/0/0/0/0.grid.json?map_key=1234',
|
||||
headers: { host: 'localhost' },
|
||||
method: 'GET'
|
||||
}, {}, function (res) {
|
||||
@ -722,11 +722,11 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
next(err);
|
||||
});
|
||||
},
|
||||
function do_get_grid_layer1 (err) {
|
||||
function doGetGridLayer1 (err) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: layergroup_url + '/' + expected_token + '/1/0/0/0.grid.json?map_key=1234',
|
||||
url: layergroupUrl + '/' + expectedToken + '/1/0/0/0.grid.json?map_key=1234',
|
||||
headers: { host: 'localhost' },
|
||||
method: 'GET'
|
||||
}, {}, function (res) {
|
||||
@ -735,11 +735,11 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
next(err);
|
||||
});
|
||||
},
|
||||
function do_get_tile_unauth (err) {
|
||||
function doGetTileUnauth (err) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: layergroup_url + '/' + expected_token + ':cb0/0/0/0.png',
|
||||
url: layergroupUrl + '/' + expectedToken + ':cb0/0/0/0.png',
|
||||
method: 'GET',
|
||||
headers: { host: 'localhost' },
|
||||
encoding: 'binary'
|
||||
@ -750,11 +750,11 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
next(err);
|
||||
});
|
||||
},
|
||||
function do_get_grid_layer0_unauth (err) {
|
||||
function doGetGridLayer0Unauth (err) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: layergroup_url + '/' + expected_token + '/0/0/0/0.grid.json',
|
||||
url: layergroupUrl + '/' + expectedToken + '/0/0/0/0.grid.json',
|
||||
headers: { host: 'localhost' },
|
||||
method: 'GET'
|
||||
}, {}, function (res) {
|
||||
@ -764,11 +764,11 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
next(err);
|
||||
});
|
||||
},
|
||||
function do_get_grid_layer1_unauth (err) {
|
||||
function doGetGridLayer1Unauth (err) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: layergroup_url + '/' + expected_token + '/1/0/0/0.grid.json',
|
||||
url: layergroupUrl + '/' + expectedToken + '/1/0/0/0.grid.json',
|
||||
headers: { host: 'localhost' },
|
||||
method: 'GET'
|
||||
}, {}, function (res) {
|
||||
@ -779,7 +779,7 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
});
|
||||
},
|
||||
function finish (err) {
|
||||
keysToDelete['map_cfg|' + expected_token] = 0;
|
||||
keysToDelete['map_cfg|' + expectedToken] = 0;
|
||||
keysToDelete['user:localhost:mapviews:global'] = 5;
|
||||
|
||||
done(err);
|
||||
@ -803,40 +803,40 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
]
|
||||
};
|
||||
|
||||
var expected_token; // = "b4ed64d93a411a59f330ab3d798e4009";
|
||||
var expectedToken; // = "b4ed64d93a411a59f330ab3d798e4009";
|
||||
step(
|
||||
function do_post () {
|
||||
function doPost () {
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: layergroup_url + '?map_key=1234',
|
||||
url: layergroupUrl + '?map_key=1234',
|
||||
method: 'POST',
|
||||
headers: { host: 'localhost', 'Content-Type': 'application/json' },
|
||||
data: JSON.stringify(layergroup)
|
||||
}, {}, function (res, err) { next(err, res); });
|
||||
},
|
||||
function check_post (err, res) {
|
||||
function checkPost (err, res) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(res.statusCode, 200, res.body);
|
||||
var parsedBody = JSON.parse(res.body);
|
||||
assert.strictEqual(parsedBody.last_updated, expected_last_updated);
|
||||
if (expected_token) {
|
||||
assert.strictEqual(parsedBody.layergroupid, expected_token + ':' + expected_last_updated_epoch);
|
||||
assert.strictEqual(parsedBody.last_updated, expectedLastUpdated);
|
||||
if (expectedToken) {
|
||||
assert.strictEqual(parsedBody.layergroupid, expectedToken + ':' + expectedLastUpdatedEpoch);
|
||||
} else {
|
||||
expected_token = parsedBody.layergroupid.split(':')[0];
|
||||
expectedToken = parsedBody.layergroupid.split(':')[0];
|
||||
}
|
||||
return null;
|
||||
},
|
||||
function do_get0 (err) {
|
||||
function doGet0 (err) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: layergroup_url + '/' + expected_token + ':cb0/0/0/0.png?map_key=1234',
|
||||
url: layergroupUrl + '/' + expectedToken + ':cb0/0/0/0.png?map_key=1234',
|
||||
method: 'GET',
|
||||
headers: { host: 'localhost' },
|
||||
encoding: 'binary'
|
||||
}, {}, function (res, err) { next(err, res); });
|
||||
},
|
||||
function do_check0 (err, res) {
|
||||
function doCheck0 (err, res) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(res.statusCode, 200, res.body);
|
||||
assert.strictEqual(res.headers['content-type'], 'image/png');
|
||||
@ -844,27 +844,27 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
// Check X-Cache-Channel
|
||||
var cc = res.headers['x-cache-channel'];
|
||||
assert.ok(cc, 'Missing X-Cache-Channel');
|
||||
var dbname = test_database;
|
||||
var dbname = testDatabase;
|
||||
assert.strictEqual(cc.substring(0, dbname.length), dbname);
|
||||
return null;
|
||||
},
|
||||
function do_restart_server (err/*, res */) {
|
||||
function doRestartServer (err/*, res */) {
|
||||
assert.ifError(err);
|
||||
// hack simulating restart...
|
||||
server = new CartodbWindshaft(serverOptions);
|
||||
return null;
|
||||
},
|
||||
function do_get1 (err) {
|
||||
function doGet1 (err) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: layergroup_url + '/' + expected_token + ':cb0/0/0/0.png?map_key=1234',
|
||||
url: layergroupUrl + '/' + expectedToken + ':cb0/0/0/0.png?map_key=1234',
|
||||
method: 'GET',
|
||||
headers: { host: 'localhost' },
|
||||
encoding: 'binary'
|
||||
}, {}, function (res, err) { next(err, res); });
|
||||
},
|
||||
function do_check1 (err, res) {
|
||||
function doCheck1 (err, res) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(res.statusCode, 200, res.body);
|
||||
assert.strictEqual(res.headers['content-type'], 'image/png');
|
||||
@ -872,12 +872,12 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
// Check X-Cache-Channel
|
||||
var cc = res.headers['x-cache-channel'];
|
||||
assert.ok(cc, 'Missing X-Cache-Channel on restart');
|
||||
var dbname = test_database;
|
||||
var dbname = testDatabase;
|
||||
assert.strictEqual(cc.substring(0, dbname.length), dbname);
|
||||
return null;
|
||||
},
|
||||
function finish (err) {
|
||||
keysToDelete['map_cfg|' + expected_token] = 0;
|
||||
keysToDelete['map_cfg|' + expectedToken] = 0;
|
||||
keysToDelete['user:localhost:mapviews:global'] = 5;
|
||||
|
||||
done(err);
|
||||
@ -901,7 +901,7 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
};
|
||||
|
||||
assert.response(server, {
|
||||
url: layergroup_url,
|
||||
url: layergroupUrl,
|
||||
method: 'POST',
|
||||
headers: { host: 'localhost', 'Content-Type': 'application/json' },
|
||||
data: JSON.stringify(layergroup)
|
||||
@ -937,7 +937,7 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
};
|
||||
|
||||
assert.response(server, {
|
||||
url: layergroup_url,
|
||||
url: layergroupUrl,
|
||||
method: 'POST',
|
||||
headers: { host: 'localhost', 'Content-Type': 'application/json' },
|
||||
data: JSON.stringify(layergroup)
|
||||
@ -964,7 +964,7 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
]
|
||||
};
|
||||
assert.response(server, {
|
||||
url: layergroup_url,
|
||||
url: layergroupUrl,
|
||||
method: 'POST',
|
||||
headers: { host: 'localhost', 'Content-Type': 'application/json' },
|
||||
data: JSON.stringify(layergroup)
|
||||
@ -991,41 +991,41 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
}
|
||||
]
|
||||
};
|
||||
var expected_token; // = "e34dd7e235138a062f8ba7ad051aa3a7";
|
||||
var expectedToken; // = "e34dd7e235138a062f8ba7ad051aa3a7";
|
||||
step(
|
||||
function do_post () {
|
||||
function doPost () {
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: layergroup_url,
|
||||
url: layergroupUrl,
|
||||
method: 'POST',
|
||||
headers: { host: 'localhost', 'Content-Type': 'application/json' },
|
||||
data: JSON.stringify(layergroup)
|
||||
}, {}, function (res) {
|
||||
assert.strictEqual(res.statusCode, 200, res.body);
|
||||
var parsedBody = JSON.parse(res.body);
|
||||
if (expected_token) {
|
||||
assert.strictEqual(parsedBody.layergroupid, expected_token + ':' + expected_last_updated_epoch);
|
||||
if (expectedToken) {
|
||||
assert.strictEqual(parsedBody.layergroupid, expectedToken + ':' + expectedLastUpdatedEpoch);
|
||||
assert.strictEqual(res.headers['x-layergroup-id'], parsedBody.layergroupid);
|
||||
} else {
|
||||
var token_components = parsedBody.layergroupid.split(':');
|
||||
expected_token = token_components[0];
|
||||
expected_last_updated_epoch = token_components[1];
|
||||
var tokenComponents = parsedBody.layergroupid.split(':');
|
||||
expectedToken = tokenComponents[0];
|
||||
expectedLastUpdatedEpoch = tokenComponents[1];
|
||||
}
|
||||
next(null, res);
|
||||
});
|
||||
},
|
||||
function do_get_tile (err) {
|
||||
function doGetTile (err) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: layergroup_url + '/' + expected_token + ':cb0/0/0/0.png',
|
||||
url: layergroupUrl + '/' + expectedToken + ':cb0/0/0/0.png',
|
||||
method: 'GET',
|
||||
headers: { host: 'localhost' },
|
||||
encoding: 'binary'
|
||||
}, {}, function (res) {
|
||||
assert.strictEqual(res.statusCode, 200, res.body);
|
||||
assert.strictEqual(res.headers['content-type'], 'image/png');
|
||||
assert.imageBufferIsSimilarToFile(res.body, windshaft_fixtures + '/test_default_mapnik_point.png',
|
||||
assert.imageBufferIsSimilarToFile(res.body, windshaftFixtures + '/test_default_mapnik_point.png',
|
||||
IMAGE_EQUALS_TOLERANCE_PER_MIL, function (err/*, similarity */) {
|
||||
next(err);
|
||||
}
|
||||
@ -1034,7 +1034,7 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
},
|
||||
function finish (err) {
|
||||
keysToDelete['user:localhost:mapviews:global'] = 5;
|
||||
keysToDelete['map_cfg|' + expected_token] = 0;
|
||||
keysToDelete['map_cfg|' + expectedToken] = 0;
|
||||
|
||||
done(err);
|
||||
}
|
||||
@ -1057,49 +1057,49 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
}
|
||||
]
|
||||
};
|
||||
var expected_token; // = "e34dd7e235138a062f8ba7ad051aa3a7";
|
||||
var expectedToken; // = "e34dd7e235138a062f8ba7ad051aa3a7";
|
||||
step(
|
||||
function do_post () {
|
||||
function doPost () {
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: layergroup_url + '?api_key=1234',
|
||||
url: layergroupUrl + '?api_key=1234',
|
||||
method: 'POST',
|
||||
headers: { host: 'localhost', 'Content-Type': 'application/json' },
|
||||
data: JSON.stringify(layergroup)
|
||||
}, {}, function (res) { next(null, res); });
|
||||
},
|
||||
function check_result (err, res) {
|
||||
function checkResult (err, res) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.strictEqual(res.statusCode, 200, res.statusCode + ': ' + res.body);
|
||||
var parsedBody = JSON.parse(res.body);
|
||||
if (expected_token) {
|
||||
assert.strictEqual(parsedBody.layergroupid, expected_token + ':' + expected_last_updated_epoch);
|
||||
if (expectedToken) {
|
||||
assert.strictEqual(parsedBody.layergroupid, expectedToken + ':' + expectedLastUpdatedEpoch);
|
||||
assert.strictEqual(res.headers['x-layergroup-id'], parsedBody.layergroupid);
|
||||
} else {
|
||||
var token_components = parsedBody.layergroupid.split(':');
|
||||
expected_token = token_components[0];
|
||||
expected_last_updated_epoch = token_components[1];
|
||||
var tokenComponents = parsedBody.layergroupid.split(':');
|
||||
expectedToken = tokenComponents[0];
|
||||
expectedLastUpdatedEpoch = tokenComponents[1];
|
||||
}
|
||||
next(null, res);
|
||||
},
|
||||
function do_get_tile (err) {
|
||||
function doGetTile (err) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: layergroup_url + '/' + expected_token + ':cb0/0/0/0.png?api_key=1234',
|
||||
url: layergroupUrl + '/' + expectedToken + ':cb0/0/0/0.png?api_key=1234',
|
||||
method: 'GET',
|
||||
headers: { host: 'localhost' },
|
||||
encoding: 'binary'
|
||||
}, {}, function (res) { next(null, res); });
|
||||
},
|
||||
function check_get_tile (err, res) {
|
||||
function checkGetTile (err, res) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
assert.strictEqual(res.statusCode, 200, res.body);
|
||||
keysToDelete['user:localhost:mapviews:global'] = 5;
|
||||
keysToDelete['map_cfg|' + expected_token] = 0;
|
||||
keysToDelete['map_cfg|' + expectedToken] = 0;
|
||||
done(err);
|
||||
}
|
||||
);
|
||||
@ -1108,14 +1108,14 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
// SQL strings can be of arbitrary length, when using POST
|
||||
// See https://github.com/CartoDB/Windshaft-cartodb/issues/111
|
||||
it('sql string can be very long', function (done) {
|
||||
var long_val = 'pretty';
|
||||
var longVal = 'pretty';
|
||||
for (var i = 0; i < 1024; ++i) {
|
||||
long_val += ' long';
|
||||
longVal += ' long';
|
||||
}
|
||||
long_val += ' string';
|
||||
longVal += ' string';
|
||||
var sql = 'SELECT ';
|
||||
for (i = 0; i < 16; ++i) {
|
||||
sql += "'" + long_val + "'::text as pretty_long_field_name_" + i + ', ';
|
||||
sql += "'" + longVal + "'::text as pretty_long_field_name_" + i + ', ';
|
||||
}
|
||||
sql += 'cartodb_id, the_geom_webmercator FROM gadm4 g';
|
||||
var layergroup = {
|
||||
@ -1130,25 +1130,25 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
}
|
||||
]
|
||||
};
|
||||
var expected_token;
|
||||
var expectedToken;
|
||||
step(
|
||||
function do_post () {
|
||||
function doPost () {
|
||||
var data = JSON.stringify(layergroup);
|
||||
assert.ok(data.length > 1024 * 64);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: layergroup_url + '?api_key=1234',
|
||||
url: layergroupUrl + '?api_key=1234',
|
||||
method: 'POST',
|
||||
headers: { host: 'localhost', 'Content-Type': 'application/json' },
|
||||
data: data
|
||||
}, {}, function (res) { next(null, res); });
|
||||
},
|
||||
function check_result (err, res) {
|
||||
function checkResult (err, res) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(res.statusCode, 200, res.statusCode + ': ' + res.body);
|
||||
var parsedBody = JSON.parse(res.body);
|
||||
var token_components = parsedBody.layergroupid.split(':');
|
||||
expected_token = token_components[0];
|
||||
var tokenComponents = parsedBody.layergroupid.split(':');
|
||||
expectedToken = tokenComponents[0];
|
||||
return null;
|
||||
},
|
||||
function cleanup (err) {
|
||||
@ -1156,7 +1156,7 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
return done(err);
|
||||
}
|
||||
keysToDelete['user:localhost:mapviews:global'] = 5;
|
||||
keysToDelete['map_cfg|' + expected_token] = 0;
|
||||
keysToDelete['map_cfg|' + expectedToken] = 0;
|
||||
|
||||
done(err);
|
||||
}
|
||||
@ -1183,16 +1183,16 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
};
|
||||
|
||||
step(
|
||||
function do_post () {
|
||||
function doPost () {
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: layergroup_url,
|
||||
url: layergroupUrl,
|
||||
method: 'POST',
|
||||
headers: { host: 'localhost', 'Content-Type': 'application/json' },
|
||||
data: JSON.stringify(layergroup)
|
||||
}, {}, function (res, err) { next(err, res); });
|
||||
},
|
||||
function check_post (err, res) {
|
||||
function checkPost (err, res) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(res.statusCode, 400, res.statusCode + ': ' + res.body);
|
||||
var parsed = JSON.parse(res.body);
|
||||
@ -1225,16 +1225,16 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
};
|
||||
|
||||
step(
|
||||
function do_post () {
|
||||
function doPost () {
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: layergroup_url,
|
||||
url: layergroupUrl,
|
||||
method: 'POST',
|
||||
headers: { host: 'localhost', 'Content-Type': 'application/json' },
|
||||
data: JSON.stringify(layergroup)
|
||||
}, {}, function (res, err) { next(err, res); });
|
||||
},
|
||||
function check_post (err, res) {
|
||||
function checkPost (err, res) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(res.statusCode, 400, res.statusCode + ': ' + res.body);
|
||||
var parsed = JSON.parse(res.body);
|
||||
@ -1252,7 +1252,7 @@ var QueryTables = require('cartodb-query-tables').queryTables;
|
||||
}
|
||||
|
||||
var layergroupTtlRequest = {
|
||||
url: layergroup_url + '?config=' + encodeURIComponent(JSON.stringify({
|
||||
url: layergroupUrl + '?config=' + encodeURIComponent(JSON.stringify({
|
||||
version: '1.0.0',
|
||||
layers: [
|
||||
{
|
||||
|
@ -20,7 +20,7 @@ describe('multilayer', function () {
|
||||
});
|
||||
|
||||
mapnik.register_system_fonts();
|
||||
var available_system_fonts = _.keys(mapnik.fontFiles());
|
||||
var availableSystemFonts = _.keys(mapnik.fontFiles());
|
||||
|
||||
var IMAGE_EQUALS_TOLERANCE_PER_MIL = 20;
|
||||
|
||||
@ -47,9 +47,9 @@ describe('multilayer', function () {
|
||||
}
|
||||
]
|
||||
};
|
||||
var expected_token;
|
||||
var expectedToken;
|
||||
step(
|
||||
function do_post () {
|
||||
function doPost () {
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: '/api/v1/map',
|
||||
@ -59,7 +59,7 @@ describe('multilayer', function () {
|
||||
}, {}, function (res) {
|
||||
assert.strictEqual(res.statusCode, 200, res.body);
|
||||
var parsedBody = JSON.parse(res.body);
|
||||
expected_token = LayergroupToken.parse(parsedBody.layergroupid).token;
|
||||
expectedToken = LayergroupToken.parse(parsedBody.layergroupid).token;
|
||||
next();
|
||||
});
|
||||
},
|
||||
@ -68,7 +68,7 @@ describe('multilayer', function () {
|
||||
return done(err);
|
||||
}
|
||||
var keysToDelete = { 'user:localhost:mapviews:global': 5 };
|
||||
keysToDelete['map_cfg|' + expected_token] = 0;
|
||||
keysToDelete['map_cfg|' + expectedToken] = 0;
|
||||
testHelper.deleteRedisKeys(keysToDelete, done);
|
||||
}
|
||||
);
|
||||
@ -89,9 +89,9 @@ describe('multilayer', function () {
|
||||
}
|
||||
]
|
||||
};
|
||||
var expected_token;
|
||||
var expectedToken;
|
||||
step(
|
||||
function do_post () {
|
||||
function doPost () {
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: '/api/v1/map',
|
||||
@ -101,15 +101,15 @@ describe('multilayer', function () {
|
||||
}, {}, function (res) {
|
||||
assert.strictEqual(res.statusCode, 200, res.body);
|
||||
var parsedBody = JSON.parse(res.body);
|
||||
expected_token = LayergroupToken.parse(parsedBody.layergroupid).token;
|
||||
expectedToken = LayergroupToken.parse(parsedBody.layergroupid).token;
|
||||
next();
|
||||
});
|
||||
},
|
||||
function do_get_tile (err) {
|
||||
function doGetTile (err) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: '/api/v1/map/' + expected_token + '/0/0/0.png',
|
||||
url: '/api/v1/map/' + expectedToken + '/0/0/0.png',
|
||||
method: 'GET',
|
||||
encoding: 'binary',
|
||||
headers: { host: 'localhost' }
|
||||
@ -129,7 +129,7 @@ describe('multilayer', function () {
|
||||
return done(err);
|
||||
}
|
||||
var keysToDelete = { 'user:localhost:mapviews:global': 5 };
|
||||
keysToDelete['map_cfg|' + expected_token] = 0;
|
||||
keysToDelete['map_cfg|' + expectedToken] = 0;
|
||||
testHelper.deleteRedisKeys(keysToDelete, done);
|
||||
}
|
||||
);
|
||||
@ -160,9 +160,9 @@ describe('multilayer', function () {
|
||||
]
|
||||
};
|
||||
|
||||
var expected_token;
|
||||
var expectedToken;
|
||||
step(
|
||||
function do_post () {
|
||||
function doPost () {
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: '/api/v1/map',
|
||||
@ -175,19 +175,19 @@ describe('multilayer', function () {
|
||||
// from layergroup creation via POST
|
||||
checkCORSHeaders(res);
|
||||
var parsedBody = JSON.parse(res.body);
|
||||
if (expected_token) {
|
||||
assert.deepStrictEqual(parsedBody, { layergroupid: expected_token, layercount: 2 });
|
||||
if (expectedToken) {
|
||||
assert.deepStrictEqual(parsedBody, { layergroupid: expectedToken, layercount: 2 });
|
||||
} else {
|
||||
expected_token = LayergroupToken.parse(parsedBody.layergroupid).token;
|
||||
expectedToken = LayergroupToken.parse(parsedBody.layergroupid).token;
|
||||
}
|
||||
next(null, res);
|
||||
});
|
||||
},
|
||||
function do_get_tile (err) {
|
||||
function doGetTile (err) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: '/api/v1/map/' + expected_token + '/0/0/0.png',
|
||||
url: '/api/v1/map/' + expectedToken + '/0/0/0.png',
|
||||
method: 'GET',
|
||||
encoding: 'binary',
|
||||
headers: { host: 'localhost' }
|
||||
@ -201,11 +201,11 @@ describe('multilayer', function () {
|
||||
});
|
||||
});
|
||||
},
|
||||
function do_get_grid0 (err) {
|
||||
function doGetGrid0 (err) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: '/api/v1/map/' + expected_token + '/0/0/0/0.grid.json',
|
||||
url: '/api/v1/map/' + expectedToken + '/0/0/0/0.grid.json',
|
||||
method: 'GET',
|
||||
headers: { host: 'localhost' }
|
||||
}, {}, function (res) {
|
||||
@ -218,11 +218,11 @@ describe('multilayer', function () {
|
||||
});
|
||||
});
|
||||
},
|
||||
function do_get_grid1 (err) {
|
||||
function doGetGrid1 (err) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: '/api/v1/map/' + expected_token +
|
||||
url: '/api/v1/map/' + expectedToken +
|
||||
'/1/0/0/0.grid.json?interactivity=cartodb_id',
|
||||
method: 'GET',
|
||||
headers: { host: 'localhost' }
|
||||
@ -241,7 +241,7 @@ describe('multilayer', function () {
|
||||
return done(err);
|
||||
}
|
||||
var keysToDelete = { 'user:localhost:mapviews:global': 5 };
|
||||
keysToDelete['map_cfg|' + expected_token] = 0;
|
||||
keysToDelete['map_cfg|' + expectedToken] = 0;
|
||||
testHelper.deleteRedisKeys(keysToDelete, done);
|
||||
}
|
||||
);
|
||||
@ -272,9 +272,9 @@ describe('multilayer', function () {
|
||||
]
|
||||
};
|
||||
|
||||
var expected_token;
|
||||
var expectedToken;
|
||||
step(
|
||||
function do_get () {
|
||||
function doGet () {
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: '/api/v1/map?' + querystring.stringify({
|
||||
@ -289,19 +289,19 @@ describe('multilayer', function () {
|
||||
// see https://github.com/CartoDB/Windshaft/issues/92
|
||||
checkCORSHeaders(res);
|
||||
var parsedBody = JSON.parse(res.body);
|
||||
if (expected_token) {
|
||||
assert.deepStrictEqual(parsedBody, { layergroupid: expected_token, layercount: 2 });
|
||||
if (expectedToken) {
|
||||
assert.deepStrictEqual(parsedBody, { layergroupid: expectedToken, layercount: 2 });
|
||||
} else {
|
||||
expected_token = LayergroupToken.parse(parsedBody.layergroupid).token;
|
||||
expectedToken = LayergroupToken.parse(parsedBody.layergroupid).token;
|
||||
}
|
||||
next(null, res);
|
||||
});
|
||||
},
|
||||
function do_get_tile (err) {
|
||||
function doGetTile (err) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: '/api/v1/map/' + expected_token + '/0/0/0.png',
|
||||
url: '/api/v1/map/' + expectedToken + '/0/0/0.png',
|
||||
method: 'GET',
|
||||
encoding: 'binary',
|
||||
headers: { host: 'localhost' }
|
||||
@ -315,11 +315,11 @@ describe('multilayer', function () {
|
||||
});
|
||||
});
|
||||
},
|
||||
function do_get_grid0 (err) {
|
||||
function doGetGrid0 (err) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: '/api/v1/map/' + expected_token +
|
||||
url: '/api/v1/map/' + expectedToken +
|
||||
'/0/0/0/0.grid.json?interactivity=cartodb_id',
|
||||
method: 'GET',
|
||||
headers: { host: 'localhost' }
|
||||
@ -333,11 +333,11 @@ describe('multilayer', function () {
|
||||
});
|
||||
});
|
||||
},
|
||||
function do_get_grid1 (err) {
|
||||
function doGetGrid1 (err) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: '/api/v1/map/' + expected_token +
|
||||
url: '/api/v1/map/' + expectedToken +
|
||||
'/1/0/0/0.grid.json?interactivity=cartodb_id',
|
||||
method: 'GET',
|
||||
headers: { host: 'localhost' }
|
||||
@ -356,7 +356,7 @@ describe('multilayer', function () {
|
||||
return done(err);
|
||||
}
|
||||
var keysToDelete = { 'user:localhost:mapviews:global': 5 };
|
||||
keysToDelete['map_cfg|' + expected_token] = 0;
|
||||
keysToDelete['map_cfg|' + expectedToken] = 0;
|
||||
testHelper.deleteRedisKeys(keysToDelete, done);
|
||||
}
|
||||
);
|
||||
@ -387,28 +387,28 @@ describe('multilayer', function () {
|
||||
]
|
||||
};
|
||||
|
||||
var expected_token;
|
||||
var expectedToken;
|
||||
step(
|
||||
function do_get_token () {
|
||||
function doGetToken () {
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: '/api/v1/map?' + querystring.stringify({
|
||||
config: JSON.stringify(layergroup),
|
||||
callback: 'jsonp_test'
|
||||
callback: 'jsonpTest'
|
||||
}),
|
||||
method: 'GET',
|
||||
headers: { host: 'localhost', 'Content-Type': 'application/json' }
|
||||
}, {}, function (res, err) { next(err, res); });
|
||||
},
|
||||
function do_check_token (err, res) {
|
||||
function doCheckToken (err, res) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(res.statusCode, 200, res.body);
|
||||
|
||||
var didRunJsonCallback = false;
|
||||
/* eslint-disable no-unused-vars, no-eval */
|
||||
function jsonp_test (body) {
|
||||
function jsonpTest (body) {
|
||||
assert.ok(body.layergroupid);
|
||||
expected_token = LayergroupToken.parse(body.layergroupid).token;
|
||||
expectedToken = LayergroupToken.parse(body.layergroupid).token;
|
||||
assert.ok(body.metadata.layers.length === 2);
|
||||
assert.ok(body.metadata.layers[0].type === 'mapnik');
|
||||
assert.ok(body.metadata.layers[0].meta);
|
||||
@ -423,11 +423,11 @@ describe('multilayer', function () {
|
||||
// TODO: check caching headers !
|
||||
return null;
|
||||
},
|
||||
function do_get_tile (err) {
|
||||
function doGetTile (err) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: '/api/v1/map/' + expected_token + '/0/0/0.png',
|
||||
url: '/api/v1/map/' + expectedToken + '/0/0/0.png',
|
||||
method: 'GET',
|
||||
encoding: 'binary',
|
||||
headers: { host: 'localhost' }
|
||||
@ -441,11 +441,11 @@ describe('multilayer', function () {
|
||||
});
|
||||
});
|
||||
},
|
||||
function do_get_grid0 (err) {
|
||||
function doGetGrid0 (err) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: '/api/v1/map/' + expected_token +
|
||||
url: '/api/v1/map/' + expectedToken +
|
||||
'/0/0/0/0.grid.json?interactivity=cartodb_id',
|
||||
method: 'GET',
|
||||
headers: { host: 'localhost' }
|
||||
@ -459,11 +459,11 @@ describe('multilayer', function () {
|
||||
});
|
||||
});
|
||||
},
|
||||
function do_get_grid1 (err) {
|
||||
function doGetGrid1 (err) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: '/api/v1/map/' + expected_token +
|
||||
url: '/api/v1/map/' + expectedToken +
|
||||
'/1/0/0/0.grid.json?interactivity=cartodb_id',
|
||||
method: 'GET',
|
||||
headers: { host: 'localhost' }
|
||||
@ -482,7 +482,7 @@ describe('multilayer', function () {
|
||||
return done(err);
|
||||
}
|
||||
var keysToDelete = { 'user:localhost:mapviews:global': 5 };
|
||||
keysToDelete['map_cfg|' + expected_token] = 0;
|
||||
keysToDelete['map_cfg|' + expectedToken] = 0;
|
||||
testHelper.deleteRedisKeys(keysToDelete, done);
|
||||
}
|
||||
);
|
||||
@ -525,9 +525,9 @@ describe('multilayer', function () {
|
||||
]
|
||||
};
|
||||
|
||||
var expected_token;
|
||||
var expectedToken;
|
||||
step(
|
||||
function do_get () {
|
||||
function doGet () {
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: '/api/v1/map',
|
||||
@ -538,18 +538,18 @@ describe('multilayer', function () {
|
||||
next(err, res);
|
||||
});
|
||||
},
|
||||
function check_create (err, res) {
|
||||
function checkCreate (err, res) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(res.statusCode, 200, res.body);
|
||||
var parsed = JSON.parse(res.body);
|
||||
expected_token = LayergroupToken.parse(parsed.layergroupid).token;
|
||||
expectedToken = LayergroupToken.parse(parsed.layergroupid).token;
|
||||
return null;
|
||||
},
|
||||
function do_get_tile (err) {
|
||||
function doGetTile (err) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: '/api/v1/map/' + expected_token + '/0/0/0.png',
|
||||
url: '/api/v1/map/' + expectedToken + '/0/0/0.png',
|
||||
method: 'GET',
|
||||
encoding: 'binary',
|
||||
headers: { host: 'localhost' }
|
||||
@ -563,11 +563,11 @@ describe('multilayer', function () {
|
||||
});
|
||||
});
|
||||
},
|
||||
function do_get_grid0 (err) {
|
||||
function doGetGrid0 (err) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: '/api/v1/map/' + expected_token +
|
||||
url: '/api/v1/map/' + expectedToken +
|
||||
'/0/0/0/0.grid.json?interactivity=cartodb_id',
|
||||
method: 'GET',
|
||||
headers: { host: 'localhost' }
|
||||
@ -581,11 +581,11 @@ describe('multilayer', function () {
|
||||
});
|
||||
});
|
||||
},
|
||||
function do_get_grid1 (err) {
|
||||
function doGetGrid1 (err) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: '/api/v1/map/' + expected_token +
|
||||
url: '/api/v1/map/' + expectedToken +
|
||||
'/1/0/0/0.grid.json?interactivity=cartodb_id',
|
||||
method: 'GET',
|
||||
headers: { host: 'localhost' }
|
||||
@ -599,18 +599,18 @@ describe('multilayer', function () {
|
||||
});
|
||||
});
|
||||
},
|
||||
function do_get_attr1 (err) {
|
||||
function doGetAttr1 (err) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: '/api/v1/map/' + expected_token + '/1/attributes/4',
|
||||
url: '/api/v1/map/' + expectedToken + '/1/attributes/4',
|
||||
method: 'GET',
|
||||
headers: { host: 'localhost' }
|
||||
}, {}, function (res, err) {
|
||||
next(err, res);
|
||||
});
|
||||
},
|
||||
function do_check_attr1 (err, res) {
|
||||
function doCheckAttr1 (err, res) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(res.statusCode, 200, res.body);
|
||||
assert.strictEqual(res.headers['content-type'], 'application/json; charset=utf-8');
|
||||
@ -618,16 +618,16 @@ describe('multilayer', function () {
|
||||
assert.deepStrictEqual(parsed, { n: 40 });
|
||||
return null;
|
||||
},
|
||||
function do_get_torque2 (err) {
|
||||
function doGetTorque2 (err) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: '/api/v1/map/' + expected_token + '/2/0/0/0.json.torque',
|
||||
url: '/api/v1/map/' + expectedToken + '/2/0/0/0.json.torque',
|
||||
method: 'GET',
|
||||
headers: { host: 'localhost' }
|
||||
}, {}, function (res, err) { next(err, res); });
|
||||
},
|
||||
function do_check_torque2 (err, res) {
|
||||
function doCheckTorque2 (err, res) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(res.statusCode, 200, res.body);
|
||||
assert.strictEqual(res.headers['content-type'], 'application/json; charset=utf-8');
|
||||
@ -638,18 +638,18 @@ describe('multilayer', function () {
|
||||
assert.strictEqual(parsed[0].y__uint8, 128);
|
||||
return null;
|
||||
},
|
||||
function do_get_torque1 (err) {
|
||||
function doGetTorque1 (err) {
|
||||
// Layer 1 is not a torque layer...
|
||||
// See https://github.com/CartoDB/Windshaft/issues/136
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: '/api/v1/map/' + expected_token + '/1/0/0/0.json.torque',
|
||||
url: '/api/v1/map/' + expectedToken + '/1/0/0/0.json.torque',
|
||||
method: 'GET',
|
||||
headers: { host: 'localhost' }
|
||||
}, {}, function (res, err) { next(err, res); });
|
||||
},
|
||||
function do_check_torque1 (err, res) {
|
||||
function doCheckTorque1 (err, res) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(res.statusCode, 400, res.statusCode + ': ' + res.body);
|
||||
var parsed = JSON.parse(res.body);
|
||||
@ -664,7 +664,7 @@ describe('multilayer', function () {
|
||||
return done(err);
|
||||
}
|
||||
var keysToDelete = { 'user:localhost:mapviews:global': 5 };
|
||||
keysToDelete['map_cfg|' + expected_token] = 0;
|
||||
keysToDelete['map_cfg|' + expectedToken] = 0;
|
||||
testHelper.deleteRedisKeys(keysToDelete, done);
|
||||
}
|
||||
);
|
||||
@ -703,7 +703,7 @@ describe('multilayer', function () {
|
||||
|
||||
var token1, token2;
|
||||
step(
|
||||
function do_post1 () {
|
||||
function doPost1 () {
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: '/api/v1/map',
|
||||
@ -718,7 +718,7 @@ describe('multilayer', function () {
|
||||
next(null);
|
||||
});
|
||||
},
|
||||
function do_post2 () {
|
||||
function doPost2 () {
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: '/api/v1/map',
|
||||
@ -733,7 +733,7 @@ describe('multilayer', function () {
|
||||
next(null);
|
||||
});
|
||||
},
|
||||
function do_get_tile1 (err) {
|
||||
function doGetTile1 (err) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
@ -751,7 +751,7 @@ describe('multilayer', function () {
|
||||
});
|
||||
});
|
||||
},
|
||||
function do_get_grid1 (err) {
|
||||
function doGetGrid1 (err) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
@ -768,7 +768,7 @@ describe('multilayer', function () {
|
||||
});
|
||||
});
|
||||
},
|
||||
function do_get_tile2 (err) {
|
||||
function doGetTile2 (err) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
@ -786,7 +786,7 @@ describe('multilayer', function () {
|
||||
});
|
||||
});
|
||||
},
|
||||
function do_get_grid_layer2 (err) {
|
||||
function doGetGridLayer2 (err) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
@ -846,9 +846,9 @@ describe('multilayer', function () {
|
||||
]
|
||||
};
|
||||
|
||||
var expected_token; // = "32994445c0a4525432fcd7013bf6524c";
|
||||
var expectedToken; // = "32994445c0a4525432fcd7013bf6524c";
|
||||
step(
|
||||
function do_post () {
|
||||
function doPost () {
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: '/api/v1/map',
|
||||
@ -859,20 +859,20 @@ describe('multilayer', function () {
|
||||
try {
|
||||
assert.strictEqual(res.statusCode, 200, res.body);
|
||||
var parsedBody = JSON.parse(res.body);
|
||||
if (expected_token) {
|
||||
assert.deepStrictEqual(parsedBody, { layergroupid: expected_token, layercount: 3 });
|
||||
if (expectedToken) {
|
||||
assert.deepStrictEqual(parsedBody, { layergroupid: expectedToken, layercount: 3 });
|
||||
} else {
|
||||
expected_token = LayergroupToken.parse(parsedBody.layergroupid).token;
|
||||
expectedToken = LayergroupToken.parse(parsedBody.layergroupid).token;
|
||||
}
|
||||
next(null, res);
|
||||
} catch (err) { next(err); }
|
||||
});
|
||||
},
|
||||
function do_get_tile (err) {
|
||||
function doGetTile (err) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: '/api/v1/map/' + expected_token + '/0/0/0.png',
|
||||
url: '/api/v1/map/' + expectedToken + '/0/0/0.png',
|
||||
method: 'GET',
|
||||
encoding: 'binary',
|
||||
headers: { host: 'localhost' }
|
||||
@ -891,7 +891,7 @@ describe('multilayer', function () {
|
||||
return done(err);
|
||||
}
|
||||
var keysToDelete = { 'user:localhost:mapviews:global': 5 };
|
||||
keysToDelete['map_cfg|' + expected_token] = 0;
|
||||
keysToDelete['map_cfg|' + expectedToken] = 0;
|
||||
testHelper.deleteRedisKeys(keysToDelete, done);
|
||||
}
|
||||
);
|
||||
@ -928,9 +928,9 @@ describe('multilayer', function () {
|
||||
}, {}, function (res) {
|
||||
assert.strictEqual(res.statusCode, 200, res.statusCode + ': ' + res.body);
|
||||
var parsed = JSON.parse(res.body);
|
||||
var expected_token = LayergroupToken.parse(parsed.layergroupid).token;
|
||||
var expectedToken = LayergroupToken.parse(parsed.layergroupid).token;
|
||||
var keysToDelete = { 'user:localhost:mapviews:global': 5 };
|
||||
keysToDelete['map_cfg|' + expected_token] = 0;
|
||||
keysToDelete['map_cfg|' + expectedToken] = 0;
|
||||
testHelper.deleteRedisKeys(keysToDelete, done);
|
||||
});
|
||||
});
|
||||
@ -958,9 +958,9 @@ describe('multilayer', function () {
|
||||
}, {}, function (res) {
|
||||
assert.strictEqual(res.statusCode, 200, res.statusCode + ': ' + res.body);
|
||||
var parsed = JSON.parse(res.body);
|
||||
var expected_token = LayergroupToken.parse(parsed.layergroupid).token;
|
||||
var expectedToken = LayergroupToken.parse(parsed.layergroupid).token;
|
||||
var keysToDelete = { 'user:localhost:mapviews:global': 5 };
|
||||
keysToDelete['map_cfg|' + expected_token] = 0;
|
||||
keysToDelete['map_cfg|' + expectedToken] = 0;
|
||||
testHelper.deleteRedisKeys(keysToDelete, done);
|
||||
});
|
||||
});
|
||||
@ -1010,16 +1010,16 @@ describe('multilayer', function () {
|
||||
url: '/api/v1/map',
|
||||
method: 'POST',
|
||||
headers: { host: 'localhost', 'Content-Type': 'application/json' },
|
||||
data: _.template(tpl, { font: available_system_fonts[0] })
|
||||
data: _.template(tpl, { font: availableSystemFonts[0] })
|
||||
}, function (res) { next(null, res); });
|
||||
},
|
||||
function checkGoodFont (err, res) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(res.statusCode, 200, res.statusCode + ': ' + res.body);
|
||||
var parsed = JSON.parse(res.body);
|
||||
var expected_token = LayergroupToken.parse(parsed.layergroupid).token;
|
||||
var expectedToken = LayergroupToken.parse(parsed.layergroupid).token;
|
||||
var keysToDelete = { 'user:localhost:mapviews:global': 5 };
|
||||
keysToDelete['map_cfg|' + expected_token] = 0;
|
||||
keysToDelete['map_cfg|' + expectedToken] = 0;
|
||||
testHelper.deleteRedisKeys(keysToDelete, done);
|
||||
}
|
||||
);
|
||||
@ -1065,9 +1065,9 @@ describe('multilayer', function () {
|
||||
]
|
||||
};
|
||||
|
||||
var expected_token;
|
||||
var expectedToken;
|
||||
step(
|
||||
function do_post () {
|
||||
function doPost () {
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: '/api/v1/map',
|
||||
@ -1078,27 +1078,27 @@ describe('multilayer', function () {
|
||||
try {
|
||||
assert.strictEqual(res.statusCode, 200, res.body);
|
||||
var parsedBody = JSON.parse(res.body);
|
||||
if (expected_token) {
|
||||
assert.deepStrictEqual(parsedBody, { layergroupid: expected_token, layercount: 3 });
|
||||
if (expectedToken) {
|
||||
assert.deepStrictEqual(parsedBody, { layergroupid: expectedToken, layercount: 3 });
|
||||
} else {
|
||||
expected_token = LayergroupToken.parse(parsedBody.layergroupid).token;
|
||||
expectedToken = LayergroupToken.parse(parsedBody.layergroupid).token;
|
||||
}
|
||||
next(null, res);
|
||||
} catch (err) { next(err); }
|
||||
});
|
||||
},
|
||||
function do_get_grid0 (err) {
|
||||
function doGetGrid0 (err) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: '/api/v1/map/' + expected_token + '/0/0/0/0.grid.json',
|
||||
url: '/api/v1/map/' + expectedToken + '/0/0/0/0.grid.json',
|
||||
method: 'GET',
|
||||
headers: { host: 'localhost' }
|
||||
}, {}, function (res) {
|
||||
next(null, res);
|
||||
});
|
||||
},
|
||||
function do_check_grid (err, res) {
|
||||
function doCheckGrid (err, res) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.strictEqual(res.statusCode, 200, res.body);
|
||||
@ -1118,7 +1118,7 @@ describe('multilayer', function () {
|
||||
return done(err);
|
||||
}
|
||||
var keysToDelete = { 'user:localhost:mapviews:global': 5 };
|
||||
keysToDelete['map_cfg|' + expected_token] = 0;
|
||||
keysToDelete['map_cfg|' + expectedToken] = 0;
|
||||
testHelper.deleteRedisKeys(keysToDelete, done);
|
||||
}
|
||||
);
|
||||
@ -1142,7 +1142,7 @@ describe('multilayer', function () {
|
||||
|
||||
var token1, token2;
|
||||
step(
|
||||
function do_post_1 () {
|
||||
function doPost1 () {
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: '/api/v1/map',
|
||||
@ -1151,14 +1151,14 @@ describe('multilayer', function () {
|
||||
data: JSON.stringify(layergroup)
|
||||
}, {}, function (res, err) { next(err, res); });
|
||||
},
|
||||
function check_post_1 (err, res) {
|
||||
function checkPost1 (err, res) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(res.statusCode, 200, res.statusCode + ': ' + res.body);
|
||||
var parsedBody = JSON.parse(res.body);
|
||||
token1 = LayergroupToken.parse(parsedBody.layergroupid).token;
|
||||
return null;
|
||||
},
|
||||
function do_post_2 () {
|
||||
function doPost2 () {
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: '/database/windshaft_test2/layergroup',
|
||||
@ -1167,7 +1167,7 @@ describe('multilayer', function () {
|
||||
data: JSON.stringify(layergroup)
|
||||
}, {}, function (res, err) { next(err, res); });
|
||||
},
|
||||
function check_post_2 (err, res) {
|
||||
function checkPost2 (err, res) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(res.statusCode, 200, res.statusCode + ': ' + res.body);
|
||||
var parsedBody = JSON.parse(res.body);
|
||||
@ -1205,7 +1205,7 @@ describe('multilayer', function () {
|
||||
|
||||
var token1;
|
||||
step(
|
||||
function do_post_1 () {
|
||||
function doPost1 () {
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
url: '/api/v1/map',
|
||||
@ -1214,14 +1214,14 @@ describe('multilayer', function () {
|
||||
data: JSON.stringify(layergroup)
|
||||
}, {}, function (res, err) { next(err, res); });
|
||||
},
|
||||
function check_post_1 (err, res) {
|
||||
function checkPost1 (err, res) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(res.statusCode, 200, res.statusCode + ': ' + res.body);
|
||||
var parsedBody = JSON.parse(res.body);
|
||||
token1 = LayergroupToken.parse(parsedBody.layergroupid).token;
|
||||
return null;
|
||||
},
|
||||
function do_get_tile (err) {
|
||||
function doGetTile (err) {
|
||||
assert.ifError(err);
|
||||
var next = this;
|
||||
assert.response(server, {
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -34,18 +34,18 @@ function tileJsonSuite (usePostGIS) {
|
||||
|
||||
const sql = 'SELECT * FROM populated_places_simple_reduced';
|
||||
const cartocss = TestClient.CARTOCSS.POINTS;
|
||||
const cartocss_version = '3.0.12';
|
||||
const cartocssVersion = '3.0.12';
|
||||
|
||||
const RASTER_LAYER = {
|
||||
options: {
|
||||
sql, cartocss, cartocss_version
|
||||
sql, cartocss, cartocss_version: cartocssVersion
|
||||
}
|
||||
};
|
||||
const RASTER_INTERACTIVITY_LAYER = {
|
||||
options: {
|
||||
sql,
|
||||
cartocss,
|
||||
cartocss_version,
|
||||
cartocss_version: cartocssVersion,
|
||||
interactivity: ['cartodb_id']
|
||||
}
|
||||
};
|
||||
|
@ -82,15 +82,15 @@ const createMapConfig = ({
|
||||
}
|
||||
});
|
||||
|
||||
const db_limit_error_message = 'You are over platform\'s limits: SQL query timeout error.' +
|
||||
const dbLimitErrorMessage = 'You are over platform\'s limits: SQL query timeout error.' +
|
||||
' Refactor your query before running again or contact CARTO support for more details.';
|
||||
|
||||
const DATASOURCE_TIMEOUT_ERROR = {
|
||||
errors: [db_limit_error_message],
|
||||
errors: [dbLimitErrorMessage],
|
||||
errors_with_context: [{
|
||||
type: 'limit',
|
||||
subtype: 'datasource',
|
||||
message: db_limit_error_message
|
||||
message: dbLimitErrorMessage
|
||||
}]
|
||||
};
|
||||
|
||||
@ -159,11 +159,11 @@ describe('user database timeout limit', function () {
|
||||
this.testClient.getLayergroup({ response: expectedResponse }, (err, timeoutError) => {
|
||||
assert.ifError(err);
|
||||
assert.deepStrictEqual(timeoutError, {
|
||||
errors: [db_limit_error_message],
|
||||
errors: [dbLimitErrorMessage],
|
||||
errors_with_context: [{
|
||||
type: 'limit',
|
||||
subtype: 'datasource',
|
||||
message: db_limit_error_message,
|
||||
message: dbLimitErrorMessage,
|
||||
layer: { id: 'layer0', index: 0, type: 'mapnik' }
|
||||
}]
|
||||
});
|
||||
@ -382,11 +382,11 @@ describe('user database timeout limit', function () {
|
||||
this.testClient.getLayergroup({ response: expectedResponse }, (err, timeoutError) => {
|
||||
assert.ifError(err);
|
||||
assert.deepStrictEqual(timeoutError, {
|
||||
errors: [db_limit_error_message],
|
||||
errors: [dbLimitErrorMessage],
|
||||
errors_with_context: [{
|
||||
type: 'limit',
|
||||
subtype: 'datasource',
|
||||
message: db_limit_error_message,
|
||||
message: dbLimitErrorMessage,
|
||||
layer: { id: 'layer0', index: 0, type: 'mapnik' }
|
||||
}]
|
||||
});
|
||||
@ -501,11 +501,11 @@ describe('user database timeout limit', function () {
|
||||
this.testClient.getLayergroup({ response: expectedResponse }, (err, timeoutError) => {
|
||||
assert.ifError(err);
|
||||
assert.deepStrictEqual(timeoutError, {
|
||||
errors: [db_limit_error_message],
|
||||
errors: [dbLimitErrorMessage],
|
||||
errors_with_context: [{
|
||||
type: 'limit',
|
||||
subtype: 'datasource',
|
||||
message: db_limit_error_message,
|
||||
message: dbLimitErrorMessage,
|
||||
layer: { id: 'layer0', index: 0, type: 'mapnik' }
|
||||
}]
|
||||
});
|
||||
@ -606,11 +606,11 @@ describe('user database timeout limit', function () {
|
||||
this.testClient.getLayergroup({ response: expectedResponse }, (err, timeoutError) => {
|
||||
assert.ifError(err);
|
||||
assert.deepStrictEqual(timeoutError, {
|
||||
errors: [db_limit_error_message],
|
||||
errors: [dbLimitErrorMessage],
|
||||
errors_with_context: [{
|
||||
type: 'limit',
|
||||
subtype: 'datasource',
|
||||
message: db_limit_error_message,
|
||||
message: dbLimitErrorMessage,
|
||||
layer: { id: 'torque-layer0', index: 0, type: 'torque' }
|
||||
}]
|
||||
});
|
||||
@ -738,11 +738,11 @@ describe('user database timeout limit', function () {
|
||||
this.testClient.getLayergroup({ response: expectedResponse }, (err, timeoutError) => {
|
||||
assert.ifError(err);
|
||||
assert.deepStrictEqual(timeoutError, {
|
||||
errors: [db_limit_error_message],
|
||||
errors: [dbLimitErrorMessage],
|
||||
errors_with_context: [{
|
||||
type: 'limit',
|
||||
subtype: 'datasource',
|
||||
message: db_limit_error_message,
|
||||
message: dbLimitErrorMessage,
|
||||
layer: {
|
||||
id: 'layer0',
|
||||
index: 0,
|
||||
|
@ -70,7 +70,7 @@ describe('named-maps widgets', function () {
|
||||
}
|
||||
};
|
||||
|
||||
var template_params = {};
|
||||
var templateParams = {};
|
||||
|
||||
step(
|
||||
function createTemplate () {
|
||||
@ -108,7 +108,7 @@ describe('named-maps widgets', function () {
|
||||
host: username,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
data: JSON.stringify(template_params)
|
||||
data: JSON.stringify(templateParams)
|
||||
},
|
||||
{
|
||||
status: 200
|
||||
|
@ -24,18 +24,18 @@ describe('MapConfigOverviewsAdapter', function () {
|
||||
it('should not modify layers for which no overviews are available', function (done) {
|
||||
var sql = 'SELECT * FROM test_table';
|
||||
var cartocss = '#layer { marker-fill: black; }';
|
||||
var cartocss_version = '2.3.0';
|
||||
var layer_without_overviews = {
|
||||
var cartocssVersion = '2.3.0';
|
||||
var layerWithoutOverviews = {
|
||||
type: 'cartodb',
|
||||
options: {
|
||||
sql: sql,
|
||||
cartocss: cartocss,
|
||||
cartocss_version: cartocss_version
|
||||
cartocss_version: cartocssVersion
|
||||
}
|
||||
};
|
||||
|
||||
var _mapConfig = {
|
||||
layers: [layer_without_overviews]
|
||||
layers: [layerWithoutOverviews]
|
||||
};
|
||||
|
||||
var params = {};
|
||||
@ -48,7 +48,7 @@ describe('MapConfigOverviewsAdapter', function () {
|
||||
assert.strictEqual(layers[0].type, 'cartodb');
|
||||
assert.strictEqual(layers[0].options.sql, sql);
|
||||
assert.strictEqual(layers[0].options.cartocss, cartocss);
|
||||
assert.strictEqual(layers[0].options.cartocss_version, cartocss_version);
|
||||
assert.strictEqual(layers[0].options.cartocss_version, cartocssVersion);
|
||||
assert.strictEqual(layers[0].options.overviews, undefined);
|
||||
done();
|
||||
});
|
||||
@ -59,18 +59,18 @@ describe('MapConfigOverviewsAdapter', function () {
|
||||
it('should add overviews metadata for layers using tables with overviews', function (done) {
|
||||
var sql = 'SELECT * FROM test_table_overviews';
|
||||
var cartocss = '#layer { marker-fill: black; }';
|
||||
var cartocss_version = '2.3.0';
|
||||
var layer_with_overviews = {
|
||||
var cartocssVersion = '2.3.0';
|
||||
var layerWithOverviews = {
|
||||
type: 'cartodb',
|
||||
options: {
|
||||
sql: sql,
|
||||
cartocss: cartocss,
|
||||
cartocss_version: cartocss_version
|
||||
cartocss_version: cartocssVersion
|
||||
}
|
||||
};
|
||||
|
||||
var _mapConfig = {
|
||||
layers: [layer_with_overviews]
|
||||
layers: [layerWithOverviews]
|
||||
};
|
||||
|
||||
var params = {};
|
||||
@ -83,9 +83,9 @@ describe('MapConfigOverviewsAdapter', function () {
|
||||
assert.strictEqual(layers[0].type, 'cartodb');
|
||||
assert.strictEqual(layers[0].options.sql, sql);
|
||||
assert.strictEqual(layers[0].options.cartocss, cartocss);
|
||||
assert.strictEqual(layers[0].options.cartocss_version, cartocss_version);
|
||||
assert.strictEqual(layers[0].options.cartocss_version, cartocssVersion);
|
||||
assert.ok(layers[0].options.query_rewrite_data);
|
||||
var expected_data = {
|
||||
var expectedData = {
|
||||
overviews: {
|
||||
test_table_overviews: {
|
||||
schema: 'public',
|
||||
@ -94,7 +94,7 @@ describe('MapConfigOverviewsAdapter', function () {
|
||||
}
|
||||
}
|
||||
};
|
||||
assert.deepStrictEqual(layers[0].options.query_rewrite_data, expected_data);
|
||||
assert.deepStrictEqual(layers[0].options.query_rewrite_data, expectedData);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
@ -185,10 +185,10 @@ function validateResponse (response, expected) {
|
||||
}
|
||||
|
||||
// @param tolerance number of tolerated grid cell differences
|
||||
assert.utfgridEqualsFile = function (buffer, file_b, tolerance, callback) {
|
||||
assert.utfgridEqualsFile = function (buffer, fileB, tolerance, callback) {
|
||||
// jshint maxcomplexity:9
|
||||
fs.writeFileSync('/tmp/grid.json', buffer, 'binary'); // <-- to debug/update
|
||||
var expected_json = JSON.parse(fs.readFileSync(file_b, 'utf8'));
|
||||
var expectedJson = JSON.parse(fs.readFileSync(fileB, 'utf8'));
|
||||
|
||||
var err = null;
|
||||
|
||||
@ -204,20 +204,20 @@ assert.utfgridEqualsFile = function (buffer, file_b, tolerance, callback) {
|
||||
};
|
||||
|
||||
try {
|
||||
var obtained_json = Object.prototype.toString() === buffer.toString() ? buffer : JSON.parse(buffer);
|
||||
var obtainedJson = Object.prototype.toString() === buffer.toString() ? buffer : JSON.parse(buffer);
|
||||
|
||||
// compare grid
|
||||
var obtained_grid = obtained_json.grid;
|
||||
var expected_grid = expected_json.grid;
|
||||
var nrows = obtained_grid.length;
|
||||
if (nrows !== expected_grid.length) {
|
||||
var obtainedGrid = obtainedJson.grid;
|
||||
var expectedGrid = expectedJson.grid;
|
||||
var nrows = obtainedGrid.length;
|
||||
if (nrows !== expectedGrid.length) {
|
||||
throw new Error('Obtained grid rows (' + nrows +
|
||||
') != expected grid rows (' + expected_grid.length + ')');
|
||||
') != expected grid rows (' + expectedGrid.length + ')');
|
||||
}
|
||||
var celldiff = [];
|
||||
for (var i = 0; i < nrows; ++i) {
|
||||
var ocols = obtained_grid[i];
|
||||
var ecols = expected_grid[i];
|
||||
var ocols = obtainedGrid[i];
|
||||
var ecols = expectedGrid[i];
|
||||
var ncols = ocols.length;
|
||||
if (ncols !== ecols.length) {
|
||||
throw new Error('Obtained grid cols (' + ncols +
|
||||
@ -237,7 +237,7 @@ assert.utfgridEqualsFile = function (buffer, file_b, tolerance, callback) {
|
||||
throw new Error(celldiff.length + ' cell differences: ' + celldiff);
|
||||
}
|
||||
|
||||
assert.deepStrictEqual(obtained_json.keys, expected_json.keys);
|
||||
assert.deepStrictEqual(obtainedJson.keys, expectedJson.keys);
|
||||
} catch (e) { err = e; }
|
||||
|
||||
callback(err);
|
||||
|
@ -29,7 +29,7 @@ log4js.configure({ appenders: [] });
|
||||
global.logger = log4js.getLogger();
|
||||
|
||||
// Utility function to compress & encode LZMA
|
||||
function lzma_compress_to_base64 (payload, mode, callback) {
|
||||
function lzmaCompressToBase64 (payload, mode, callback) {
|
||||
lzmaWorker.compress(payload, mode,
|
||||
function (ints) {
|
||||
ints = ints.map(function (c) { return String.fromCharCode(c + 128); }).join('');
|
||||
@ -200,7 +200,7 @@ function configureMetadata (action, params, callback) {
|
||||
|
||||
module.exports = {
|
||||
deleteRedisKeys: deleteRedisKeys,
|
||||
lzma_compress_to_base64: lzma_compress_to_base64,
|
||||
lzma_compress_to_base64: lzmaCompressToBase64,
|
||||
checkNoCache: checkNoCache,
|
||||
checkSurrogateKey: checkSurrogateKey,
|
||||
checkCache: checkCache,
|
||||
|
@ -34,12 +34,12 @@ describe('turbo-carto-postgres-datasource', function () {
|
||||
var method = 'equal';
|
||||
this.datasource.getRamp(column, buckets, method, function (err, result) {
|
||||
assert.ifError(err);
|
||||
var expected_result = {
|
||||
var expectedResult = {
|
||||
ramp: [252, 501, 750, 999],
|
||||
stats: { min_val: 3, max_val: 999, avg_val: 501 },
|
||||
strategy: undefined
|
||||
};
|
||||
assert.deepStrictEqual(result, expected_result);
|
||||
assert.deepStrictEqual(result, expectedResult);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
@ -8,24 +8,24 @@ var overviewsQueryRewriter = new OverviewsQueryRewriter({
|
||||
zoom_level: 'ZoomLevel()'
|
||||
});
|
||||
|
||||
function normalize_whitespace (txt) {
|
||||
function normalizeWhitespace (txt) {
|
||||
return txt.replace(/\s+/g, ' ').trim();
|
||||
}
|
||||
|
||||
// compare SQL statements ignoring whitespace
|
||||
function assertSameSql (sql1, sql2) {
|
||||
assert.strictEqual(normalize_whitespace(sql1), normalize_whitespace(sql2));
|
||||
assert.strictEqual(normalizeWhitespace(sql1), normalizeWhitespace(sql2));
|
||||
}
|
||||
|
||||
describe('Overviews query rewriter', function () {
|
||||
it('does not alter queries if no overviews data is present', function () {
|
||||
var sql = 'SELECT * FROM table1';
|
||||
var overviews_sql = overviewsQueryRewriter.query(sql);
|
||||
assert.strictEqual(overviews_sql, sql);
|
||||
overviews_sql = overviewsQueryRewriter.query(sql, {});
|
||||
assert.strictEqual(overviews_sql, sql);
|
||||
overviews_sql = overviewsQueryRewriter.query(sql, { overviews: {} });
|
||||
assert.strictEqual(overviews_sql, sql);
|
||||
var overviewsSql = overviewsQueryRewriter.query(sql);
|
||||
assert.strictEqual(overviewsSql, sql);
|
||||
overviewsSql = overviewsQueryRewriter.query(sql, {});
|
||||
assert.strictEqual(overviewsSql, sql);
|
||||
overviewsSql = overviewsQueryRewriter.query(sql, { overviews: {} });
|
||||
assert.strictEqual(overviewsSql, sql);
|
||||
});
|
||||
|
||||
it('does not alter queries which don\'t use overviews', function () {
|
||||
@ -39,8 +39,8 @@ describe('Overviews query rewriter', function () {
|
||||
}
|
||||
}
|
||||
};
|
||||
var overviews_sql = overviewsQueryRewriter.query(sql, data);
|
||||
assert.strictEqual(overviews_sql, sql);
|
||||
var overviewsSql = overviewsQueryRewriter.query(sql, data);
|
||||
assert.strictEqual(overviewsSql, sql);
|
||||
});
|
||||
|
||||
it('generates query with single overview layer for level 0', function () {
|
||||
@ -52,9 +52,9 @@ describe('Overviews query rewriter', function () {
|
||||
}
|
||||
}
|
||||
};
|
||||
var overviews_sql = overviewsQueryRewriter.query(sql, data);
|
||||
var overviewsSql = overviewsQueryRewriter.query(sql, data);
|
||||
|
||||
var expected_sql = `
|
||||
var expectedSql = `
|
||||
WITH
|
||||
_vovw_scale AS ( SELECT ZoomLevel() AS _vovw_z )
|
||||
SELECT * FROM (
|
||||
@ -63,7 +63,7 @@ describe('Overviews query rewriter', function () {
|
||||
SELECT * FROM table1, _vovw_scale WHERE _vovw_z > 0
|
||||
) AS _vovw_table1
|
||||
`;
|
||||
assertSameSql(overviews_sql, expected_sql);
|
||||
assertSameSql(overviewsSql, expectedSql);
|
||||
});
|
||||
|
||||
it('generates query with single overview layer for level >0', function () {
|
||||
@ -75,8 +75,8 @@ describe('Overviews query rewriter', function () {
|
||||
}
|
||||
}
|
||||
};
|
||||
var overviews_sql = overviewsQueryRewriter.query(sql, data);
|
||||
var expected_sql = `
|
||||
var overviewsSql = overviewsQueryRewriter.query(sql, data);
|
||||
var expectedSql = `
|
||||
WITH
|
||||
_vovw_scale AS ( SELECT ZoomLevel() AS _vovw_z )
|
||||
SELECT * FROM (
|
||||
@ -85,7 +85,7 @@ describe('Overviews query rewriter', function () {
|
||||
SELECT * FROM table1, _vovw_scale WHERE _vovw_z > 2
|
||||
) AS _vovw_table1
|
||||
`;
|
||||
assertSameSql(overviews_sql, expected_sql);
|
||||
assertSameSql(overviewsSql, expectedSql);
|
||||
});
|
||||
|
||||
it('generates query with multiple overview layers for all levels up to N', function () {
|
||||
@ -100,8 +100,8 @@ describe('Overviews query rewriter', function () {
|
||||
}
|
||||
}
|
||||
};
|
||||
var overviews_sql = overviewsQueryRewriter.query(sql, data);
|
||||
var expected_sql = `
|
||||
var overviewsSql = overviewsQueryRewriter.query(sql, data);
|
||||
var expectedSql = `
|
||||
WITH
|
||||
_vovw_scale AS ( SELECT ZoomLevel() AS _vovw_z )
|
||||
SELECT * FROM (
|
||||
@ -116,7 +116,7 @@ describe('Overviews query rewriter', function () {
|
||||
SELECT * FROM table1, _vovw_scale WHERE _vovw_z > 3
|
||||
) AS _vovw_table1
|
||||
`;
|
||||
assertSameSql(overviews_sql, expected_sql);
|
||||
assertSameSql(overviewsSql, expectedSql);
|
||||
});
|
||||
|
||||
it('generates query with multiple overview layers for random levels', function () {
|
||||
@ -130,8 +130,8 @@ describe('Overviews query rewriter', function () {
|
||||
}
|
||||
}
|
||||
};
|
||||
var overviews_sql = overviewsQueryRewriter.query(sql, data);
|
||||
var expected_sql = `
|
||||
var overviewsSql = overviewsQueryRewriter.query(sql, data);
|
||||
var expectedSql = `
|
||||
WITH
|
||||
_vovw_scale AS ( SELECT ZoomLevel() AS _vovw_z )
|
||||
SELECT * FROM (
|
||||
@ -144,7 +144,7 @@ describe('Overviews query rewriter', function () {
|
||||
SELECT * FROM table1, _vovw_scale WHERE _vovw_z > 6
|
||||
) AS _vovw_table1
|
||||
`;
|
||||
assertSameSql(overviews_sql, expected_sql);
|
||||
assertSameSql(overviewsSql, expectedSql);
|
||||
});
|
||||
|
||||
it('generates query for a table with explicit schema', function () {
|
||||
@ -156,8 +156,8 @@ describe('Overviews query rewriter', function () {
|
||||
}
|
||||
}
|
||||
};
|
||||
var overviews_sql = overviewsQueryRewriter.query(sql, data);
|
||||
var expected_sql = `
|
||||
var overviewsSql = overviewsQueryRewriter.query(sql, data);
|
||||
var expectedSql = `
|
||||
WITH
|
||||
_vovw_scale AS ( SELECT ZoomLevel() AS _vovw_z )
|
||||
SELECT * FROM (
|
||||
@ -166,7 +166,7 @@ describe('Overviews query rewriter', function () {
|
||||
SELECT * FROM public.table1, _vovw_scale WHERE _vovw_z > 2
|
||||
) AS _vovw_table1
|
||||
`;
|
||||
assertSameSql(overviews_sql, expected_sql);
|
||||
assertSameSql(overviewsSql, expectedSql);
|
||||
});
|
||||
|
||||
it('generates query for a table with explicit schema in the overviews info', function () {
|
||||
@ -178,8 +178,8 @@ describe('Overviews query rewriter', function () {
|
||||
}
|
||||
}
|
||||
};
|
||||
var overviews_sql = overviewsQueryRewriter.query(sql, data);
|
||||
var expected_sql = `
|
||||
var overviewsSql = overviewsQueryRewriter.query(sql, data);
|
||||
var expectedSql = `
|
||||
WITH
|
||||
_vovw_scale AS ( SELECT ZoomLevel() AS _vovw_z )
|
||||
SELECT * FROM (
|
||||
@ -189,7 +189,7 @@ describe('Overviews query rewriter', function () {
|
||||
) AS _vovw_table1
|
||||
`;
|
||||
|
||||
assertSameSql(overviews_sql, expected_sql);
|
||||
assertSameSql(overviewsSql, expectedSql);
|
||||
});
|
||||
|
||||
it('uses schema name from overviews', function () {
|
||||
@ -202,8 +202,8 @@ describe('Overviews query rewriter', function () {
|
||||
}
|
||||
}
|
||||
};
|
||||
var overviews_sql = overviewsQueryRewriter.query(sql, data);
|
||||
var expected_sql = `
|
||||
var overviewsSql = overviewsQueryRewriter.query(sql, data);
|
||||
var expectedSql = `
|
||||
WITH
|
||||
_vovw_scale AS ( SELECT ZoomLevel() AS _vovw_z )
|
||||
SELECT * FROM (
|
||||
@ -212,7 +212,7 @@ describe('Overviews query rewriter', function () {
|
||||
SELECT * FROM table1, _vovw_scale WHERE _vovw_z > 2
|
||||
) AS _vovw_table1
|
||||
`;
|
||||
assertSameSql(overviews_sql, expected_sql);
|
||||
assertSameSql(overviewsSql, expectedSql);
|
||||
});
|
||||
|
||||
it('ignores schema name from overviews if not necessary', function () {
|
||||
@ -225,8 +225,8 @@ describe('Overviews query rewriter', function () {
|
||||
}
|
||||
}
|
||||
};
|
||||
var overviews_sql = overviewsQueryRewriter.query(sql, data);
|
||||
var expected_sql = `
|
||||
var overviewsSql = overviewsQueryRewriter.query(sql, data);
|
||||
var expectedSql = `
|
||||
WITH
|
||||
_vovw_scale AS ( SELECT ZoomLevel() AS _vovw_z )
|
||||
SELECT * FROM (
|
||||
@ -235,7 +235,7 @@ describe('Overviews query rewriter', function () {
|
||||
SELECT * FROM table1, _vovw_scale WHERE _vovw_z > 2
|
||||
) AS _vovw_table1
|
||||
`;
|
||||
assertSameSql(overviews_sql, expected_sql);
|
||||
assertSameSql(overviewsSql, expectedSql);
|
||||
});
|
||||
|
||||
it('uses redundant schema information', function () {
|
||||
@ -248,8 +248,8 @@ describe('Overviews query rewriter', function () {
|
||||
}
|
||||
}
|
||||
};
|
||||
var overviews_sql = overviewsQueryRewriter.query(sql, data);
|
||||
var expected_sql = `
|
||||
var overviewsSql = overviewsQueryRewriter.query(sql, data);
|
||||
var expectedSql = `
|
||||
WITH
|
||||
_vovw_scale AS ( SELECT ZoomLevel() AS _vovw_z )
|
||||
SELECT * FROM (
|
||||
@ -258,7 +258,7 @@ describe('Overviews query rewriter', function () {
|
||||
SELECT * FROM public.table1, _vovw_scale WHERE _vovw_z > 2
|
||||
) AS _vovw_table1
|
||||
`;
|
||||
assertSameSql(overviews_sql, expected_sql);
|
||||
assertSameSql(overviewsSql, expectedSql);
|
||||
});
|
||||
|
||||
it('generates query for a table that needs quoting with explicit schema', function () {
|
||||
@ -270,8 +270,8 @@ describe('Overviews query rewriter', function () {
|
||||
}
|
||||
}
|
||||
};
|
||||
var overviews_sql = overviewsQueryRewriter.query(sql, data);
|
||||
var expected_sql = `
|
||||
var overviewsSql = overviewsQueryRewriter.query(sql, data);
|
||||
var expectedSql = `
|
||||
WITH
|
||||
_vovw_scale AS ( SELECT ZoomLevel() AS _vovw_z )
|
||||
SELECT * FROM (
|
||||
@ -280,7 +280,7 @@ describe('Overviews query rewriter', function () {
|
||||
SELECT * FROM public."table 1", _vovw_scale WHERE _vovw_z > 2
|
||||
) AS "_vovw_table 1"
|
||||
`;
|
||||
assertSameSql(overviews_sql, expected_sql);
|
||||
assertSameSql(overviewsSql, expectedSql);
|
||||
});
|
||||
|
||||
it('generates query for a table with explicit schema that needs quoting', function () {
|
||||
@ -292,8 +292,8 @@ describe('Overviews query rewriter', function () {
|
||||
}
|
||||
}
|
||||
};
|
||||
var overviews_sql = overviewsQueryRewriter.query(sql, data);
|
||||
var expected_sql = `
|
||||
var overviewsSql = overviewsQueryRewriter.query(sql, data);
|
||||
var expectedSql = `
|
||||
WITH
|
||||
_vovw_scale AS ( SELECT ZoomLevel() AS _vovw_z )
|
||||
SELECT * FROM (
|
||||
@ -302,7 +302,7 @@ describe('Overviews query rewriter', function () {
|
||||
SELECT * FROM "user-1".table1, _vovw_scale WHERE _vovw_z > 2
|
||||
) AS _vovw_table1
|
||||
`;
|
||||
assertSameSql(overviews_sql, expected_sql);
|
||||
assertSameSql(overviewsSql, expectedSql);
|
||||
});
|
||||
|
||||
it('generates query for a table with explicit schema both needing quoting', function () {
|
||||
@ -315,8 +315,8 @@ describe('Overviews query rewriter', function () {
|
||||
}
|
||||
}
|
||||
};
|
||||
var overviews_sql = overviewsQueryRewriter.query(sql, data);
|
||||
var expected_sql = `
|
||||
var overviewsSql = overviewsQueryRewriter.query(sql, data);
|
||||
var expectedSql = `
|
||||
WITH
|
||||
_vovw_scale AS ( SELECT ZoomLevel() AS _vovw_z )
|
||||
SELECT * FROM (
|
||||
@ -325,7 +325,7 @@ describe('Overviews query rewriter', function () {
|
||||
SELECT * FROM "user-1"."table 1", _vovw_scale WHERE _vovw_z > 2
|
||||
) AS "_vovw_table 1"
|
||||
`;
|
||||
assertSameSql(overviews_sql, expected_sql);
|
||||
assertSameSql(overviewsSql, expectedSql);
|
||||
});
|
||||
|
||||
it('generates query using overviews for queries with selected columns', function () {
|
||||
@ -337,8 +337,8 @@ describe('Overviews query rewriter', function () {
|
||||
}
|
||||
}
|
||||
};
|
||||
var overviews_sql = overviewsQueryRewriter.query(sql, data);
|
||||
var expected_sql = `
|
||||
var overviewsSql = overviewsQueryRewriter.query(sql, data);
|
||||
var expectedSql = `
|
||||
WITH
|
||||
_vovw_scale AS ( SELECT ZoomLevel() AS _vovw_z )
|
||||
SELECT column1, column2, column3 FROM (
|
||||
@ -347,7 +347,7 @@ describe('Overviews query rewriter', function () {
|
||||
SELECT * FROM table1, _vovw_scale WHERE _vovw_z > 2
|
||||
) AS _vovw_table1
|
||||
`;
|
||||
assertSameSql(overviews_sql, expected_sql);
|
||||
assertSameSql(overviewsSql, expectedSql);
|
||||
});
|
||||
|
||||
it('generates query using overviews for queries with a semicolon', function () {
|
||||
@ -359,9 +359,9 @@ describe('Overviews query rewriter', function () {
|
||||
}
|
||||
}
|
||||
};
|
||||
var overviews_sql = overviewsQueryRewriter.query(sql, data);
|
||||
var overviewsSql = overviewsQueryRewriter.query(sql, data);
|
||||
|
||||
var expected_sql = `
|
||||
var expectedSql = `
|
||||
WITH
|
||||
_vovw_scale AS ( SELECT ZoomLevel() AS _vovw_z )
|
||||
SELECT column1, column2, column3 FROM (
|
||||
@ -370,7 +370,7 @@ describe('Overviews query rewriter', function () {
|
||||
SELECT * FROM table1, _vovw_scale WHERE _vovw_z > 2
|
||||
) AS _vovw_table1;
|
||||
`;
|
||||
assertSameSql(overviews_sql, expected_sql);
|
||||
assertSameSql(overviewsSql, expectedSql);
|
||||
});
|
||||
|
||||
it('generates query using overviews for queries with extra whitespace', function () {
|
||||
@ -382,8 +382,8 @@ describe('Overviews query rewriter', function () {
|
||||
}
|
||||
}
|
||||
};
|
||||
var overviews_sql = overviewsQueryRewriter.query(sql, data);
|
||||
var expected_sql = `
|
||||
var overviewsSql = overviewsQueryRewriter.query(sql, data);
|
||||
var expectedSql = `
|
||||
WITH
|
||||
_vovw_scale AS ( SELECT ZoomLevel() AS _vovw_z )
|
||||
SELECT column1,column2, column3 FROM (
|
||||
@ -392,7 +392,7 @@ describe('Overviews query rewriter', function () {
|
||||
SELECT * FROM table1, _vovw_scale WHERE _vovw_z > 2
|
||||
) AS _vovw_table1
|
||||
`;
|
||||
assertSameSql(overviews_sql, expected_sql);
|
||||
assertSameSql(overviewsSql, expectedSql);
|
||||
});
|
||||
|
||||
it('does not alter queries which have not the simple supported form', function () {
|
||||
@ -404,44 +404,44 @@ describe('Overviews query rewriter', function () {
|
||||
}
|
||||
}
|
||||
};
|
||||
var overviews_sql = overviewsQueryRewriter.query(sql, data);
|
||||
assert.strictEqual(overviews_sql, sql);
|
||||
var overviewsSql = overviewsQueryRewriter.query(sql, data);
|
||||
assert.strictEqual(overviewsSql, sql);
|
||||
|
||||
sql = 'SELECT * FROM table1 JOIN table2 ON (table1.col1=table2.col1)';
|
||||
overviews_sql = overviewsQueryRewriter.query(sql, data);
|
||||
assert.strictEqual(overviews_sql, sql);
|
||||
overviewsSql = overviewsQueryRewriter.query(sql, data);
|
||||
assert.strictEqual(overviewsSql, sql);
|
||||
|
||||
sql = 'SELECT a+b AS c FROM table1';
|
||||
overviews_sql = overviewsQueryRewriter.query(sql, data);
|
||||
assert.strictEqual(overviews_sql, sql);
|
||||
overviewsSql = overviewsQueryRewriter.query(sql, data);
|
||||
assert.strictEqual(overviewsSql, sql);
|
||||
|
||||
sql = 'SELECT f(a) AS b FROM table1';
|
||||
overviews_sql = overviewsQueryRewriter.query(sql, data);
|
||||
assert.strictEqual(overviews_sql, sql);
|
||||
overviewsSql = overviewsQueryRewriter.query(sql, data);
|
||||
assert.strictEqual(overviewsSql, sql);
|
||||
|
||||
sql = 'SELECT * FROM table1 AS x';
|
||||
overviews_sql = overviewsQueryRewriter.query(sql, data);
|
||||
assert.strictEqual(overviews_sql, sql);
|
||||
overviewsSql = overviewsQueryRewriter.query(sql, data);
|
||||
assert.strictEqual(overviewsSql, sql);
|
||||
|
||||
sql = 'WITH a AS (1) SELECT * FROM table1';
|
||||
overviews_sql = overviewsQueryRewriter.query(sql, data);
|
||||
assert.strictEqual(overviews_sql, sql);
|
||||
overviewsSql = overviewsQueryRewriter.query(sql, data);
|
||||
assert.strictEqual(overviewsSql, sql);
|
||||
|
||||
sql = 'SELECT * FROM table1 WHERE a=1';
|
||||
overviews_sql = overviewsQueryRewriter.query(sql, data);
|
||||
assert.strictEqual(overviews_sql, sql);
|
||||
overviewsSql = overviewsQueryRewriter.query(sql, data);
|
||||
assert.strictEqual(overviewsSql, sql);
|
||||
|
||||
sql = `
|
||||
SELECT table1.* FROM table1
|
||||
JOIN areas ON ST_Intersects(table1.the_geom, areas.the_geom)
|
||||
WHERE areas.name='A'
|
||||
`;
|
||||
overviews_sql = overviewsQueryRewriter.query(sql, data);
|
||||
assert.strictEqual(overviews_sql, sql);
|
||||
overviewsSql = overviewsQueryRewriter.query(sql, data);
|
||||
assert.strictEqual(overviewsSql, sql);
|
||||
|
||||
sql = 'SELECT table1.*, column1, column2, column3 FROM table1';
|
||||
overviews_sql = overviewsQueryRewriter.query(sql, data);
|
||||
assert.strictEqual(overviews_sql, sql);
|
||||
overviewsSql = overviewsQueryRewriter.query(sql, data);
|
||||
assert.strictEqual(overviewsSql, sql);
|
||||
});
|
||||
|
||||
it('generates overviews for wrapped query', function () {
|
||||
@ -455,8 +455,8 @@ describe('Overviews query rewriter', function () {
|
||||
}
|
||||
}
|
||||
};
|
||||
var overviews_sql = overviewsQueryRewriter.query(sql, data);
|
||||
var expected_sql = `
|
||||
var overviewsSql = overviewsQueryRewriter.query(sql, data);
|
||||
var expectedSql = `
|
||||
WITH
|
||||
_vovw_scale AS ( SELECT ZoomLevel() AS _vovw_z )
|
||||
SELECT * FROM (SELECT * FROM (
|
||||
@ -469,7 +469,7 @@ describe('Overviews query rewriter', function () {
|
||||
SELECT * FROM table1, _vovw_scale WHERE _vovw_z > 2
|
||||
) AS _vovw_table1) AS wrapped_query WHERE 1=1
|
||||
`;
|
||||
assertSameSql(overviews_sql, expected_sql);
|
||||
assertSameSql(overviewsSql, expectedSql);
|
||||
});
|
||||
|
||||
it('generates query for specific Z level', function () {
|
||||
@ -483,9 +483,9 @@ describe('Overviews query rewriter', function () {
|
||||
}
|
||||
}
|
||||
};
|
||||
var overviews_sql = overviewsQueryRewriter.query(sql, data, { zoom_level: 3 });
|
||||
var expected_sql = 'SELECT * FROM table1_ov3';
|
||||
assertSameSql(overviews_sql, expected_sql);
|
||||
var overviewsSql = overviewsQueryRewriter.query(sql, data, { zoom_level: 3 });
|
||||
var expectedSql = 'SELECT * FROM table1_ov3';
|
||||
assertSameSql(overviewsSql, expectedSql);
|
||||
});
|
||||
|
||||
it('generates query for specific nonpresent Z level', function () {
|
||||
@ -499,9 +499,9 @@ describe('Overviews query rewriter', function () {
|
||||
}
|
||||
}
|
||||
};
|
||||
var overviews_sql = overviewsQueryRewriter.query(sql, data, { zoom_level: 1 });
|
||||
var expected_sql = 'SELECT * FROM table1_ov2';
|
||||
assertSameSql(overviews_sql, expected_sql);
|
||||
var overviewsSql = overviewsQueryRewriter.query(sql, data, { zoom_level: 1 });
|
||||
var expectedSql = 'SELECT * FROM table1_ov2';
|
||||
assertSameSql(overviewsSql, expectedSql);
|
||||
});
|
||||
|
||||
it('does not use overviews for specific out-of-range Z level', function () {
|
||||
@ -515,9 +515,9 @@ describe('Overviews query rewriter', function () {
|
||||
}
|
||||
}
|
||||
};
|
||||
var overviews_sql = overviewsQueryRewriter.query(sql, data, { zoom_level: 4 });
|
||||
var expected_sql = 'SELECT * FROM table1';
|
||||
assertSameSql(overviews_sql, expected_sql);
|
||||
var overviewsSql = overviewsQueryRewriter.query(sql, data, { zoom_level: 4 });
|
||||
var expectedSql = 'SELECT * FROM table1';
|
||||
assertSameSql(overviewsSql, expectedSql);
|
||||
});
|
||||
|
||||
it('generates query with filters', function () {
|
||||
@ -537,8 +537,8 @@ describe('Overviews query rewriter', function () {
|
||||
filters: { name_filter: { type: 'category', column: 'name', params: { accept: ['X'] } } },
|
||||
unfiltered_query: 'SELECT * FROM table1'
|
||||
};
|
||||
var overviews_sql = overviewsQueryRewriter.query(sql, data);
|
||||
var expected_sql = `
|
||||
var overviewsSql = overviewsQueryRewriter.query(sql, data);
|
||||
var expectedSql = `
|
||||
SELECT * FROM (WITH
|
||||
_vovw_scale AS ( SELECT ZoomLevel() AS _vovw_z )
|
||||
SELECT * FROM (
|
||||
@ -554,7 +554,7 @@ describe('Overviews query rewriter', function () {
|
||||
) AS _vovw_table1) _analysis_category_filter
|
||||
WHERE name IN ($escape_0$X$escape_0$)
|
||||
`;
|
||||
assertSameSql(overviews_sql, expected_sql);
|
||||
assertSameSql(overviewsSql, expectedSql);
|
||||
});
|
||||
|
||||
it('generates query with filters for specific zoom level', function () {
|
||||
@ -575,12 +575,12 @@ describe('Overviews query rewriter', function () {
|
||||
unfiltered_query: 'SELECT * FROM table1',
|
||||
filter_stats: { unfiltered_rows: 1000, filtered_rows: 900 }
|
||||
};
|
||||
var overviews_sql = overviewsQueryRewriter.query(sql, data, { zoom_level: 2 });
|
||||
var expected_sql = `
|
||||
var overviewsSql = overviewsQueryRewriter.query(sql, data, { zoom_level: 2 });
|
||||
var expectedSql = `
|
||||
SELECT * FROM (SELECT * FROM table1_ov2) _analysis_category_filter
|
||||
WHERE name IN ($escape_0$X$escape_0$)
|
||||
`;
|
||||
assertSameSql(overviews_sql, expected_sql);
|
||||
assertSameSql(overviewsSql, expectedSql);
|
||||
});
|
||||
|
||||
it('does not generates query with aggressive filtering', function () {
|
||||
@ -601,7 +601,7 @@ describe('Overviews query rewriter', function () {
|
||||
unfiltered_query: 'SELECT * FROM table1',
|
||||
filter_stats: { unfiltered_rows: 1000, filtered_rows: 10 }
|
||||
};
|
||||
var overviews_sql = overviewsQueryRewriter.query(sql, data);
|
||||
assert.strictEqual(overviews_sql, sql);
|
||||
var overviewsSql = overviewsQueryRewriter.query(sql, data);
|
||||
assert.strictEqual(overviewsSql, sql);
|
||||
});
|
||||
});
|
||||
|
@ -17,9 +17,9 @@ const credentialsMiddleware = require('../../lib/api/middlewares/credentials');
|
||||
var windshaft = require('windshaft');
|
||||
|
||||
describe('prepare-context', function () {
|
||||
var test_user = _.template(global.environment.postgres_auth_user, { user_id: 1 });
|
||||
var test_pubuser = global.environment.postgres.user;
|
||||
var test_database = test_user + '_db';
|
||||
var testUser = _.template(global.environment.postgres_auth_user, { user_id: 1 });
|
||||
var testPubuser = global.environment.postgres.user;
|
||||
var testDatabase = testUser + '_db';
|
||||
|
||||
let cleanUpQueryParams;
|
||||
let dbConnSetup;
|
||||
@ -89,8 +89,8 @@ describe('prepare-context', function () {
|
||||
assert.ok(!Object.prototype.hasOwnProperty.call(req.query, 'dbuser'), 'dbuser was removed from query');
|
||||
assert.ok(Object.prototype.hasOwnProperty.call(res, 'locals'), 'response has locals');
|
||||
assert.ok(!Object.prototype.hasOwnProperty.call(res.locals, 'interactivity'), 'response locals do not have interactivity');
|
||||
assert.strictEqual(res.locals.dbname, test_database);
|
||||
assert.ok(res.locals.dbuser === test_pubuser, 'could inject dbuser (' + res.locals.dbuser + ')');
|
||||
assert.strictEqual(res.locals.dbname, testDatabase);
|
||||
assert.ok(res.locals.dbuser === testPubuser, 'could inject dbuser (' + res.locals.dbuser + ')');
|
||||
done();
|
||||
});
|
||||
});
|
||||
@ -120,8 +120,8 @@ describe('prepare-context', function () {
|
||||
assert.ok(!Object.prototype.hasOwnProperty.call(req.query, 'dbuser'), 'dbuser was removed from query');
|
||||
assert.ok(Object.prototype.hasOwnProperty.call(res, 'locals'), 'response has locals');
|
||||
assert.ok(!Object.prototype.hasOwnProperty.call(res.locals, 'interactivity'), 'request params do not have interactivity');
|
||||
assert.strictEqual(res.locals.dbname, test_database);
|
||||
assert.strictEqual(res.locals.dbuser, test_user);
|
||||
assert.strictEqual(res.locals.dbname, testDatabase);
|
||||
assert.strictEqual(res.locals.dbuser, testUser);
|
||||
|
||||
req = {
|
||||
headers: {
|
||||
@ -136,7 +136,7 @@ describe('prepare-context', function () {
|
||||
|
||||
dbConnSetup(prepareRequest(req), prepareResponse(res), function () {
|
||||
// wrong key resets params to no user
|
||||
assert.ok(res.locals.dbuser === test_pubuser, 'could inject dbuser (' + res.locals.dbuser + ')');
|
||||
assert.ok(res.locals.dbuser === testPubuser, 'could inject dbuser (' + res.locals.dbuser + ')');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
@ -7,7 +7,7 @@ var TableNameParser = require('../../lib/utils/table-name-parser');
|
||||
|
||||
describe('TableNameParser', function () {
|
||||
it('parses table names with scheme and quotes', function (done) {
|
||||
var test_cases = [
|
||||
var testCases = [
|
||||
['xyz', { schema: null, table: 'xyz' }],
|
||||
['"xyz"', { schema: null, table: 'xyz' }],
|
||||
['"xy z"', { schema: null, table: 'xy z' }],
|
||||
@ -26,11 +26,11 @@ describe('TableNameParser', function () {
|
||||
['"a""bc"."x""yz"', { schema: 'a"bc', table: 'x"yz' }]
|
||||
];
|
||||
|
||||
test_cases.forEach(function (test_case) {
|
||||
var table_name = test_case[0];
|
||||
var expected_result = test_case[1];
|
||||
var result = TableNameParser.parse(table_name);
|
||||
assert.deepStrictEqual(result, expected_result);
|
||||
testCases.forEach(function (testCase) {
|
||||
var tableName = testCase[0];
|
||||
var expectedResult = testCase[1];
|
||||
var result = TableNameParser.parse(tableName);
|
||||
assert.deepStrictEqual(result, expectedResult);
|
||||
});
|
||||
done();
|
||||
});
|
||||
|
@ -10,7 +10,7 @@ var _ = require('underscore');
|
||||
|
||||
describe('template_maps', function () {
|
||||
// configure redis pool instance to use in tests
|
||||
var redis_pool = new RedisPool(global.environment.redis);
|
||||
var redisPool = new RedisPool(global.environment.redis);
|
||||
|
||||
var keysToDelete;
|
||||
beforeEach(function () {
|
||||
@ -36,7 +36,7 @@ describe('template_maps', function () {
|
||||
};
|
||||
|
||||
it('does not accept template with unsupported version', function (done) {
|
||||
var tmap = new TemplateMaps(redis_pool);
|
||||
var tmap = new TemplateMaps(redisPool);
|
||||
assert.ok(tmap);
|
||||
var tpl = {
|
||||
version: '6.6.6',
|
||||
@ -60,7 +60,7 @@ describe('template_maps', function () {
|
||||
});
|
||||
|
||||
it('does not accept template with missing name', function (done) {
|
||||
var tmap = new TemplateMaps(redis_pool);
|
||||
var tmap = new TemplateMaps(redisPool);
|
||||
assert.ok(tmap);
|
||||
var tpl = {
|
||||
version: '0.0.1',
|
||||
@ -95,7 +95,7 @@ describe('template_maps', function () {
|
||||
}
|
||||
};
|
||||
}
|
||||
var templateMaps = new TemplateMaps(redis_pool);
|
||||
var templateMaps = new TemplateMaps(redisPool);
|
||||
|
||||
var invalidNames = ['ab|', 'a b', 'a@b', '-1ab', '_x', '', ' x', 'x '];
|
||||
invalidNames.forEach(function (invalidName) {
|
||||
@ -126,7 +126,7 @@ describe('template_maps', function () {
|
||||
});
|
||||
|
||||
it('does not accept template with invalid placeholder name', function (done) {
|
||||
var tmap = new TemplateMaps(redis_pool);
|
||||
var tmap = new TemplateMaps(redisPool);
|
||||
assert.ok(tmap);
|
||||
var tpl = {
|
||||
version: '0.0.1',
|
||||
@ -155,7 +155,7 @@ describe('template_maps', function () {
|
||||
});
|
||||
|
||||
it('does not accept template with missing placeholder default', function (done) {
|
||||
var tmap = new TemplateMaps(redis_pool);
|
||||
var tmap = new TemplateMaps(redisPool);
|
||||
assert.ok(tmap);
|
||||
var tpl = {
|
||||
version: '0.0.1',
|
||||
@ -176,7 +176,7 @@ describe('template_maps', function () {
|
||||
});
|
||||
|
||||
it('does not accept template with missing placeholder type', function (done) {
|
||||
var tmap = new TemplateMaps(redis_pool);
|
||||
var tmap = new TemplateMaps(redisPool);
|
||||
assert.ok(tmap);
|
||||
var tpl = {
|
||||
version: '0.0.1',
|
||||
@ -199,7 +199,7 @@ describe('template_maps', function () {
|
||||
// See http://github.com/CartoDB/Windshaft-cartodb/issues/128
|
||||
it('does not accept template with invalid token auth (undefined tokens)',
|
||||
function (done) {
|
||||
var tmap = new TemplateMaps(redis_pool);
|
||||
var tmap = new TemplateMaps(redisPool);
|
||||
assert.ok(tmap);
|
||||
var tpl = {
|
||||
version: '0.0.1',
|
||||
@ -220,10 +220,10 @@ describe('template_maps', function () {
|
||||
});
|
||||
|
||||
it('add, get and delete a valid template', function (done) {
|
||||
var tmap = new TemplateMaps(redis_pool);
|
||||
var tmap = new TemplateMaps(redisPool);
|
||||
assert.ok(tmap);
|
||||
var expected_failure = false;
|
||||
var tpl_id;
|
||||
var expectedFailure = false;
|
||||
var tplId;
|
||||
var tpl = {
|
||||
version: '0.0.1',
|
||||
name: 'first',
|
||||
@ -236,24 +236,24 @@ describe('template_maps', function () {
|
||||
},
|
||||
function addOmonimousTemplate (err, id) {
|
||||
assert.ifError(err);
|
||||
tpl_id = id;
|
||||
assert.strictEqual(tpl_id, 'first');
|
||||
expected_failure = true;
|
||||
tplId = id;
|
||||
assert.strictEqual(tplId, 'first');
|
||||
expectedFailure = true;
|
||||
// should fail, as it already exists
|
||||
tmap.addTemplate('me', tpl, this);
|
||||
},
|
||||
function getTemplate (err) {
|
||||
if (!expected_failure && err) {
|
||||
if (!expectedFailure && err) {
|
||||
throw err;
|
||||
}
|
||||
assert.ok(err);
|
||||
assert.ok(err.message.match(/already exists/i), err);
|
||||
tmap.getTemplate('me', tpl_id, this);
|
||||
tmap.getTemplate('me', tplId, this);
|
||||
},
|
||||
function delTemplate (err, got_tpl) {
|
||||
function delTemplate (err, gotTpl) {
|
||||
assert.ifError(err);
|
||||
assert.deepStrictEqual(got_tpl, _.extend({}, tpl, { auth: { method: 'open' }, placeholders: {} }));
|
||||
tmap.delTemplate('me', tpl_id, this);
|
||||
assert.deepStrictEqual(gotTpl, _.extend({}, tpl, { auth: { method: 'open' }, placeholders: {} }));
|
||||
tmap.delTemplate('me', tplId, this);
|
||||
},
|
||||
function finish (err) {
|
||||
done(err);
|
||||
@ -262,37 +262,37 @@ describe('template_maps', function () {
|
||||
});
|
||||
|
||||
it('add multiple templates, list them', function (done) {
|
||||
var tmap = new TemplateMaps(redis_pool);
|
||||
var tmap = new TemplateMaps(redisPool);
|
||||
assert.ok(tmap);
|
||||
var tpl1 = { version: '0.0.1', name: 'first', auth: {}, layergroup: { layers: [wadusLayer] } };
|
||||
var tpl1_id;
|
||||
var tpl1Id;
|
||||
var tpl2 = { version: '0.0.1', name: 'second', auth: {}, layergroup: { layers: [wadusLayer] } };
|
||||
var tpl2_id;
|
||||
var tpl2Id;
|
||||
step(
|
||||
function addTemplate1 () {
|
||||
tmap.addTemplate('me', tpl1, this);
|
||||
},
|
||||
function addTemplate2 (err, id) {
|
||||
assert.ifError(err);
|
||||
tpl1_id = id;
|
||||
tpl1Id = id;
|
||||
tmap.addTemplate('me', tpl2, this);
|
||||
},
|
||||
function listTemplates (err, id) {
|
||||
assert.ifError(err);
|
||||
tpl2_id = id;
|
||||
tpl2Id = id;
|
||||
tmap.listTemplates('me', this);
|
||||
},
|
||||
function checkTemplates (err, ids) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(ids.length, 2);
|
||||
assert.ok(ids.indexOf(tpl1_id) !== -1, ids.join(','));
|
||||
assert.ok(ids.indexOf(tpl2_id) !== -1, ids.join(','));
|
||||
assert.ok(ids.indexOf(tpl1Id) !== -1, ids.join(','));
|
||||
assert.ok(ids.indexOf(tpl2Id) !== -1, ids.join(','));
|
||||
return null;
|
||||
},
|
||||
function delTemplate1 (err) {
|
||||
if (tpl1_id) {
|
||||
if (tpl1Id) {
|
||||
var next = this;
|
||||
tmap.delTemplate('me', tpl1_id, function (e) {
|
||||
tmap.delTemplate('me', tpl1Id, function (e) {
|
||||
if (err || e) {
|
||||
next(new Error(err + '; ' + e));
|
||||
} else {
|
||||
@ -305,9 +305,9 @@ describe('template_maps', function () {
|
||||
}
|
||||
},
|
||||
function delTemplate2 (err) {
|
||||
if (tpl2_id) {
|
||||
if (tpl2Id) {
|
||||
var next = this;
|
||||
tmap.delTemplate('me', tpl2_id, function (e) {
|
||||
tmap.delTemplate('me', tpl2Id, function (e) {
|
||||
if (err || e) {
|
||||
next(new Error(err + '; ' + e));
|
||||
} else {
|
||||
@ -326,9 +326,9 @@ describe('template_maps', function () {
|
||||
});
|
||||
|
||||
it('update templates', function (done) {
|
||||
var tmap = new TemplateMaps(redis_pool);
|
||||
var tmap = new TemplateMaps(redisPool);
|
||||
assert.ok(tmap);
|
||||
var expected_failure = false;
|
||||
var expectedFailure = false;
|
||||
var owner = 'me';
|
||||
var tpl = {
|
||||
version: '0.0.1',
|
||||
@ -336,7 +336,7 @@ describe('template_maps', function () {
|
||||
auth: { method: 'open' },
|
||||
layergroup: { layers: [wadusLayer] }
|
||||
};
|
||||
var tpl_id;
|
||||
var tplId;
|
||||
step(
|
||||
function addTemplate () {
|
||||
tmap.addTemplate(owner, tpl, this);
|
||||
@ -344,46 +344,46 @@ describe('template_maps', function () {
|
||||
// Updating template name should fail
|
||||
function updateTemplateName (err, id) {
|
||||
assert.ifError(err);
|
||||
tpl_id = id;
|
||||
expected_failure = true;
|
||||
tplId = id;
|
||||
expectedFailure = true;
|
||||
tpl.name = 'second';
|
||||
tmap.updTemplate(owner, tpl_id, tpl, this);
|
||||
tmap.updTemplate(owner, tplId, tpl, this);
|
||||
},
|
||||
function updateTemplateAuth (err) {
|
||||
if (err && !expected_failure) {
|
||||
if (err && !expectedFailure) {
|
||||
throw err;
|
||||
}
|
||||
expected_failure = false;
|
||||
expectedFailure = false;
|
||||
assert.ok(err);
|
||||
tpl.name = 'first';
|
||||
tpl.auth.method = 'token';
|
||||
tpl.auth.valid_tokens = ['tok1'];
|
||||
tmap.updTemplate(owner, tpl_id, tpl, this);
|
||||
tmap.updTemplate(owner, tplId, tpl, this);
|
||||
},
|
||||
function updateTemplateWithInvalid (err) {
|
||||
assert.ifError(err);
|
||||
tpl.version = '999.999.999';
|
||||
expected_failure = true;
|
||||
tmap.updTemplate(owner, tpl_id, tpl, this);
|
||||
expectedFailure = true;
|
||||
tmap.updTemplate(owner, tplId, tpl, this);
|
||||
},
|
||||
function updateUnexistentTemplate (err) {
|
||||
if (err && !expected_failure) {
|
||||
if (err && !expectedFailure) {
|
||||
throw err;
|
||||
}
|
||||
assert.ok(err);
|
||||
assert.ok(err.message.match(/unsupported.*version/i), err);
|
||||
tpl.version = '0.0.1';
|
||||
expected_failure = true;
|
||||
expectedFailure = true;
|
||||
tmap.updTemplate(owner, 'unexistent', tpl, this);
|
||||
},
|
||||
function delTemplate (err) {
|
||||
if (err && !expected_failure) {
|
||||
if (err && !expectedFailure) {
|
||||
throw err;
|
||||
}
|
||||
expected_failure = false;
|
||||
expectedFailure = false;
|
||||
assert.ok(err);
|
||||
assert.ok(err.message.match(/cannot update name/i), err);
|
||||
tmap.delTemplate(owner, tpl_id, this);
|
||||
tmap.delTemplate(owner, tplId, this);
|
||||
},
|
||||
function finish (err) {
|
||||
done(err);
|
||||
@ -393,7 +393,7 @@ describe('template_maps', function () {
|
||||
|
||||
it('instanciate templates', function () {
|
||||
// jshint maxcomplexity:7
|
||||
var tmap = new TemplateMaps(redis_pool);
|
||||
var tmap = new TemplateMaps(redisPool);
|
||||
assert.ok(tmap);
|
||||
|
||||
var tpl1 = {
|
||||
@ -491,7 +491,7 @@ describe('template_maps', function () {
|
||||
|
||||
// Can set a limit on the number of user templates
|
||||
it('can limit number of user templates', function (done) {
|
||||
var tmap = new TemplateMaps(redis_pool, {
|
||||
var tmap = new TemplateMaps(redisPool, {
|
||||
max_user_templates: 2
|
||||
});
|
||||
assert.ok(tmap);
|
||||
@ -596,7 +596,7 @@ describe('template_maps', function () {
|
||||
var templateUpdated = _.extend({}, template, { layergroup: { layers: [LAYER_PLAIN] } });
|
||||
var templateMaps;
|
||||
beforeEach(function () {
|
||||
templateMaps = new TemplateMaps(redis_pool);
|
||||
templateMaps = new TemplateMaps(redisPool);
|
||||
});
|
||||
|
||||
it('should emit on template update', function (done) {
|
||||
|
Loading…
Reference in New Issue
Block a user