palos de ciego

This commit is contained in:
Francisco Dans 2015-08-05 12:20:46 +02:00
parent f9bf4264b3
commit 2e03c784ae

View File

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