2018-10-24 00:39:02 +08:00
|
|
|
'use strict';
|
|
|
|
|
2019-10-07 16:44:45 +08:00
|
|
|
var testHelper = require('../../support/test-helper');
|
2015-07-08 05:46:58 +08:00
|
|
|
|
|
|
|
var assert = require('../../support/assert');
|
2019-10-07 15:40:50 +08:00
|
|
|
var cartodbServer = require('../../../lib/server');
|
2019-10-07 16:44:45 +08:00
|
|
|
var ServerOptions = require('./support/ported-server-options');
|
|
|
|
var testClient = require('./support/test-client');
|
2015-07-08 05:46:58 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('server', function () {
|
2018-04-16 22:16:23 +08:00
|
|
|
var server;
|
2015-07-08 05:46:58 +08:00
|
|
|
|
2018-04-16 22:16:23 +08:00
|
|
|
before(function () {
|
|
|
|
server = cartodbServer(ServerOptions);
|
|
|
|
server.setMaxListeners(0);
|
|
|
|
});
|
2015-07-08 05:46:58 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
after(function () {
|
2015-09-26 01:56:28 +08:00
|
|
|
testHelper.rmdirRecursiveSync(global.environment.millstone.cache_basedir);
|
2015-07-08 05:46:58 +08:00
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
/// /////////////////////////////////////////////////////////////////
|
2015-07-08 05:46:58 +08:00
|
|
|
//
|
|
|
|
// GET INVALID
|
|
|
|
//
|
2019-10-22 01:07:24 +08:00
|
|
|
/// /////////////////////////////////////////////////////////////////
|
2015-07-08 05:46:58 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('get call to server returns 200', function (done) {
|
2015-07-08 05:46:58 +08:00
|
|
|
assert.response(server, {
|
|
|
|
url: '/',
|
|
|
|
method: 'GET'
|
2019-10-22 01:07:24 +08:00
|
|
|
}, {
|
2015-07-08 05:46:58 +08:00
|
|
|
// FIXME: shouldn't this be a 404 ?
|
|
|
|
status: 200
|
2019-10-22 01:07:24 +08:00
|
|
|
}, function () { done(); });
|
2015-07-08 05:46:58 +08:00
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
/// /////////////////////////////////////////////////////////////////
|
2015-07-08 05:46:58 +08:00
|
|
|
//
|
|
|
|
// GET VERSION
|
|
|
|
//
|
2019-10-22 01:07:24 +08:00
|
|
|
/// /////////////////////////////////////////////////////////////////
|
2015-07-08 05:46:58 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('get /version returns versions', function (done) {
|
2015-07-08 05:46:58 +08:00
|
|
|
assert.response(server, {
|
|
|
|
url: '/version',
|
|
|
|
method: 'GET'
|
2019-10-22 01:07:24 +08:00
|
|
|
}, {
|
2015-07-08 05:46:58 +08:00
|
|
|
status: 200
|
2019-10-22 01:07:24 +08:00
|
|
|
}, function (res) {
|
|
|
|
var parsed = JSON.parse(res.body);
|
2019-10-22 05:33:27 +08:00
|
|
|
assert.ok(Object.prototype.hasOwnProperty.call(parsed, 'windshaft'), "No 'windshaft' version in " + parsed);
|
|
|
|
assert.ok(Object.prototype.hasOwnProperty.call(parsed, 'grainstore'), "No 'grainstore' version in " + parsed);
|
|
|
|
assert.ok(Object.prototype.hasOwnProperty.call(parsed, 'node_mapnik'), "No 'node_mapnik' version in " + parsed);
|
|
|
|
assert.ok(Object.prototype.hasOwnProperty.call(parsed, 'mapnik'), "No 'mapnik' version in " + parsed);
|
2019-10-22 01:07:24 +08:00
|
|
|
// TODO: check actual versions ?
|
|
|
|
done();
|
2015-07-08 05:46:58 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
/// /////////////////////////////////////////////////////////////////
|
2015-07-08 05:46:58 +08:00
|
|
|
//
|
|
|
|
// GET GRID
|
|
|
|
//
|
2019-10-22 01:07:24 +08:00
|
|
|
/// /////////////////////////////////////////////////////////////////
|
2015-07-08 05:46:58 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('grid jsonp', function (done) {
|
2015-07-08 05:46:58 +08:00
|
|
|
var mapConfig = testClient.singleLayerMapConfig('select * from test_table', null, null, 'name');
|
2019-11-14 02:36:30 +08:00
|
|
|
testClient.getGridJsonp(mapConfig, 0, 13, 4011, 3088, 'jsonpTest', function (err, res) {
|
2019-10-25 00:38:37 +08:00
|
|
|
assert.ifError(err);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 200, res.body);
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(res.headers['content-type'], 'text/javascript; charset=utf-8');
|
2015-09-17 08:06:32 +08:00
|
|
|
var didRunJsonCallback = false;
|
|
|
|
var response = {};
|
2019-10-25 16:58:00 +08:00
|
|
|
/* eslint-disable no-unused-vars, no-eval */
|
2019-11-14 02:36:30 +08:00
|
|
|
function jsonpTest (body) {
|
2015-09-17 08:06:32 +08:00
|
|
|
response = body;
|
|
|
|
didRunJsonCallback = true;
|
|
|
|
}
|
|
|
|
eval(res.body);
|
2019-10-25 16:58:00 +08:00
|
|
|
/* eslint-enable */
|
2015-09-17 08:06:32 +08:00
|
|
|
assert.ok(didRunJsonCallback);
|
|
|
|
assert.utfgridEqualsFile(response, './test/fixtures/test_table_13_4011_3088.grid.json', 2, done);
|
2015-07-08 05:46:58 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it("get'ing a json with default style and single interactivity should return a grid", function (done) {
|
2015-07-08 05:46:58 +08:00
|
|
|
var mapConfig = testClient.singleLayerMapConfig('select * from test_table', null, null, 'name');
|
2019-10-22 01:07:24 +08:00
|
|
|
testClient.getGrid(mapConfig, 0, 13, 4011, 3088, function (err, res) {
|
2019-10-25 00:38:37 +08:00
|
|
|
assert.ifError(err);
|
2019-11-14 02:36:30 +08:00
|
|
|
var expectedJson = {
|
2019-10-22 01:07:24 +08:00
|
|
|
1: { name: 'Hawai' },
|
|
|
|
2: { name: 'El Estocolmo' },
|
|
|
|
3: { name: 'El Rey del Tallarín' },
|
|
|
|
4: { name: 'El Lacón' },
|
|
|
|
5: { name: 'El Pico' }
|
2015-07-08 05:46:58 +08:00
|
|
|
};
|
2019-11-14 02:36:30 +08:00
|
|
|
assert.deepStrictEqual(JSON.parse(res.body).data, expectedJson);
|
2015-07-08 05:46:58 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it("get'ing a json with default style and no interactivity should return an error", function (done) {
|
2015-07-08 05:46:58 +08:00
|
|
|
var mapConfig = testClient.singleLayerMapConfig('select * from test_table');
|
|
|
|
var expectedResponse = {
|
|
|
|
status: 400,
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json; charset=utf-8'
|
|
|
|
}
|
|
|
|
};
|
2019-10-22 01:07:24 +08:00
|
|
|
testClient.getGrid(mapConfig, 0, 13, 4011, 3088, expectedResponse, function (err, res) {
|
2019-10-25 00:38:37 +08:00
|
|
|
assert.ifError(err);
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(JSON.parse(res.body).errors, ['Tileset has no interactivity']);
|
2015-07-08 05:46:58 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('get grid jsonp error is returned with 200 status', function (done) {
|
2015-07-08 05:46:58 +08:00
|
|
|
var mapConfig = testClient.singleLayerMapConfig('select * from test_table');
|
|
|
|
var expectedResponse = {
|
|
|
|
status: 200,
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'text/javascript; charset=utf-8'
|
|
|
|
}
|
|
|
|
};
|
2019-10-22 01:07:24 +08:00
|
|
|
testClient.getGridJsonp(mapConfig, 0, 13, 4011, 3088, 'test', expectedResponse, function (err, res) {
|
2019-10-25 00:38:37 +08:00
|
|
|
assert.ifError(err);
|
2015-07-08 05:46:58 +08:00
|
|
|
assert.ok(res.body.match(/"errors":/), 'missing error in response: ' + res.body);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// See http://github.com/Vizzuality/Windshaft/issues/50
|
2019-10-22 01:07:24 +08:00
|
|
|
it("get'ing a json with no data should return an empty grid", function (done) {
|
2015-07-08 05:46:58 +08:00
|
|
|
var query = 'select * from test_table limit 0';
|
|
|
|
var mapConfig = testClient.singleLayerMapConfig(query, null, null, 'name');
|
2019-10-22 01:07:24 +08:00
|
|
|
testClient.getGrid(mapConfig, 0, 13, 4011, 3088, function (err, res) {
|
2019-10-25 00:38:37 +08:00
|
|
|
assert.ifError(err);
|
2015-07-08 05:46:58 +08:00
|
|
|
assert.utfgridEqualsFile(res.body, './test/fixtures/test_table_13_4011_3088_empty.grid.json', 2, done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Another test for http://github.com/Vizzuality/Windshaft/issues/50
|
2019-10-22 01:07:24 +08:00
|
|
|
it("get'ing a json with no data but interactivity should return an empty grid", function (done) {
|
2015-07-08 05:46:58 +08:00
|
|
|
var query = 'SELECT * FROM test_table limit 0';
|
|
|
|
var mapConfig = testClient.singleLayerMapConfig(query, null, null, 'cartodb_id');
|
2019-10-22 01:07:24 +08:00
|
|
|
testClient.getGrid(mapConfig, 0, 13, 4011, 3088, function (err, res) {
|
2019-10-25 00:38:37 +08:00
|
|
|
assert.ifError(err);
|
2015-07-08 05:46:58 +08:00
|
|
|
assert.utfgridEqualsFile(res.body, './test/fixtures/test_table_13_4011_3088_empty.grid.json', 2, done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// See https://github.com/Vizzuality/Windshaft-cartodb/issues/67
|
2019-10-22 01:07:24 +08:00
|
|
|
it("get'ing a solid grid while changing interactivity fields", function (done) {
|
2015-07-08 05:46:58 +08:00
|
|
|
var query = 'SELECT * FROM test_big_poly';
|
2019-10-22 01:07:24 +08:00
|
|
|
var style211 = '#test_big_poly{polygon-fill:blue;}'; // for solid
|
2015-07-08 05:46:58 +08:00
|
|
|
var mapConfigName = testClient.singleLayerMapConfig(query, style211, null, 'name');
|
2019-10-22 01:07:24 +08:00
|
|
|
testClient.getGrid(mapConfigName, 0, 3, 2, 2, function (err, res) {
|
2019-10-25 00:38:37 +08:00
|
|
|
assert.ifError(err);
|
2019-11-14 02:36:30 +08:00
|
|
|
var expectedData = { 1: { name: 'west' } };
|
|
|
|
assert.deepStrictEqual(JSON.parse(res.body).data, expectedData);
|
2015-07-08 05:46:58 +08:00
|
|
|
|
|
|
|
var mapConfigCartodbId = testClient.singleLayerMapConfig(query, style211, null, 'cartodb_id');
|
2019-10-22 01:07:24 +08:00
|
|
|
testClient.getGrid(mapConfigCartodbId, 0, 3, 2, 2, function (err, res) {
|
2019-10-25 00:38:37 +08:00
|
|
|
assert.ifError(err);
|
2019-11-14 02:36:30 +08:00
|
|
|
var expectedData = { 1: { cartodb_id: 1 } };
|
|
|
|
assert.deepStrictEqual(JSON.parse(res.body).data, expectedData);
|
2015-07-08 05:46:58 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|