Remove cartodb folder in unit test
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
'use strict';
|
||||
|
||||
//require('../../../support/test-helper');
|
||||
var assert = require('assert');
|
||||
|
||||
var MapConfigAdapter = require('../../../lib/models/mapconfig/adapter');
|
||||
|
||||
describe('MapConfigAdapter', function() {
|
||||
var user = 'wadus';
|
||||
function requestMapConfig() {
|
||||
return {
|
||||
val: 0
|
||||
};
|
||||
}
|
||||
function params() {
|
||||
return {};
|
||||
}
|
||||
function context() {
|
||||
return {};
|
||||
}
|
||||
|
||||
function createAdapter(valOperatorFn) {
|
||||
return function ValMapConfigAdapter() {
|
||||
this.getMapConfig = function(user, requestMapConfig, params, context, callback) {
|
||||
requestMapConfig.val = valOperatorFn(requestMapConfig.val);
|
||||
return callback(null, requestMapConfig);
|
||||
};
|
||||
};
|
||||
}
|
||||
var IncValMapConfigAdapter = createAdapter(function(val) { return val + 1; });
|
||||
var Mul2ValMapConfigAdapter = createAdapter(function(val) { return val * 2; });
|
||||
|
||||
function validateMapConfig(adapter, expectedNumAdapters, expectedVal, callback) {
|
||||
assert.equal(adapter.adapters.length, expectedNumAdapters);
|
||||
adapter.getMapConfig(user, requestMapConfig(), params(), context(), function(err, mapConfig) {
|
||||
assert.equal(mapConfig.val, expectedVal);
|
||||
return callback(err);
|
||||
});
|
||||
}
|
||||
|
||||
it('works with no adapters', function(done) {
|
||||
var adapter = new MapConfigAdapter();
|
||||
validateMapConfig(adapter, 0, 0, done);
|
||||
});
|
||||
|
||||
it('works with no adapters as empty array', function(done) {
|
||||
var adapter = new MapConfigAdapter([]);
|
||||
validateMapConfig(adapter, 0, 0, done);
|
||||
});
|
||||
|
||||
it('works with basic adapter', function(done) {
|
||||
var adapter = new MapConfigAdapter(new IncValMapConfigAdapter());
|
||||
validateMapConfig(adapter, 1, 1, done);
|
||||
});
|
||||
|
||||
it('works with basic adapter as array', function(done) {
|
||||
var adapter = new MapConfigAdapter([new IncValMapConfigAdapter()]);
|
||||
validateMapConfig(adapter, 1, 1, done);
|
||||
});
|
||||
|
||||
it('works with several adapters', function(done) {
|
||||
var adapter = new MapConfigAdapter(new IncValMapConfigAdapter(), new IncValMapConfigAdapter());
|
||||
validateMapConfig(adapter, 2, 2, done);
|
||||
});
|
||||
|
||||
it('works with several adapters as array', function(done) {
|
||||
var adapter = new MapConfigAdapter([new IncValMapConfigAdapter(), new IncValMapConfigAdapter()]);
|
||||
validateMapConfig(adapter, 2, 2, done);
|
||||
});
|
||||
|
||||
it('should execute in order 1', function(done) {
|
||||
var adapter = new MapConfigAdapter([new Mul2ValMapConfigAdapter(), new IncValMapConfigAdapter()]);
|
||||
validateMapConfig(adapter, 2, 1, done);
|
||||
});
|
||||
|
||||
it('should execute in order 2', function(done) {
|
||||
var adapter = new MapConfigAdapter([new IncValMapConfigAdapter(), new Mul2ValMapConfigAdapter()]);
|
||||
validateMapConfig(adapter, 2, 2, done);
|
||||
});
|
||||
|
||||
it('should execute in order 3', function(done) {
|
||||
var adapter = new MapConfigAdapter([new Mul2ValMapConfigAdapter(), new Mul2ValMapConfigAdapter()]);
|
||||
validateMapConfig(adapter, 2, 0, done);
|
||||
});
|
||||
|
||||
it('should execute in order 4', function(done) {
|
||||
var Mul5ValMapConfigAdapter = createAdapter(function(val) { return val * 5; });
|
||||
var adapter = new MapConfigAdapter(
|
||||
new IncValMapConfigAdapter(),
|
||||
new Mul2ValMapConfigAdapter(),
|
||||
new Mul5ValMapConfigAdapter()
|
||||
);
|
||||
validateMapConfig(adapter, 3, 10, done);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,260 @@
|
||||
'use strict';
|
||||
|
||||
//require('../../../support/test-helper');
|
||||
var assert = require('assert');
|
||||
|
||||
var DataviewsMapConfigAdapter = require('../../../lib/models/mapconfig/adapter/dataviews-widgets-adapter');
|
||||
|
||||
describe('dataviews-widgets-adapter', function() {
|
||||
|
||||
var widgetsMapConfigs = [
|
||||
{
|
||||
"input": {
|
||||
"version": "1.4.0",
|
||||
"layers": [
|
||||
{
|
||||
"type": "mapnik",
|
||||
"options": {
|
||||
"sql": "select * from populated_places_simple_reduced",
|
||||
"cartocss": "#layer { marker-fill: red; marker-width: 32; marker-allow-overlap: true; }",
|
||||
"cartocss_version": "2.3.0",
|
||||
"widgets": {
|
||||
"country_places_count": {
|
||||
"type": "aggregation",
|
||||
"options": {
|
||||
"column": "adm0_a3",
|
||||
"aggregation": "count"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"expected": {
|
||||
"version": "1.4.0",
|
||||
"layers": [
|
||||
{
|
||||
"type": "mapnik",
|
||||
"options": {
|
||||
"source": {
|
||||
"id": "cdb-layer-source-0"
|
||||
},
|
||||
"cartocss": "#layer { marker-fill: red; marker-width: 32; marker-allow-overlap: true; }",
|
||||
"cartocss_version": "2.3.0",
|
||||
// keep them for now
|
||||
"widgets": {
|
||||
"country_places_count": {
|
||||
"type": "aggregation",
|
||||
"options": {
|
||||
"column": "adm0_a3",
|
||||
"aggregation": "count"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"analyses": [
|
||||
{
|
||||
"id": "cdb-layer-source-0",
|
||||
"type": "source",
|
||||
"params": {
|
||||
"query": "select * from populated_places_simple_reduced"
|
||||
}
|
||||
}
|
||||
],
|
||||
"dataviews": {
|
||||
"country_places_count": {
|
||||
"source": {
|
||||
"id": "cdb-layer-source-0"
|
||||
},
|
||||
"type": "aggregation",
|
||||
"options": {
|
||||
"column": "adm0_a3",
|
||||
"aggregation": "count"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"input": {
|
||||
"version": "1.4.0",
|
||||
"layers": [
|
||||
{
|
||||
"type": "mapnik",
|
||||
"options": {
|
||||
"sql": "select * from populated_places_simple_reduced",
|
||||
"cartocss": "#layer { marker-fill: red; marker-width: 32; marker-allow-overlap: true; }",
|
||||
"cartocss_version": "2.3.0",
|
||||
"widgets": {
|
||||
"pop_max": {
|
||||
"type": "histogram",
|
||||
"options": {
|
||||
"column": "pop_max"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"expected": {
|
||||
"version": "1.4.0",
|
||||
"layers": [
|
||||
{
|
||||
"type": "mapnik",
|
||||
"options": {
|
||||
"source": {
|
||||
"id": "cdb-layer-source-0"
|
||||
},
|
||||
"cartocss": "#layer { marker-fill: red; marker-width: 32; marker-allow-overlap: true; }",
|
||||
"cartocss_version": "2.3.0",
|
||||
// keep them for now
|
||||
"widgets": {
|
||||
"pop_max": {
|
||||
"type": "histogram",
|
||||
"options": {
|
||||
"column": "pop_max"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"analyses": [
|
||||
{
|
||||
"id": "cdb-layer-source-0",
|
||||
"type": "source",
|
||||
"params": {
|
||||
"query": "select * from populated_places_simple_reduced"
|
||||
}
|
||||
}
|
||||
],
|
||||
"dataviews": {
|
||||
"pop_max": {
|
||||
"source": {
|
||||
"id": "cdb-layer-source-0"
|
||||
},
|
||||
"type": "histogram",
|
||||
"options": {
|
||||
"column": "pop_max"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"input": {
|
||||
"version": "1.4.0",
|
||||
"layers": [
|
||||
{
|
||||
"type": "mapnik",
|
||||
"options": {
|
||||
"sql": "select * from populated_places_simple_reduced",
|
||||
"cartocss": "#layer { marker-fill: red; marker-width: 32; marker-allow-overlap: true; }",
|
||||
"cartocss_version": "2.3.0",
|
||||
"widgets": {
|
||||
"country_places_count": {
|
||||
"type": "aggregation",
|
||||
"options": {
|
||||
"column": "adm0_a3",
|
||||
"aggregation": "count"
|
||||
}
|
||||
},
|
||||
"country_places_histogram": {
|
||||
"type": "histogram",
|
||||
"options": {
|
||||
"column": "pop_max"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"expected": {
|
||||
"version": "1.4.0",
|
||||
"layers": [
|
||||
{
|
||||
"type": "mapnik",
|
||||
"options": {
|
||||
"source": {
|
||||
"id": "cdb-layer-source-0"
|
||||
},
|
||||
"cartocss": "#layer { marker-fill: red; marker-width: 32; marker-allow-overlap: true; }",
|
||||
"cartocss_version": "2.3.0",
|
||||
// keep them for now
|
||||
"widgets": {
|
||||
"country_places_count": {
|
||||
"type": "aggregation",
|
||||
"options": {
|
||||
"column": "adm0_a3",
|
||||
"aggregation": "count"
|
||||
}
|
||||
},
|
||||
"country_places_histogram": {
|
||||
"type": "histogram",
|
||||
"options": {
|
||||
"column": "pop_max"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"analyses": [
|
||||
{
|
||||
"id": "cdb-layer-source-0",
|
||||
"type": "source",
|
||||
"params": {
|
||||
"query": "select * from populated_places_simple_reduced"
|
||||
}
|
||||
}
|
||||
],
|
||||
"dataviews": {
|
||||
"country_places_count": {
|
||||
"source": {
|
||||
"id": "cdb-layer-source-0"
|
||||
},
|
||||
"type": "aggregation",
|
||||
"options": {
|
||||
"column": "adm0_a3",
|
||||
"aggregation": "count"
|
||||
}
|
||||
},
|
||||
"country_places_histogram": {
|
||||
"source": {
|
||||
"id": "cdb-layer-source-0"
|
||||
},
|
||||
"type": "histogram",
|
||||
"options": {
|
||||
"column": "pop_max"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
var user = 'wadus';
|
||||
function params() {
|
||||
return {};
|
||||
}
|
||||
function context() {
|
||||
return {};
|
||||
}
|
||||
|
||||
var dataviewsMapConfigAdapter = new DataviewsMapConfigAdapter();
|
||||
|
||||
widgetsMapConfigs.forEach(function(mapConfig, index) {
|
||||
it('should adapt widgets ' + index, function(done) {
|
||||
dataviewsMapConfigAdapter.getMapConfig(user, mapConfig.input, params(), context(), function(err, result) {
|
||||
assert.deepEqual(result, mapConfig.expected);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user