Even more code coverage

This commit is contained in:
Timothy Warren 2015-12-08 10:06:29 -05:00
parent 577700ed10
commit dd4d7e2db0
7 changed files with 28 additions and 17 deletions

View File

@ -29,6 +29,6 @@ module.exports = class Adapter {
* @return {void} * @return {void}
*/ */
close() { close() {
this.instance.close(); this.instance.end();
} }
}; };

View File

@ -52,8 +52,9 @@ module.exports = class QueryParser {
let output = []; let output = [];
// Return non-array matches // Return non-array matches
if (helpers.isNull(array)) return null; if (helpers.isNull(array)) {
if (helpers.isScalar(array) || helpers.isUndefined(array)) return output; return null;
}
array.forEach(item => { array.forEach(item => {
output.push(item); output.push(item);
@ -157,9 +158,9 @@ module.exports = class QueryParser {
// Filter explicit literals from lists of matches // Filter explicit literals from lists of matches
if (whereValues.indexOf(whereMap[key]) !== -1) { if (whereValues.indexOf(whereMap[key]) !== -1) {
let value = whereMap[key]; let value = whereMap[key];
let identIndex = (helpers.isArray(parts.identifiers)) ? parts.identifiers.indexOf(value) : -1; let identIndex = parts.identifiers.indexOf(value);
let litIndex = (helpers.isArray(parts.literals)) ? parts.literals.indexOf(value) : -1; let litIndex = (helpers.isArray(parts.literals)) ? parts.literals.indexOf(value) : -1;
let combIndex = (helpers.isArray(parts.combined)) ? parts.combined.indexOf(value) : -1; let combIndex = parts.combined.indexOf(value);
let funcIndex = (helpers.isArray(parts.functions)) ? parts.functions.indexOf(value) : -1; let funcIndex = (helpers.isArray(parts.functions)) ? parts.functions.indexOf(value) : -1;
let inOutputArray = outputValues.indexOf(value) !== -1; let inOutputArray = outputValues.indexOf(value) !== -1;
@ -190,16 +191,10 @@ module.exports = class QueryParser {
if (combIndex !== -1 && funcIndex === -1) { if (combIndex !== -1 && funcIndex === -1) {
// Make sure to skip functions when replacing values // Make sure to skip functions when replacing values
parts.combined[combIndex] = '?'; parts.combined[combIndex] = '?';
if (! inOutputArray) {
outputValues.push(value);
inOutputArray = true;
}
} }
} }
// Filter false positive identifiers // Filter false positive identifiers
parts.identifiers = parts.identifiers || [];
parts.identifiers = parts.identifiers.filter(item => { parts.identifiers = parts.identifiers.filter(item => {
let isInCombinedMatches = parts.combined.indexOf(item) !== -1; let isInCombinedMatches = parts.combined.indexOf(item) !== -1;
let isNotInBlackList = this.identifierBlacklist.indexOf(item.toLowerCase()) === -1; let isNotInBlackList = this.identifierBlacklist.indexOf(item.toLowerCase()) === -1;
@ -227,7 +222,7 @@ module.exports = class QueryParser {
let litIndex = parts.combined.indexOf(lit); let litIndex = parts.combined.indexOf(lit);
if (litIndex !== -1) { if (litIndex !== -1) {
parts.combined[litIndex] = (helpers.isArray(parts.operators)) ? '?' : '= ?'; parts.combined[litIndex] = '?';
outputValues.push(lit); outputValues.push(lit);
} }
}); });

View File

@ -16,4 +16,12 @@ module.exports = class dblite extends Adapter {
let args = getArgs('sql:string, [params]:array, callback:function', arguments); let args = getArgs('sql:string, [params]:array, callback:function', arguments);
this.instance.query(args.sql, args.params, args.callback); this.instance.query(args.sql, args.params, args.callback);
} }
/**
* Close the current database connection
* @return {void}
*/
close() {
this.instance.close();
}
}; };

View File

@ -56,6 +56,6 @@ suite('Mysql2 adapter tests', () => {
}); });
}); });
suiteTeardown(() => { suiteTeardown(() => {
connection.end(); qb.end();
}); });
}); });

View File

@ -56,6 +56,6 @@ suite('Mysql adapter tests', () => {
}); });
}); });
suiteTeardown(() => { suiteTeardown(() => {
connection.end(); qb.end();
}); });
}); });

View File

@ -15,7 +15,7 @@ let config = reload(configFile)[adapterName];
// Set up the connection // Set up the connection
let pg = reload(adapterName); let pg = reload(adapterName);
let connection = new pg.Client(config.conn); let connection = new pg.Client(config.conn);
connection.connect(function(err) { connection.connect(err => {
if (err) { if (err) {
throw new Error(err); throw new Error(err);
} }
@ -59,6 +59,6 @@ suite('Pg adapter tests', () => {
}); });
}); });
suiteTeardown(() => { suiteTeardown(() => {
connection.end(); qb.end();
}); });
}); });

View File

@ -3,7 +3,8 @@
let expect = require('chai').expect, let expect = require('chai').expect,
reload = require('require-reload')(require), reload = require('require-reload')(require),
glob = require('glob'), glob = require('glob'),
nodeQuery = reload('../lib/NodeQuery'); nodeQuery = reload('../lib/NodeQuery'),
Adapter = reload('../lib/Adapter');
suite('Base tests', () => { suite('Base tests', () => {
suite('Sanity check', () => { suite('Sanity check', () => {
@ -32,4 +33,11 @@ suite('Base tests', () => {
nodeQuery.init('foo', {}, 'bar'); nodeQuery.init('foo', {}, 'bar');
}).to.throw(Error, 'Selected driver (Foo) does not exist!'); }).to.throw(Error, 'Selected driver (Foo) does not exist!');
}); });
test('Invalid adapter', () => {
expect(() => {
let a = new Adapter();
a.execute();
}).to.throw(Error, 'Correct adapter not defined for query execution');
});
}); });