Update dependencies, and fix linting issues
This commit is contained in:
parent
806a1e1702
commit
a94038cd47
@ -34,5 +34,6 @@
|
|||||||
"callback-return": [1],
|
"callback-return": [1],
|
||||||
"object-shorthand": [1, "methods"],
|
"object-shorthand": [1, "methods"],
|
||||||
"prefer-template": [1]
|
"prefer-template": [1]
|
||||||
}
|
},
|
||||||
|
"parser": "babel-eslint"
|
||||||
}
|
}
|
@ -1,5 +1,3 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class that wraps database connection libraries
|
* Class that wraps database connection libraries
|
||||||
*
|
*
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const Helpers = require('./Helpers');
|
const Helpers = require('./Helpers');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const QueryBuilder = require('./QueryBuilder');
|
const QueryBuilder = require('./QueryBuilder');
|
||||||
|
|
||||||
// Map config driver name to code class name
|
// Map config driver name to code class name
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const Helpers = require('./Helpers');
|
const Helpers = require('./Helpers');
|
||||||
const QueryBuilderBase = require('./QueryBuilderBase');
|
const QueryBuilderBase = require('./QueryBuilderBase');
|
||||||
|
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const Helpers = require('./Helpers');
|
const Helpers = require('./Helpers');
|
||||||
const QueryParser = require('./QueryParser');
|
const QueryParser = require('./QueryParser');
|
||||||
const State = require('./State');
|
const State = require('./State');
|
||||||
@ -127,6 +125,10 @@ class QueryBuilderBase {
|
|||||||
* when appending to state
|
* when appending to state
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
|
* @param {mixed} letName Lorem Ipsum
|
||||||
|
* @param {mixed} valType Lorem Ipsum
|
||||||
|
* @param {mixed} key Lorem Ipsum
|
||||||
|
* @param {mixed} val Lorem Ipsum
|
||||||
* @return {Array} - modified state array
|
* @return {Array} - modified state array
|
||||||
*/
|
*/
|
||||||
_mixedSet (letName, valType, key, val) {
|
_mixedSet (letName, valType, key, val) {
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const XRegExp = require('xregexp');
|
const XRegExp = require('xregexp');
|
||||||
const Helpers = require('./Helpers');
|
const Helpers = require('./Helpers');
|
||||||
|
|
||||||
@ -35,7 +33,7 @@ class QueryParser {
|
|||||||
${matchPatterns['function'].source}|
|
${matchPatterns['function'].source}|
|
||||||
${matchPatterns.literal.source}
|
${matchPatterns.literal.source}
|
||||||
)
|
)
|
||||||
([a-z_\-]+[0-9]*\\.?)
|
([a-z_-]+[0-9]*\\.?)
|
||||||
)+`, 'igx');
|
)+`, 'igx');
|
||||||
|
|
||||||
// Full pattern for determining ordering of the pieces
|
// Full pattern for determining ordering of the pieces
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const Helpers = require('./Helpers');
|
const Helpers = require('./Helpers');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -16,7 +14,7 @@ class Result {
|
|||||||
* @param {Array} [rows] - the data rows of the result
|
* @param {Array} [rows] - the data rows of the result
|
||||||
* @param {Array} [columns] - the column names in the result
|
* @param {Array} [columns] - the column names in the result
|
||||||
*/
|
*/
|
||||||
constructor (rows=[], columns=[]) {
|
constructor (rows = [], columns = []) {
|
||||||
this._rows = rows;
|
this._rows = rows;
|
||||||
this._columns = columns;
|
this._columns = columns;
|
||||||
|
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for objects containing the query builder state
|
* Class for objects containing the query builder state
|
||||||
* @private
|
* @private
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const NodeFirebird = require('./node-firebird');
|
|
||||||
|
|
||||||
module.exports = config => {
|
|
||||||
return new NodeFirebird(config.connection);
|
|
||||||
};
|
|
||||||
|
|
@ -1,61 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const Adapter = require('../../Adapter');
|
|
||||||
const Result = require('../../Result');
|
|
||||||
const fb = require('node-firebird');
|
|
||||||
|
|
||||||
class Firebird extends Adapter {
|
|
||||||
constructor (config) {
|
|
||||||
super({});
|
|
||||||
this.instance = new Promise((resolve, reject) => {
|
|
||||||
fb.attach(config, (err, instance) => {
|
|
||||||
if (err) {
|
|
||||||
return reject(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
return resolve(instance);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Run the sql query as a prepared statement
|
|
||||||
*
|
|
||||||
* @param {String} sql - The sql with placeholders
|
|
||||||
* @param {Array} params - The values to insert into the query
|
|
||||||
* @return {Promise} - Returns a promise if no callback is provided
|
|
||||||
*/
|
|
||||||
execute (sql, params) {
|
|
||||||
return this.instance.then(conn => {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
conn.query(sql, params, (err, result) => {
|
|
||||||
if (err) {
|
|
||||||
return reject(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
return resolve(this.transformResult(result));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transform the adapter's result into a standard format
|
|
||||||
*
|
|
||||||
* @param {*} originalResult - the original result object from the driver
|
|
||||||
* @return {Result} - the new result object
|
|
||||||
*/
|
|
||||||
transformResult (originalResult) {
|
|
||||||
return new Result(originalResult);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Close the current database connection
|
|
||||||
* @return {void}
|
|
||||||
*/
|
|
||||||
close () {
|
|
||||||
this.instance.then(conn => conn.detach());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = Firebird;
|
|
@ -1,3 +1 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = require('../Mysql');
|
module.exports = require('../Mysql');
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const Mysql2 = require('./mysql2');
|
const Mysql2 = require('./mysql2');
|
||||||
|
|
||||||
module.exports = config => {
|
module.exports = config => {
|
||||||
|
@ -1,12 +1,9 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const Adapter = require('../../Adapter');
|
const Adapter = require('../../Adapter');
|
||||||
const Result = require('../../Result');
|
const Result = require('../../Result');
|
||||||
const Helpers = require('../../Helpers');
|
const Helpers = require('../../Helpers');
|
||||||
const mysql2 = require('mysql2/promise');
|
const mysql2 = require('mysql2/promise');
|
||||||
|
|
||||||
class Mysql extends Adapter {
|
class Mysql extends Adapter {
|
||||||
|
|
||||||
constructor (config) {
|
constructor (config) {
|
||||||
const instance = mysql2.createConnection(config);
|
const instance = mysql2.createConnection(config);
|
||||||
super(instance);
|
super(instance);
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const Adapter = require('../../Adapter');
|
const Adapter = require('../../Adapter');
|
||||||
const Result = require('../../Result');
|
const Result = require('../../Result');
|
||||||
const Helpers = require('../../Helpers');
|
const Helpers = require('../../Helpers');
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const Pg = require('./Pg');
|
const Pg = require('./Pg');
|
||||||
const Result = require('../../Result');
|
|
||||||
const pg = require('pg').native;
|
const pg = require('pg').native;
|
||||||
const url = require('url');
|
|
||||||
|
|
||||||
class PgNative extends Pg {
|
class PgNative extends Pg {
|
||||||
constructor (config) {
|
constructor (config) {
|
||||||
@ -21,7 +17,8 @@ class PgNative extends Pg {
|
|||||||
|
|
||||||
instance = Promise.resolve(conn);
|
instance = Promise.resolve(conn);
|
||||||
}
|
}
|
||||||
super(instance);
|
|
||||||
|
super.instance = instance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const Pg = require('./Pg');
|
const Pg = require('./Pg');
|
||||||
const PgNative = require('./PgNative')
|
const PgNative = require('./PgNative');
|
||||||
|
|
||||||
module.exports = config => {
|
module.exports = config => {
|
||||||
return (config.native)
|
return (config.native)
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const Adapter = require('../../Adapter');
|
const Adapter = require('../../Adapter');
|
||||||
const Result = require('../../Result');
|
const Result = require('../../Result');
|
||||||
const Helpers = require('../../Helpers');
|
const Helpers = require('../../Helpers');
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = config => {
|
module.exports = config => {
|
||||||
const Implementation = (config.native)
|
const Implementation = (config.native)
|
||||||
? require('./sqlite3')
|
? require('./sqlite3')
|
||||||
@ -7,4 +5,3 @@ module.exports = config => {
|
|||||||
|
|
||||||
return new Implementation(config.connection);
|
return new Implementation(config.connection);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const Adapter = require('../../Adapter');
|
const Adapter = require('../../Adapter');
|
||||||
const Result = require('../../Result');
|
const Result = require('../../Result');
|
||||||
const Helpers = require('../../Helpers');
|
const Helpers = require('../../Helpers');
|
||||||
|
@ -1,45 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
let Helpers = require('../Helpers');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Driver for Firebird databases
|
|
||||||
*
|
|
||||||
* @module drivers/firebird
|
|
||||||
*/
|
|
||||||
module.exports = (() => {
|
|
||||||
delete require.cache[require.resolve('../Driver')];
|
|
||||||
let driver = require('../Driver');
|
|
||||||
|
|
||||||
driver.hasTruncate = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the limit clause
|
|
||||||
|
|
||||||
* @param {String} origSql - SQL statement to modify
|
|
||||||
* @param {Number} limit - Maximum number of rows to fetch
|
|
||||||
* @param {Number|null} offset - Number of rows to skip
|
|
||||||
* @return {String} - Modified SQL statement
|
|
||||||
*/
|
|
||||||
driver.limit = (origSql, limit, offset) => {
|
|
||||||
let sql = `FIRST ${limit}`;
|
|
||||||
|
|
||||||
if (Helpers.isNumber(offset)) {
|
|
||||||
sql += ` SKIP ${offset}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return origSql.replace(/SELECT/i, `SELECT ${sql}`);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SQL to insert a group of rows
|
|
||||||
*
|
|
||||||
* @return {void}
|
|
||||||
* @throws {Error}
|
|
||||||
*/
|
|
||||||
driver.insertBatch = () => {
|
|
||||||
throw new Error('Not Implemented');
|
|
||||||
};
|
|
||||||
|
|
||||||
return driver;
|
|
||||||
})();
|
|
@ -1,5 +1,3 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Driver for MariaDB databases
|
* Driver for MariaDB databases
|
||||||
*
|
*
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Driver for MySQL databases
|
* Driver for MySQL databases
|
||||||
*
|
*
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Driver for PostgreSQL databases
|
* Driver for PostgreSQL databases
|
||||||
*
|
*
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Driver for SQLite databases
|
* Driver for SQLite databases
|
||||||
*
|
*
|
||||||
|
194
package.json
194
package.json
@ -1,96 +1,102 @@
|
|||||||
{
|
{
|
||||||
"name": "ci-node-query",
|
"name": "ci-node-query",
|
||||||
"version": "5.0.0",
|
"version": "6.0.0",
|
||||||
"description": "A query builder for node based on the one in CodeIgniter",
|
"description": "A query builder for node based on the one in CodeIgniter",
|
||||||
"author": "Timothy J Warren <tim@timshomepage.net>",
|
"author": "Timothy J Warren <tim@timshomepage.net>",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=6.0.0"
|
"node": ">=8.0.0"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"lib/"
|
"lib/"
|
||||||
],
|
],
|
||||||
"contributors": [
|
"contributors": [
|
||||||
{
|
{
|
||||||
"name": "Timothy J Warren",
|
"name": "Timothy J Warren",
|
||||||
"email": "tim@timshomepage.net"
|
"email": "tim@timshomepage.net"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://git.timshomepage.net/timw4mail/node-query.git"
|
"url": "https://git.timshomepage.net/timw4mail/node-query.git"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"codeigniter",
|
"codeigniter",
|
||||||
"mariadb",
|
"mariadb",
|
||||||
"mysql",
|
"mysql",
|
||||||
"mssql",
|
"mssql",
|
||||||
"query builder",
|
"query builder",
|
||||||
"postgres",
|
"postgres",
|
||||||
"postgresql",
|
"postgresql",
|
||||||
"sql",
|
"sql",
|
||||||
"sqlite",
|
"sqlite",
|
||||||
"sqlite3",
|
"sqlite3",
|
||||||
"sqlserver"
|
"sqlserver"
|
||||||
],
|
],
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://git.timshomepage.net/timw4mail/node-query/issues"
|
"url": "https://git.timshomepage.net/timw4mail/node-query/issues"
|
||||||
},
|
},
|
||||||
"main": "lib/NodeQuery.js",
|
"main": "lib/NodeQuery.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"dblite": "^0.7.8",
|
"dblite": "^0.8.0",
|
||||||
"getargs": "~0.0.8",
|
"getargs": "~0.0.8",
|
||||||
"glob": "^7.0.3",
|
"glob": "^7.0.3",
|
||||||
"mysql2": "^1.2.0",
|
"mysql2": "^1.2.0",
|
||||||
"node-firebird": "^0.8.1",
|
"pg": "^7.4",
|
||||||
"pg": "^6.1.2",
|
"require-reload": "~0.2.2",
|
||||||
"require-reload": "~0.2.2",
|
"sqlite3": "^3.1.8",
|
||||||
"sqlite3": "^3.1.8",
|
"tedious": "^2.0.0",
|
||||||
"tedious": "^1.14.0",
|
"xregexp": "^4.0.0"
|
||||||
"xregexp": "^3.0.0"
|
},
|
||||||
},
|
"devDependencies": {
|
||||||
"devDependencies": {
|
"babel-eslint": "^8.2.1",
|
||||||
"chai": "^3.5.0",
|
"chai": "^4.1",
|
||||||
"chai-as-promised": "^6.0.0",
|
"chai-as-promised": "^7.1",
|
||||||
"documentation": "latest",
|
"documentation": "latest",
|
||||||
"eslint": "^3.5.0",
|
"eslint": "^4.16.0",
|
||||||
"globstar": "^1.0.0",
|
"globstar": "^1.0.0",
|
||||||
"happiness": "^7.1.2",
|
"happiness": "^10.0",
|
||||||
"jest": "^19.0.2",
|
"jest": "^22.0.0",
|
||||||
"jsdoc": "^3.4.3",
|
"jsdoc": "^3.4.3",
|
||||||
"npm-run-all": "^4.0.2",
|
"npm-run-all": "^4.0.2",
|
||||||
"nsp": "^2.2.1"
|
"nsp": "^3.1",
|
||||||
},
|
"pg-native": "^2.2"
|
||||||
"license": "MIT",
|
},
|
||||||
"jest": {
|
"license": "MIT",
|
||||||
"coverageDirectory": "coverage",
|
"jest": {
|
||||||
"coverageReporters": [
|
"coverageDirectory": "coverage",
|
||||||
"html",
|
"coverageReporters": [
|
||||||
"json",
|
"html",
|
||||||
"lcov",
|
"json",
|
||||||
"text-summary"
|
"lcov",
|
||||||
],
|
"text-summary"
|
||||||
"testEnvironment": "node",
|
],
|
||||||
"testMatch": [
|
"testEnvironment": "node",
|
||||||
"**/test/**/*_test.js"
|
"testMatch": [
|
||||||
]
|
"**/test/**/*_test.js"
|
||||||
},
|
]
|
||||||
"scripts": {
|
},
|
||||||
"audit": "nsp check",
|
"scripts": {
|
||||||
"build": "npm-run-all --parallel lint:src lint:tests docs coverage",
|
"audit": "nsp check",
|
||||||
"coverage": "jest --coverage",
|
"build": "npm-run-all --parallel lint:src lint:tests docs coverage",
|
||||||
"default": "npm-run-all --parallel audit lint:src lint:tests && npm run test",
|
"coverage": "jest --coverage",
|
||||||
"predocs": "globstar -- documentation build -f md -o API.md \"lib/*.js\"",
|
"default": "npm-run-all --parallel audit lint:src lint:tests && npm run test",
|
||||||
"docs": "globstar -- documentation build -f html -o docs \"lib/*.js\"",
|
"predocs": "globstar -- documentation build -f md -o API.md \"lib/*.js\"",
|
||||||
"postdocs": "jsdoc lib -r -d documentation",
|
"docs": "globstar -- documentation build -f html -o docs \"lib/*.js\"",
|
||||||
"happy": "happiness \"lib/**/*.js\" \"test/**/*.js\"",
|
"fix": "happiness --fix \"lib/**/*.js\" \"test/**/*.js\"",
|
||||||
"happy:src": "happiness \"lib/**/*.js\"",
|
"postdocs": "jsdoc lib -r -d documentation",
|
||||||
"happy:tests": "happiness \"test/**/*.js\"",
|
"happy": "happiness \"lib/**/*.js\" \"test/**/*.js\"",
|
||||||
"lint": "npm-run-all lint:tests lint:src happy",
|
"happy:src": "happiness \"lib/**/*.js\"",
|
||||||
"lint:src": "eslint ./lib",
|
"happy:tests": "happiness \"test/**/*.js\"",
|
||||||
"lint:tests": "eslint ./test",
|
"lint": "npm-run-all lint:tests lint:src happy",
|
||||||
"test": "jest"
|
"lint:src": "eslint ./lib",
|
||||||
},
|
"lint:tests": "eslint ./test",
|
||||||
"peerDependencies": {
|
"test": "jest"
|
||||||
"pg-native": "^1.10.0"
|
},
|
||||||
}
|
"happiness": {
|
||||||
|
"env": {
|
||||||
|
"es6": true,
|
||||||
|
"jest": true
|
||||||
|
},
|
||||||
|
"parser": "babel-eslint"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
@ -1,11 +1,7 @@
|
|||||||
/* eslint-env node, mocha */
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
// Load the test base
|
// Load the test base
|
||||||
const reload = require('require-reload')(require);
|
const reload = require('require-reload')(require);
|
||||||
reload.emptyCache();
|
reload.emptyCache();
|
||||||
const testBase = reload('../base');
|
const testBase = reload('../base');
|
||||||
const expect = testBase.expect;
|
|
||||||
const testRunner = testBase.promiseTestRunner;
|
const testRunner = testBase.promiseTestRunner;
|
||||||
|
|
||||||
// Load the test config file
|
// Load the test config file
|
||||||
@ -23,15 +19,15 @@ describe('Dblite adapter tests -', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
testRunner(qb);
|
testRunner(qb);
|
||||||
it('Promise - Select with function and argument in WHERE clause', () => {
|
it('Promise - Select with function and argument in WHERE clause', async () => {
|
||||||
let promise = qb.select('id')
|
let promise = await qb.select('id')
|
||||||
.from('create_test')
|
.from('create_test')
|
||||||
.where('id', 'ABS(-88)')
|
.where('id', 'ABS(-88)')
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
expect(promise).to.be.fulfilled;
|
expect(promise).toEqual(expect.anything());
|
||||||
});
|
});
|
||||||
it('Promise - Test Insert Batch', () => {
|
it('Promise - Test Insert Batch', async () => {
|
||||||
let data = [
|
let data = [
|
||||||
{
|
{
|
||||||
id: 544,
|
id: 544,
|
||||||
@ -48,8 +44,8 @@ describe('Dblite adapter tests -', () => {
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
let promise = qb.insertBatch('create_test', data);
|
let promise = await qb.insertBatch('create_test', data);
|
||||||
expect(promise).to.be.fulfilled;
|
expect(promise).toEqual(expect.anything());
|
||||||
});
|
});
|
||||||
afterAll(() => {
|
afterAll(() => {
|
||||||
qb.end();
|
qb.end();
|
||||||
|
@ -1,11 +1,7 @@
|
|||||||
/* eslint-env node, mocha */
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
// Load the test base
|
// Load the test base
|
||||||
const reload = require('require-reload')(require);
|
const reload = require('require-reload')(require);
|
||||||
reload.emptyCache();
|
reload.emptyCache();
|
||||||
const testBase = reload('../base');
|
const testBase = reload('../base');
|
||||||
const expect = testBase.expect;
|
|
||||||
const testRunner = testBase.promiseTestRunner;
|
const testRunner = testBase.promiseTestRunner;
|
||||||
|
|
||||||
// Load the test config file
|
// Load the test config file
|
||||||
@ -24,24 +20,23 @@ describe('Mysql2 adapter tests -', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('nodeQuery.getQuery = nodeQuery.init', () => {
|
it('nodeQuery.getQuery = nodeQuery.init', () => {
|
||||||
expect(nodeQuery.getQuery())
|
expect(nodeQuery.getQuery()).toEqual(qb);
|
||||||
.to.be.deep.equal(qb);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
testRunner(qb);
|
testRunner(qb);
|
||||||
it('Promise - Select with function and argument in WHERE clause', () => {
|
it('Promise - Select with function and argument in WHERE clause', async () => {
|
||||||
let promise = qb.select('id')
|
let promise = await qb.select('id')
|
||||||
.from('create_test')
|
.from('create_test')
|
||||||
.where('id', 'CEILING(SQRT(88))')
|
.where('id', 'CEILING(SQRT(88))')
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
return expect(promise).to.be.fulfilled;
|
expect(promise).toEqual(expect.anything());
|
||||||
});
|
});
|
||||||
it('Test Truncate', () => {
|
it('Test Truncate', async () => {
|
||||||
let promise = qb.truncate('create_test');
|
let promise = await qb.truncate('create_test');
|
||||||
return expect(promise).to.be.fullfilled;
|
expect(promise).toEqual(expect.anything());
|
||||||
});
|
});
|
||||||
it('Test Insert Batch', () => {
|
it('Test Insert Batch', async () => {
|
||||||
let data = [
|
let data = [
|
||||||
{
|
{
|
||||||
id: 5442,
|
id: 5442,
|
||||||
@ -58,7 +53,8 @@ describe('Mysql2 adapter tests -', () => {
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
return expect(qb.insertBatch('create_test', data)).to.be.fulfilled;
|
const promise = await qb.insertBatch('create_test', data);
|
||||||
|
expect(promise).toEqual(expect.anything());
|
||||||
});
|
});
|
||||||
|
|
||||||
/* describeTeardown(() => {
|
/* describeTeardown(() => {
|
||||||
|
@ -1,38 +0,0 @@
|
|||||||
/* eslint-env node, mocha */
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
// Load the test base
|
|
||||||
const path = require('path');
|
|
||||||
const reload = require('require-reload')(require);
|
|
||||||
const testBase = reload('../base');
|
|
||||||
const expect = testBase.expect;
|
|
||||||
const testRunner = testBase.promiseTestRunner;
|
|
||||||
|
|
||||||
// Skip on CI
|
|
||||||
if (!(process.env.CI || process.env.TRAVIS)) {
|
|
||||||
// Load the test config file
|
|
||||||
let adapterName = 'node-firebird';
|
|
||||||
const config = reload('../config.json')[adapterName];
|
|
||||||
config.connection.database = path.join(__dirname, config.connection.database);
|
|
||||||
let nodeQuery = reload('../../lib/NodeQuery')(config);
|
|
||||||
|
|
||||||
let qb = nodeQuery.getQuery();
|
|
||||||
|
|
||||||
describe('Firebird adapter tests -', () => {
|
|
||||||
it('nodeQuery.getQuery = nodeQuery.init', () => {
|
|
||||||
expect(nodeQuery.getQuery())
|
|
||||||
.to.be.deep.equal(qb);
|
|
||||||
});
|
|
||||||
it('insertBatch throws error', () => {
|
|
||||||
expect(() => {
|
|
||||||
qb.driver.insertBatch('create_test', []);
|
|
||||||
}).to.throw(Error, 'Not Implemented');
|
|
||||||
});
|
|
||||||
|
|
||||||
testRunner(qb);
|
|
||||||
|
|
||||||
afterAll(() => {
|
|
||||||
qb.end();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
@ -1,11 +1,7 @@
|
|||||||
/* eslint-env node, mocha */
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
// Load the test base
|
// Load the test base
|
||||||
const reload = require('require-reload')(require);
|
const reload = require('require-reload')(require);
|
||||||
reload.emptyCache();
|
reload.emptyCache();
|
||||||
const testBase = reload('../base');
|
const testBase = reload('../base');
|
||||||
const expect = testBase.expect;
|
|
||||||
const testRunner = testBase.promiseTestRunner;
|
const testRunner = testBase.promiseTestRunner;
|
||||||
|
|
||||||
// Load the test config file
|
// Load the test config file
|
||||||
@ -27,7 +23,7 @@ describe('Pg adapter tests -', () => {
|
|||||||
|
|
||||||
it('nodeQuery.getQuery = nodeQuery.init', () => {
|
it('nodeQuery.getQuery = nodeQuery.init', () => {
|
||||||
expect(nodeQuery.getQuery())
|
expect(nodeQuery.getQuery())
|
||||||
.to.be.deep.equal(qb);
|
.toEqual(qb);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Connecting with an object also works', () => {
|
it('Connecting with an object also works', () => {
|
||||||
@ -35,7 +31,7 @@ describe('Pg adapter tests -', () => {
|
|||||||
let nodeQuery = reload('../../lib/NodeQuery')(config);
|
let nodeQuery = reload('../../lib/NodeQuery')(config);
|
||||||
qb2 = nodeQuery.getQuery();
|
qb2 = nodeQuery.getQuery();
|
||||||
|
|
||||||
expect(qb2).to.be.ok;
|
expect(qb2).toEqual(expect.anything());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Test Connection Error', done => {
|
it('Test Connection Error', done => {
|
||||||
@ -43,26 +39,25 @@ describe('Pg adapter tests -', () => {
|
|||||||
reload('../../lib/NodeQuery')({});
|
reload('../../lib/NodeQuery')({});
|
||||||
done(true);
|
done(true);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
expect(e).to.be.ok;
|
expect(e).toEqual(expect.anything());
|
||||||
expect(e).is.an('Error');
|
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
testRunner(qb);
|
testRunner(qb);
|
||||||
it('Promise - Select with function and argument in WHERE clause', () => {
|
it('Promise - Select with function and argument in WHERE clause', async () => {
|
||||||
let promise = qb.select('id')
|
let promise = await qb.select('id')
|
||||||
.from('create_test')
|
.from('create_test')
|
||||||
.where('id', 'CEILING(SQRT(88))')
|
.where('id', 'CEILING(SQRT(88))')
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
return expect(promise).to.be.fulfilled;
|
expect(promise).toEqual(expect.anything());
|
||||||
});
|
});
|
||||||
it('Promise - Test Truncate', () => {
|
it('Promise - Test Truncate', async () => {
|
||||||
let promise = qb.truncate('create_test');
|
let promise = await qb.truncate('create_test');
|
||||||
return expect(promise).to.be.fulfilled;
|
expect(promise).toEqual(expect.anything());
|
||||||
});
|
});
|
||||||
it('Promise - Test Insert Batch', () => {
|
it('Promise - Test Insert Batch', async () => {
|
||||||
let data = [
|
let data = [
|
||||||
{
|
{
|
||||||
id: 544,
|
id: 544,
|
||||||
@ -79,8 +74,8 @@ describe('Pg adapter tests -', () => {
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
let promise = qb.insertBatch('create_test', data);
|
let promise = await qb.insertBatch('create_test', data);
|
||||||
return expect(promise).to.be.fulfilled;
|
expect(promise).toEqual(expect.anything());
|
||||||
});
|
});
|
||||||
afterAll(() => {
|
afterAll(() => {
|
||||||
qb.end();
|
qb.end();
|
||||||
|
@ -1,11 +1,7 @@
|
|||||||
/* eslint-env node, mocha */
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
// Load the test base
|
// Load the test base
|
||||||
const reload = require('require-reload')(require);
|
const reload = require('require-reload')(require);
|
||||||
reload.emptyCache();
|
reload.emptyCache();
|
||||||
const testBase = reload('../base');
|
const testBase = reload('../base');
|
||||||
const expect = testBase.expect;
|
|
||||||
const testRunner = testBase.promiseTestRunner;
|
const testRunner = testBase.promiseTestRunner;
|
||||||
|
|
||||||
// Load the test config file
|
// Load the test config file
|
||||||
@ -24,15 +20,15 @@ describe('Sqlite3 adapter tests -', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
testRunner(qb);
|
testRunner(qb);
|
||||||
it('Promise - Select with function and argument in WHERE clause', () => {
|
it('Promise - Select with function and argument in WHERE clause', async () => {
|
||||||
let promise = qb.select('id')
|
let promise = await qb.select('id')
|
||||||
.from('create_test')
|
.from('create_test')
|
||||||
.where('id', 'ABS(-88)')
|
.where('id', 'ABS(-88)')
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
expect(promise).to.be.fulfilled;
|
expect(promise).toEqual(expect.anything());
|
||||||
});
|
});
|
||||||
it('Promise - Test Insert Batch', () => {
|
it('Promise - Test Insert Batch', async () => {
|
||||||
let data = [
|
let data = [
|
||||||
{
|
{
|
||||||
id: 544,
|
id: 544,
|
||||||
@ -49,8 +45,8 @@ describe('Sqlite3 adapter tests -', () => {
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
let promise = qb.insertBatch('create_test', data);
|
let promise = await qb.insertBatch('create_test', data);
|
||||||
expect(promise).to.be.fulfilled;
|
expect(promise).toEqual(expect.anything());
|
||||||
});
|
});
|
||||||
afterAll(() => {
|
afterAll(() => {
|
||||||
qb.end();
|
qb.end();
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const chai = require('chai');
|
const chai = require('chai');
|
||||||
const chaiAsPromised = require('chai-as-promised');
|
const chaiAsPromised = require('chai-as-promised');
|
||||||
chai.use(chaiAsPromised);
|
chai.use(chaiAsPromised);
|
||||||
|
@ -1,18 +1,10 @@
|
|||||||
/* eslint-env node, mocha */
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
// Load the test base
|
// Load the test base
|
||||||
const chai = require('chai');
|
|
||||||
const chaiAsPromised = require('chai-as-promised');
|
|
||||||
chai.use(chaiAsPromised);
|
|
||||||
const expect = chai.expect;
|
|
||||||
|
|
||||||
const reload = require('require-reload')(require);
|
const reload = require('require-reload')(require);
|
||||||
const tests = reload('../base/tests');
|
const tests = reload('../base/tests');
|
||||||
|
|
||||||
module.exports = function promiseTestRunner (qb) {
|
module.exports = function promiseTestRunner (qb) {
|
||||||
Object.keys(tests).forEach(describeName => {
|
Object.keys(tests).forEach(describeName => {
|
||||||
describe(describeName, () => {
|
describe(describeName, async () => {
|
||||||
let currentSuite = tests[describeName];
|
let currentSuite = tests[describeName];
|
||||||
Object.keys(currentSuite).forEach(testDesc => {
|
Object.keys(currentSuite).forEach(testDesc => {
|
||||||
it(testDesc, done => {
|
it(testDesc, done => {
|
||||||
@ -34,94 +26,94 @@ module.exports = function promiseTestRunner (qb) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let promise = results.pop();
|
const promise = results.pop();
|
||||||
promise.then(result => {
|
promise.then(result => {
|
||||||
expect(result.rows).is.an('array');
|
// expect(result.rows).is.an('array');
|
||||||
expect(result.rowCount()).to.not.be.undefined;
|
expect(result.rowCount()).toEqual(expect.anything());
|
||||||
expect(result.columnCount()).to.not.be.undefined;
|
expect(result.columnCount()).toEqual(expect.anything());
|
||||||
return done();
|
return done();
|
||||||
}).catch(e => done(e));
|
}).catch(e => done(e));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('DB update tests -', () => {
|
describe('DB update tests -', async () => {
|
||||||
beforeAll(done => {
|
beforeAll(done => {
|
||||||
let sql = qb.driver.truncate('create_test');
|
let sql = qb.driver.truncate('create_test');
|
||||||
qb.query(sql).then(res => done())
|
qb.query(sql).then(res => done())
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
it('Promise - Test Insert', () => {
|
it('Promise - Test Insert', async () => {
|
||||||
let promise = qb.set('id', 98)
|
const promise = await qb.set('id', 98)
|
||||||
.set('key', '84')
|
.set('key', '84')
|
||||||
.set('val', Buffer.from('120'))
|
.set('val', Buffer.from('120'))
|
||||||
.insert('create_test');
|
.insert('create_test');
|
||||||
|
|
||||||
return expect(promise).to.be.fulfilled;
|
expect(promise).toEqual(expect.anything());
|
||||||
});
|
});
|
||||||
it('Promise - Test Insert Object', () => {
|
it('Promise - Test Insert Object', async () => {
|
||||||
let promise = qb.insert('create_test', {
|
const promise = await qb.insert('create_test', {
|
||||||
id: 587,
|
id: 587,
|
||||||
key: 1,
|
key: 1,
|
||||||
val: Buffer.from('2')
|
val: Buffer.from('2')
|
||||||
});
|
});
|
||||||
|
|
||||||
return expect(promise).to.be.fulfilled;
|
expect(promise).toEqual(expect.anything());
|
||||||
});
|
});
|
||||||
it('Promise - Test Update', () => {
|
it('Promise - Test Update', async () => {
|
||||||
let promise = qb.where('id', 7)
|
const promise = await qb.where('id', 7)
|
||||||
.update('create_test', {
|
.update('create_test', {
|
||||||
id: 7,
|
id: 7,
|
||||||
key: 'gogle',
|
key: 'gogle',
|
||||||
val: Buffer.from('non-word')
|
val: Buffer.from('non-word')
|
||||||
});
|
});
|
||||||
|
|
||||||
return expect(promise).to.be.fulfilled;
|
expect(promise).toEqual(expect.anything());
|
||||||
});
|
});
|
||||||
it('Promise - Test set Array Update', () => {
|
it('Promise - Test set Array Update', async () => {
|
||||||
let object = {
|
let object = {
|
||||||
id: 22,
|
id: 22,
|
||||||
key: 'gogle',
|
key: 'gogle',
|
||||||
val: Buffer.from('non-word')
|
val: Buffer.from('non-word')
|
||||||
};
|
};
|
||||||
|
|
||||||
let promise = qb.set(object)
|
const promise = await qb.set(object)
|
||||||
.where('id', 22)
|
.where('id', 22)
|
||||||
.update('create_test');
|
.update('create_test');
|
||||||
|
|
||||||
return expect(promise).to.be.fulfilled;
|
expect(promise).toEqual(expect.anything());
|
||||||
});
|
});
|
||||||
it('Promise - Test where set update', () => {
|
it('Promise - Test where set update', async () => {
|
||||||
let promise = qb.where('id', 36)
|
const promise = await qb.where('id', 36)
|
||||||
.set('id', 36)
|
.set('id', 36)
|
||||||
.set('key', 'gogle')
|
.set('key', 'gogle')
|
||||||
.set('val', Buffer.from('non-word'))
|
.set('val', Buffer.from('non-word'))
|
||||||
.update('create_test');
|
.update('create_test');
|
||||||
|
|
||||||
return expect(promise).to.be.fulfilled;
|
expect(promise).toEqual(expect.anything());
|
||||||
});
|
});
|
||||||
it('Promise - Test delete', () => {
|
it('Promise - Test delete', async () => {
|
||||||
let promise = qb.delete('create_test', {id: 5});
|
const promise = await qb.delete('create_test', {id: 5});
|
||||||
return expect(promise).to.be.fulfilled;
|
expect(promise).toEqual(expect.anything());
|
||||||
});
|
});
|
||||||
it('Promise - Delete with where', () => {
|
it('Promise - Delete with where', async () => {
|
||||||
let promise = qb.where('id', 5)
|
const promise = await qb.where('id', 5)
|
||||||
.delete('create_test');
|
.delete('create_test');
|
||||||
|
|
||||||
return expect(promise).to.be.fulfilled;
|
expect(promise).toEqual(expect.anything());
|
||||||
});
|
});
|
||||||
it('Promise - Delete multiple where values', () => {
|
it('Promise - Delete multiple where values', async () => {
|
||||||
let promise = qb.delete('create_test', {
|
const promise = await qb.delete('create_test', {
|
||||||
id: 5,
|
id: 5,
|
||||||
key: 'gogle'
|
key: 'gogle'
|
||||||
});
|
});
|
||||||
|
|
||||||
return expect(promise).to.be.fulfilled;
|
expect(promise).toEqual(expect.anything());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('Grouping tests -', () => {
|
describe('Grouping tests -', async () => {
|
||||||
it('Promise - Using grouping method', () => {
|
it('Promise - Using grouping method', async () => {
|
||||||
let promise = qb.select('id, key as k, val')
|
const promise = await qb.select('id, key as k, val')
|
||||||
.from('create_test')
|
.from('create_test')
|
||||||
.groupStart()
|
.groupStart()
|
||||||
.where('id >', 1)
|
.where('id >', 1)
|
||||||
@ -130,10 +122,10 @@ module.exports = function promiseTestRunner (qb) {
|
|||||||
.limit(2, 1)
|
.limit(2, 1)
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
return expect(promise).to.be.fulfilled;
|
expect(promise).toEqual(expect.anything());
|
||||||
});
|
});
|
||||||
it('Promise - Using where first grouping', () => {
|
it('Promise - Using where first grouping', async () => {
|
||||||
let promise = qb.select('id, key as k, val')
|
const promise = await qb.select('id, key as k, val')
|
||||||
.from('create_test')
|
.from('create_test')
|
||||||
.where('id !=', 5)
|
.where('id !=', 5)
|
||||||
.groupStart()
|
.groupStart()
|
||||||
@ -143,10 +135,10 @@ module.exports = function promiseTestRunner (qb) {
|
|||||||
.limit(2, 1)
|
.limit(2, 1)
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
return expect(promise).to.be.fulfilled;
|
expect(promise).toEqual(expect.anything());
|
||||||
});
|
});
|
||||||
it('Promise - Using or grouping method', () => {
|
it('Promise - Using or grouping method', async () => {
|
||||||
let promise = qb.select('id, key as k, val')
|
const promise = await qb.select('id, key as k, val')
|
||||||
.from('create_test')
|
.from('create_test')
|
||||||
.groupStart()
|
.groupStart()
|
||||||
.where('id >', 1)
|
.where('id >', 1)
|
||||||
@ -158,10 +150,10 @@ module.exports = function promiseTestRunner (qb) {
|
|||||||
.limit(2, 1)
|
.limit(2, 1)
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
return expect(promise).to.be.fulfilled;
|
expect(promise).toEqual(expect.anything());
|
||||||
});
|
});
|
||||||
it('Promise - Using or not grouping method', () => {
|
it('Promise - Using or not grouping method', async () => {
|
||||||
let promise = qb.select('id, key as k, val')
|
const promise = await qb.select('id, key as k, val')
|
||||||
.from('create_test')
|
.from('create_test')
|
||||||
.groupStart()
|
.groupStart()
|
||||||
.where('id >', 1)
|
.where('id >', 1)
|
||||||
@ -173,7 +165,7 @@ module.exports = function promiseTestRunner (qb) {
|
|||||||
.limit(2, 1)
|
.limit(2, 1)
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
return expect(promise).to.be.fulfilled;
|
expect(promise).toEqual(expect.anything());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
'Get tests -': {
|
'Get tests -': {
|
||||||
'Get with function': {
|
'Get with function': {
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
/* eslint-env node, mocha */
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const expect = require('chai').expect;
|
|
||||||
const reload = require('require-reload')(require);
|
const reload = require('require-reload')(require);
|
||||||
const glob = require('glob');
|
const glob = require('glob');
|
||||||
const nodeQuery = reload('../lib/NodeQuery')();
|
const nodeQuery = reload('../lib/NodeQuery')();
|
||||||
@ -14,7 +10,7 @@ describe('Base tests -', () => {
|
|||||||
let obj = require(mod);
|
let obj = require(mod);
|
||||||
let shortName = mod.replace(/^\/(.*?)\/lib\/(.*?)\.js$/g, '$2');
|
let shortName = mod.replace(/^\/(.*?)\/lib\/(.*?)\.js$/g, '$2');
|
||||||
it(`${shortName} module is sane`, () => {
|
it(`${shortName} module is sane`, () => {
|
||||||
expect(obj).to.be.ok;
|
expect(obj).toEqual(expect.anything());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -26,7 +22,7 @@ describe('Base tests -', () => {
|
|||||||
nodeQueryCopy.instance = null;
|
nodeQueryCopy.instance = null;
|
||||||
expect(() => {
|
expect(() => {
|
||||||
nodeQueryCopy.getQuery();
|
nodeQueryCopy.getQuery();
|
||||||
}).to.throw(Error, 'No Query Builder instance to return');
|
}).toThrow(Error, 'No Query Builder instance to return');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Invalid driver type', () => {
|
it('Invalid driver type', () => {
|
||||||
@ -34,20 +30,20 @@ describe('Base tests -', () => {
|
|||||||
reload('../lib/NodeQuery')({
|
reload('../lib/NodeQuery')({
|
||||||
driver: 'Foo'
|
driver: 'Foo'
|
||||||
});
|
});
|
||||||
}).to.throw(Error, 'Selected driver (Foo) does not exist!');
|
}).toThrow(Error, 'Selected driver (Foo) does not exist!');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Invalid adapter', () => {
|
it('Invalid adapter', () => {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
let a = new Adapter();
|
let a = new Adapter();
|
||||||
a.execute();
|
a.execute();
|
||||||
}).to.throw(Error, 'Correct adapter not defined for query execution');
|
}).toThrow(Error, 'Correct adapter not defined for query execution');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Invalid adapter - missing transformResult', () => {
|
it('Invalid adapter - missing transformResult', () => {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
let a = new Adapter();
|
let a = new Adapter();
|
||||||
a.transformResult([]);
|
a.transformResult([]);
|
||||||
}).to.throw(Error, 'Result transformer method not defined for current adapter');
|
}).toThrow(Error, 'Result transformer method not defined for current adapter');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,26 +1,19 @@
|
|||||||
/* eslint-env node, mocha */
|
const Helpers = require('../lib/Helpers');
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const chai = require('chai');
|
|
||||||
const assert = chai.assert;
|
|
||||||
const expect = chai.expect;
|
|
||||||
|
|
||||||
let Helpers = require('../lib/Helpers');
|
|
||||||
|
|
||||||
describe('Helper Module Tests -', () => {
|
describe('Helper Module Tests -', () => {
|
||||||
describe('Type-checking methods -', () => {
|
describe('Type-checking methods -', () => {
|
||||||
describe('Object wrappers are listed as their native type', () => {
|
describe('Object wrappers are listed as their native type', () => {
|
||||||
it('Boolean Wrapper returns \'boolean\' not \'object\'', () => {
|
it('Boolean Wrapper returns \'boolean\' not \'object\'', () => {
|
||||||
let item = Boolean(true);
|
let item = Boolean(true);
|
||||||
expect(Helpers.type(item)).to.deep.equal('boolean');
|
expect(Helpers.type(item)).toEqual('boolean');
|
||||||
});
|
});
|
||||||
it('Number Wrapper returns \'number\' not \'object\'', () => {
|
it('Number Wrapper returns \'number\' not \'object\'', () => {
|
||||||
let item = Number(4867);
|
let item = Number(4867);
|
||||||
expect(Helpers.type(item)).to.deep.equal('number');
|
expect(Helpers.type(item)).toEqual('number');
|
||||||
});
|
});
|
||||||
it('String Wrapper returns \'string\' not \'object\'', () => {
|
it('String Wrapper returns \'string\' not \'object\'', () => {
|
||||||
let item = String('Foo');
|
let item = String('Foo');
|
||||||
expect(Helpers.type(item)).to.deep.equal('string');
|
expect(Helpers.type(item)).toEqual('string');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('is..Method methods exist -', () => {
|
describe('is..Method methods exist -', () => {
|
||||||
@ -40,7 +33,7 @@ describe('Helper Module Tests -', () => {
|
|||||||
|
|
||||||
types.forEach(type => {
|
types.forEach(type => {
|
||||||
it(`is${type} method exists`, () => {
|
it(`is${type} method exists`, () => {
|
||||||
assert.ok(Helpers[`is${type}`]);
|
expect(Helpers[`is${type}`]).toBeDefined();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -52,7 +45,7 @@ describe('Helper Module Tests -', () => {
|
|||||||
};
|
};
|
||||||
Object.keys(trueCases).forEach(desc => {
|
Object.keys(trueCases).forEach(desc => {
|
||||||
it(desc, () => {
|
it(desc, () => {
|
||||||
expect(Helpers.isScalar(trueCases[desc])).to.be.true;
|
expect(Helpers.isScalar(trueCases[desc])).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -62,24 +55,24 @@ describe('Helper Module Tests -', () => {
|
|||||||
};
|
};
|
||||||
Object.keys(falseCases).forEach(desc => {
|
Object.keys(falseCases).forEach(desc => {
|
||||||
it(desc, () => {
|
it(desc, () => {
|
||||||
expect(Helpers.isScalar(falseCases[desc])).to.be.false;
|
expect(Helpers.isScalar(falseCases[desc])).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('isInfinity -', () => {
|
describe('isInfinity -', () => {
|
||||||
it('The type of 1/0 is infinity', () => {
|
it('The type of 1/0 is infinity', () => {
|
||||||
expect(Helpers.type(1 / 0)).to.equal('infinity');
|
expect(Helpers.type(1 / 0)).toBe('infinity');
|
||||||
});
|
});
|
||||||
it('isInfinity is the same as isInfinite', () => {
|
it('isInfinity is the same as isInfinite', () => {
|
||||||
expect(Helpers.isInfinite(1 / 0)).to.be.true;
|
expect(Helpers.isInfinite(1 / 0)).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('isNaN -', () => {
|
describe('isNaN -', () => {
|
||||||
it('The type of 0 / 0 is NaN', () => {
|
it('The type of 0 / 0 is NaN', () => {
|
||||||
expect(Helpers.type(0 / 0)).to.equal('nan');
|
expect(Helpers.type(0 / 0)).toBe('nan');
|
||||||
});
|
});
|
||||||
it('isNaN method agrees with type', () => {
|
it('isNaN method agrees with type', () => {
|
||||||
expect(Helpers.isNaN(0 / 0)).to.be.true;
|
expect(Helpers.isNaN(0 / 0)).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -89,7 +82,7 @@ describe('Helper Module Tests -', () => {
|
|||||||
let orig = [' x y ', 'z ', ' q'];
|
let orig = [' x y ', 'z ', ' q'];
|
||||||
let ret = ['x y', 'z', 'q'];
|
let ret = ['x y', 'z', 'q'];
|
||||||
|
|
||||||
expect(orig.map(Helpers.stringTrim)).to.be.deep.equal(ret);
|
expect(orig.map(Helpers.stringTrim)).toEqual(ret);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('arrayPluck -', () => {
|
describe('arrayPluck -', () => {
|
||||||
@ -106,13 +99,13 @@ describe('Helper Module Tests -', () => {
|
|||||||
];
|
];
|
||||||
|
|
||||||
it('Finding members in all objects', () => {
|
it('Finding members in all objects', () => {
|
||||||
expect(Helpers.arrayPluck(orig, 'foo')).to.be.deep.equal([1, 2, 3]);
|
expect(Helpers.arrayPluck(orig, 'foo')).toEqual([1, 2, 3]);
|
||||||
});
|
});
|
||||||
it('Some members are missing in some objects', () => {
|
it('Some members are missing in some objects', () => {
|
||||||
expect(Helpers.arrayPluck(orig, 'bar')).to.be.deep.equal([10, 15]);
|
expect(Helpers.arrayPluck(orig, 'bar')).toEqual([10, 15]);
|
||||||
});
|
});
|
||||||
it('Empty case', () => {
|
it('Empty case', () => {
|
||||||
expect(Helpers.arrayPluck([], 'apple')).to.be.deep.equal([]);
|
expect(Helpers.arrayPluck([], 'apple')).toEqual([]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('regexInArray -', () => {
|
describe('regexInArray -', () => {
|
||||||
@ -133,25 +126,25 @@ describe('Helper Module Tests -', () => {
|
|||||||
Object.keys(boolCase).forEach(desc => {
|
Object.keys(boolCase).forEach(desc => {
|
||||||
it(desc, () => {
|
it(desc, () => {
|
||||||
if (i) {
|
if (i) {
|
||||||
expect(Helpers.regexInArray(orig, boolCase[desc])).to.be.true;
|
expect(Helpers.regexInArray(orig, boolCase[desc])).toBe(true);
|
||||||
} else {
|
} else {
|
||||||
expect(Helpers.regexInArray(orig, boolCase[desc])).to.be.false;
|
expect(Helpers.regexInArray(orig, boolCase[desc])).toBe(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('First argument is not an array', () => {
|
it('First argument is not an array', () => {
|
||||||
expect(Helpers.regexInArray(5, /5/)).to.be.false;
|
expect(Helpers.regexInArray(5, /5/)).toBe(false);
|
||||||
});
|
});
|
||||||
it('Array is empty', () => {
|
it('Array is empty', () => {
|
||||||
expect(Helpers.regexInArray([], /.*/)).to.be.false;
|
expect(Helpers.regexInArray([], /.*/)).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('upperCaseFirst -', () => {
|
describe('upperCaseFirst -', () => {
|
||||||
it('Capitalizes only the first letter of the string', () => {
|
it('Capitalizes only the first letter of the string', () => {
|
||||||
expect(Helpers.upperCaseFirst('foobar')).to.equal('Foobar');
|
expect(Helpers.upperCaseFirst('foobar')).toBe('Foobar');
|
||||||
expect(Helpers.upperCaseFirst('FOOBAR')).to.equal('FOOBAR');
|
expect(Helpers.upperCaseFirst('FOOBAR')).toBe('FOOBAR');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
/* eslint-env node, mocha */
|
|
||||||
'use strict';
|
|
||||||
const expect = require('chai').expect;
|
|
||||||
|
|
||||||
// Use the base driver as a mock for testing
|
// Use the base driver as a mock for testing
|
||||||
const Helpers = require('../lib/Helpers');
|
const Helpers = require('../lib/Helpers');
|
||||||
const driver = require('../lib/Driver');
|
const driver = require('../lib/Driver');
|
||||||
@ -56,11 +52,11 @@ describe('Query Parser Tests', () => {
|
|||||||
describe('Has operator tests', () => {
|
describe('Has operator tests', () => {
|
||||||
it('Has operator', () => {
|
it('Has operator', () => {
|
||||||
let matches = parser.hasOperator('foo <> 2');
|
let matches = parser.hasOperator('foo <> 2');
|
||||||
expect(matches).to.be.deep.equal(['<>']);
|
expect(matches).toEqual(['<>']);
|
||||||
});
|
});
|
||||||
it('Has no operator', () => {
|
it('Has no operator', () => {
|
||||||
let matches = parser.hasOperator('foo');
|
let matches = parser.hasOperator('foo');
|
||||||
expect(matches).to.be.null;
|
expect(matches).toBe(null);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('Where parser tests', () => {
|
describe('Where parser tests', () => {
|
||||||
@ -71,13 +67,13 @@ describe('Query Parser Tests', () => {
|
|||||||
whereMock('time < SUM(FOO(BAR()))');
|
whereMock('time < SUM(FOO(BAR()))');
|
||||||
parser.parseWhere(driver, state);
|
parser.parseWhere(driver, state);
|
||||||
expect(state.whereMap)
|
expect(state.whereMap)
|
||||||
.to.be.deep.equal(['"time" < SUM(FOO(BAR()))']);
|
.toEqual(['"time" < SUM(FOO(BAR()))']);
|
||||||
});
|
});
|
||||||
it('Has function key/val', () => {
|
it('Has function key/val', () => {
|
||||||
whereMock('time <', 'SUM(FOO(BAR()))');
|
whereMock('time <', 'SUM(FOO(BAR()))');
|
||||||
parser.parseWhere(driver, state);
|
parser.parseWhere(driver, state);
|
||||||
expect(state.whereMap)
|
expect(state.whereMap)
|
||||||
.to.be.deep.equal(['"time" < SUM(FOO(BAR()))']);
|
.toEqual(['"time" < SUM(FOO(BAR()))']);
|
||||||
});
|
});
|
||||||
it('Has function key/val object', () => {
|
it('Has function key/val object', () => {
|
||||||
whereMock({
|
whereMock({
|
||||||
@ -85,7 +81,7 @@ describe('Query Parser Tests', () => {
|
|||||||
});
|
});
|
||||||
parser.parseWhere(driver, state);
|
parser.parseWhere(driver, state);
|
||||||
expect(state.whereMap)
|
expect(state.whereMap)
|
||||||
.to.be.deep.equal(['"time" < SUM(FOO(BAR(\'x\')))']);
|
.toEqual(['"time" < SUM(FOO(BAR(\'x\')))']);
|
||||||
});
|
});
|
||||||
it('Has literal value', () => {
|
it('Has literal value', () => {
|
||||||
whereMock({
|
whereMock({
|
||||||
@ -93,9 +89,9 @@ describe('Query Parser Tests', () => {
|
|||||||
});
|
});
|
||||||
parser.parseWhere(driver, state);
|
parser.parseWhere(driver, state);
|
||||||
expect(state.whereMap)
|
expect(state.whereMap)
|
||||||
.to.be.deep.equal(['"foo" = ?']);
|
.toEqual(['"foo" = ?']);
|
||||||
expect(state.whereValues)
|
expect(state.whereValues)
|
||||||
.to.be.deep.equal(['3']);
|
.toEqual(['3']);
|
||||||
});
|
});
|
||||||
it('Has multiple literal values', () => {
|
it('Has multiple literal values', () => {
|
||||||
whereMock({
|
whereMock({
|
||||||
@ -104,9 +100,9 @@ describe('Query Parser Tests', () => {
|
|||||||
});
|
});
|
||||||
parser.parseWhere(driver, state);
|
parser.parseWhere(driver, state);
|
||||||
expect(state.whereMap)
|
expect(state.whereMap)
|
||||||
.to.be.deep.equal(['"foo" = ?', '"bar" = ?']);
|
.toEqual(['"foo" = ?', '"bar" = ?']);
|
||||||
expect(state.whereValues)
|
expect(state.whereValues)
|
||||||
.to.be.deep.equal(['3', '5']);
|
.toEqual(['3', '5']);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('Parse join tests', () => {
|
describe('Parse join tests', () => {
|
||||||
@ -133,7 +129,7 @@ describe('Query Parser Tests', () => {
|
|||||||
data.forEach(datum => {
|
data.forEach(datum => {
|
||||||
it(datum.desc, () => {
|
it(datum.desc, () => {
|
||||||
let matches = parser.parseJoin(datum.join);
|
let matches = parser.parseJoin(datum.join);
|
||||||
expect(matches.combined).to.be.deep.equal(datum.expected);
|
expect(matches.combined).toEqual(datum.expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -161,7 +157,7 @@ describe('Query Parser Tests', () => {
|
|||||||
data.forEach(datum => {
|
data.forEach(datum => {
|
||||||
it(datum.desc, () => {
|
it(datum.desc, () => {
|
||||||
let join = parser.compileJoin(datum.clause);
|
let join = parser.compileJoin(datum.clause);
|
||||||
expect(join).to.be.deep.equal(datum.expected);
|
expect(join).toEqual(datum.expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user