node-query/test/adapters/mysql2_test.js

68 lines
1.5 KiB
JavaScript
Raw Normal View History

/* eslint-env node, mocha */
2015-12-07 12:03:42 -05:00
'use strict';
// Load the test base
const reload = require('require-reload')(require);
2015-12-07 12:03:42 -05:00
reload.emptyCache();
const testBase = reload('../base');
const expect = testBase.expect;
const testRunner = testBase.promiseTestRunner;
2015-12-07 12:03:42 -05:00
// Load the test config file
let adapterName = 'mysql2';
const config = testBase.config[adapterName];
2015-12-07 12:03:42 -05:00
// Set up the query builder object
let nodeQuery = reload('../../lib/NodeQuery')(config);
let qb = nodeQuery.getQuery();
2016-03-11 16:32:38 -05:00
suite('Mysql2 adapter tests -', () => {
suiteSetup(done => {
qb.queryFile(`${__dirname}/../sql/mysql.sql`)
.then(() => done())
.catch(e => done(e));
});
2016-03-11 16:32:38 -05:00
test('nodeQuery.getQuery = nodeQuery.init', () => {
expect(nodeQuery.getQuery())
.to.be.deep.equal(qb);
});
testRunner(qb);
2016-03-11 16:32:38 -05:00
test('Promise - Select with function and argument in WHERE clause', () => {
let promise = qb.select('id')
.from('create_test')
.where('id', 'CEILING(SQRT(88))')
.get();
2016-03-11 16:32:38 -05:00
return expect(promise).to.be.fulfilled;
});
test('Test Truncate', () => {
let promise = qb.truncate('create_test');
return expect(promise).to.be.fullfilled;
});
2016-03-11 16:32:38 -05:00
test('Test Insert Batch', () => {
let data = [
{
id: 5442,
key: 4,
val: Buffer.from('7')
2016-03-11 16:32:38 -05:00
}, {
id: 892,
key: 35,
val: Buffer.from('10 o\'clock')
2016-03-11 16:32:38 -05:00
}, {
id: 482,
key: 404,
val: 97
}
2016-03-11 16:32:38 -05:00
];
2016-03-11 16:32:38 -05:00
return expect(qb.insertBatch('create_test', data)).to.be.fulfilled;
});
/* suiteTeardown(() => {
2016-03-11 16:32:38 -05:00
qb.end();
}); */
2016-03-11 16:32:38 -05:00
});