72 lines
2.6 KiB
JavaScript
72 lines
2.6 KiB
JavaScript
|
require('../helper');
|
||
|
|
||
|
var qs = require('querystring');
|
||
|
|
||
|
var app = require(global.settings.app_root + '/app/app')();
|
||
|
var assert = require('../support/assert');
|
||
|
|
||
|
var QueryTablesApi = require('../../app/services/query-tables-api');
|
||
|
|
||
|
describe('query-tables-api', function() {
|
||
|
|
||
|
var scenarios = [
|
||
|
{
|
||
|
apiKey: 1234,
|
||
|
shouldSkipCache: true
|
||
|
},
|
||
|
{
|
||
|
apiKey: null,
|
||
|
shouldSkipCache: false
|
||
|
}
|
||
|
];
|
||
|
|
||
|
scenarios.forEach(function(scenario) {
|
||
|
var shouldOrShouldNot = scenario.shouldSkipCache ? 'should' : 'should NOT';
|
||
|
var desc = 'authenticated=' + JSON.stringify(!!scenario.apiKey) + ' requests' +
|
||
|
' ' + shouldOrShouldNot + ' skip internal query-tables-api cache';
|
||
|
it(desc, function(done) {
|
||
|
var getAffectedTablesAndLastUpdatedTimeCalled = false;
|
||
|
var skippedCache = null;
|
||
|
var getAffectedTablesAndLastUpdatedTimeFn = QueryTablesApi.prototype.getAffectedTablesAndLastUpdatedTime;
|
||
|
QueryTablesApi.prototype.getAffectedTablesAndLastUpdatedTime =
|
||
|
function(connectionParams, sql, skipCache, callback) {
|
||
|
getAffectedTablesAndLastUpdatedTimeCalled = true;
|
||
|
skippedCache = skipCache;
|
||
|
return callback(null, {
|
||
|
affectedTables: [],
|
||
|
lastModified: Date.now(),
|
||
|
mayWrite: false,
|
||
|
hits: 1
|
||
|
});
|
||
|
};
|
||
|
assert.response(
|
||
|
app,
|
||
|
{
|
||
|
url: '/api/v1/sql?' + qs.stringify({
|
||
|
api_key: scenario.apiKey,
|
||
|
q: 'SELECT * FROM untitle_table_4'
|
||
|
}),
|
||
|
headers: {
|
||
|
host: 'vizzuality.cartodb.com'
|
||
|
},
|
||
|
method: 'GET'
|
||
|
},
|
||
|
{
|
||
|
// status: 200 // not using this as we cannot restore getAffectedTablesAndLastUpdatedTime
|
||
|
},
|
||
|
function(res, err) {
|
||
|
QueryTablesApi.prototype.getAffectedTablesAndLastUpdatedTime = getAffectedTablesAndLastUpdatedTimeFn;
|
||
|
|
||
|
assert.ok(!err, err);
|
||
|
assert.equal(res.statusCode, 200, res.statusCode + ': ' + res.body);
|
||
|
|
||
|
assert.equal(skippedCache, scenario.shouldSkipCache, 'skip cache expected as true');
|
||
|
assert.ok(getAffectedTablesAndLastUpdatedTimeCalled, 'getAffectedTablesAndLastUpdatedTime NOT called');
|
||
|
|
||
|
done();
|
||
|
}
|
||
|
);
|
||
|
});
|
||
|
});
|
||
|
});
|