2018-10-24 00:39:02 +08:00
|
|
|
'use strict';
|
|
|
|
|
2019-10-07 16:44:45 +08:00
|
|
|
require('../support/test-helper');
|
2016-03-04 02:27:44 +08:00
|
|
|
|
|
|
|
var assert = require('assert');
|
|
|
|
|
|
|
|
var RedisPool = require('redis-mpool');
|
|
|
|
var cartodbRedis = require('cartodb-redis');
|
|
|
|
|
2019-10-07 15:43:40 +08:00
|
|
|
var PgConnection = require('../../lib/backends/pg-connection');
|
2016-03-04 02:27:44 +08:00
|
|
|
|
2019-09-13 22:32:37 +08:00
|
|
|
var QueryTables = require('cartodb-query-tables').queryTables;
|
2016-03-04 02:27:44 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('QueryTables', function () {
|
2016-03-04 02:27:44 +08:00
|
|
|
var connection;
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
before(function (done) {
|
2016-03-04 02:27:44 +08:00
|
|
|
var redisPool = new RedisPool(global.environment.redis);
|
2019-10-22 01:07:24 +08:00
|
|
|
var metadataBackend = cartodbRedis({ pool: redisPool });
|
2016-03-04 02:27:44 +08:00
|
|
|
var pgConnection = new PgConnection(metadataBackend);
|
2019-10-22 01:07:24 +08:00
|
|
|
pgConnection.getConnection('localhost', function (err, pgConnection) {
|
2016-03-04 02:27:44 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
connection = pgConnection;
|
|
|
|
|
|
|
|
return done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Check test/support/sql/windshaft.test.sql to understand where the values come from.
|
|
|
|
|
2019-10-15 17:46:44 +08:00
|
|
|
it('should return an object with affected tables array and last updated time', function () {
|
2016-03-04 02:27:44 +08:00
|
|
|
var query = 'select * from test_table';
|
2019-10-15 17:46:44 +08:00
|
|
|
return QueryTables.getQueryMetadataModel(connection, query)
|
|
|
|
.then(result => {
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(result.getLastUpdatedAt(), 1234567890123);
|
2016-03-04 02:27:44 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(result.tables.length, 1);
|
|
|
|
assert.strictEqual(result.tables[0].dbname, 'test_windshaft_cartodb_user_1_db');
|
|
|
|
assert.strictEqual(result.tables[0].schema_name, 'public');
|
|
|
|
assert.strictEqual(result.tables[0].table_name, 'test_table');
|
2019-10-15 17:46:44 +08:00
|
|
|
});
|
2016-03-04 02:27:44 +08:00
|
|
|
});
|
|
|
|
|
2019-10-15 17:46:44 +08:00
|
|
|
it('should work with private tables', function () {
|
2016-03-04 02:27:44 +08:00
|
|
|
var query = 'select * from test_table_private_1';
|
2019-10-15 17:46:44 +08:00
|
|
|
return QueryTables.getQueryMetadataModel(connection, query)
|
|
|
|
.then(result => {
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(result.getLastUpdatedAt(), 1234567890123);
|
2019-10-15 17:46:44 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(result.tables.length, 1);
|
|
|
|
assert.strictEqual(result.tables[0].dbname, 'test_windshaft_cartodb_user_1_db');
|
|
|
|
assert.strictEqual(result.tables[0].schema_name, 'public');
|
|
|
|
assert.strictEqual(result.tables[0].table_name, 'test_table_private_1');
|
2019-10-15 17:46:44 +08:00
|
|
|
});
|
2016-03-04 02:27:44 +08:00
|
|
|
});
|
2018-10-24 00:39:02 +08:00
|
|
|
});
|