Windshaft-cartodb/test/integration/query-tables-test.js

59 lines
2.0 KiB
JavaScript
Raw Normal View History

'use strict';
require('../support/test-helper');
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');
2019-09-13 22:32:37 +08:00
var QueryTables = require('cartodb-query-tables').queryTables;
2016-03-04 02:29:42 +08:00
describe('QueryTables', function() {
var connection;
before(function(done) {
var redisPool = new RedisPool(global.environment.redis);
var metadataBackend = cartodbRedis({pool: redisPool});
var pgConnection = new PgConnection(metadataBackend);
pgConnection.getConnection('localhost', function(err, pgConnection) {
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 16:39:31 +08:00
it('should return an object with affected tables array and last updated time', async function () {
var query = 'select * from test_table';
2019-10-15 16:39:31 +08:00
const result = await QueryTables.getQueryMetadataModel(connection, query);
2019-10-15 16:39:31 +08:00
assert.equal(result.getLastUpdatedAt(), 1234567890123);
2019-10-15 16:39:31 +08:00
assert.equal(result.tables.length, 1);
assert.equal(result.tables[0].dbname, 'test_windshaft_cartodb_user_1_db');
assert.equal(result.tables[0].schema_name, 'public');
assert.equal(result.tables[0].table_name, 'test_table');
});
2019-10-15 16:39:31 +08:00
it('should work with private tables', async function () {
var query = 'select * from test_table_private_1';
2019-10-15 16:39:31 +08:00
const result = await QueryTables.getQueryMetadataModel(connection, query);
2019-10-15 16:39:31 +08:00
assert.equal(result.getLastUpdatedAt(), 1234567890123);
2019-10-15 16:39:31 +08:00
assert.equal(result.tables.length, 1);
assert.equal(result.tables[0].dbname, 'test_windshaft_cartodb_user_1_db');
assert.equal(result.tables[0].schema_name, 'public');
assert.equal(result.tables[0].table_name, 'test_table_private_1');
});
});