Windshaft-cartodb/test/unit/backends/turbo-carto-postgres-datasource-test.js

47 lines
1.6 KiB
JavaScript
Raw Normal View History

'use strict';
2019-10-07 17:29:07 +08:00
var PostgresDatasource = require('../../../lib/backends/turbo-carto-postgres-datasource');
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 () {
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 = [
'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');
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) {
2019-10-25 00:38:37 +08:00
assert.ifError(err);
2019-11-06 23:44:17 +08:00
var expectedResult = {
2019-10-22 01:07:24 +08:00
ramp: [252, 501, 750, 999],
stats: { min_val: 3, max_val: 999, avg_val: 501 },
strategy: undefined
};
2019-11-06 23:44:17 +08:00
assert.deepStrictEqual(result, expectedResult);
2019-10-22 01:07:24 +08:00
done();
});
});
});