merge master
This commit is contained in:
@@ -70,12 +70,8 @@ describe('aggregations happy cases', function() {
|
||||
].join(' UNION ALL ');
|
||||
|
||||
operations.forEach(function (operation) {
|
||||
var not = operation === 'count' ? ' not ' : ' ';
|
||||
var description = 'should' +
|
||||
not +
|
||||
'handle NULL values in category and aggregation columns using "' +
|
||||
operation +
|
||||
'" as aggregation operation';
|
||||
var description = 'should handle NULL values in category and aggregation columns using "' +
|
||||
operation + '" as aggregation operation';
|
||||
|
||||
it(description, function (done) {
|
||||
this.testClient = new TestClient(aggregationOperationMapConfig(operation, query, 'cat', 'val'));
|
||||
@@ -96,12 +92,7 @@ describe('aggregations happy cases', function() {
|
||||
}
|
||||
});
|
||||
|
||||
if (operation === 'count') {
|
||||
assert.ok(hasNullCategory, 'aggregation has not a category NULL');
|
||||
} else {
|
||||
assert.ok(!hasNullCategory, 'aggregation has category NULL');
|
||||
}
|
||||
|
||||
assert.ok(!hasNullCategory, 'aggregation has category NULL');
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -425,3 +416,79 @@ describe('aggregation dataview tuned by categories query param', function () {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
describe('Count aggregation', function () {
|
||||
const mapConfig = {
|
||||
version: '1.5.0',
|
||||
layers: [
|
||||
{
|
||||
type: "cartodb",
|
||||
options: {
|
||||
source: {
|
||||
"id": "a0"
|
||||
},
|
||||
cartocss: "#points { marker-width: 10; marker-fill: red; }",
|
||||
cartocss_version: "2.3.0"
|
||||
}
|
||||
}
|
||||
],
|
||||
dataviews: {
|
||||
categories: {
|
||||
source: {
|
||||
id: 'a0'
|
||||
},
|
||||
type: 'aggregation',
|
||||
options: {
|
||||
column: 'cat',
|
||||
aggregation: 'count'
|
||||
}
|
||||
}
|
||||
},
|
||||
analyses: [
|
||||
{
|
||||
id: "a0",
|
||||
type: "source",
|
||||
params: {
|
||||
query: `
|
||||
SELECT
|
||||
null::geometry the_geom_webmercator,
|
||||
CASE
|
||||
WHEN x % 4 = 0 THEN 1
|
||||
WHEN x % 4 = 1 THEN 2
|
||||
WHEN x % 4 = 2 THEN 3
|
||||
ELSE null
|
||||
END AS val,
|
||||
CASE
|
||||
WHEN x % 4 = 0 THEN 'category_1'
|
||||
WHEN x % 4 = 1 THEN 'category_2'
|
||||
WHEN x % 4 = 2 THEN 'category_3'
|
||||
ELSE null
|
||||
END AS cat
|
||||
FROM generate_series(1, 1000) x
|
||||
`
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
it(`should handle null values correctly when aggregationColumn isn't provided`, function (done) {
|
||||
this.testClient = new TestClient(mapConfig, 1234);
|
||||
this.testClient.getDataview('categories', { own_filter: 0, categories: 0 }, (err, dataview) => {
|
||||
assert.ifError(err);
|
||||
assert.equal(dataview.categories.length, 3);
|
||||
this.testClient.drain(done);
|
||||
});
|
||||
});
|
||||
|
||||
it(`should handle null values correctly when aggregationColumn is provided`, function (done) {
|
||||
mapConfig.dataviews.categories.options.aggregationColumn = 'val';
|
||||
this.testClient = new TestClient(mapConfig, 1234);
|
||||
this.testClient.getDataview('categories', { own_filter: 0, categories: 0 }, (err, dataview) => {
|
||||
assert.ifError(err);
|
||||
assert.equal(dataview.categories.length, 3);
|
||||
this.testClient.drain(done);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -125,7 +125,7 @@ describe('attributes', function() {
|
||||
var parsed = JSON.parse(res.body);
|
||||
assert.ok(parsed.errors);
|
||||
var msg = parsed.errors[0];
|
||||
assert.ok(msg.match(/0 features.*identified by fid -666/), msg);
|
||||
assert.equal(msg, "Multiple features (0) identified by 'i' = -666 in layer 1");
|
||||
return null;
|
||||
},
|
||||
function finish(err) {
|
||||
|
||||
@@ -12,6 +12,7 @@ describe('lzma-middleware', function() {
|
||||
}
|
||||
};
|
||||
testHelper.lzma_compress_to_base64(JSON.stringify(qo), 1, function(err, data) {
|
||||
const lzma = lzmaMiddleware();
|
||||
var req = {
|
||||
headers: {
|
||||
host:'localhost'
|
||||
@@ -19,9 +20,13 @@ describe('lzma-middleware', function() {
|
||||
query: {
|
||||
api_key: 'test',
|
||||
lzma: data
|
||||
},
|
||||
profiler: {
|
||||
done: function () {}
|
||||
}
|
||||
};
|
||||
lzmaMiddleware(req, {}, function(err) {
|
||||
|
||||
lzma(req, {}, function(err) {
|
||||
if ( err ) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
require('../../../support/test_helper.js');
|
||||
|
||||
var assert = require('assert');
|
||||
|
||||
var LayergroupController = require('../../../../lib/cartodb/controllers/layergroup');
|
||||
|
||||
describe('tile stats', function() {
|
||||
|
||||
beforeEach(function () {
|
||||
this.statsClient = global.statsClient;
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
global.statsClient = this.statsClient;
|
||||
});
|
||||
|
||||
it('finalizeGetTileOrGrid does not call statsClient when format is not supported', function() {
|
||||
var expectedCalls = 2, // it will call increment once for the general error
|
||||
invalidFormat = 'png2',
|
||||
invalidFormatRegexp = new RegExp('invalid'),
|
||||
formatMatched = false;
|
||||
mockStatsClientGetInstance({
|
||||
increment: function(label) {
|
||||
formatMatched = formatMatched || !!label.match(invalidFormatRegexp);
|
||||
expectedCalls--;
|
||||
}
|
||||
});
|
||||
|
||||
var layergroupController = new LayergroupController();
|
||||
|
||||
var reqMock = {
|
||||
profiler: { toJSONString:function() {} },
|
||||
params: {
|
||||
format: invalidFormat
|
||||
}
|
||||
};
|
||||
var resMock = {
|
||||
status: function() { return this; },
|
||||
set: function() {},
|
||||
json: function() {},
|
||||
jsonp: function() {},
|
||||
send: function() {}
|
||||
};
|
||||
|
||||
var next = function () {};
|
||||
layergroupController.finalizeGetTileOrGrid('Unsupported format png2', reqMock, resMock, null, null, next);
|
||||
|
||||
assert.ok(formatMatched, 'Format was never matched in increment method');
|
||||
assert.equal(expectedCalls, 0, 'Unexpected number of calls to increment method');
|
||||
});
|
||||
|
||||
it('finalizeGetTileOrGrid calls statsClient when format is supported', function() {
|
||||
var expectedCalls = 2, // general error + format error
|
||||
validFormat = 'png',
|
||||
validFormatRegexp = new RegExp(validFormat),
|
||||
formatMatched = false;
|
||||
mockStatsClientGetInstance({
|
||||
increment: function(label) {
|
||||
formatMatched = formatMatched || !!label.match(validFormatRegexp);
|
||||
expectedCalls--;
|
||||
}
|
||||
});
|
||||
var reqMock = {
|
||||
profiler: { toJSONString:function() {} },
|
||||
params: {
|
||||
format: validFormat
|
||||
}
|
||||
};
|
||||
var resMock = {
|
||||
status: function() { return this; },
|
||||
set: function() {},
|
||||
json: function() {},
|
||||
jsonp: function() {},
|
||||
send: function() {}
|
||||
};
|
||||
|
||||
var layergroupController = new LayergroupController();
|
||||
|
||||
var next = function () {};
|
||||
layergroupController.finalizeGetTileOrGrid('Another error happened', reqMock, resMock, null, null, next);
|
||||
|
||||
assert.ok(formatMatched, 'Format was never matched in increment method');
|
||||
assert.equal(expectedCalls, 0, 'Unexpected number of calls to increment method');
|
||||
});
|
||||
|
||||
function mockStatsClientGetInstance(instance) {
|
||||
global.statsClient = Object.assign(global.statsClient, instance);
|
||||
}
|
||||
|
||||
});
|
||||
@@ -10,7 +10,7 @@ var TemplateMaps = require('../../../lib/cartodb/backends/template_maps');
|
||||
const cleanUpQueryParamsMiddleware = require('../../../lib/cartodb/middleware/context/clean-up-query-params');
|
||||
const authorizeMiddleware = require('../../../lib/cartodb/middleware/context/authorize');
|
||||
const dbConnSetupMiddleware = require('../../../lib/cartodb/middleware/context/db-conn-setup');
|
||||
const apikeyCredentialsMiddleware = require('../../../lib/cartodb/middleware/context/apikey-credentials');
|
||||
const credentialsMiddleware = require('../../../lib/cartodb/middleware/context/credentials');
|
||||
const localsMiddleware = require('../../../lib/cartodb/middleware/context/locals');
|
||||
|
||||
var windshaft = require('windshaft');
|
||||
@@ -24,7 +24,7 @@ describe('prepare-context', function() {
|
||||
let cleanUpQueryParams;
|
||||
let dbConnSetup;
|
||||
let authorize;
|
||||
let setApikeyCredentials;
|
||||
let setCredentials;
|
||||
|
||||
before(function() {
|
||||
var redisPool = new RedisPool(global.environment.redis);
|
||||
@@ -37,7 +37,7 @@ describe('prepare-context', function() {
|
||||
cleanUpQueryParams = cleanUpQueryParamsMiddleware();
|
||||
authorize = authorizeMiddleware(authApi);
|
||||
dbConnSetup = dbConnSetupMiddleware(pgConnection);
|
||||
setApikeyCredentials = apikeyCredentialsMiddleware();
|
||||
setCredentials = credentialsMiddleware();
|
||||
});
|
||||
|
||||
|
||||
@@ -67,16 +67,17 @@ describe('prepare-context', function() {
|
||||
}
|
||||
|
||||
it('res.locals are created', function(done) {
|
||||
const locals = localsMiddleware();
|
||||
let req = {};
|
||||
let res = {};
|
||||
|
||||
localsMiddleware(prepareRequest(req), prepareResponse(res), function(err) {
|
||||
locals(prepareRequest(req), prepareResponse(res), function(err) {
|
||||
if ( err ) { done(err); return; }
|
||||
assert.ok(res.hasOwnProperty('locals'), 'response has locals');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('cleans up request', function(done){
|
||||
var req = {headers: { host:'localhost' }, query: {dbuser:'hacker',dbname:'secret'}};
|
||||
var res = {};
|
||||
@@ -108,18 +109,18 @@ describe('prepare-context', function() {
|
||||
});
|
||||
|
||||
it('sets also dbuser for authenticated requests', function(done){
|
||||
var req = {
|
||||
headers: {
|
||||
host: 'localhost'
|
||||
},
|
||||
var req = {
|
||||
headers: {
|
||||
host: 'localhost'
|
||||
},
|
||||
query: {
|
||||
api_key: '1234'
|
||||
}
|
||||
};
|
||||
var res = {
|
||||
var res = {
|
||||
set: function () {},
|
||||
locals: {
|
||||
api_key: '1234'
|
||||
api_key: '1234'
|
||||
}
|
||||
};
|
||||
|
||||
@@ -171,7 +172,7 @@ describe('prepare-context', function() {
|
||||
}
|
||||
};
|
||||
var res = {};
|
||||
|
||||
|
||||
cleanUpQueryParams(prepareRequest(req), prepareResponse(res), function (err) {
|
||||
if ( err ) {
|
||||
return done(err);
|
||||
@@ -196,12 +197,12 @@ describe('prepare-context', function() {
|
||||
}
|
||||
};
|
||||
var res = {};
|
||||
setApikeyCredentials(prepareRequest(req), prepareResponse(res), function (err) {
|
||||
setCredentials(prepareRequest(req), prepareResponse(res), function (err) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
var query = res.locals;
|
||||
|
||||
|
||||
assert.equal('1234', query.api_key);
|
||||
done();
|
||||
});
|
||||
@@ -217,7 +218,7 @@ describe('prepare-context', function() {
|
||||
}
|
||||
};
|
||||
var res = {};
|
||||
setApikeyCredentials(prepareRequest(req), prepareResponse(res), function (err) {
|
||||
setCredentials(prepareRequest(req), prepareResponse(res), function (err) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
@@ -236,7 +237,7 @@ describe('prepare-context', function() {
|
||||
}
|
||||
};
|
||||
var res = {};
|
||||
setApikeyCredentials(prepareRequest(req), prepareResponse(res), function (err) {
|
||||
setCredentials(prepareRequest(req), prepareResponse(res), function (err) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user