Windshaft-cartodb/test/acceptance/ported/raster-test.js

154 lines
5.5 KiB
JavaScript
Raw Normal View History

'use strict';
2019-10-22 01:07:24 +08:00
var testHelper = require('../../support/test-helper');
2015-07-08 05:46:58 +08:00
var assert = require('../../support/assert');
var step = require('step');
2019-10-07 15:40:50 +08:00
var cartodbServer = require('../../../lib/server');
var ServerOptions = require('./support/ported-server-options');
2019-10-07 15:40:50 +08:00
var LayergroupToken = require('../../../lib/models/layergroup-token');
2019-10-22 01:07:24 +08:00
describe('raster', function () {
var server;
before(function () {
server = cartodbServer(ServerOptions);
server.setMaxListeners(0);
});
2015-07-08 05:46:58 +08:00
2019-10-22 01:07:24 +08:00
function checkCORSHeaders (res) {
assert.strictEqual(
res.headers['access-control-allow-headers'],
'X-Requested-With, X-Prototype-Version, X-CSRF-Token, Authorization'
);
assert.strictEqual(res.headers['access-control-allow-origin'], '*');
2015-07-08 05:46:58 +08:00
}
var IMAGE_EQUALS_TOLERANCE_PER_MIL = 2;
2019-10-22 01:07:24 +08:00
it('can render raster for valid mapconfig', function (done) {
var mapconfig = {
version: '1.2.0',
layers: [
{
type: 'mapnik',
options: {
sql: 'select ST_AsRaster(' +
' ST_MakeEnvelope(-100,-40, 100, 40, 4326), ' +
2015-07-08 05:46:58 +08:00
" 1.0, -1.0, '8BUI', 127) as rst",
2019-10-22 01:07:24 +08:00
geom_column: 'rst',
geom_type: 'raster',
cartocss: '#layer { raster-opacity:1.0 }',
cartocss_version: '2.0.1'
}
}
]
};
2019-11-14 02:36:30 +08:00
var expectedToken;
2019-10-22 01:07:24 +08:00
step(
2019-11-14 02:36:30 +08:00
function doPost () {
2019-10-22 01:07:24 +08:00
var next = this;
assert.response(server, {
url: '/api/v1/map',
method: 'POST',
headers: { host: 'localhost', 'Content-Type': 'application/json' },
data: JSON.stringify(mapconfig)
}, {}, function (res, err) { next(err, res); });
},
function checkPost (err, res) {
2015-07-08 05:46:58 +08:00
assert.ifError(err);
assert.strictEqual(res.statusCode, 200, res.statusCode + ': ' + res.body);
2019-10-22 01:07:24 +08:00
// CORS headers should be sent with response
// from layergroup creation via POST
checkCORSHeaders(res);
var parsedBody = JSON.parse(res.body);
2019-11-14 02:36:30 +08:00
if (expectedToken) {
assert.deepStrictEqual(parsedBody, { layergroupid: expectedToken, layercount: 2 });
2019-10-22 01:07:24 +08:00
} else {
2019-11-14 02:36:30 +08:00
expectedToken = parsedBody.layergroupid;
2019-10-22 01:07:24 +08:00
}
return null;
},
2019-11-14 02:36:30 +08:00
function doGetTile (err) {
2019-10-22 01:07:24 +08:00
assert.ifError(err);
var next = this;
assert.response(server, {
2019-11-14 02:36:30 +08:00
url: '/api/v1/map/' + expectedToken + '/0/0/0.png',
2019-10-22 01:07:24 +08:00
method: 'GET',
encoding: 'binary',
headers: { host: 'localhost' }
}, {}, function (res, err) { next(err, res); });
},
2019-11-14 02:36:30 +08:00
function checkResponse (err, res) {
2019-10-22 01:07:24 +08:00
assert.ifError(err);
assert.strictEqual(res.statusCode, 200, res.body);
assert.deepStrictEqual(res.headers['content-type'], 'image/png');
2019-10-22 01:07:24 +08:00
var next = this;
assert.imageBufferIsSimilarToFile(res.body,
'./test/fixtures/raster_gray_rect.png',
IMAGE_EQUALS_TOLERANCE_PER_MIL, function (err) {
try {
assert.ifError(err);
next();
} catch (err) { next(err); }
});
},
function finish (err) {
if (err) {
return done(err);
}
2015-09-25 20:49:59 +08:00
2019-10-22 01:07:24 +08:00
var keysToDelete = {
'user:localhost:mapviews:global': 5
};
2019-11-14 02:36:30 +08:00
keysToDelete['map_cfg|' + LayergroupToken.parse(expectedToken).token] = 0;
2019-10-22 01:07:24 +08:00
testHelper.deleteRedisKeys(keysToDelete, done);
}
);
2015-07-08 05:46:58 +08:00
});
2019-10-22 01:07:24 +08:00
it('raster geom type does not allow interactivity', function (done) {
var mapconfig = {
2015-07-08 05:46:58 +08:00
version: '1.2.0',
layers: [
{
type: 'cartodb',
options: {
sql: [
2019-10-22 01:07:24 +08:00
'select 1 id,',
"ST_AsRaster(ST_MakeEnvelope(-100, -40, 100, 40, 4326), 1.0, -1.0, '8BUI', 127) as rst"
2015-07-08 05:46:58 +08:00
].join(' '),
geom_column: 'rst',
geom_type: 'raster',
cartocss: '#layer { raster-opacity: 1.0 }',
cartocss_version: '2.0.1',
interactivity: 'id'
}
}
]
};
assert.response(server,
{
2019-10-02 01:34:03 +08:00
url: '/api/v1/map',
2015-07-08 05:46:58 +08:00
method: 'POST',
headers: {
2018-03-17 01:59:07 +08:00
host: 'localhost',
2015-07-08 05:46:58 +08:00
'Content-Type': 'application/json'
},
data: JSON.stringify(mapconfig)
},
{
status: 400
},
2019-10-22 01:07:24 +08:00
function (res, err) {
2015-07-08 05:46:58 +08:00
assert.ok(!err);
checkCORSHeaders(res);
var parsedBody = JSON.parse(res.body);
assert.deepStrictEqual(parsedBody.errors, ['Mapnik raster layers do not support interactivity']);
2015-07-08 05:46:58 +08:00
done();
}
);
});
});