From 734c373f3db1c2aaa9b82f24253e48a9ddd1221a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Wed, 6 Nov 2019 16:44:17 +0100 Subject: [PATCH] Camel case --- lib/utils/overviews-query-rewriter.js | 248 ++++----- test/acceptance/multilayer-test.js | 318 +++++------ test/acceptance/ported/multilayer-test.js | 210 +++---- test/acceptance/templates-test.js | 522 +++++++++--------- test/acceptance/tilejson-test.js | 6 +- .../user-database-timeout-limit-test.js | 26 +- test/acceptance/widgets/named-maps-test.js | 4 +- .../mapconfig-overviews-adapter-test.js | 24 +- test/support/assert.js | 22 +- test/support/test-helper.js | 4 +- .../turbo-carto-postgres-datasource-test.js | 4 +- test/unit/overviews-query-rewriter-test.js | 186 +++---- test/unit/prepare-context-test.js | 16 +- test/unit/table-name-parser-test.js | 12 +- test/unit/template-maps-test.js | 98 ++-- 15 files changed, 850 insertions(+), 850 deletions(-) diff --git a/lib/utils/overviews-query-rewriter.js b/lib/utils/overviews-query-rewriter.js index 8eac3c54..01dc2cae 100644 --- a/lib/utils/overviews-query-rewriter.js +++ b/lib/utils/overviews-query-rewriter.js @@ -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)); } diff --git a/test/acceptance/multilayer-test.js b/test/acceptance/multilayer-test.js index 33dd6b8c..a91d5e99 100644 --- a/test/acceptance/multilayer-test.js +++ b/test/acceptance/multilayer-test.js @@ -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: [ { diff --git a/test/acceptance/ported/multilayer-test.js b/test/acceptance/ported/multilayer-test.js index 6f8f802c..739f4926 100644 --- a/test/acceptance/ported/multilayer-test.js +++ b/test/acceptance/ported/multilayer-test.js @@ -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, { diff --git a/test/acceptance/templates-test.js b/test/acceptance/templates-test.js index 0ae93e7a..a18b1507 100644 --- a/test/acceptance/templates-test.js +++ b/test/acceptance/templates-test.js @@ -7,7 +7,7 @@ var step = require('step'); var strftime = require('strftime'); var QueryTables = require('cartodb-query-tables').queryTables; var NamedMapsCacheEntry = require('../../lib/cache/model/named-maps-entry'); -var redis_stats_db = 5; +var redisStatsDb = 5; // Pollute the PG environment to make sure // configuration settings are always enforced @@ -66,7 +66,7 @@ describe('template_api', function () { helper.deleteRedisKeys(keysToDelete, done); }); - var template_acceptance1 = { + var templateAcceptance1 = { version: '0.0.1', name: 'acceptance1', auth: { method: 'open' }, @@ -113,17 +113,17 @@ describe('template_api', function () { } it('can add template, returning id', function (done) { - var expected_tpl_id = 'acceptance1'; - var post_request_1 = { + var expectedTplId = 'acceptance1'; + var postRequest1 = { url: '/api/v1/map/named', method: 'POST', headers: { host: 'localhost', 'Content-Type': 'application/json' }, - data: JSON.stringify(template_acceptance1) + data: JSON.stringify(templateAcceptance1) }; step( function postUnauthenticated () { var next = this; - assert.response(server, post_request_1, {}, + assert.response(server, postRequest1, {}, function (res) { next(null, res); }); }, function postTemplate (err, res) { @@ -134,22 +134,22 @@ describe('template_api', function () { err = parsed.errors[0]; assert.ok(err.match(/only.*authenticated.*user/i), 'Unexpected error response: ' + err); - post_request_1.url += '?api_key=1234'; + postRequest1.url += '?api_key=1234'; var next = this; - assert.response(server, post_request_1, {}, + assert.response(server, postRequest1, {}, function (res) { next(null, res); }); }, function rePostTemplate (err, res) { assert.ifError(err); assert.strictEqual(res.statusCode, 200, res.body); var parsedBody = JSON.parse(res.body); - var expectedBody = { template_id: expected_tpl_id }; + var expectedBody = { template_id: expectedTplId }; assert.deepStrictEqual(parsedBody, expectedBody); keysToDelete['map_tpl|localhost'] = 0; var next = this; - assert.response(server, post_request_1, {}, + assert.response(server, postRequest1, {}, function (res) { next(null, res); }); }, function checkFailure (err, res) { @@ -167,23 +167,23 @@ describe('template_api', function () { // See https://github.com/CartoDB/Windshaft-cartodb/issues/128 it("cannot create template with auth='token' and no valid tokens", function (done) { - var tpl_id; + var tplId; step( function postTemplate1 () { // clone the valid one, and give it another name - var broken_template = JSON.parse(JSON.stringify(template_acceptance1)); - broken_template.name = 'broken1'; + var brokenTemplate = JSON.parse(JSON.stringify(templateAcceptance1)); + brokenTemplate.name = 'broken1'; // Set auth='token' and specify no tokens - broken_template.auth.method = 'token'; - delete broken_template.auth.tokens; - var post_request_1 = { + brokenTemplate.auth.method = 'token'; + delete brokenTemplate.auth.tokens; + var postRequest1 = { url: '/api/v1/map/named?api_key=1234', method: 'POST', headers: { host: 'localhost', 'Content-Type': 'application/json' }, - data: JSON.stringify(broken_template) + data: JSON.stringify(brokenTemplate) }; var next = this; - assert.response(server, post_request_1, {}, + assert.response(server, postRequest1, {}, function (res) { next(null, res); }); }, function checkFailure1 (err, res) { @@ -199,19 +199,19 @@ describe('template_api', function () { function postTemplate2 (err) { assert.ifError(err); // clone the valid one and rename it - var broken_template = JSON.parse(JSON.stringify(template_acceptance1)); - broken_template.name = 'broken1'; + var brokenTemplate = JSON.parse(JSON.stringify(templateAcceptance1)); + brokenTemplate.name = 'broken1'; // Set auth='token' and specify no tokens - broken_template.auth.method = 'token'; - broken_template.auth.tokens = []; - var post_request_1 = { + brokenTemplate.auth.method = 'token'; + brokenTemplate.auth.tokens = []; + var postRequest1 = { url: '/api/v1/map/named?api_key=1234', method: 'POST', headers: { host: 'localhost', 'Content-Type': 'application/json' }, - data: JSON.stringify(broken_template) + data: JSON.stringify(brokenTemplate) }; var next = this; - assert.response(server, post_request_1, {}, + assert.response(server, postRequest1, {}, function (res) { next(null, res); }); }, function checkFailure2 (err, res) { @@ -227,16 +227,16 @@ describe('template_api', function () { function postTemplateValid (err) { assert.ifError(err); // clone the valid one and rename it - var broken_template = JSON.parse(JSON.stringify(template_acceptance1)); - broken_template.name = 'broken1'; - var post_request_1 = { + var brokenTemplate = JSON.parse(JSON.stringify(templateAcceptance1)); + brokenTemplate.name = 'broken1'; + var postRequest1 = { url: '/api/v1/map/named?api_key=1234', method: 'POST', headers: { host: 'localhost', 'Content-Type': 'application/json' }, - data: JSON.stringify(broken_template) + data: JSON.stringify(brokenTemplate) }; var next = this; - assert.response(server, post_request_1, {}, + assert.response(server, postRequest1, {}, function (res) { next(null, res); }); }, function putTemplateInvalid (err, res) { @@ -245,21 +245,21 @@ describe('template_api', function () { var parsed = JSON.parse(res.body); assert.ok(Object.prototype.hasOwnProperty.call(parsed, 'template_id'), "Missing 'template_id' from response body: " + res.body); - tpl_id = parsed.template_id; + tplId = parsed.template_id; // clone the valid one and rename it - var broken_template = JSON.parse(JSON.stringify(template_acceptance1)); - broken_template.name = 'broken1'; + var brokenTemplate = JSON.parse(JSON.stringify(templateAcceptance1)); + brokenTemplate.name = 'broken1'; // Set auth='token' and specify no tokens - broken_template.auth.method = 'token'; - broken_template.auth.tokens = []; - var put_request_1 = { - url: '/api/v1/map/named/' + tpl_id + '/?api_key=1234', + brokenTemplate.auth.method = 'token'; + brokenTemplate.auth.tokens = []; + var putRequest1 = { + url: '/api/v1/map/named/' + tplId + '/?api_key=1234', method: 'PUT', headers: { host: 'localhost', 'Content-Type': 'application/json' }, - data: JSON.stringify(broken_template) + data: JSON.stringify(brokenTemplate) }; var next = this; - assert.response(server, put_request_1, {}, + assert.response(server, putRequest1, {}, function (res) { next(null, res); }); }, function deleteTemplate (err, res) { @@ -272,13 +272,13 @@ describe('template_api', function () { assert.ok(parsed.errors[0].match(re), 'Error for invalid authentication on PUT does not match ' + re + ': ' + parsed.errors); - var del_request = { - url: '/api/v1/map/named/' + tpl_id + '?api_key=1234', + var delRequest = { + url: '/api/v1/map/named/' + tplId + '?api_key=1234', method: 'DELETE', headers: { host: 'localhost' } }; var next = this; - assert.response(server, del_request, {}, + assert.response(server, delRequest, {}, function (res, err) { next(err, res); }); }, function checkDelete (err, res) { @@ -294,13 +294,13 @@ describe('template_api', function () { it('instance endpoint should return CORS headers', function (done) { step(function postTemplate1 () { var next = this; - var post_request = { + var postRequest = { url: '/api/v1/map/named?api_key=1234', method: 'POST', headers: { host: 'localhost.localhost', 'Content-Type': 'application/json' }, - data: JSON.stringify(template_acceptance1) + data: JSON.stringify(templateAcceptance1) }; - assert.response(server, post_request, {}, function (res) { next(null, res); }); + assert.response(server, postRequest, {}, function (res) { next(null, res); }); }, function testCORS () { const allowHeaders = 'X-Requested-With, X-Prototype-Version, X-CSRF-Token, Authorization, Content-Type'; @@ -329,18 +329,18 @@ describe('template_api', function () { }); it('instance endpoint should return server metadata', function (done) { - var tmpl = _.clone(template_acceptance1); + var tmpl = _.clone(templateAcceptance1); tmpl.name = 'rambotemplate2'; step(function postTemplate1 () { var next = this; - var post_request = { + var postRequest = { url: '/api/v1/map/named?api_key=1234', method: 'POST', headers: { host: 'localhost', 'Content-Type': 'application/json' }, data: JSON.stringify(tmpl) }; - assert.response(server, post_request, {}, function (res) { + assert.response(server, postRequest, {}, function (res) { next(null, res); }); }, @@ -362,12 +362,12 @@ describe('template_api', function () { }, function deleteTemplate (err) { assert.ifError(err); - var del_request = { + var delRequest = { url: '/api/v1/map/named/' + tmpl.name + '?api_key=1234', method: 'DELETE', headers: { host: 'localhost', 'Content-Type': 'application/json' } }; - assert.response(server, del_request, {}, function () { + assert.response(server, delRequest, {}, function () { done(); }); } @@ -380,13 +380,13 @@ describe('template_api', function () { step( function postTemplate1 () { var next = this; - var post_request = { + var postRequest = { url: '/api/v1/map/named?api_key=1234', method: 'POST', headers: { host: 'localhost', 'Content-Type': 'application/json' }, - data: JSON.stringify(template_acceptance1) + data: JSON.stringify(templateAcceptance1) }; - assert.response(server, post_request, {}, + assert.response(server, postRequest, {}, function (res) { next(null, res); }); }, function postTemplate2 (err, res) { @@ -398,16 +398,16 @@ describe('template_api', function () { tplid1 = parsed.template_id; var next = this; - var backup_name = template_acceptance1.name; - template_acceptance1.name += '_new'; - var post_request = { + var backupName = templateAcceptance1.name; + templateAcceptance1.name += '_new'; + var postRequest = { url: '/api/v1/map/named?api_key=1234', method: 'POST', headers: { host: 'localhost', 'Content-Type': 'application/json' }, - data: JSON.stringify(template_acceptance1) + data: JSON.stringify(templateAcceptance1) }; - template_acceptance1.name = backup_name; - assert.response(server, post_request, {}, + templateAcceptance1.name = backupName; + assert.response(server, postRequest, {}, function (res) { next(null, res); }); }, function litsTemplatesUnauthenticated (err, res) { @@ -418,12 +418,12 @@ describe('template_api', function () { "Missing 'template_id' from response body: " + res.body); tplid2 = parsed.template_id; var next = this; - var get_request = { + var getRequest = { url: '/api/v1/map/named', method: 'GET', headers: { host: 'localhost' } }; - assert.response(server, get_request, {}, + assert.response(server, getRequest, {}, function (res) { next(null, res); }); }, function litsTemplates (err, res) { @@ -435,12 +435,12 @@ describe('template_api', function () { err = parsed.errors[0]; assert.ok(err.match(/authenticated user/), err); var next = this; - var get_request = { + var getRequest = { url: '/api/v1/map/named?api_key=1234', method: 'GET', headers: { host: 'localhost' } }; - assert.response(server, get_request, {}, + assert.response(server, getRequest, {}, function (res) { next(null, res); }); }, function checkList (err, res) { @@ -464,17 +464,17 @@ describe('template_api', function () { }); it('can update template', function (done) { - var tpl_id; + var tplId; step( function postTemplate () { var next = this; - var post_request = { + var postRequest = { url: '/api/v1/map/named?api_key=1234', method: 'POST', headers: { host: 'localhost', 'Content-Type': 'application/json' }, data: JSON.stringify(makeTemplate()) }; - assert.response(server, post_request, {}, + assert.response(server, postRequest, {}, function (res) { next(null, res); }); }, function putMisnamedTemplate (err, res) { @@ -483,18 +483,18 @@ describe('template_api', function () { var parsed = JSON.parse(res.body); assert.ok(Object.prototype.hasOwnProperty.call(parsed, 'template_id'), "Missing 'template_id' from response body: " + res.body); - tpl_id = parsed.template_id; - var backup_name = template_acceptance1.name; - template_acceptance1.name = 'changed_name'; - var put_request = { - url: '/api/v1/map/named/' + tpl_id + '/?api_key=1234', + tplId = parsed.template_id; + var backupName = templateAcceptance1.name; + templateAcceptance1.name = 'changed_name'; + var putRequest = { + url: '/api/v1/map/named/' + tplId + '/?api_key=1234', method: 'PUT', headers: { host: 'localhost', 'Content-Type': 'application/json' }, - data: JSON.stringify(template_acceptance1) + data: JSON.stringify(templateAcceptance1) }; - template_acceptance1.name = backup_name; + templateAcceptance1.name = backupName; var next = this; - assert.response(server, put_request, {}, + assert.response(server, putRequest, {}, function (res) { next(null, res); }); }, function putUnexistentTemplate (err, res) { @@ -504,14 +504,14 @@ describe('template_api', function () { assert.ok(Object.prototype.hasOwnProperty.call(parsedBody, 'errors'), res.body); assert.ok(parsedBody.errors[0].match(/cannot update name/i), 'Unexpected error for invalid update: ' + parsedBody.errors); - var put_request = { + var putRequest = { url: '/api/v1/map/named/unexistent/?api_key=1234', method: 'PUT', headers: { host: 'localhost', 'Content-Type': 'application/json' }, data: JSON.stringify(makeTemplate()) }; var next = this; - assert.response(server, put_request, {}, + assert.response(server, putRequest, {}, function (res) { next(null, res); }); }, function putValidTemplate (err, res) { @@ -521,14 +521,14 @@ describe('template_api', function () { assert.ok(Object.prototype.hasOwnProperty.call(parsedBody, 'errors'), res.body); assert.ok(parsedBody.errors[0].match(/cannot update name/i), 'Unexpected error for invalid update: ' + parsedBody.errors); - var put_request = { - url: '/api/v1/map/named/' + tpl_id + '/?api_key=1234', + var putRequest = { + url: '/api/v1/map/named/' + tplId + '/?api_key=1234', method: 'PUT', headers: { host: 'localhost', 'Content-Type': 'application/json' }, data: JSON.stringify(makeTemplate()) }; var next = this; - assert.response(server, put_request, {}, + assert.response(server, putRequest, {}, function (res) { next(null, res); }); }, function checkValidUpate (err, res) { @@ -537,7 +537,7 @@ describe('template_api', function () { var parsed = JSON.parse(res.body); assert.ok(Object.prototype.hasOwnProperty.call(parsed, 'template_id'), "Missing 'template_id' from response body: " + res.body); - assert.strictEqual(tpl_id, parsed.template_id); + assert.strictEqual(tplId, parsed.template_id); keysToDelete['map_tpl|localhost'] = 0; @@ -547,17 +547,17 @@ describe('template_api', function () { }); it('can get a template by id', function (done) { - var tpl_id; + var tplId; step( function postTemplate () { var next = this; - var post_request = { + var postRequest = { url: '/api/v1/map/named?api_key=1234', method: 'POST', headers: { host: 'localhost', 'Content-Type': 'application/json' }, data: JSON.stringify(makeTemplate()) }; - assert.response(server, post_request, {}, + assert.response(server, postRequest, {}, function (res) { next(null, res); }); }, function getTemplateUnauthorized (err, res) { @@ -566,14 +566,14 @@ describe('template_api', function () { var parsed = JSON.parse(res.body); assert.ok(Object.prototype.hasOwnProperty.call(parsed, 'template_id'), "Missing 'template_id' from response body: " + res.body); - tpl_id = parsed.template_id; - var get_request = { - url: '/api/v1/map/named/' + tpl_id, + tplId = parsed.template_id; + var getRequest = { + url: '/api/v1/map/named/' + tplId, method: 'GET', headers: { host: 'localhost' } }; var next = this; - assert.response(server, get_request, {}, + assert.response(server, getRequest, {}, function (res) { next(null, res); }); }, function getTemplate (err, res) { @@ -583,13 +583,13 @@ describe('template_api', function () { assert.ok(Object.prototype.hasOwnProperty.call(parsedBody, 'errors'), res.body); assert.ok(parsedBody.errors[0].match(/only.*authenticated.*user/i), 'Unexpected error for unauthenticated template get: ' + parsedBody.errors); - var get_request = { - url: '/api/v1/map/named/' + tpl_id + '?api_key=1234', + var getRequest = { + url: '/api/v1/map/named/' + tplId + '?api_key=1234', method: 'GET', headers: { host: 'localhost' } }; var next = this; - assert.response(server, get_request, {}, + assert.response(server, getRequest, {}, function (res) { next(null, res); }); }, function checkReturnTemplate (err, res) { @@ -608,17 +608,17 @@ describe('template_api', function () { }); it('can delete a template by id', function (done) { - var tpl_id; + var tplId; step( function postTemplate () { var next = this; - var post_request = { + var postRequest = { url: '/api/v1/map/named?api_key=1234', method: 'POST', headers: { host: 'localhost', 'Content-Type': 'application/json' }, data: JSON.stringify(makeTemplate()) }; - assert.response(server, post_request, {}, + assert.response(server, postRequest, {}, function (res) { next(null, res); }); }, function getTemplate (err, res) { @@ -627,14 +627,14 @@ describe('template_api', function () { var parsed = JSON.parse(res.body); assert.ok(Object.prototype.hasOwnProperty.call(parsed, 'template_id'), "Missing 'template_id' from response body: " + res.body); - tpl_id = parsed.template_id; - var get_request = { - url: '/api/v1/map/named/' + tpl_id + '?api_key=1234', + tplId = parsed.template_id; + var getRequest = { + url: '/api/v1/map/named/' + tplId + '?api_key=1234', method: 'GET', headers: { host: 'localhost' } }; var next = this; - assert.response(server, get_request, {}, + assert.response(server, getRequest, {}, function (res) { next(null, res); }); }, function deleteTemplateUnauthorized (err, res) { @@ -644,13 +644,13 @@ describe('template_api', function () { assert.ok(Object.prototype.hasOwnProperty.call(parsed, 'template'), "Missing 'template' from response body: " + res.body); assert.deepStrictEqual(extendDefaultsTemplate(makeTemplate()), parsed.template); - var del_request = { - url: '/api/v1/map/named/' + tpl_id, + var delRequest = { + url: '/api/v1/map/named/' + tplId, method: 'DELETE', headers: { host: 'localhost' } }; var next = this; - assert.response(server, del_request, {}, + assert.response(server, delRequest, {}, function (res) { next(null, res); }); }, function deleteTemplate (err, res) { @@ -661,26 +661,26 @@ describe('template_api', function () { "Missing 'errors' from response body: " + res.body); assert.ok(parsed.errors[0].match(/only.*authenticated.*user/i), 'Unexpected error for unauthenticated template get: ' + parsed.errors); - var del_request = { - url: '/api/v1/map/named/' + tpl_id + '?api_key=1234', + var delRequest = { + url: '/api/v1/map/named/' + tplId + '?api_key=1234', method: 'DELETE', headers: { host: 'localhost' } }; var next = this; - assert.response(server, del_request, {}, + assert.response(server, delRequest, {}, function (res) { next(null, res); }); }, function getMissingTemplate (err, res) { assert.ifError(err); assert.strictEqual(res.statusCode, 204, res.statusCode + ': ' + res.body); assert.ok(!res.body, 'Unexpected body in DELETE /template response'); - var get_request = { - url: '/api/v1/map/named/' + tpl_id + '?api_key=1234', + var getRequest = { + url: '/api/v1/map/named/' + tplId + '?api_key=1234', method: 'GET', headers: { host: 'localhost' } }; var next = this; - assert.response(server, get_request, {}, + assert.response(server, getRequest, {}, function (res) { next(null, res); }); }, function checkGetFailure (err, res) { @@ -699,7 +699,7 @@ describe('template_api', function () { it('can instanciate a template by id wadus', function (done) { // This map fetches data from a private table - var template_acceptance2 = { + var templateAcceptance2 = { version: '0.0.1', name: 'acceptance1', auth: { method: 'token', valid_tokens: ['valid1', 'valid2'] }, @@ -718,20 +718,20 @@ describe('template_api', function () { } }; - var template_params = {}; + var templateParams = {}; - var tpl_id; + var tplId; var layergroupid; step( function postTemplate () { var next = this; - var post_request = { + var postRequest = { url: '/api/v1/map/named?api_key=1234', method: 'POST', headers: { host: 'localhost', 'Content-Type': 'application/json' }, - data: JSON.stringify(template_acceptance2) + data: JSON.stringify(templateAcceptance2) }; - assert.response(server, post_request, {}, + assert.response(server, postRequest, {}, function (res) { next(null, res); }); }, function instanciateNoAuth (err, res) { @@ -740,15 +740,15 @@ describe('template_api', function () { var parsed = JSON.parse(res.body); assert.ok(Object.prototype.hasOwnProperty.call(parsed, 'template_id'), "Missing 'template_id' from response body: " + res.body); - tpl_id = parsed.template_id; - var post_request = { - url: '/api/v1/map/named/' + tpl_id, + tplId = parsed.template_id; + var postRequest = { + url: '/api/v1/map/named/' + tplId, method: 'POST', headers: { host: 'localhost', 'Content-Type': 'application/json' }, - data: JSON.stringify(template_params) + data: JSON.stringify(templateParams) }; var next = this; - assert.response(server, post_request, {}, + assert.response(server, postRequest, {}, function (res) { next(null, res); }); }, // See https://github.com/CartoDB/Windshaft-cartodb/issues/173 @@ -761,14 +761,14 @@ describe('template_api', function () { "Missing 'errors' from response body: " + res.body); assert.ok(parsed.errors[0].match(/unauthorized/i), 'Unexpected error for unauthorized instance : ' + parsed.errors); - var post_request = { - url: '/api/v1/map/named/' + tpl_id + '?auth_token=valid2', + var postRequest = { + url: '/api/v1/map/named/' + tplId + '?auth_token=valid2', method: 'POST', headers: { host: 'foreign', 'Content-Type': 'application/json' }, - data: JSON.stringify(template_params) + data: JSON.stringify(templateParams) }; var next = this; - assert.response(server, post_request, {}, + assert.response(server, postRequest, {}, function (res) { next(null, res); }); }, function instanciateAuth (err, res) { @@ -777,14 +777,14 @@ describe('template_api', function () { var parsed = JSON.parse(res.body); assert.ok(Object.prototype.hasOwnProperty.call(parsed, 'errors'), "Missing 'errors' from response body: " + res.body); assert.ok(parsed.errors[0].match(/not found/i), 'Unexpected error for forbidden instance : ' + parsed.errors); - var post_request = { - url: '/api/v1/map/named/' + tpl_id + '?auth_token=valid2', + var postRequest = { + url: '/api/v1/map/named/' + tplId + '?auth_token=valid2', method: 'POST', headers: { host: 'localhost', 'Content-Type': 'application/json' }, - data: JSON.stringify(template_params) + data: JSON.stringify(templateParams) }; var next = this; - assert.response(server, post_request, {}, + assert.response(server, postRequest, {}, function (res) { next(null, res); }); }, function fetchTileNoAuth (err, res) { @@ -804,14 +804,14 @@ describe('template_api', function () { keysToDelete['map_cfg|' + LayergroupToken.parse(parsed.layergroupid).token] = 0; // TODO: check value of last_updated ? - var get_request = { + var getRequest = { url: '/api/v1/map/' + layergroupid + ':cb0/0/0/0.png', method: 'GET', headers: { host: 'localhost' }, encoding: 'binary' }; var next = this; - assert.response(server, get_request, {}, + assert.response(server, getRequest, {}, function (res) { next(null, res); }); }, function fetchTileAuth (err, res) { @@ -823,14 +823,14 @@ describe('template_api', function () { "Missing 'errors' from response body: " + res.body); assert.ok(parsed.errors[0].match(/permission denied/i), 'Unexpected error for unauthorized instance (expected /permission denied/): ' + parsed.errors); - var get_request = { + var getRequest = { url: '/api/v1/map/' + layergroupid + '/0/0/0.png?auth_token=valid1', method: 'GET', headers: { host: 'localhost' }, encoding: 'binary' }; var next = this; - assert.response(server, get_request, {}, + assert.response(server, getRequest, {}, function (res) { next(null, res); }); }, function checkTile (err, res) { @@ -844,14 +844,14 @@ describe('template_api', function () { function fetchTileForeignSignature (err) { assert.ifError(err); var foreignsigned = layergroupid.replace(/[^@]*@/, 'foreign@'); - var get_request = { + var getRequest = { url: '/api/v1/map/' + foreignsigned + '/0/0/0.png?auth_token=valid1', method: 'GET', headers: { host: 'localhost' }, encoding: 'binary' }; var next = this; - assert.response(server, get_request, {}, + assert.response(server, getRequest, {}, function (res) { next(null, res); }); }, function checkForeignSignerError (err, res) { @@ -867,27 +867,27 @@ describe('template_api', function () { }, function deleteTemplate (err) { assert.ifError(err); - var del_request = { - url: '/api/v1/map/named/' + tpl_id + '?api_key=1234', + var delRequest = { + url: '/api/v1/map/named/' + tplId + '?api_key=1234', method: 'DELETE', headers: { host: 'localhost' } }; var next = this; - assert.response(server, del_request, {}, + assert.response(server, delRequest, {}, function (res) { next(null, res); }); }, function fetchTileDeleted (err, res) { assert.ifError(err); assert.strictEqual(res.statusCode, 204, 'Deleting template: ' + res.statusCode + ':' + res.body); - var get_request = { + var getRequest = { url: '/api/v1/map/' + layergroupid + '/0/0/0.png?auth_token=valid1', method: 'GET', headers: { host: 'localhost' }, encoding: 'binary' }; var next = this; - assert.response(server, get_request, {}, + assert.response(server, getRequest, {}, function (res) { next(null, res); }); }, function checkTileAvailable (err, res) { @@ -921,20 +921,20 @@ describe('template_api', function () { } }; - var template_params = {}; + var templateParams = {}; - var tpl_id; + var tplId; var layergroupid; step( function postTemplate () { var next = this; - var post_request = { + var postRequest = { url: '/api/v1/map/named?api_key=1234', method: 'POST', headers: { host: 'localhost', 'Content-Type': 'application/json' }, data: JSON.stringify(template) }; - assert.response(server, post_request, {}, + assert.response(server, postRequest, {}, function (res) { next(null, res); }); }, function instanciateNoAuth (err, res) { @@ -943,15 +943,15 @@ describe('template_api', function () { var parsed = JSON.parse(res.body); assert.ok(Object.prototype.hasOwnProperty.call(parsed, 'template_id'), "Missing 'template_id' from response body: " + res.body); - tpl_id = parsed.template_id; - var post_request = { - url: '/api/v1/map/named/' + tpl_id, + tplId = parsed.template_id; + var postRequest = { + url: '/api/v1/map/named/' + tplId, method: 'POST', headers: { host: 'localhost', 'Content-Type': 'application/json' }, - data: JSON.stringify(template_params) + data: JSON.stringify(templateParams) }; var next = this; - assert.response(server, post_request, {}, + assert.response(server, postRequest, {}, function (res) { next(null, res); }); }, function instanciateAuth (err, res) { @@ -963,14 +963,14 @@ describe('template_api', function () { "Missing 'errors' from response body: " + res.body); assert.ok(parsed.errors[0].match(/unauthorized/i), 'Unexpected error for unauthorized instance : ' + parsed.errors); - var post_request = { - url: '/api/v1/map/named/' + tpl_id + '?auth_token=valid2', + var postRequest = { + url: '/api/v1/map/named/' + tplId + '?auth_token=valid2', method: 'POST', headers: { host: 'localhost', 'Content-Type': 'application/json' }, - data: JSON.stringify(template_params) + data: JSON.stringify(templateParams) }; var next = this; - assert.response(server, post_request, {}, + assert.response(server, postRequest, {}, function (res) { next(null, res); }); }, function fetchTileNoAuth (err, res) { @@ -990,14 +990,14 @@ describe('template_api', function () { keysToDelete['user:localhost:mapviews:global'] = 5; // TODO: check value of last_updated ? - var get_request = { + var getRequest = { url: '/api/v1/map/' + layergroupid + ':cb0/0/0/0/0.json.torque', method: 'GET', headers: { host: 'localhost' }, encoding: 'binary' }; var next = this; - assert.response(server, get_request, {}, + assert.response(server, getRequest, {}, function (res) { next(null, res); }); }, function fetchTileAuth (err, res) { @@ -1009,17 +1009,17 @@ describe('template_api', function () { "Missing 'errors' from response body: " + res.body); assert.ok(parsed.errors[0].match(/permission denied/i), 'Unexpected error for unauthorized instance (expected /permission denied): ' + parsed.errors); - var get_request = { + var getRequest = { url: '/api/v1/map/' + layergroupid + ':cb1/0/0/0/0.json.torque?auth_token=valid1', method: 'GET', headers: { host: 'localhost' }, encoding: 'binary' }; var next = this; - assert.response(server, get_request, {}, + assert.response(server, getRequest, {}, function (res) { next(null, res); }); }, - function checkTile_fetchOnRestart (err, res) { + function checkTileFetchOnRestart (err, res) { assert.ifError(err); assert.strictEqual(res.statusCode, 200, 'Unexpected error for authorized instance: ' + res.statusCode + ' -- ' + res.body); @@ -1031,14 +1031,14 @@ describe('template_api', function () { // hack simulating restart... // FIXME: we need a better way to reset cache while running tests server.layergroupAffectedTablesCache.cache.reset(); // need to clean channel cache - var get_request = { + var getRequest = { url: '/api/v1/map/' + layergroupid + ':cb1/0/0/0/1.json.torque?auth_token=valid1', method: 'GET', headers: { host: 'localhost' }, encoding: 'binary' }; var next = this; - assert.response(server, get_request, {}, + assert.response(server, getRequest, {}, function (res) { next(null, res); }); }, function checkCacheChannel (err, res) { @@ -1054,27 +1054,27 @@ describe('template_api', function () { }, function deleteTemplate (err) { assert.ifError(err); - var del_request = { - url: '/api/v1/map/named/' + tpl_id + '?api_key=1234', + var delRequest = { + url: '/api/v1/map/named/' + tplId + '?api_key=1234', method: 'DELETE', headers: { host: 'localhost' } }; var next = this; - assert.response(server, del_request, {}, + assert.response(server, delRequest, {}, function (res) { next(null, res); }); }, function fetchTileDeleted (err, res) { assert.ifError(err); assert.strictEqual(res.statusCode, 204, 'Deleting template: ' + res.statusCode + ':' + res.body); - var get_request = { + var getRequest = { url: '/api/v1/map/' + layergroupid + ':cb2/0/0/0/0.json.torque?auth_token=valid1', method: 'GET', headers: { host: 'localhost' }, encoding: 'binary' }; var next = this; - assert.response(server, get_request, {}, + assert.response(server, getRequest, {}, function (res) { next(null, res); }); }, function checkTorqueTileAvailable (err, res) { @@ -1108,20 +1108,20 @@ describe('template_api', function () { } }; - var template_params = {}; + var templateParams = {}; - var tpl_id; + var tplId; var layergroupid; step( function postTemplate () { var next = this; - var post_request = { + var postRequest = { url: '/api/v1/map/named?api_key=1234', method: 'POST', headers: { host: 'localhost', 'Content-Type': 'application/json' }, data: JSON.stringify(template) }; - assert.response(server, post_request, {}, + assert.response(server, postRequest, {}, function (res) { next(null, res); }); }, function instanciateNoAuth (err, res) { @@ -1130,15 +1130,15 @@ describe('template_api', function () { var parsed = JSON.parse(res.body); assert.ok(Object.prototype.hasOwnProperty.call(parsed, 'template_id'), "Missing 'template_id' from response body: " + res.body); - tpl_id = parsed.template_id; - var post_request = { - url: '/api/v1/map/named/' + tpl_id, + tplId = parsed.template_id; + var postRequest = { + url: '/api/v1/map/named/' + tplId, method: 'POST', headers: { host: 'localhost', 'Content-Type': 'application/json' }, - data: JSON.stringify(template_params) + data: JSON.stringify(templateParams) }; var next = this; - assert.response(server, post_request, {}, + assert.response(server, postRequest, {}, function (res) { next(null, res); }); }, function instanciateAuth (err, res) { @@ -1150,14 +1150,14 @@ describe('template_api', function () { "Missing 'errors' from response body: " + res.body); assert.ok(parsed.errors[0].match(/unauthorized/i), 'Unexpected error for unauthorized instance : ' + parsed.errors); - var post_request = { - url: '/api/v1/map/named/' + tpl_id + '?auth_token=valid2', + var postRequest = { + url: '/api/v1/map/named/' + tplId + '?auth_token=valid2', method: 'POST', headers: { host: 'localhost', 'Content-Type': 'application/json' }, - data: JSON.stringify(template_params) + data: JSON.stringify(templateParams) }; var next = this; - assert.response(server, post_request, {}, + assert.response(server, postRequest, {}, function (res) { next(null, res); }); }, function fetchAttributeNoAuth (err, res) { @@ -1178,14 +1178,14 @@ describe('template_api', function () { keysToDelete['user:localhost:mapviews:global'] = 5; // TODO: check value of last_updated ? - var get_request = { + var getRequest = { url: '/api/v1/map/' + layergroupid + ':cb0/0/attributes/5', method: 'GET', headers: { host: 'localhost' }, encoding: 'binary' }; var next = this; - assert.response(server, get_request, {}, + assert.response(server, getRequest, {}, function (res) { next(null, res); }); }, function fetchAttributeAuth (err, res) { @@ -1197,14 +1197,14 @@ describe('template_api', function () { "Missing 'errors' from response body: " + res.body); assert.ok(parsed.errors[0].match(/permission denied/i), 'Unexpected error for unauthorized getAttributes (expected /permission denied/): ' + parsed.errors); - var get_request = { + var getRequest = { url: '/api/v1/map/' + layergroupid + ':cb1/0/attributes/5?auth_token=valid2', method: 'GET', headers: { host: 'localhost' }, encoding: 'binary' }; var next = this; - assert.response(server, get_request, {}, + assert.response(server, getRequest, {}, function (res) { next(null, res); }); }, function checkAttribute (err, res) { @@ -1216,27 +1216,27 @@ describe('template_api', function () { }, function deleteTemplate (err) { assert.ifError(err); - var del_request = { - url: '/api/v1/map/named/' + tpl_id + '?api_key=1234', + var delRequest = { + url: '/api/v1/map/named/' + tplId + '?api_key=1234', method: 'DELETE', headers: { host: 'localhost' } }; var next = this; - assert.response(server, del_request, {}, + assert.response(server, delRequest, {}, function (res) { next(null, res); }); }, function fetchAttrDeleted (err, res) { assert.ifError(err); assert.strictEqual(res.statusCode, 204, 'Deleting template: ' + res.statusCode + ':' + res.body); - var get_request = { + var getRequest = { url: '/api/v1/map/' + layergroupid + ':cb2/0/attributes/5?auth_token=valid2', method: 'GET', headers: { host: 'localhost' }, encoding: 'binary' }; var next = this; - assert.response(server, get_request, {}, + assert.response(server, getRequest, {}, function (res) { next(null, res); }); }, function checkLayerAttributesAvailable (err, res) { @@ -1251,7 +1251,7 @@ describe('template_api', function () { it('can instanciate a template by id with open auth', function (done) { // This map fetches data from a private table - var template_acceptance_open = { + var templateAcceptanceOpen = { version: '0.0.1', name: 'acceptance_open', auth: { method: 'open' }, @@ -1270,19 +1270,19 @@ describe('template_api', function () { } }; - var template_params = {}; + var templateParams = {}; - var tpl_id; + var tplId; step( function postTemplate () { var next = this; - var post_request = { + var postRequest = { url: '/api/v1/map/named?api_key=1234', method: 'POST', headers: { host: 'localhost', 'Content-Type': 'application/json' }, - data: JSON.stringify(template_acceptance_open) + data: JSON.stringify(templateAcceptanceOpen) }; - assert.response(server, post_request, {}, + assert.response(server, postRequest, {}, function (res) { next(null, res); }); }, function instanciateNoAuth (err, res) { @@ -1291,16 +1291,16 @@ describe('template_api', function () { var parsed = JSON.parse(res.body); assert.ok(Object.prototype.hasOwnProperty.call(parsed, 'template_id'), "Missing 'template_id' from response body: " + res.body); - tpl_id = parsed.template_id; - var post_request = { - url: '/api/v1/map/named/' + tpl_id, + tplId = parsed.template_id; + var postRequest = { + url: '/api/v1/map/named/' + tplId, method: 'POST', headers: { host: 'localhost', 'Content-Type': 'application/json' }, - data: JSON.stringify(template_params) + data: JSON.stringify(templateParams) }; helper.checkNoCache(res); var next = this; - assert.response(server, post_request, {}, + assert.response(server, postRequest, {}, function (res) { next(null, res); }); }, function instanciateAuth (err, res) { @@ -1319,7 +1319,7 @@ describe('template_api', function () { it('can instanciate a template using jsonp', function (done) { // This map fetches data from a private table - var template_acceptance_open = { + var templateAcceptanceOpen = { version: '0.0.1', name: 'acceptance_open_jsonp', auth: { method: 'open' }, @@ -1338,17 +1338,17 @@ describe('template_api', function () { } }; - var tpl_id; + var tplId; step( function postTemplate () { var next = this; - var post_request = { + var postRequest = { url: '/api/v1/map/named?api_key=1234', method: 'POST', headers: { host: 'localhost', 'Content-Type': 'application/json' }, - data: JSON.stringify(template_acceptance_open) + data: JSON.stringify(templateAcceptanceOpen) }; - assert.response(server, post_request, {}, + assert.response(server, postRequest, {}, function (res) { next(null, res); }); }, function instanciateNoAuth (err, res) { @@ -1357,14 +1357,14 @@ describe('template_api', function () { var parsed = JSON.parse(res.body); assert.ok(Object.prototype.hasOwnProperty.call(parsed, 'template_id'), "Missing 'template_id' from response body: " + res.body); - tpl_id = parsed.template_id; - var post_request = { - url: '/api/v1/map/named/' + tpl_id + '/jsonp?callback=json_test', + tplId = parsed.template_id; + var postRequest = { + url: '/api/v1/map/named/' + tplId + '/jsonp?callback=jsonTest', method: 'GET', headers: { host: 'localhost' } }; var next = this; - assert.response(server, post_request, {}, + assert.response(server, postRequest, {}, function (res) { next(null, res); }); }, function checkInstanciation (err, res) { @@ -1378,12 +1378,12 @@ describe('template_api', function () { schema_name: 'public', table_name: 'test_table_private_1' }]).key(), - new NamedMapsCacheEntry('localhost', template_acceptance_open.name).key() + new NamedMapsCacheEntry('localhost', templateAcceptanceOpen.name).key() ].join(' '); helper.checkSurrogateKey(res, expectedSurrogateKey); /* eslint-disable no-unused-vars, no-eval */ - function json_test (body) { + function jsonTest (body) { keysToDelete['map_cfg|' + LayergroupToken.parse(body.layergroupid).token] = 0; } eval(res.body); @@ -1402,7 +1402,7 @@ describe('template_api', function () { it('can instanciate a template using jsonp with params', function (done) { // This map fetches data from a private table - var template_acceptance_open = { + var templateAcceptanceOpen = { version: '0.0.1', name: 'acceptance_open_jsonp_params', auth: { method: 'open' }, @@ -1424,17 +1424,17 @@ describe('template_api', function () { } }; - var tpl_id; + var tplId; step( function postTemplate () { var next = this; - var post_request = { + var postRequest = { url: '/api/v1/map/named?api_key=1234', method: 'POST', headers: { host: 'localhost', 'Content-Type': 'application/json' }, - data: JSON.stringify(template_acceptance_open) + data: JSON.stringify(templateAcceptanceOpen) }; - assert.response(server, post_request, {}, + assert.response(server, postRequest, {}, function (res) { next(null, res); }); }, function instanciateNoAuth (err, res) { @@ -1443,14 +1443,14 @@ describe('template_api', function () { var parsed = JSON.parse(res.body); assert.ok(Object.prototype.hasOwnProperty.call(parsed, 'template_id'), "Missing 'template_id' from response body: " + res.body); - tpl_id = parsed.template_id; - var post_request = { - url: '/api/v1/map/named/' + tpl_id + '/jsonp?callback=json_test&config=' + JSON.stringify({ color: 'blue' }), + tplId = parsed.template_id; + var postRequest = { + url: '/api/v1/map/named/' + tplId + '/jsonp?callback=jsonTest&config=' + JSON.stringify({ color: 'blue' }), method: 'GET', headers: { host: 'localhost' } }; var next = this; - assert.response(server, post_request, {}, + assert.response(server, postRequest, {}, function (res) { next(null, res); }); }, function checkInstanciation (err, res) { @@ -1464,12 +1464,12 @@ describe('template_api', function () { schema_name: 'public', table_name: 'test_table_private_1' }]).key(), - new NamedMapsCacheEntry('localhost', template_acceptance_open.name).key() + new NamedMapsCacheEntry('localhost', templateAcceptanceOpen.name).key() ].join(' '); helper.checkSurrogateKey(res, expectedSurrogateKey); /* eslint-disable no-unused-vars, no-eval */ - function json_test (body) { + function jsonTest (body) { keysToDelete['map_cfg|' + LayergroupToken.parse(body.layergroupid).token] = 0; } eval(res.body); @@ -1505,48 +1505,48 @@ describe('template_api', function () { layergroup: layergroup }; var statskey = 'user:localhost:mapviews'; - var redis_stats_client = redis.createClient(global.environment.redis.port); - var template_id; // will be set on template post + var redisStatsClient = redis.createClient(global.environment.redis.port); + var templateId; // will be set on template post var now = strftime('%Y%m%d', new Date()); var errors = []; 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_tempate (err) { + function doPostTempate (err) { assert.ifError(err); - var post_request = { + var postRequest = { url: '/api/v1/map/named?api_key=1234', method: 'POST', headers: { host: 'localhost', 'Content-Type': 'application/json' }, data: JSON.stringify(template) }; var next = this; - assert.response(server, post_request, {}, + assert.response(server, postRequest, {}, function (res) { next(null, res); }); }, function instantiateTemplate (err, res) { assert.ifError(err); assert.strictEqual(res.statusCode, 200, res.body); - template_id = JSON.parse(res.body).template_id; - var post_request = { - url: '/api/v1/map/named/' + template_id, + templateId = JSON.parse(res.body).template_id; + var postRequest = { + url: '/api/v1/map/named/' + templateId, method: 'POST', headers: { host: 'localhost', 'Content-Type': 'application/json' }, data: JSON.stringify({}) }; var next = this; - assert.response(server, post_request, {}, + assert.response(server, postRequest, {}, function (res) { next(null, res); }); }, - function check_global_stats (err, res) { + function checkGlobalStats (err, res) { assert.ifError(err); assert.strictEqual(res.statusCode, 200, 'Instantiating template: ' + res.statusCode + ': ' + res.body); @@ -1554,14 +1554,14 @@ describe('template_api', function () { assert.ok(Object.prototype.hasOwnProperty.call(parsed, 'layergroupid'), "Missing 'layergroupid' from response body: " + res.body); keysToDelete['map_cfg|' + LayergroupToken.parse(parsed.layergroupid).token] = 0; - redis_stats_client.ZSCORE(statskey + ':global', now, this); + redisStatsClient.ZSCORE(statskey + ':global', now, this); }, - function check_tag_stats (err, val) { + function checkTagStats (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_value (err, val) { + function checkTagStatsValue (err, val) { assert.ifError(err); assert.equal(val, '1', 'Expected score of ' + now + ' in ' + statskey + ':stat_tag:' + layergroup.stat_tag + ' to be 1, got ' + val); @@ -1569,16 +1569,16 @@ describe('template_api', function () { }, function deleteTemplate (err) { assert.ifError(err); - var del_request = { - url: '/api/v1/map/named/' + template_id + '?api_key=1234', + var delRequest = { + url: '/api/v1/map/named/' + templateId + '?api_key=1234', method: 'DELETE', headers: { host: 'localhost' } }; var next = this; - assert.response(server, del_request, {}, + assert.response(server, delRequest, {}, function (res) { next(null, res); }); }, - function cleanup_stats (err, res) { + function cleanupStats (err, res) { if (err) { return done(err); } @@ -1597,7 +1597,7 @@ describe('template_api', function () { it('instance map token changes with templates certificate changes', function (done) { // This map fetches data from a private table - var template_acceptance2 = { + var templateAcceptance2 = { version: '0.0.1', name: 'acceptance2', auth: { method: 'token', valid_tokens: ['valid1', 'valid2'] }, @@ -1616,20 +1616,20 @@ describe('template_api', function () { } }; - var template_params = {}; + var templateParams = {}; - var tpl_id; + var tplId; var layergroupid; step( function postTemplate () { var next = this; - var post_request = { + var postRequest = { url: '/api/v1/map/named?api_key=1234', method: 'POST', headers: { host: 'localhost', 'Content-Type': 'application/json' }, - data: JSON.stringify(template_acceptance2) + data: JSON.stringify(templateAcceptance2) }; - assert.response(server, post_request, {}, + assert.response(server, postRequest, {}, function (res) { next(null, res); }); }, function instance1 (err, res) { @@ -1638,15 +1638,15 @@ describe('template_api', function () { var parsed = JSON.parse(res.body); assert.ok(Object.prototype.hasOwnProperty.call(parsed, 'template_id'), "Missing 'template_id' from response body: " + res.body); - tpl_id = parsed.template_id; - var post_request = { - url: '/api/v1/map/named/' + tpl_id + '?auth_token=valid2', + tplId = parsed.template_id; + var postRequest = { + url: '/api/v1/map/named/' + tplId + '?auth_token=valid2', method: 'POST', headers: { host: 'localhost', 'Content-Type': 'application/json' }, - data: JSON.stringify(template_params) + data: JSON.stringify(templateParams) }; var next = this; - assert.response(server, post_request, {}, + assert.response(server, postRequest, {}, function (res, err) { next(err, res); }); }, function checkInstance1 (err, res) { @@ -1657,7 +1657,7 @@ describe('template_api', function () { assert.ok(Object.prototype.hasOwnProperty.call(parsed, 'layergroupid'), "Missing 'layergroupid' from response body: " + res.body); layergroupid = parsed.layergroupid; - helper.checkSurrogateKey(res, new NamedMapsCacheEntry('localhost', template_acceptance2.name).key()); + helper.checkSurrogateKey(res, new NamedMapsCacheEntry('localhost', templateAcceptance2.name).key()); keysToDelete['map_cfg|' + LayergroupToken.parse(parsed.layergroupid).token] = 0; return null; @@ -1665,16 +1665,16 @@ describe('template_api', function () { function updateTemplate (err) { assert.ifError(err); // clone the valid one and rename it - var changedTemplate = JSON.parse(JSON.stringify(template_acceptance2)); + var changedTemplate = JSON.parse(JSON.stringify(templateAcceptance2)); changedTemplate.auth.method = 'open'; - var post_request = { - url: '/api/v1/map/named/' + tpl_id + '/?api_key=1234', + var postRequest = { + url: '/api/v1/map/named/' + tplId + '/?api_key=1234', method: 'PUT', headers: { host: 'localhost', 'Content-Type': 'application/json' }, data: JSON.stringify(changedTemplate) }; var next = this; - assert.response(server, post_request, {}, + assert.response(server, postRequest, {}, function (res) { next(null, res); }); }, function instance2 (err, res) { @@ -1683,15 +1683,15 @@ describe('template_api', function () { var parsed = JSON.parse(res.body); assert.ok(Object.prototype.hasOwnProperty.call(parsed, 'template_id'), "Missing 'template_id' from response body: " + res.body); - assert.strictEqual(tpl_id, parsed.template_id); - var post_request = { - url: '/api/v1/map/named/' + tpl_id + '?auth_token=valid2', + assert.strictEqual(tplId, parsed.template_id); + var postRequest = { + url: '/api/v1/map/named/' + tplId + '?auth_token=valid2', method: 'POST', headers: { host: 'localhost', 'Content-Type': 'application/json' }, - data: JSON.stringify(template_params) + data: JSON.stringify(templateParams) }; var next = this; - assert.response(server, post_request, {}, + assert.response(server, postRequest, {}, function (res, err) { next(err, res); }); }, function checkInstance2 (err, res) { @@ -1702,7 +1702,7 @@ describe('template_api', function () { assert.ok(Object.prototype.hasOwnProperty.call(parsed, 'layergroupid'), "Missing 'layergroupid' from response body: " + res.body); assert.ok(layergroupid !== parsed.layergroupid); - helper.checkSurrogateKey(res, new NamedMapsCacheEntry('localhost', template_acceptance2.name).key()); + helper.checkSurrogateKey(res, new NamedMapsCacheEntry('localhost', templateAcceptance2.name).key()); keysToDelete['map_tpl|localhost'] = 0; keysToDelete['map_cfg|' + LayergroupToken.parse(parsed.layergroupid).token] = 0; @@ -1747,7 +1747,7 @@ describe('template_api', function () { } }; - var template_params = {}; + var templateParams = {}; var expectedTemplateId = httpTemplateName; var layergroupid; @@ -1788,7 +1788,7 @@ describe('template_api', function () { host: username, 'Content-Type': 'application/json' }, - data: JSON.stringify(template_params) + data: JSON.stringify(templateParams) }, { status: 200 diff --git a/test/acceptance/tilejson-test.js b/test/acceptance/tilejson-test.js index 918ef677..70aece24 100644 --- a/test/acceptance/tilejson-test.js +++ b/test/acceptance/tilejson-test.js @@ -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'] } }; diff --git a/test/acceptance/user-database-timeout-limit-test.js b/test/acceptance/user-database-timeout-limit-test.js index 3db59b0a..c1e86b46 100644 --- a/test/acceptance/user-database-timeout-limit-test.js +++ b/test/acceptance/user-database-timeout-limit-test.js @@ -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, diff --git a/test/acceptance/widgets/named-maps-test.js b/test/acceptance/widgets/named-maps-test.js index d5581a84..b93f26eb 100644 --- a/test/acceptance/widgets/named-maps-test.js +++ b/test/acceptance/widgets/named-maps-test.js @@ -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 diff --git a/test/integration/mapconfig-overviews-adapter-test.js b/test/integration/mapconfig-overviews-adapter-test.js index e71dfc7c..60bb793c 100644 --- a/test/integration/mapconfig-overviews-adapter-test.js +++ b/test/integration/mapconfig-overviews-adapter-test.js @@ -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(); }); }); diff --git a/test/support/assert.js b/test/support/assert.js index 84d7e7f3..a088a967 100644 --- a/test/support/assert.js +++ b/test/support/assert.js @@ -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); diff --git a/test/support/test-helper.js b/test/support/test-helper.js index d08a700b..9ec178f7 100644 --- a/test/support/test-helper.js +++ b/test/support/test-helper.js @@ -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, diff --git a/test/unit/backends/turbo-carto-postgres-datasource-test.js b/test/unit/backends/turbo-carto-postgres-datasource-test.js index 9827381b..8e090a9b 100644 --- a/test/unit/backends/turbo-carto-postgres-datasource-test.js +++ b/test/unit/backends/turbo-carto-postgres-datasource-test.js @@ -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(); }); }); diff --git a/test/unit/overviews-query-rewriter-test.js b/test/unit/overviews-query-rewriter-test.js index 73f0c5a9..d510a12d 100644 --- a/test/unit/overviews-query-rewriter-test.js +++ b/test/unit/overviews-query-rewriter-test.js @@ -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); }); }); diff --git a/test/unit/prepare-context-test.js b/test/unit/prepare-context-test.js index 0abb49e9..928816d3 100644 --- a/test/unit/prepare-context-test.js +++ b/test/unit/prepare-context-test.js @@ -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(); }); }); diff --git a/test/unit/table-name-parser-test.js b/test/unit/table-name-parser-test.js index 75f682f5..1b97fea8 100644 --- a/test/unit/table-name-parser-test.js +++ b/test/unit/table-name-parser-test.js @@ -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(); }); diff --git a/test/unit/template-maps-test.js b/test/unit/template-maps-test.js index 2bd6fc9e..57249be4 100644 --- a/test/unit/template-maps-test.js +++ b/test/unit/template-maps-test.js @@ -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) {