2014-12-09 22:46:03 +08:00
|
|
|
var torque = require('../lib/torque');
|
|
|
|
var providers = torque.providers;
|
2013-10-10 16:59:19 +08:00
|
|
|
|
2017-11-07 21:40:05 +08:00
|
|
|
var json, url, _XMLHttpRequest;
|
2014-12-09 22:46:03 +08:00
|
|
|
QUnit.module('provider.json');
|
2017-11-07 21:40:05 +08:00
|
|
|
QUnit.moduleStart(function() {
|
|
|
|
_XMLHttpRequest = window.XMLHttpRequest;
|
|
|
|
window.XMLHttpRequest = function () {
|
|
|
|
return {
|
|
|
|
open: function () { },
|
|
|
|
send: function () { },
|
|
|
|
readyState: 4,
|
|
|
|
responseText: {}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
QUnit.moduleDone(function() {
|
|
|
|
window.XMLHttpRequest = _XMLHttpRequest;
|
|
|
|
});
|
2013-10-15 16:40:31 +08:00
|
|
|
QUnit.testStart(function() {
|
2014-12-09 22:46:03 +08:00
|
|
|
json = new providers.json({
|
2013-10-17 21:51:12 +08:00
|
|
|
table: 'test',
|
2013-10-31 21:41:19 +08:00
|
|
|
user: "rambo",
|
2013-10-10 16:59:19 +08:00
|
|
|
resolution: 1,
|
2013-10-15 16:40:31 +08:00
|
|
|
steps: 10,
|
|
|
|
extra_params: {
|
|
|
|
testing: 'abcd%'
|
|
|
|
}
|
2013-10-10 16:59:19 +08:00
|
|
|
});
|
2013-10-15 16:40:31 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test("url", function() {
|
2013-10-10 16:59:19 +08:00
|
|
|
equal("http://rambo.cartodb.com/api/v2/sql", json.url());
|
|
|
|
});
|
|
|
|
|
2013-10-15 16:40:31 +08:00
|
|
|
test("extra_params", function() {
|
|
|
|
var url = "http://rambo.cartodb.com/api/v2/sql?q=1&testing=abcd%25";
|
|
|
|
json.sql('1');
|
|
|
|
equal(torque.net.lastCall().url, url);
|
|
|
|
});
|
|
|
|
|
2013-11-09 00:09:19 +08:00
|
|
|
test("no_cdn", function() {
|
|
|
|
var url = "http://rambo.cartodb.com/api/v2/sql?q=1&testing=abcd%25";
|
2014-12-10 01:11:10 +08:00
|
|
|
json.options.cdn_url = { http: 'test.com' };
|
2013-11-09 00:09:19 +08:00
|
|
|
json.sql('1', null, { no_cdn: true });
|
|
|
|
equal(torque.net.lastCall().url, url);
|
|
|
|
});
|
|
|
|
|
2013-10-17 21:51:12 +08:00
|
|
|
test("getSQL", function() {
|
|
|
|
var s;
|
|
|
|
equal(json.getSQL(), "select * from test");
|
|
|
|
json.setSQL(s='select * from test limit 10');
|
|
|
|
equal(json.getSQL(), s);
|
|
|
|
json.setSQL(null);
|
|
|
|
equal(json.getSQL(), "select * from test");
|
|
|
|
});
|
|
|
|
|
2013-11-01 02:07:27 +08:00
|
|
|
test("cdn_url", function() {
|
|
|
|
json.options.cdn_url = { http: 'test.com' };
|
2013-11-09 00:09:19 +08:00
|
|
|
equal(json.url('a'), 'http://a.test.com/rambo/api/v2/sql');
|
2013-11-01 02:07:27 +08:00
|
|
|
});
|
|
|
|
|
2013-10-10 16:59:19 +08:00
|
|
|
|
|
|
|
|