2018-10-24 21:42:33 +08:00
|
|
|
'use strict';
|
|
|
|
|
2016-12-09 18:01:47 +08:00
|
|
|
require('../helper');
|
|
|
|
|
2019-10-04 00:24:39 +08:00
|
|
|
var server = require('../../lib/server')();
|
2016-12-09 18:01:47 +08:00
|
|
|
var assert = require('../support/assert');
|
|
|
|
var querystring = require('querystring');
|
|
|
|
var _ = require('underscore');
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
describe('skipfields', function () {
|
2016-12-09 18:01:47 +08:00
|
|
|
var RESPONSE_OK = {
|
|
|
|
statusCode: 200
|
|
|
|
};
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
it('skipfields controls included fields', function (done) {
|
2016-12-09 18:01:47 +08:00
|
|
|
assert.response(server, {
|
|
|
|
url: '/api/v1/sql?q=' +
|
|
|
|
'SELECT%20*%20FROM%20untitle_table_4&skipfields=the_geom_webmercator,cartodb_id,unexistant',
|
2019-12-24 01:19:08 +08:00
|
|
|
headers: { host: 'vizzuality.cartodb.com' },
|
2016-12-09 18:01:47 +08:00
|
|
|
method: 'GET'
|
2019-12-24 01:19:08 +08:00
|
|
|
}, RESPONSE_OK, function (err, res) {
|
2016-12-09 18:01:47 +08:00
|
|
|
var row0 = JSON.parse(res.body).rows[0];
|
2019-12-24 01:19:08 +08:00
|
|
|
var checkfields = { name: 1, cartodb_id: 0, the_geom: 1, the_geom_webmercator: 0 };
|
|
|
|
for (var f in checkfields) {
|
|
|
|
if (checkfields[f]) {
|
|
|
|
assert.ok(row0.hasOwnProperty(f), "result does not include '" + f + "'");
|
|
|
|
} else {
|
|
|
|
assert.ok(!row0.hasOwnProperty(f), "result includes '" + f + "'");
|
|
|
|
}
|
2016-12-09 18:01:47 +08:00
|
|
|
}
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
it('multiple skipfields parameter do not kill the backend', function (done) {
|
2016-12-09 18:01:47 +08:00
|
|
|
assert.response(server, {
|
|
|
|
url: '/api/v1/sql?q=SELECT%20*%20FROM%20untitle_table_4&skipfields=unexistent,the_geom_webmercator' +
|
|
|
|
'&skipfields=cartodb_id,unexistant',
|
2019-12-24 01:19:08 +08:00
|
|
|
headers: { host: 'vizzuality.cartodb.com' },
|
2016-12-09 18:01:47 +08:00
|
|
|
method: 'GET'
|
2019-12-24 01:19:08 +08:00
|
|
|
}, RESPONSE_OK, function (err, res) {
|
2016-12-09 18:01:47 +08:00
|
|
|
var row0 = JSON.parse(res.body).rows[0];
|
2019-12-24 01:19:08 +08:00
|
|
|
var checkfields = { name: 1, cartodb_id: 0, the_geom: 1, the_geom_webmercator: 0 };
|
|
|
|
for (var f in checkfields) {
|
|
|
|
if (checkfields[f]) {
|
|
|
|
assert.ok(row0.hasOwnProperty(f), "result does not include '" + f + "'");
|
|
|
|
} else {
|
|
|
|
assert.ok(!row0.hasOwnProperty(f), "result includes '" + f + "'");
|
|
|
|
}
|
2016-12-09 18:01:47 +08:00
|
|
|
}
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// See https://github.com/CartoDB/CartoDB-SQL-API/issues/109
|
2019-12-24 01:19:08 +08:00
|
|
|
it('schema response takes skipfields into account', function (done) {
|
2016-12-09 18:01:47 +08:00
|
|
|
assert.response(server, {
|
|
|
|
url: '/api/v1/sql?' + querystring.stringify({
|
2019-12-24 01:19:08 +08:00
|
|
|
q: 'SELECT 1 as a, 2 as b, 3 as c ',
|
|
|
|
skipfields: 'b'
|
2016-12-09 18:01:47 +08:00
|
|
|
}),
|
2019-12-24 01:19:08 +08:00
|
|
|
headers: { host: 'vizzuality.cartodb.com' },
|
2016-12-09 18:01:47 +08:00
|
|
|
method: 'GET'
|
2019-12-24 01:19:08 +08:00
|
|
|
}, RESPONSE_OK, function (err, res) {
|
2016-12-09 18:01:47 +08:00
|
|
|
var parsedBody = JSON.parse(res.body);
|
|
|
|
assert.equal(_.keys(parsedBody.fields).length, 2);
|
|
|
|
assert.ok(parsedBody.fields.hasOwnProperty('a'));
|
|
|
|
assert.ok(!parsedBody.fields.hasOwnProperty('b'));
|
|
|
|
assert.ok(parsedBody.fields.hasOwnProperty('c'));
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2019-12-24 01:19:08 +08:00
|
|
|
it('field named "the_geom_webmercator" is not skipped by default', function (done) {
|
2016-12-09 18:01:47 +08:00
|
|
|
assert.response(server, {
|
|
|
|
url: '/api/v1/sql?q=SELECT%20*%20FROM%20untitle_table_4',
|
2019-12-24 01:19:08 +08:00
|
|
|
headers: { host: 'vizzuality.cartodb.com' },
|
2016-12-09 18:01:47 +08:00
|
|
|
method: 'GET'
|
2019-12-24 01:19:08 +08:00
|
|
|
}, { }, function (err, res) {
|
2016-12-09 18:01:47 +08:00
|
|
|
assert.equal(res.statusCode, 200, res.body);
|
|
|
|
var row0 = JSON.parse(res.body).rows[0];
|
2019-12-24 01:19:08 +08:00
|
|
|
var checkfields = { name: 1, cartodb_id: 1, the_geom: 1, the_geom_webmercator: 1 };
|
|
|
|
for (var f in checkfields) {
|
|
|
|
if (checkfields[f]) {
|
|
|
|
assert.ok(row0.hasOwnProperty(f), "result does not include '" + f + "'");
|
|
|
|
} else {
|
|
|
|
assert.ok(!row0.hasOwnProperty(f), "result includes '" + f + "'");
|
|
|
|
}
|
2016-12-09 18:01:47 +08:00
|
|
|
}
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|