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();
2017-02-28 15:47:29 -05:00
describe('Mysql2 adapter tests -', () => {
beforeAll(done => {
qb.queryFile(`${__dirname}/../sql/mysql.sql`)
.then(() => done())
.catch(e => done(e));
});
2017-02-28 15:47:29 -05:00
it('nodeQuery.getQuery = nodeQuery.init', () => {
2016-03-11 16:32:38 -05:00
expect(nodeQuery.getQuery())
.to.be.deep.equal(qb);
});
testRunner(qb);
2017-02-28 15:47:29 -05:00
it('Promise - Select with function and argument in WHERE clause', () => {
2016-03-11 16:32:38 -05:00
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;
});
2017-02-28 15:47:29 -05:00
it('Test Truncate', () => {
let promise = qb.truncate('create_test');
return expect(promise).to.be.fullfilled;
});
2017-02-28 15:47:29 -05:00
it('Test Insert Batch', () => {
2016-03-11 16:32:38 -05:00
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;
});
2017-02-28 15:47:29 -05:00
/* describeTeardown(() => {
2016-03-11 16:32:38 -05:00
qb.end();
}); */
2016-03-11 16:32:38 -05:00
});