2018-10-24 00:39:02 +08:00
|
|
|
'use strict';
|
|
|
|
|
2019-10-07 17:29:07 +08:00
|
|
|
var PostgresDatasource = require('../../../lib/backends/turbo-carto-postgres-datasource');
|
2017-08-04 01:07:02 +08:00
|
|
|
var PSQL = require('cartodb-psql');
|
|
|
|
var _ = require('underscore');
|
|
|
|
var assert = require('assert');
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('turbo-carto-postgres-datasource', function () {
|
2017-08-04 01:07:02 +08:00
|
|
|
beforeEach(function () {
|
|
|
|
const dbname = _.template(global.environment.postgres_auth_user, { user_id: 1 }) + '_db';
|
|
|
|
const psql = new PSQL({
|
|
|
|
user: 'postgres',
|
|
|
|
dbname: dbname,
|
|
|
|
host: global.environment.postgres.host,
|
|
|
|
port: global.environment.postgres.port
|
|
|
|
});
|
2019-10-22 01:07:24 +08:00
|
|
|
const sql = [
|
2017-08-04 01:07:02 +08:00
|
|
|
'SELECT',
|
|
|
|
' null::geometry the_geom_webmercator,',
|
|
|
|
' CASE',
|
|
|
|
' WHEN x % 4 = 0 THEN \'infinity\'::float',
|
|
|
|
' WHEN x % 4 = 1 THEN \'-infinity\'::float',
|
|
|
|
' WHEN x % 4 = 2 THEN \'NaN\'::float',
|
|
|
|
' ELSE x',
|
|
|
|
' END AS values',
|
|
|
|
'FROM generate_series(1, 1000) x'
|
2017-08-04 01:16:08 +08:00
|
|
|
].join('\n');
|
2017-08-04 01:07:02 +08:00
|
|
|
this.datasource = new PostgresDatasource(psql, sql);
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should ignore NaNs and Infinities when computing ramps', function (done) {
|
|
|
|
var column = 'values';
|
|
|
|
var buckets = 4;
|
|
|
|
var method = 'equal';
|
|
|
|
this.datasource.getRamp(column, buckets, method, function (err, result) {
|
|
|
|
var expected_result = {
|
|
|
|
ramp: [252, 501, 750, 999],
|
|
|
|
stats: { min_val: 3, max_val: 999, avg_val: 501 },
|
|
|
|
strategy: undefined
|
2017-08-04 01:07:02 +08:00
|
|
|
};
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(result, expected_result);
|
2019-10-22 01:07:24 +08:00
|
|
|
done();
|
|
|
|
});
|
2017-08-04 01:07:02 +08:00
|
|
|
});
|
|
|
|
});
|