2016-02-01 23:53:28 +08:00
|
|
|
require('../helper');
|
|
|
|
|
|
|
|
var qs = require('querystring');
|
|
|
|
|
|
|
|
var app = require(global.settings.app_root + '/app/app')();
|
|
|
|
var assert = require('../support/assert');
|
|
|
|
|
|
|
|
describe('query-tables-api', function() {
|
|
|
|
|
2016-02-02 08:16:24 +08:00
|
|
|
function getCacheStatus(callback) {
|
|
|
|
assert.response(
|
|
|
|
app,
|
|
|
|
{
|
|
|
|
method: 'GET',
|
|
|
|
url: '/api/v1/cachestatus'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
status: 200
|
|
|
|
},
|
|
|
|
function(res) {
|
|
|
|
callback(null, JSON.parse(res.body));
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
var request = {
|
|
|
|
url: '/api/v1/sql?' + qs.stringify({
|
|
|
|
q: 'SELECT * FROM untitle_table_4'
|
|
|
|
}),
|
|
|
|
headers: {
|
|
|
|
host: 'vizzuality.cartodb.com'
|
2016-02-01 23:53:28 +08:00
|
|
|
},
|
2016-02-02 08:16:24 +08:00
|
|
|
method: 'GET'
|
|
|
|
};
|
|
|
|
|
|
|
|
var RESPONSE_OK = {
|
|
|
|
status: 200
|
|
|
|
};
|
|
|
|
|
|
|
|
it('should create a key in affected tables cache', function(done) {
|
|
|
|
assert.response(app, request, RESPONSE_OK, function(res, err) {
|
|
|
|
assert.ok(!err, err);
|
2016-02-01 23:53:28 +08:00
|
|
|
|
2016-02-02 08:16:24 +08:00
|
|
|
getCacheStatus(function(err, cacheStatus) {
|
|
|
|
assert.ok(!err, err);
|
|
|
|
assert.equal(cacheStatus.explain.keys, 1);
|
2016-03-08 21:50:08 +08:00
|
|
|
assert.equal(cacheStatus.explain.hits, 0);
|
2016-02-02 08:16:24 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2016-02-01 23:53:28 +08:00
|
|
|
|
2016-02-02 08:16:24 +08:00
|
|
|
it('should use cache to retrieve affected tables', function(done) {
|
|
|
|
assert.response(app, request, RESPONSE_OK, function(res, err) {
|
|
|
|
assert.ok(!err, err);
|
2016-02-01 23:53:28 +08:00
|
|
|
|
2016-02-02 08:16:24 +08:00
|
|
|
getCacheStatus(function(err, cacheStatus) {
|
|
|
|
assert.ok(!err, err);
|
|
|
|
assert.equal(cacheStatus.explain.keys, 1);
|
2016-03-08 21:50:08 +08:00
|
|
|
assert.equal(cacheStatus.explain.hits, 1);
|
2016-02-01 23:53:28 +08:00
|
|
|
|
2016-02-02 08:16:24 +08:00
|
|
|
done();
|
|
|
|
});
|
2016-02-01 23:53:28 +08:00
|
|
|
});
|
|
|
|
});
|
2016-03-11 02:20:56 +08:00
|
|
|
|
|
|
|
it('should skip cache to retrieve affected tables', function(done) {
|
|
|
|
var authenticatedRequest = {
|
|
|
|
url: '/api/v1/sql?' + qs.stringify({
|
|
|
|
q: 'SELECT * FROM untitle_table_4',
|
|
|
|
api_key: '1234'
|
|
|
|
}),
|
|
|
|
headers: {
|
|
|
|
host: 'vizzuality.cartodb.com'
|
|
|
|
},
|
|
|
|
method: 'GET'
|
|
|
|
};
|
|
|
|
assert.response(app, authenticatedRequest, RESPONSE_OK, function(res, err) {
|
|
|
|
assert.ok(!err, err);
|
|
|
|
|
|
|
|
getCacheStatus(function(err, cacheStatus) {
|
|
|
|
assert.ok(!err, err);
|
|
|
|
assert.equal(cacheStatus.explain.keys, 1);
|
|
|
|
assert.equal(cacheStatus.explain.hits, 0);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2016-02-01 23:53:28 +08:00
|
|
|
});
|