replace mysql module with mysql2
mysql is deprecated since years now
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
/* global it:false */
|
||||
/* global describe:false */
|
||||
/* global before:false */
|
||||
/* global it, describe, before, after */
|
||||
|
||||
'use strict';
|
||||
|
||||
const database = require('../database'),
|
||||
const BoxError = require('../boxerror.js'),
|
||||
database = require('../database'),
|
||||
expect = require('expect.js'),
|
||||
fs = require('fs'),
|
||||
safe = require('safetydance');
|
||||
|
||||
describe('database', function () {
|
||||
@@ -24,7 +22,54 @@ describe('database', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('importFromFile', function () {
|
||||
describe('query', function () {
|
||||
before(async () => { await database.initialize(); });
|
||||
after(async () => { await database.uninitialize(); });
|
||||
|
||||
it('basic query', async function () {
|
||||
const result = await database.query('SELECT COUNT(*) as count FROM apps');
|
||||
expect(result[0].count).to.be(0);
|
||||
});
|
||||
|
||||
it('bad queries', async function () {
|
||||
const queries = [
|
||||
'SELECT COUNT(*) FROM oops', // bad table
|
||||
'SELECT', // incomplete
|
||||
];
|
||||
|
||||
for (const query of queries) {
|
||||
const [error] = await safe(database.query(query));
|
||||
expect(error.reason).to.be(BoxError.DATABASE_ERROR);
|
||||
expect(error.sqlMessage).to.be.a('string');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('transaction', function () {
|
||||
before(async () => { await database.initialize(); });
|
||||
after(async () => { await database.uninitialize(); });
|
||||
|
||||
it('basic transaction', async function () {
|
||||
const results = await database.transaction([
|
||||
{ query: 'SELECT COUNT(*) as count FROM apps', args: [] },
|
||||
{ query: 'SELECT COUNT(*) as count FROM settings', args: [] },
|
||||
]);
|
||||
expect(results[0][0].count).to.be(0);
|
||||
expect(results[1][0].count).to.be(0);
|
||||
});
|
||||
|
||||
it('bad transaction', async function () {
|
||||
const [error] = await safe(database.transaction([
|
||||
{ query: 'SELECT COUNT(*) as count FROM apps', args: [] },
|
||||
{ query: 'stuff', args: [] },
|
||||
]));
|
||||
|
||||
expect(error.reason).to.be(BoxError.DATABASE_ERROR);
|
||||
expect(error.sqlMessage).to.be.a('string');
|
||||
});
|
||||
});
|
||||
|
||||
describe('import/export', function () {
|
||||
before(async function () {
|
||||
await database.initialize();
|
||||
await database._clear();
|
||||
@@ -42,5 +87,9 @@ describe('database', function () {
|
||||
it('can import from file', async function () {
|
||||
await database.importFromFile('/tmp/box.mysqldump');
|
||||
});
|
||||
|
||||
it('can uninitialize database', async function () {
|
||||
await database.uninitialize();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user