2014-02-04 00:38:05 +08:00
|
|
|
var windshaft, url;
|
|
|
|
var lastCall;
|
|
|
|
var old_net;
|
|
|
|
module('provider.windshaft', {
|
|
|
|
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%'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
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",
|
2014-07-07 20:50:48 +08:00
|
|
|
"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';
|
|
|
|
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;
|
|
|
|
windshaft.getTileData({x: 0, y: 1}, 2, 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);
|
|
|
|
})
|
|
|
|
|
2014-07-07 20:50:48 +08:00
|
|
|
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
|
|
|
|
|
|
|
|