1 /*jshint trailing:true, white:true, indent:2, strict:true, curly:true,
2 immed:true, eqeqeq:true, forin:true, latedef:true,
3 newcap:true, noarg:true, undef:true */
4 /*global XT:true, describe:true, it:true, require:true, __dirname:true, after:true */
6 var _ = require("underscore"),
7 assert = require('chai').assert,
8 datasource = require('../../node-datasource/lib/ext/datasource').dataSource,
9 path = require('path');
13 describe('The database', function () {
14 this.timeout(10 * 1000);
16 var loginData = require(path.join(__dirname, "../lib/login_data.js")).data,
17 datasource = require('../../../xtuple/node-datasource/lib/ext/datasource').dataSource,
18 config = require(path.join(__dirname, "../../node-datasource/config.js")),
19 creds = config.databaseServer,
20 databaseName = loginData.org;
22 it('must not have any overriden tables or views', function (done) {
23 var sql = "select pub.relname " +
24 "from pg_class pub " +
25 "inner join pg_namespace pubns on pub.relnamespace = pubns.oid and pubns.nspname = 'public' " +
26 "inner join pg_class xt on pub.relname = xt.relname " +
27 "inner join pg_namespace xtns on xt.relnamespace = xtns.oid and xtns.nspname = 'xt' " +
28 "where pub.relkind NOT IN ('i', 'c'); ";
30 creds.database = databaseName;
31 datasource.query(sql, creds, function (err, res) {
33 assert.equal(1, res.rowCount, JSON.stringify(res.rows));
34 // TODO: we should eliminate this override as well, either by renaming and migrating
35 // the xt table, or by removing the public table if (as we suspect) it is not used.
36 assert.equal(res.rows[0].relname, "potype");
41 it('must only override a few whitelisted functions', function (done) {
42 var sql = "select pub.proname " +
44 "inner join pg_namespace pubns on pub.pronamespace = pubns.oid and pubns.nspname = 'public' " +
45 "inner join pg_proc xt on pub.proname = xt.proname " +
46 "inner join pg_namespace xtns on xt.pronamespace = xtns.oid and xtns.nspname = 'xt'; ";
48 creds.database = databaseName;
49 datasource.query(sql, creds, function (err, res) {
50 var overriddenFunctions = _.map(res.rows, function (row) {
53 whitelist = ["cntctmerge", "cntctrestore", "createuser",
54 "mergecrmaccts", "trylock", "undomerge"],
55 illegalFunctions = _.difference(overriddenFunctions, whitelist);
58 assert.equal(illegalFunctions.length, 0, JSON.stringify(illegalFunctions));