Merge pull request #164 from CartoDB/CDB-3780

Fixes for GeoJSON stream responses
This commit is contained in:
Raul Ochoa 2014-08-05 00:57:35 +02:00
commit 41fe1f4cb5
2 changed files with 44 additions and 0 deletions

View File

@ -53,6 +53,15 @@ GeoJsonFormat.prototype.handleQueryRow = function(row) {
};
GeoJsonFormat.prototype.handleQueryEnd = function(result) {
if (this.error) {
this.callback(this.error);
return;
}
if ( ! this._streamingStarted ) {
this.startStreaming();
}
this.buffer += ']}'; // end of features
if (this.opts.callback) {
this.buffer += ')';

View File

@ -182,4 +182,39 @@ test('null geometries in geojson output', function(done){
});
});
test('stream response handle errors', function(done) {
assert.response(app, {
url: '/api/v1/sql?' + querystring.stringify({
q: "SELECTT 1 as gid, null::geometry as the_geom ",
format: 'geojson'
}),
headers: {host: 'vizzuality.cartodb.com'},
method: 'GET'
},{ }, function(res){
console.log(res);
assert.equal(res.statusCode, 400, res.body);
var geoJson = JSON.parse(res.body);
var expectedError = {"error":["syntax error at or near \"1\""]}
assert.deepEqual(geoJson, expectedError);
done();
});
});
test('stream response with empty result set has valid output', function(done) {
assert.response(app, {
url: '/api/v1/sql?' + querystring.stringify({
q: "SELECT 1 as gid, null::geometry as the_geom limit 0",
format: 'geojson'
}),
headers: {host: 'vizzuality.cartodb.com'},
method: 'GET'
},{ }, function(res){
assert.equal(res.statusCode, 200, res.body);
var geoJson = JSON.parse(res.body);
var expectedGeoJson = {"type": "FeatureCollection", "features": []};
assert.deepEqual(geoJson, expectedGeoJson);
done();
});
});
});