2015-12-03 20:43:42 -05:00
|
|
|
'use strict';
|
|
|
|
|
2015-12-07 12:03:42 -05:00
|
|
|
let expect = require('chai').expect,
|
|
|
|
reload = require('require-reload')(require),
|
|
|
|
glob = require('glob'),
|
2016-03-11 10:41:04 -05:00
|
|
|
nodeQuery = reload('../lib/NodeQuery')(),
|
2015-12-08 10:06:29 -05:00
|
|
|
Adapter = reload('../lib/Adapter');
|
2015-12-03 20:43:42 -05:00
|
|
|
|
2016-01-26 19:29:12 -05:00
|
|
|
suite('Base tests -', () => {
|
2015-12-07 12:03:42 -05:00
|
|
|
suite('Sanity check', () => {
|
|
|
|
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');
|
2015-12-07 12:03:42 -05:00
|
|
|
test(`${shortName} module is sane`, () => {
|
|
|
|
expect(obj).to.be.ok;
|
|
|
|
});
|
2015-12-03 20:43:42 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('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();
|
2015-12-07 17:03:36 -05:00
|
|
|
}).to.throw(Error, 'No Query Builder instance to return');
|
2015-12-03 20:43:42 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Invalid driver type', () => {
|
2015-12-07 12:03:42 -05:00
|
|
|
expect(() => {
|
2016-03-11 16:32:38 -05:00
|
|
|
reload('../lib/NodeQuery')({
|
|
|
|
driver: 'Foo',
|
|
|
|
});
|
2015-12-07 17:03:36 -05:00
|
|
|
}).to.throw(Error, 'Selected driver (Foo) does not exist!');
|
2015-12-03 20:43:42 -05:00
|
|
|
});
|
2015-12-08 10:06:29 -05:00
|
|
|
|
|
|
|
test('Invalid adapter', () => {
|
|
|
|
expect(() => {
|
|
|
|
let a = new Adapter();
|
|
|
|
a.execute();
|
|
|
|
}).to.throw(Error, 'Correct adapter not defined for query execution');
|
|
|
|
});
|
2015-12-03 20:43:42 -05:00
|
|
|
});
|