2013-02-14 00:31:53 +08:00
|
|
|
require('../helper');
|
|
|
|
|
2015-05-13 17:21:44 +08:00
|
|
|
var app = require(global.settings.app_root + '/app/controllers/app')();
|
|
|
|
var assert = require('../support/assert');
|
|
|
|
var querystring = require('querystring');
|
|
|
|
var _ = require('underscore');
|
2013-02-14 00:31:53 +08:00
|
|
|
|
|
|
|
// allow lots of emitters to be set to silence warning
|
|
|
|
app.setMaxListeners(0);
|
|
|
|
|
2015-05-13 17:21:44 +08:00
|
|
|
describe('x_cache_channel', function() {
|
2013-02-14 00:31:53 +08:00
|
|
|
|
|
|
|
assert.contains = function(ary, elem) {
|
|
|
|
assert.ok(_.contains(ary,elem), 'missing "' + elem +'" from x-cache-channel: '+ ary);
|
|
|
|
};
|
|
|
|
|
2015-05-13 17:21:44 +08:00
|
|
|
it('supports joins', function(done) {
|
2013-02-14 00:31:53 +08:00
|
|
|
var query = querystring.stringify({
|
2015-05-13 17:21:44 +08:00
|
|
|
q: "SELECT a.name as an, b.name as bn FROM untitle_table_4 a " +
|
|
|
|
"left join private_table b ON (a.cartodb_id = b.cartodb_id)",
|
2013-02-14 00:31:53 +08:00
|
|
|
api_key: 1234
|
|
|
|
});
|
|
|
|
assert.response(app, {
|
|
|
|
url: '/api/v1/sql?' + query,
|
|
|
|
headers: {host: 'vizzuality.cartodb.com' },
|
|
|
|
method: 'GET'
|
|
|
|
},{ }, function(res) {
|
|
|
|
assert.equal(res.statusCode, 200, res.body);
|
|
|
|
// Check x-cache headers
|
|
|
|
var cc = res.headers['x-cache-channel'].split(':');
|
|
|
|
assert.equal(cc[0], 'cartodb_test_user_1_db');
|
|
|
|
var tt = cc[1].split(',');
|
|
|
|
assert.equal(tt.length, 2);
|
2014-06-26 17:22:40 +08:00
|
|
|
assert.contains(tt, 'public.private_table');
|
|
|
|
assert.contains(tt, 'public.untitle_table_4');
|
2013-02-14 00:31:53 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-05-13 17:21:44 +08:00
|
|
|
it('supports multistatements', function(done) {
|
2013-02-14 00:31:53 +08:00
|
|
|
var query = querystring.stringify({
|
|
|
|
q: "SELECT * FROM untitle_table_4; SELECT * FROM private_table",
|
|
|
|
api_key: 1234
|
|
|
|
});
|
|
|
|
assert.response(app, {
|
|
|
|
url: '/api/v1/sql?' + query,
|
|
|
|
headers: {host: 'vizzuality.cartodb.com' },
|
|
|
|
method: 'GET'
|
|
|
|
},{ }, function(res) {
|
|
|
|
assert.equal(res.statusCode, 200, res.body);
|
|
|
|
// Check x-cache headers
|
|
|
|
var cc = res.headers['x-cache-channel'].split(':');
|
|
|
|
assert.equal(cc[0], 'cartodb_test_user_1_db');
|
|
|
|
var tt = cc[1].split(',');
|
|
|
|
assert.equal(tt.length, 2);
|
2014-06-26 17:22:40 +08:00
|
|
|
assert.contains(tt, 'public.private_table');
|
|
|
|
assert.contains(tt, 'public.untitle_table_4');
|
2013-02-14 00:31:53 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-05-13 17:21:44 +08:00
|
|
|
it('supports explicit transactions', function(done) {
|
2013-02-14 00:31:53 +08:00
|
|
|
var query = querystring.stringify({
|
|
|
|
q: "BEGIN; SELECT * FROM untitle_table_4; COMMIT; BEGIN; SELECT * FROM private_table; COMMIT;",
|
|
|
|
api_key: 1234
|
|
|
|
});
|
|
|
|
assert.response(app, {
|
|
|
|
url: '/api/v1/sql?' + query,
|
|
|
|
headers: {host: 'vizzuality.cartodb.com' },
|
|
|
|
method: 'GET'
|
|
|
|
},{ }, function(res) {
|
|
|
|
assert.equal(res.statusCode, 200, res.body);
|
|
|
|
// Check x-cache headers
|
|
|
|
var cc = res.headers['x-cache-channel'].split(':');
|
|
|
|
assert.equal(cc[0], 'cartodb_test_user_1_db');
|
|
|
|
var tt = cc[1].split(',');
|
|
|
|
assert.equal(tt.length, 2);
|
2014-06-26 17:22:40 +08:00
|
|
|
assert.contains(tt, 'public.private_table');
|
|
|
|
assert.contains(tt, 'public.untitle_table_4');
|
2013-02-14 00:31:53 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-05-13 17:21:44 +08:00
|
|
|
it('survives partial transactions', function(done) {
|
2013-02-14 00:31:53 +08:00
|
|
|
var query = querystring.stringify({
|
|
|
|
q: "BEGIN; SELECT * FROM untitle_table_4",
|
|
|
|
api_key: 1234
|
|
|
|
});
|
|
|
|
assert.response(app, {
|
|
|
|
url: '/api/v1/sql?' + query,
|
|
|
|
headers: {host: 'vizzuality.cartodb.com' },
|
|
|
|
method: 'GET'
|
|
|
|
},{ }, function(res) {
|
|
|
|
assert.equal(res.statusCode, 200, res.body);
|
|
|
|
// Check x-cache headers
|
|
|
|
var cc = res.headers['x-cache-channel'].split(':');
|
|
|
|
assert.equal(cc[0], 'cartodb_test_user_1_db');
|
|
|
|
var tt = cc[1].split(',');
|
|
|
|
assert.equal(tt.length, 1);
|
2014-06-26 17:22:40 +08:00
|
|
|
assert.contains(tt, 'public.untitle_table_4');
|
2013-02-14 00:31:53 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|