From 74898e4261f22edb1b6cfff8a4a8f7c0ae161aa9 Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Wed, 30 Dec 2015 17:48:24 +0100 Subject: [PATCH] Integration tests for QueryTablesApi Again this is more about how it would be possible to use it isolated. --- test/integration/query-tables-api.js | 55 ++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 test/integration/query-tables-api.js diff --git a/test/integration/query-tables-api.js b/test/integration/query-tables-api.js new file mode 100644 index 00000000..d05b1ed0 --- /dev/null +++ b/test/integration/query-tables-api.js @@ -0,0 +1,55 @@ +require('../support/test_helper'); + +var assert = require('assert'); + +var RedisPool = require('redis-mpool'); +var cartodbRedis = require('cartodb-redis'); + +var PgConnection = require('../../lib/cartodb/backends/pg_connection'); +var PgQueryRunner = require('../../lib/cartodb/backends/pg_query_runner'); +var QueryTablesApi = require('../../lib/cartodb/api/query_tables_api'); + + +describe('QueryTablesApi', function() { + + var queryTablesApi; + + before(function() { + var redisPool = new RedisPool(global.environment.redis); + var metadataBackend = cartodbRedis({pool: redisPool}); + var pgConnection = new PgConnection(metadataBackend); + var pgQueryRunner = new PgQueryRunner(pgConnection); + queryTablesApi = new QueryTablesApi(pgQueryRunner); + }); + + // Check test/support/sql/windshaft.test.sql to understand where the values come from. + + it('should return an object with affected tables array and last updated time', function(done) { + var query = 'select * from test_table'; + queryTablesApi.getAffectedTablesAndLastUpdatedTime('localhost', query, function(err, result) { + assert.ok(!err, err); + + assert.deepEqual(result, { + affectedTables: [ 'public.test_table' ], + lastUpdatedTime: 1234567890123 + }); + + done(); + }); + }); + + it('should work with private tables', function(done) { + var query = 'select * from test_table_private_1'; + queryTablesApi.getAffectedTablesAndLastUpdatedTime('localhost', query, function(err, result) { + assert.ok(!err, err); + + assert.deepEqual(result, { + affectedTables: [ 'public.test_table_private_1' ], + lastUpdatedTime: 1234567890123 + }); + + done(); + }); + }); + +});