CartoDB-SQL-API/test/acceptance/stream-responses-test.js

64 lines
1.9 KiB
JavaScript
Raw Normal View History

2018-10-24 21:42:33 +08:00
'use strict';
require('../helper');
var server = require('../../lib/server')();
var assert = require('../support/assert');
var querystring = require('querystring');
2019-12-24 01:19:08 +08:00
describe('stream-responses', function () {
function createFailingQueryRequest (format) {
var params = {
2019-12-24 01:19:08 +08:00
q: 'SELECT the_geom, 100/(cartodb_id - 3) cdb_ratio FROM untitle_table_4'
};
if (format) {
params.format = format;
}
return {
2019-12-24 01:19:08 +08:00
url: '/api/v1/sql?' + querystring.stringify(params),
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) {
assert.response(
server,
createFailingQueryRequest(),
okResponse,
2019-12-24 01:19:08 +08:00
function (err, res) {
var parsedBody = JSON.parse(res.body);
assert.equal(parsedBody.rows.length, 2);
2019-12-24 01:19:08 +08:00
assert.deepEqual(parsedBody.error, ['division by zero']);
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) {
assert.response(
server,
createFailingQueryRequest('geojson'),
okResponse,
2019-12-24 01:19:08 +08:00
function (err, res) {
var parsedBody = JSON.parse(res.body);
assert.equal(parsedBody.features.length, 2);
2019-12-24 01:19:08 +08:00
assert.deepEqual(parsedBody.error, ['division by zero']);
done();
}
);
});
});
});