2018-10-24 21:42:33 +08:00
|
|
|
'use strict';
|
|
|
|
|
2015-05-14 00:15:38 +08:00
|
|
|
require('../helper');
|
|
|
|
|
2019-10-04 00:24:39 +08:00
|
|
|
var server = require('../../lib/server')();
|
2015-05-14 00:15:38 +08:00
|
|
|
var assert = require('../support/assert');
|
|
|
|
var querystring = require('querystring');
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
describe('stream-responses', function () {
|
|
|
|
function createFailingQueryRequest (format) {
|
2015-05-14 00:15:38 +08:00
|
|
|
var params = {
|
2019-12-24 01:19:08 +08:00
|
|
|
q: 'SELECT the_geom, 100/(cartodb_id - 3) cdb_ratio FROM untitle_table_4'
|
2015-05-14 00:15:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
if (format) {
|
|
|
|
params.format = format;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
2019-12-24 01:19:08 +08:00
|
|
|
url: '/api/v1/sql?' + querystring.stringify(params),
|
2015-05-14 00:15:38 +08:00
|
|
|
headers: {
|
|
|
|
host: 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'GET'
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
var okResponse = {
|
|
|
|
status: 200
|
|
|
|
};
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
describe('format-json', function () {
|
|
|
|
it('should close on error and error message must be part of the response', function (done) {
|
2015-05-14 00:15:38 +08:00
|
|
|
assert.response(
|
2016-09-15 02:54:24 +08:00
|
|
|
server,
|
2015-05-14 00:15:38 +08:00
|
|
|
createFailingQueryRequest(),
|
|
|
|
okResponse,
|
2019-12-24 01:19:08 +08:00
|
|
|
function (err, res) {
|
2019-12-26 23:10:41 +08:00
|
|
|
assert.ifError(err);
|
2015-05-14 00:15:38 +08:00
|
|
|
var parsedBody = JSON.parse(res.body);
|
2019-12-26 21:01:18 +08:00
|
|
|
assert.strictEqual(parsedBody.rows.length, 2);
|
|
|
|
assert.deepStrictEqual(parsedBody.error, ['division by zero']);
|
2015-05-14 00:15:38 +08:00
|
|
|
done();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
describe('format-geojson', function () {
|
|
|
|
it('should close on error and error message must be part of the response', function (done) {
|
2015-05-14 00:15:38 +08:00
|
|
|
assert.response(
|
2016-09-15 02:54:24 +08:00
|
|
|
server,
|
2015-05-14 00:15:38 +08:00
|
|
|
createFailingQueryRequest('geojson'),
|
|
|
|
okResponse,
|
2019-12-24 01:19:08 +08:00
|
|
|
function (err, res) {
|
2019-12-26 23:10:41 +08:00
|
|
|
assert.ifError(err);
|
2015-05-14 00:15:38 +08:00
|
|
|
var parsedBody = JSON.parse(res.body);
|
2019-12-26 21:01:18 +08:00
|
|
|
assert.strictEqual(parsedBody.features.length, 2);
|
|
|
|
assert.deepStrictEqual(parsedBody.error, ['division by zero']);
|
2015-05-14 00:15:38 +08:00
|
|
|
done();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|