2018-10-24 00:39:02 +08:00
|
|
|
'use strict';
|
|
|
|
|
2016-05-19 18:10:19 +08:00
|
|
|
var assert = require('assert');
|
2019-10-07 17:29:07 +08:00
|
|
|
var SubstitutionTokens = require('../../lib/utils/substitution-tokens');
|
2016-05-19 18:10:19 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('SubstitutionTokens', function () {
|
2016-05-19 18:10:19 +08:00
|
|
|
var sql = [
|
|
|
|
'WITH hgrid AS (',
|
|
|
|
' SELECT CDB_HexagonGrid(',
|
|
|
|
' ST_Expand(!bbox!, greatest(!pixel_width!,!pixel_height!) * 100),',
|
|
|
|
' greatest(!pixel_width!,!pixel_height!) * 100',
|
|
|
|
' ) as cell',
|
|
|
|
')',
|
|
|
|
'SELECT',
|
|
|
|
' hgrid.cell as the_geom_webmercator,',
|
|
|
|
' count(1) as points_count,',
|
|
|
|
' count(1)/power(100 * CDB_XYZ_Resolution(CDB_ZoomFromScale(!scale_denominator!)), 2) as points_density,',
|
|
|
|
' 1 as cartodb_id',
|
|
|
|
'FROM hgrid, (select * from table) i',
|
|
|
|
'where ST_Intersects(i.the_geom_webmercator, hgrid.cell)',
|
|
|
|
'GROUP BY hgrid.cell'
|
|
|
|
].join('\n');
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should return tokens present in sql', function () {
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(SubstitutionTokens.tokens(sql), ['bbox', 'scale_denominator', 'pixel_width', 'pixel_height']);
|
2016-05-19 18:10:19 +08:00
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should return just one token', function () {
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(SubstitutionTokens.tokens('select !bbox! from wadus'), ['bbox']);
|
2016-05-19 18:10:19 +08:00
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should not return other tokens', function () {
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(SubstitutionTokens.tokens('select !wadus! from wadus'), []);
|
2016-05-19 18:10:19 +08:00
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should report sql has tokens', function () {
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(SubstitutionTokens.hasTokens(sql), true);
|
|
|
|
assert.strictEqual(SubstitutionTokens.hasTokens('select !bbox! from wadus'), true);
|
|
|
|
assert.strictEqual(SubstitutionTokens.hasTokens('select !wadus! from wadus'), false);
|
2016-05-19 18:10:19 +08:00
|
|
|
});
|
|
|
|
});
|