torque/test/provider.windshaft.test.js

181 lines
5.2 KiB
JavaScript
Raw Normal View History

2014-12-09 22:46:03 +08:00
var torque = require('../lib/torque/core');
2014-02-04 00:38:05 +08:00
var windshaft, url;
var lastCall;
var old_net;
2014-12-09 22:46:03 +08:00
QUnit.module('provider.windshaft', {
2014-02-04 00:38:05 +08:00
setup: function() {
2014-02-05 01:13:34 +08:00
old_net = torque.net.jsonp;
old_get = torque.net.get;
torque.net.jsonp = function(url, callback) {
lastCall = url;
callback({ layergroupid: 'testlg', metadata: { torque: { 0: { data_steps:10 }} } });
};
2014-02-04 00:38:05 +08:00
torque.net.get = function(url, callback) {
lastCall = url;
2014-02-05 01:13:34 +08:00
callback(null);
2014-02-04 00:38:05 +08:00
};
windshaft = new torque.providers.windshaft({
table: 'test',
user: "rambo",
cartocss: '#test{}',
sql: 'test',
resolution: 1,
steps: 10,
extra_params: {
testing: 'abcd%'
}
});
2017-11-07 19:06:20 +08:00
},
2014-02-04 00:38:05 +08:00
teardown: function() {
2014-02-05 01:13:34 +08:00
torque.net.jsonp = old_net;
torque.net.get = old_get;
2014-02-04 00:38:05 +08:00
}
});
test("tiler request", function() {
var layergroup = {
"version": "1.0.1",
"stat_tag": 'torque',
"layers": [{
"type": "torque",
"options": {
2014-02-25 23:04:20 +08:00
"cartocss_version": "1.0.0",
"cartocss": 'Map{-torque-frame-count:10;-torque-resolution:1;-torque-aggregation-function:\'undefined\';-torque-time-attribute:\'undefined\';-torque-data-aggregation:linear;}',
2014-02-04 00:38:05 +08:00
"sql": 'test'
}
}]
};
2014-02-06 21:25:47 +08:00
var url = "http://rambo.cartodb.com:80/api/v1/map?config=" + encodeURIComponent(JSON.stringify(layergroup)) + "&callback="
2014-02-04 00:38:05 +08:00
equal(lastCall.indexOf(url), 0);
2014-02-05 01:13:34 +08:00
equal(windshaft.options.data_steps, 10);
2014-02-04 00:38:05 +08:00
});
test("url", function() {
equal(windshaft.url(), "http://rambo.cartodb.com:80");
});
test("url cdn", function() {
windshaft.options.cdn_url = { http: 'cartocdn.com' };
equal(windshaft.url(), "http://{s}.cartocdn.com/rambo");
});
2014-02-25 23:04:20 +08:00
test("url cdn https", function() {
windshaft.options.tiler_protocol = 'https';
2015-03-31 21:20:35 +08:00
windshaft._buildMapsApiTemplate(windshaft.options);
2014-02-25 23:04:20 +08:00
windshaft.options.cdn_url = { https: 'cartocdn.com' };
equal(windshaft.url(), "https://cartocdn.com/rambo");
});
2014-02-04 00:38:05 +08:00
test("named map", function() {
windshaft_named = new torque.providers.windshaft({
table: 'test',
user: "rambo",
named_map: {
name: 'test_named'
}
});
2014-02-06 21:25:47 +08:00
var url = "http://rambo.cartodb.com:80/api/v1/map/named/test_named/jsonp?config";
2014-02-04 00:38:05 +08:00
equal(lastCall.indexOf(url), 0);
});
test("fetch tile", function() {
windshaft._ready = true;
2017-11-07 19:06:20 +08:00
windshaft.getTileData({x: 0, y: 1, corrected: {x: 0, y: 1}}, 2, function() {}, function() {});
2014-02-06 21:25:47 +08:00
equal(lastCall,"http://rambo.cartodb.com:80/api/v1/map/testlg/0/2/0/1.json.torque?testing=abcd%25");
2014-02-04 00:38:05 +08:00
});
2014-02-06 21:25:47 +08:00
test("include auth_token", function() {
windshaft_named = new torque.providers.windshaft({
table: 'test',
user: "rambo",
auth_token: 'test_auth_token',
named_map: {
name: 'test_named'
}
});
ok(lastCall.indexOf("auth_token=test_auth_token") !== -1);
})
2014-10-02 15:07:49 +08:00
test("include stat_tag", function() {
windshaft_named = new torque.providers.windshaft({
table: 'test',
user: "rambo",
stat_tag: 'test',
named_map: {
name: 'test_named'
}
});
ok(lastCall.indexOf("stat_tag=test") !== -1);
})
2015-02-13 23:10:20 +08:00
test("include extra params in named maps", function() {
windshaft_named = new torque.providers.windshaft({
table: 'test',
user: "rambo",
stat_tag: 'test',
named_map: {
name: 'test_named',
params: {
"wololo": "wololo"
}
}
});
ok(lastCall.indexOf("wololo%22%3A%22wololo") !== -1);
})
test("auth_token as array param", function() {
windshaft_named = new torque.providers.windshaft({
table: 'test',
user: "rambo",
auth_token: ['test_auth_token'],
named_map: {
name: 'test_named'
}
});
ok(lastCall.indexOf("auth_token[]=test_auth_token") !== -1);
});
test("auth_token with several params as array param and present in url", function() {
windshaft_named = new torque.providers.windshaft({
table: 'test',
user: "rambo",
auth_token: ['token1', 'token2'],
named_map: {
name: 'test_named'
}
});
ok(lastCall.indexOf("auth_token[]=token1") !== -1);
ok(lastCall.indexOf("auth_token[]=token2") !== -1);
});
2014-02-04 00:38:05 +08:00
[
{ shouldInvokeFetchMap: true, desc: 'undefined no_fetch_map option provided should invoke _fetchMap' },
{ no_fetch_map: false, shouldInvokeFetchMap: true, desc: 'no_fetch_map=false should invoke _fetchMap' },
{ no_fetch_map: true, shouldInvokeFetchMap: false, desc: 'no_fetch_map=true should NOT invoke _fetchMap' }
].forEach(function(fetchMapCase) {
test("no_fetch_map option: " + fetchMapCase.desc, function() {
var fetchMapFn = torque.providers.windshaft.prototype._fetchMap;
var _fetchMapInvoked = false;
torque.providers.windshaft.prototype._fetchMap = function() {
_fetchMapInvoked = true;
};
new torque.providers.windshaft({
table: 'test',
user: "rambo",
no_fetch_map: fetchMapCase.no_fetch_map
});
equal(_fetchMapInvoked, fetchMapCase.shouldInvokeFetchMap);
torque.providers.windshaft.prototype._fetchMap = fetchMapFn;
});
});
2014-02-04 00:38:05 +08:00