Fix test setup to actually run an assertion for each generated query

This commit is contained in:
Timothy Warren 2014-10-24 14:26:31 -04:00
parent 3b1284ec95
commit 7fa78ace67
4 changed files with 101 additions and 56 deletions

View File

@ -23,7 +23,8 @@ testBase._setUp(qb, function(test, err, rows) {
throw new Error(err); throw new Error(err);
} }
test.ok(rows); test.ok(rows, 'Valid result for generated query');
test.done();
}); });
// Export the final test object // Export the final test object

View File

@ -23,7 +23,8 @@ testBase._setUp(qb, function(test, err, rows) {
throw new Error(err); throw new Error(err);
} }
test.ok(rows); test.ok(rows, 'Valid result for generated query');
test.done();
}); });
tests["mysql adapter with query builder"] = function(test) { tests["mysql adapter with query builder"] = function(test) {

View File

@ -19,12 +19,12 @@ var qb = nodeQuery('pg', connection, adapterName);
// Set up the test base // Set up the test base
testBase._setUp(qb, function(test, err, rows) { testBase._setUp(qb, function(test, err, result) {
if (err) { if (err) {
throw new Error(err); throw new Error(err);
} }
test.ok(rows); test.ok.call(test, result);
}); });
// Export the final test object // Export the final test object

View File

@ -19,31 +19,36 @@ module.exports = (function() {
* Generic query builder tests * Generic query builder tests
*/ */
base.tests = { base.tests = {
// ! Get tests
'Get tests' : { 'Get tests' : {
'Get with function': function(test) { 'Get with function': function(test) {
base.qb.select('id, COUNT(id) as count') base.qb.select('id, COUNT(id) as count')
.from('create_test') .from('create_test')
.groupBy('id') .groupBy('id')
.get(base.testCallback.bind(test, test)); .get(base.testCallback.bind(null, test));
test.done();
}, },
'Basic select all get': function(test) { 'Basic select all get': function(test) {
base.qb.get('create_test', base.testCallback.bind(test, test)); base.qb.get('create_test', base.testCallback.bind(null, test));
test.done();
}, },
'Basic select all with from': function(test) { 'Basic select all with from': function(test) {
base.qb.from('create_test') base.qb.from('create_test')
.get(base.testCallback.bind(test, test)); .get(base.testCallback.bind(null, test));
test.done();
}, },
'Get with limit': function(test) { 'Get with limit': function(test) {
base.qb.get('create_test', 2, base.testCallback.bind(test, test)); base.qb.get('create_test', 2, base.testCallback.bind(null, test));
test.done();
}, },
'Get with limit and offset': function(test) { 'Get with limit and offset': function(test) {
base.qb.get('create_test', 2, 1, base.testCallback.bind(test, test)); base.qb.get('create_test', 2, 1, base.testCallback.bind(null, test));
test.done();
}, },
'Test get with having': function(test) { 'Test get with having': function(test) {
base.qb.select('id') base.qb.select('id')
@ -51,9 +56,9 @@ module.exports = (function() {
.groupBy('id') .groupBy('id')
.having({'id >':1}) .having({'id >':1})
.having('id !=', 3) .having('id !=', 3)
.get(base.testCallback.bind(test, test)); .get(base.testCallback.bind(null, test));
test.done();
}, },
"Test get with 'orHaving'": function(test) { "Test get with 'orHaving'": function(test) {
base.qb.select('id') base.qb.select('id')
@ -61,55 +66,56 @@ module.exports = (function() {
.groupBy('id') .groupBy('id')
.having({'id >':1}) .having({'id >':1})
.orHaving('id !=', 3) .orHaving('id !=', 3)
.get(base.testCallback.bind(test, test)); .get(base.testCallback.bind(null, test));
test.done();
} }
}, },
// ! Select tests
'Select tests' : { 'Select tests' : {
'Select where get': function(test) { 'Select where get': function(test) {
base.qb.select(['id', 'key as k', 'val']) base.qb.select(['id', 'key as k', 'val'])
.where('id >', 1) .where('id >', 1)
.where('id <', 900) .where('id <', 900)
.get('create_test', 2, 1, base.testCallback.bind(test, test)); .get('create_test', 2, 1, base.testCallback.bind(null, test));
},
'Select where get 2': function(test) {
base.qb.select('id, key as k, val') base.qb.select('id, key as k, val')
.where('id !=', 1) .where('id !=', 1)
.get('create_test', 2, 1, base.testCallback.bind(test, test)); .get('create_test', 2, 1, base.testCallback.bind(null, test));
test.done();
}, },
'Multi Order By': function(test) { 'Multi Order By': function(test) {
base.qb.from('create_test') base.qb.from('create_test')
.orderBy('id, key') .orderBy('id, key')
.get(base.testCallback.bind(test, test)); .get(base.testCallback.bind(null, test));
test.done();
}, },
'Select get': function(test) { 'Select get': function(test) {
base.qb.select('id, key as k, val') base.qb.select('id, key as k, val')
.get('create_test', 2, 1, base.testCallback.bind(test, test)); .get('create_test', 2, 1, base.testCallback.bind(null, test));
test.done();
}, },
'Select from get': function(test) { 'Select from get': function(test) {
base.qb.select('id, key as k, val') base.qb.select('id, key as k, val')
.from('create_test ct') .from('create_test ct')
.where('id >', 1) .where('id >', 1)
.get(base.testCallback.bind(test, test)); .get(base.testCallback.bind(null, test));
test.done();
}, },
'Select from limit get': function(test) { 'Select from limit get': function(test) {
base.qb.select('id, key as k, val') base.qb.select('id, key as k, val')
.from('create_test ct') .from('create_test ct')
.where('id >', 1) .where('id >', 1)
.limit(3) .limit(3)
.get(base.testCallback.bind(test, test)); .get(base.testCallback.bind(null, test));
test.done();
} }
}, },
// ! Grouping tests
'Grouping tests' : { 'Grouping tests' : {
'Using grouping method': function(test) { 'Using grouping method': function(test) {
base.qb.select('id, key as k, val') base.qb.select('id, key as k, val')
@ -119,9 +125,9 @@ module.exports = (function() {
.where('id <', 900) .where('id <', 900)
.groupEnd() .groupEnd()
.limit(2, 1) .limit(2, 1)
.get(base.testCallback.bind(test, test)); .get(base.testCallback.bind(null, test));
test.done();
}, },
'Using or grouping method': function(test) { 'Using or grouping method': function(test) {
base.qb.select('id, key as k, val') base.qb.select('id, key as k, val')
@ -134,9 +140,9 @@ module.exports = (function() {
.where('id', 0) .where('id', 0)
.groupEnd() .groupEnd()
.limit(2, 1) .limit(2, 1)
.get(base.testCallback.bind(test, test)); .get(base.testCallback.bind(null, test));
test.done();
}, },
'Using or not grouping method': function(test) { 'Using or not grouping method': function(test) {
base.qb.select('id, key as k, val') base.qb.select('id, key as k, val')
@ -149,44 +155,46 @@ module.exports = (function() {
.where('id', 0) .where('id', 0)
.groupEnd() .groupEnd()
.limit(2, 1) .limit(2, 1)
.get(base.testCallback.bind(test, test)); .get(base.testCallback.bind(null, test));
test.done();
} }
}, },
// ! Where in tests
'Where in tests' : { 'Where in tests' : {
'Where in': function(test) { 'Where in': function(test) {
base.qb.from('create_test') base.qb.from('create_test')
.whereIn('id', [0, 6, 56, 563, 341]) .whereIn('id', [0, 6, 56, 563, 341])
.get(base.testCallback.bind(test, test)); .get(base.testCallback.bind(null, test));
test.done();
}, },
'Or Where in': function(test) { 'Or Where in': function(test) {
base.qb.from('create_test') base.qb.from('create_test')
.where('key', 'false') .where('key', 'false')
.orWhereIn('id', [0, 6, 56, 563, 341]) .orWhereIn('id', [0, 6, 56, 563, 341])
.get(base.testCallback.bind(test, test)); .get(base.testCallback.bind(null, test));
test.done();
}, },
'Where Not in': function(test) { 'Where Not in': function(test) {
base.qb.from('create_test') base.qb.from('create_test')
.where('key', 'false') .where('key', 'false')
.whereNotIn('id', [0, 6, 56, 563, 341]) .whereNotIn('id', [0, 6, 56, 563, 341])
.get(base.testCallback.bind(test, test)); .get(base.testCallback.bind(null, test));
test.done();
}, },
'Or Where Not in': function(test) { 'Or Where Not in': function(test) {
base.qb.from('create_test') base.qb.from('create_test')
.where('key', 'false') .where('key', 'false')
.orWhereNotIn('id', [0, 6, 56, 563, 341]) .orWhereNotIn('id', [0, 6, 56, 563, 341])
.get(base.testCallback.bind(test, test)); .get(base.testCallback.bind(null, test));
test.done();
} }
}, },
// ! Query modifier testss
'Query modifier tests': { 'Query modifier tests': {
'Order By': function(test) { 'Order By': function(test) {
base.qb.select('id, key as k, val') base.qb.select('id, key as k, val')
@ -196,9 +204,9 @@ module.exports = (function() {
.orderBy('id', 'DESC') .orderBy('id', 'DESC')
.orderBy('k', "ASC") .orderBy('k', "ASC")
.limit(5, 2) .limit(5, 2)
.get(base.testCallback.bind(test, test)); .get(base.testCallback.bind(null, test));
test.done();
}, },
'Group by': function(test) { 'Group by': function(test) {
base.qb.select('id, key as k, val') base.qb.select('id, key as k, val')
@ -210,9 +218,9 @@ module.exports = (function() {
.orderBy('id', 'DESC') .orderBy('id', 'DESC')
.orderBy('k', "ASC") .orderBy('k', "ASC")
.limit(5, 2) .limit(5, 2)
.get(base.testCallback.bind(test, test)); .get(base.testCallback.bind(null, test));
test.done();
}, },
'Or Where': function(test) { 'Or Where': function(test) {
base.qb.select('id, key as k, val') base.qb.select('id, key as k, val')
@ -220,25 +228,60 @@ module.exports = (function() {
.where(' id ', 1) .where(' id ', 1)
.orWhere('key >', 0) .orWhere('key >', 0)
.limit(2, 1) .limit(2, 1)
.get(base.testCallback.bind(test, test)); .get(base.testCallback.bind(null, test));
test.done();
}, },
'Like' : function(test) { 'Like' : function(test) {
base.qb.from('create_test') base.qb.from('create_test')
.like('key', 'og') .like('key', 'og')
.get(base.testCallback.bind(test, test)); .get(base.testCallback.bind(null, test));
test.done();
}, },
'Or Like': function(test) { 'Or Like': function(test) {
base.qb.from('create_test') base.qb.from('create_test')
.like('key', 'og') .like('key', 'og')
.orLike('key', 'val') .orLike('key', 'val')
.get(base.testCallback.bind(test, test)); .get(base.testCallback.bind(null, test));
test.done();
} },
'Not Like': function(test) {
base.qb.from('create_test')
.like('key', 'og', 'before')
.notLike('key', 'val')
.get(base.testCallback.bind(null, test));
},
'Or Not Like': function(test) {
base.qb.from('create_test')
.like('key', 'og', 'before')
.orNotLike('key', 'val')
.get(base.testCallback.bind(null, test));
},
'Like Before': function(test) {
base.qb.from('create_test')
.like('key', 'og', 'before')
.get(base.testCallback.bind(null, test));
},
'Like After': function(test) {
base.qb.from('create_test')
.like('key', 'og', 'after')
.get(base.testCallback.bind(null, test));
}/*,
'Basic Join': function(test) {
base.qb.from('create_test ct')
.join('create_join cj', 'cj.id', '=', 'ct.id', 'left')
.get(base.testCallback.bind(null, test));
}*/
}, },
'DB update tests' : { 'DB update tests' : {