diff --git a/test/acceptance/multilayer_server.js b/test/acceptance/multilayer_server.js index e0bf8460..d7b2c16b 100644 --- a/test/acceptance/multilayer_server.js +++ b/test/acceptance/multilayer_server.js @@ -12,8 +12,6 @@ server.setMaxListeners(0); describe('tests from old api translated to multilayer', function() { - var test_database = _.template(global.environment.postgres_auth_user, {user_id:1}) + '_db'; - var layergroupUrl = '/api/v1/map'; var redisClient = redis.createClient(global.environment.redis.port); @@ -28,6 +26,7 @@ describe('tests from old api translated to multilayer', function() { }); var wadusSql = 'select 1 as cartodb_id, null::geometry as the_geom_webmercator'; + var pointSql = "SELECT 'SRID=3857;POINT(0 0)'::geometry as the_geom_webmercator, 1::int as cartodb_id"; function singleLayergroupConfig(sql, cartocss) { return { @@ -46,9 +45,13 @@ describe('tests from old api translated to multilayer', function() { }; } - function createRequest(layergroup, userHost) { + function createRequest(layergroup, userHost, apiKey) { + var url = layergroupUrl; + if (apiKey) { + url += '?api_key=' + apiKey; + } return { - url: layergroupUrl, + url: url, method: 'POST', headers: { host: userHost || 'localhost', @@ -93,12 +96,8 @@ describe('tests from old api translated to multilayer', function() { }); // Zoom is a special variable - it("Specifying zoom level in CartoCSS does not need a 'zoom' variable in SQL output", function(done){ - // NOTE: may fail if grainstore < 0.3.0 is used by Windshaft - var sql = "SELECT 'SRID=3857;POINT(0 0)'::geometry as the_geom_webmercator, 1::int as cartodb_id"; - var cartocss = '#gadm4 [ zoom>=3] { marker-fill:red; }'; - - var layergroup = singleLayergroupConfig(sql, cartocss); + it("Specifying zoom level in CartoCSS does not need a 'zoom' variable in SQL output", function(done) { + var layergroup = singleLayergroupConfig(pointSql, '#gadm4 [ zoom>=3] { marker-fill:red; }'); assert.response(server, createRequest(layergroup), @@ -113,4 +112,48 @@ describe('tests from old api translated to multilayer', function() { ); }); + // See https://github.com/CartoDB/Windshaft-cartodb/issues/88 + it("getting a tile from a user-specific database should return an expected tile", function(done) { + var layergroup = singleLayergroupConfig(pointSql, '#layer { marker-fill:red; }'); + + var backupDBHost = global.environment.postgres.host; + global.environment.postgres.host = '6.6.6.6'; + + assert.response(server, + createRequest(layergroup, 'cartodb250user'), + { + status: 200 + }, + function(res) { + var parsed = JSON.parse(res.body); + assert.ok(parsed.layergroupid); + + global.environment.postgres.host = backupDBHost; + done(); + } + ); + }); + + // See https://github.com/CartoDB/Windshaft-cartodb/issues/89 + it("getting a tile with a user-specific database password", function(done) { + var layergroup = singleLayergroupConfig(pointSql, '#layer { marker-fill:red; }'); + + var backupDBPass = global.environment.postgres_auth_pass; + global.environment.postgres_auth_pass = '<%= user_password %>'; + + assert.response(server, + createRequest(layergroup, 'cartodb250user', '4321'), + { + status: 200 + }, + function(res) { + var parsed = JSON.parse(res.body); + assert.ok(parsed.layergroupid); + + global.environment.postgres_auth_pass = backupDBPass; + done(); + } + ); + }); + }); diff --git a/test/acceptance/server.js b/test/acceptance/server.js index f5ad4d50..33fd9817 100644 --- a/test/acceptance/server.js +++ b/test/acceptance/server.js @@ -71,81 +71,8 @@ suite.skip('server old_api', function() { var test_database = _.template(global.environment.postgres_auth_user, {user_id:1}) + '_db'; // A couple of styles to use during testing - var test_style_black_200 = "#test_table{marker-fill:black;marker-line-color:red;marker-width:10}"; var test_style_black_210 = "#test_table{marker-fill:black;marker-line-color:red;marker-width:20}"; - // See https://github.com/CartoDB/Windshaft-cartodb/issues/88 - test("get'ing a tile from a user-specific database should return an expected tile", function(done){ - var style = querystring.stringify({style: test_style_black_200, style_version: '2.0.0'}); - var backupDBHost = global.environment.postgres.host; - global.environment.postgres.host = '6.6.6.6'; - step ( - function() { - var next = this; - assert.response(server, { - headers: {host: 'cartodb250user'}, - url: '/tiles/test_table/15/16046/12354.png?cache_buster=4.10&' + style, - method: 'GET', - encoding: 'binary' - },{}, function(res){ - next(null, res); - }); - }, - function checkRes(err, res) { - assert.equal(res.statusCode, 200, res.statusCode + ': ' + res.body); - var ct = res.headers['content-type']; - assert.equal(ct, 'image/png'); - assert.imageEqualsFile(res.body, - './test/fixtures/test_table_15_16046_12354_styled_black.png', - IMAGE_EQUALS_TOLERANCE_PER_MIL, this); - }, - function checkImage(err/*, similarity*/) { - if (err) throw err; - return null; - }, - function finish(err) { - global.environment.postgres.host = backupDBHost; - done(err); - } - ); - }); - - // See https://github.com/CartoDB/Windshaft-cartodb/issues/89 - test("get'ing a tile with a user-specific database password", function(done){ - var style = querystring.stringify({style: test_style_black_200, style_version: '2.0.0'}); - var backupDBPass = global.environment.postgres_auth_pass; - global.environment.postgres_auth_pass = '<%= user_password %>'; - step ( - function() { - var next = this; - assert.response(server, { - headers: {host: 'cartodb250user'}, - url: '/tiles/test_table/15/16046/12354.png?' + 'cache_buster=4.20&api_key=4321&' + style, - method: 'GET', - encoding: 'binary' - },{}, function(res){ - next(null, res); - }); - }, - function checkRes(err, res) { - assert.equal(res.statusCode, 200, res.statusCode + ': ' + res.body); - var ct = res.headers['content-type']; - assert.equal(ct, 'image/png'); - assert.imageEqualsFile(res.body, - './test/fixtures/test_table_15_16046_12354_styled_black.png', - IMAGE_EQUALS_TOLERANCE_PER_MIL, this); - }, - function checkImage(err/*, similarity*/) { - if (err) throw err; - return null; - }, - function finish(err) { - global.environment.postgres_auth_pass = backupDBPass; - done(err); - } - ); - }); - test("get'ing a tile with url specified 2.1.0 style (lzma version)", function(done){ var qo = { style: test_style_black_210,