2018-10-15 22:29:53 -04:00
|
|
|
const knex = require('../../../knex');
|
|
|
|
const expect = require('chai').expect;
|
2018-07-09 08:10:34 -04:00
|
|
|
|
|
|
|
describe('Postgres Unit Tests', function() {
|
|
|
|
it('Validates searchPath as Array/String', function() {
|
2018-10-15 22:29:53 -04:00
|
|
|
const knexInstance = knex({
|
2018-07-09 08:10:34 -04:00
|
|
|
client: 'pg',
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(function() {
|
|
|
|
knexInstance.client.setSchemaSearchPath(null, {});
|
|
|
|
}).to.throw(TypeError);
|
|
|
|
|
|
|
|
expect(function() {
|
|
|
|
knexInstance.client.setSchemaSearchPath(null, 4);
|
|
|
|
}).to.throw(TypeError);
|
|
|
|
|
2018-10-15 22:29:53 -04:00
|
|
|
const fakeQueryFn = function(expectedSearchPath) {
|
2018-07-09 08:10:34 -04:00
|
|
|
return {
|
|
|
|
query: function(sql, callback) {
|
|
|
|
try {
|
|
|
|
expect(sql).to.equal('set search_path to ' + expectedSearchPath);
|
|
|
|
callback(null);
|
|
|
|
} catch (error) {
|
|
|
|
callback(error);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
return knexInstance.client
|
|
|
|
.setSchemaSearchPath(fakeQueryFn('"public,knex"'), 'public,knex')
|
|
|
|
.then(function() {
|
|
|
|
return knexInstance.client.setSchemaSearchPath(
|
|
|
|
fakeQueryFn('"public","knex"'),
|
|
|
|
['public', 'knex']
|
|
|
|
);
|
|
|
|
})
|
|
|
|
.then(function() {
|
|
|
|
return knexInstance.client.setSchemaSearchPath(
|
|
|
|
fakeQueryFn('"public"'),
|
|
|
|
'public'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|