2015-12-07 12:03:42 -05:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// Load the test base
|
2016-01-26 19:29:12 -05:00
|
|
|
const reload = require('require-reload')(require);
|
|
|
|
reload.emptyCache();
|
|
|
|
const testBase = reload('../base');
|
|
|
|
const expect = testBase.expect,
|
|
|
|
promiseTestRunner = testBase.promiseTestRunner,
|
|
|
|
testRunner = testBase.testRunner;
|
|
|
|
|
|
|
|
let tests = reload('../base/tests');
|
2015-12-07 12:03:42 -05:00
|
|
|
|
|
|
|
// Load the test config file
|
|
|
|
let adapterName = 'dblite';
|
|
|
|
let sqlite = null;
|
|
|
|
let connection = null;
|
|
|
|
|
|
|
|
// Set up the connection
|
|
|
|
try {
|
|
|
|
sqlite = require(adapterName).withSQLite('3.7.11');
|
|
|
|
connection = sqlite(':memory:');
|
|
|
|
} catch (e) {
|
|
|
|
// Export an empty testsuite if module not loaded
|
|
|
|
}
|
|
|
|
|
|
|
|
if (connection) {
|
|
|
|
// Set up the query builder object
|
|
|
|
let nodeQuery = require('../../lib/NodeQuery');
|
|
|
|
let qb = nodeQuery.init('sqlite', connection, adapterName);
|
|
|
|
|
2016-01-26 19:29:12 -05:00
|
|
|
suite('Dblite adapter tests -', () => {
|
|
|
|
suiteSetup(done => {
|
2015-12-07 12:03:42 -05:00
|
|
|
// Set up the sqlite database
|
|
|
|
let sql = 'CREATE TABLE IF NOT EXISTS "create_test" ("id" INTEGER PRIMARY KEY, "key" TEXT, "val" TEXT);' +
|
|
|
|
'CREATE TABLE IF NOT EXISTS "create_join" ("id" INTEGER PRIMARY KEY, "key" TEXT, "val" TEXT);';
|
2016-01-26 19:29:12 -05:00
|
|
|
connection.query(sql, () => {
|
|
|
|
return done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
test('nodeQuery.getQuery = nodeQuery.init', () => {
|
|
|
|
expect(nodeQuery.getQuery())
|
|
|
|
.to.be.deep.equal(qb);
|
2015-12-07 12:03:42 -05:00
|
|
|
});
|
2016-01-26 19:29:12 -05:00
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
Callback Tests
|
|
|
|
---------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
testRunner(qb, (err, done) => {
|
2015-12-07 12:03:42 -05:00
|
|
|
expect(err).is.not.ok;
|
|
|
|
done();
|
|
|
|
});
|
2016-01-26 19:29:12 -05:00
|
|
|
test('Callback - Select with function and argument in WHERE clause', done => {
|
|
|
|
qb.select('id')
|
|
|
|
.from('create_test')
|
|
|
|
.where('id', 'ABS(-88)')
|
|
|
|
.get((err, rows) => {
|
2015-12-07 14:33:48 -05:00
|
|
|
expect(err).is.not.ok;
|
|
|
|
return done();
|
|
|
|
});
|
2016-01-26 19:29:12 -05:00
|
|
|
});
|
|
|
|
test('Callback - Test Insert Batch', done => {
|
|
|
|
let data = [
|
|
|
|
{
|
|
|
|
id: 544,
|
|
|
|
key: 3,
|
|
|
|
val: new Buffer('7'),
|
|
|
|
}, {
|
|
|
|
id: 89,
|
|
|
|
key: 34,
|
|
|
|
val: new Buffer('10 o\'clock'),
|
|
|
|
}, {
|
|
|
|
id: 48,
|
|
|
|
key: 403,
|
|
|
|
val: new Buffer('97'),
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
qb.insertBatch('create_test', data, (err, rows) => {
|
|
|
|
expect(err).is.not.ok;
|
|
|
|
return done();
|
2015-12-07 14:33:48 -05:00
|
|
|
});
|
2015-12-07 12:03:42 -05:00
|
|
|
});
|
2016-01-26 19:29:12 -05:00
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
Promise Tests
|
|
|
|
---------------------------------------------------------------------------*/
|
|
|
|
promiseTestRunner(qb);
|
|
|
|
test('Promise - Select with function and argument in WHERE clause', () => {
|
|
|
|
let promise = qb.select('id')
|
|
|
|
.from('create_test')
|
|
|
|
.where('id', 'ABS(-88)')
|
|
|
|
.get();
|
|
|
|
|
|
|
|
expect(promise).to.be.fulfilled;
|
|
|
|
});
|
|
|
|
|
2015-12-07 12:03:42 -05:00
|
|
|
suiteTeardown(() => {
|
2015-12-07 15:58:31 -05:00
|
|
|
qb.end();
|
2015-12-07 12:03:42 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|