2016-09-14 16:50:32 -04:00
|
|
|
const reload = require('require-reload')(require);
|
|
|
|
const glob = require('glob');
|
|
|
|
const nodeQuery = reload('../lib/NodeQuery')();
|
|
|
|
const Adapter = reload('../lib/Adapter');
|
2015-12-03 20:43:42 -05:00
|
|
|
|
2017-02-28 15:47:29 -05:00
|
|
|
describe('Base tests -', () => {
|
|
|
|
describe('Sanity check', () => {
|
2015-12-07 12:03:42 -05:00
|
|
|
let files = glob.sync(`${__dirname}/../lib/**/*.js`);
|
|
|
|
files.forEach(mod => {
|
|
|
|
let obj = require(mod);
|
2015-12-07 17:03:36 -05:00
|
|
|
let shortName = mod.replace(/^\/(.*?)\/lib\/(.*?)\.js$/g, '$2');
|
2017-02-28 15:47:29 -05:00
|
|
|
it(`${shortName} module is sane`, () => {
|
2018-02-02 11:50:29 -05:00
|
|
|
expect(obj).toEqual(expect.anything());
|
2015-12-07 12:03:42 -05:00
|
|
|
});
|
2015-12-03 20:43:42 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-02-28 15:47:29 -05:00
|
|
|
it('NodeQuery.getQuery with no instance', () => {
|
2015-12-07 12:03:42 -05:00
|
|
|
// Hack for testing to work around node
|
|
|
|
// module caching
|
|
|
|
let nodeQueryCopy = Object.create(nodeQuery);
|
|
|
|
nodeQueryCopy.instance = null;
|
|
|
|
expect(() => {
|
|
|
|
nodeQueryCopy.getQuery();
|
2018-02-02 11:50:29 -05:00
|
|
|
}).toThrow(Error, 'No Query Builder instance to return');
|
2015-12-03 20:43:42 -05:00
|
|
|
});
|
|
|
|
|
2017-02-28 15:47:29 -05:00
|
|
|
it('Invalid driver type', () => {
|
2015-12-07 12:03:42 -05:00
|
|
|
expect(() => {
|
2016-03-11 16:32:38 -05:00
|
|
|
reload('../lib/NodeQuery')({
|
2016-09-14 16:50:32 -04:00
|
|
|
driver: 'Foo'
|
2016-03-11 16:32:38 -05:00
|
|
|
});
|
2018-02-02 11:50:29 -05:00
|
|
|
}).toThrow(Error, 'Selected driver (Foo) does not exist!');
|
2015-12-03 20:43:42 -05:00
|
|
|
});
|
2015-12-08 10:06:29 -05:00
|
|
|
|
2017-02-28 15:47:29 -05:00
|
|
|
it('Invalid adapter', () => {
|
2015-12-08 10:06:29 -05:00
|
|
|
expect(() => {
|
|
|
|
let a = new Adapter();
|
|
|
|
a.execute();
|
2018-02-02 11:50:29 -05:00
|
|
|
}).toThrow(Error, 'Correct adapter not defined for query execution');
|
2015-12-08 10:06:29 -05:00
|
|
|
});
|
2016-03-15 15:37:24 -04:00
|
|
|
|
2017-02-28 15:47:29 -05:00
|
|
|
it('Invalid adapter - missing transformResult', () => {
|
2016-03-15 15:37:24 -04:00
|
|
|
expect(() => {
|
|
|
|
let a = new Adapter();
|
|
|
|
a.transformResult([]);
|
2018-02-02 11:50:29 -05:00
|
|
|
}).toThrow(Error, 'Result transformer method not defined for current adapter');
|
2016-03-15 15:37:24 -04:00
|
|
|
});
|
2016-09-14 16:50:32 -04:00
|
|
|
});
|