From 9355a5ca246d0e0bb1e6dff228b35df5fd2b13ba Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Mon, 13 Jul 2015 16:54:08 +0200 Subject: [PATCH] Tests for surrogate keys in layergroup anonymous instantiation --- test/acceptance/multilayer.js | 41 +++++++++++++++++++++-------------- test/support/test_helper.js | 1 + 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/test/acceptance/multilayer.js b/test/acceptance/multilayer.js index b23521ce..fb04eb07 100644 --- a/test/acceptance/multilayer.js +++ b/test/acceptance/multilayer.js @@ -17,6 +17,8 @@ var serverOptions = require('../../lib/cartodb/server_options'); var server = new CartodbWindshaft(serverOptions); server.setMaxListeners(0); +var TablesCacheEntry = require('../../lib/cartodb/cache/model/database_tables_entry'); + ['/api/v1/map', '/user/localhost/api/v1/map'].forEach(function(layergroup_url) { var suiteName = 'multilayer:postgres=layergroup_url=' + layergroup_url; @@ -67,11 +69,8 @@ suite(suiteName, function() { assert.equal(res.statusCode, 200, res.body); var parsedBody = JSON.parse(res.body); assert.equal(parsedBody.last_updated, expected_last_updated); - if ( expected_token ) { - assert.equal(parsedBody.layergroupid, expected_token + ':' + expected_last_updated_epoch); - assert.equal(res.headers['x-layergroup-id'], parsedBody.layergroupid); - } - else expected_token = parsedBody.layergroupid.split(':')[0]; + assert.equal(res.headers['x-layergroup-id'], parsedBody.layergroupid); + expected_token = parsedBody.layergroupid.split(':')[0]; next(null, res); }); }, @@ -226,17 +225,23 @@ suite(suiteName, function() { test("get creation requests has cache", function(done) { - var layergroup = { - version: '1.0.0', - layers: [ - { options: { - sql: 'select cartodb_id, ST_Translate(the_geom_webmercator, 5e6, 0) as the_geom_webmercator' + - ' from test_table limit 2', - cartocss: '#layer { marker-fill:red; marker-width:32; marker-allow-overlap:true; }', - cartocss_version: '2.0.1' - } } - ] - }; + var layergroup = { + version: '1.0.0', + layers: [ + { options: { + sql: 'select cartodb_id, the_geom_webmercator from test_table', + cartocss: '#layer { marker-fill:red; marker-width:32; marker-allow-overlap:true; }', + cartocss_version: '2.0.1', + interactivity: 'cartodb_id' + } }, + { options: { + sql: 'select cartodb_id, the_geom_webmercator from test_table_2', + cartocss: '#layer { marker-fill:blue; marker-allow-overlap:true; }', + cartocss_version: '2.0.2', + interactivity: 'cartodb_id' + } } + ] + }; var expected_token; step( @@ -255,6 +260,10 @@ suite(suiteName, function() { var parsedBody = JSON.parse(res.body); expected_token = parsedBody.layergroupid.split(':')[0]; helper.checkCache(res); + helper.checkSurrogateKey(res, new TablesCacheEntry('test_windshaft_cartodb_user_1_db', [ + 'public.test_table', + 'public.test_table_2' + ]).key().join(' ')); return null; }, function finish(err) { diff --git a/test/support/test_helper.js b/test/support/test_helper.js index f7924dad..00351eee 100644 --- a/test/support/test_helper.js +++ b/test/support/test_helper.js @@ -34,6 +34,7 @@ function lzma_compress_to_base64(payload, mode, callback) { // Throws on failure function checkNoCache(res) { assert.ok(!res.headers.hasOwnProperty('x-cache-channel')); + assert.ok(!res.headers.hasOwnProperty('surrogate-key')); assert.ok(!res.headers.hasOwnProperty('cache-control')); // is this correct ? assert.ok(!res.headers.hasOwnProperty('last-modified')); // is this correct ? }