tests raising pg_typeof error

This commit is contained in:
Simon Martín 2018-05-10 15:59:38 +02:00
parent 39a1b0742f
commit 913b29070f
2 changed files with 164 additions and 63 deletions

View File

@ -491,4 +491,4 @@ describe('Count aggregation', function () {
this.testClient.drain(done);
});
});
});
});

View File

@ -3,8 +3,8 @@ require('../../support/test_helper');
var assert = require('../../support/assert');
var TestClient = require('../../support/test-client');
describe('histogram-dataview', function() {
describe('dataview error cases', function() {
afterEach(function(done) {
if (this.testClient) {
this.testClient.drain(done);
@ -13,75 +13,176 @@ describe('histogram-dataview', function() {
}
});
var ERROR_RESPONSE = {
status: 400,
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
};
function createMapConfig(dataviews) {
return {
version: '1.5.0',
layers: [
{
"type": "cartodb",
"options": {
"source": {
"id": "HEAD"
},
"cartocss": "#points { marker-width: 10; marker-fill: red; }",
"cartocss_version": "2.3.0"
}
}
],
dataviews: dataviews,
analyses: [
{
"id": "HEAD",
"type": "source",
"params": {
"query": "select null::geometry the_geom_webmercator, x from generate_series(0,1000) x"
}
}
]
describe('generic errors', function() {
var ERROR_RESPONSE = {
status: 400,
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
};
}
it('should fail when invalid dataviews object is provided, string case', function(done) {
var mapConfig = createMapConfig("wadus-string");
this.testClient = new TestClient(mapConfig, 1234);
this.testClient.getLayergroup({ response: ERROR_RESPONSE }, function(err, errObj) {
assert.ok(!err, err);
assert.deepEqual(errObj.errors, [ '"dataviews" must be a valid JSON object: "string" type found' ]);
done();
function createMapConfig(dataviews) {
return {
version: '1.5.0',
layers: [
{
"type": "cartodb",
"options": {
"source": {
"id": "HEAD"
},
"cartocss": "#points { marker-width: 10; marker-fill: red; }",
"cartocss_version": "2.3.0"
}
}
],
dataviews: dataviews,
analyses: [
{
"id": "HEAD",
"type": "source",
"params": {
"query": "select null::geometry the_geom_webmercator, x from generate_series(0,1000) x"
}
}
]
};
}
it('should fail when invalid dataviews object is provided, string case', function(done) {
var mapConfig = createMapConfig("wadus-string");
this.testClient = new TestClient(mapConfig, 1234);
this.testClient.getLayergroup({ response: ERROR_RESPONSE }, function(err, errObj) {
assert.ok(!err, err);
assert.deepEqual(errObj.errors, [ '"dataviews" must be a valid JSON object: "string" type found' ]);
done();
});
});
it('should fail when invalid dataviews object is provided, array case', function(done) {
var mapConfig = createMapConfig([]);
this.testClient = new TestClient(mapConfig, 1234);
this.testClient.getLayergroup({ response: ERROR_RESPONSE }, function(err, errObj) {
assert.ok(!err, err);
assert.deepEqual(errObj.errors, [ '"dataviews" must be a valid JSON object: "array" type found' ]);
done();
});
});
it('should work with empty but valid objects', function(done) {
var mapConfig = createMapConfig({});
this.testClient = new TestClient(mapConfig, 1234);
this.testClient.getLayergroup(function(err, layergroup) {
assert.ok(!err, err);
assert.ok(layergroup);
assert.ok(layergroup.layergroupid);
done();
});
});
});
it('should fail when invalid dataviews object is provided, array case', function(done) {
var mapConfig = createMapConfig([]);
this.testClient = new TestClient(mapConfig, 1234);
this.testClient.getLayergroup({ response: ERROR_RESPONSE }, function(err, errObj) {
assert.ok(!err, err);
describe('pg_typeof', function() {
assert.deepEqual(errObj.errors, [ '"dataviews" must be a valid JSON object: "array" type found' ]);
done();
afterEach(function(done) {
if (this.testClient) {
this.testClient.drain(done);
} else {
done();
}
});
});
it('should work with empty but valid objects', function(done) {
var mapConfig = createMapConfig({});
this.testClient = new TestClient(mapConfig, 1234);
this.testClient.getLayergroup(function(err, layergroup) {
assert.ok(!err, err);
function createMapConfig(query) {
query = query || 'select * from populated_places_simple_reduced';
assert.ok(layergroup);
assert.ok(layergroup.layergroupid);
return {
version: '1.5.0',
layers: [
{
type: 'mapnik',
options: {
sql: query,
cartocss: '#layer0 { marker-fill: red; marker-width: 10; }',
cartocss_version: '2.0.1',
source: { id: "a0" }
}
}
],
analyses: [{
id: "a0",
type: "source",
params: {
query: query
}
}],
dataviews: {
aggregation_count_dataview: {
type: "aggregation",
source: { id: "a0" },
options: {
column: "adm0name",
aggregation: "count",
aggregationColumn: "adm0name"
}
},
done();
formula_count_dataview: {
type: 'formula',
source: { id: "a0" },
options: {
column: 'adm0_a3',
operation: 'count'
}
},
}
};
}
it('should work without filters', function(done) {
this.testClient = new TestClient(createMapConfig());
this.testClient.getDataview('aggregation_count_dataview', { own_filter: 0 }, function(err, result) {
if (err) {
return done(err);
}
done();
});
});
it('should work with filters', function(done) {
var params = {
filters: {
dataviews: {aggregation_count_dataview: {accept: ['Canada']}}
}
};
this.testClient = new TestClient(createMapConfig());
this.testClient.getDataview('aggregation_count_dataview', params, function(err, result) {
if (err) {
return done(err);
}
done();
});
});
it('should return an error if query row equals to 0', function(done) {
const query = 'select * from populated_places_simple_reduced limit 0';
this.testClient = new TestClient(createMapConfig(query));
this.testClient.getDataview('aggregation_count_dataview', { own_filter: 0 }, function(err, result) {
if (err) {
return done(err);
}
done();
});
});
});
});