2013-05-08 20:16:39 -04:00
|
|
|
|
2013-05-09 03:47:03 -04:00
|
|
|
module.exports = function(Knex, dbName, resolver) {
|
2013-05-05 12:38:32 -04:00
|
|
|
|
|
|
|
|
describe(dbName, function() {
|
|
|
|
|
|
2013-05-08 20:16:39 -04:00
|
|
|
it('uses inner join by default', function(ok) {
|
|
|
|
|
Knex('accounts')
|
|
|
|
|
.join('test_table_two', 'accounts.id', '=', 'test_table_two.account_id')
|
|
|
|
|
.select('accounts.*', 'test_table_two.details')
|
2013-05-09 03:47:03 -04:00
|
|
|
.then(resolver(ok), ok);
|
2013-05-08 20:16:39 -04:00
|
|
|
});
|
2013-05-05 12:38:32 -04:00
|
|
|
|
2013-05-08 20:16:39 -04:00
|
|
|
it('takes a fifth parameter to specify the join type', function(ok) {
|
|
|
|
|
Knex('accounts')
|
|
|
|
|
.join('test_table_two', 'accounts.id', '=', 'test_table_two.account_id', 'left')
|
|
|
|
|
.select('accounts.*', 'test_table_two.details')
|
2013-05-09 03:47:03 -04:00
|
|
|
.then(resolver(ok), ok);
|
2013-05-08 20:16:39 -04:00
|
|
|
});
|
2013-05-05 12:38:32 -04:00
|
|
|
|
2013-05-08 20:16:39 -04:00
|
|
|
it('accepts a callback as the second argument for advanced joins', function(ok) {
|
|
|
|
|
Knex('accounts').join('test_table_two', function(join) {
|
|
|
|
|
join.on('accounts.id', '=', 'test_table_two.account_id');
|
|
|
|
|
join.orOn('accounts.email', '=', 'test_table_two.details');
|
|
|
|
|
}, 'left')
|
|
|
|
|
.select()
|
2013-05-09 03:47:03 -04:00
|
|
|
.then(resolver(ok), ok);
|
2013-05-08 20:16:39 -04:00
|
|
|
});
|
2013-05-05 12:38:32 -04:00
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
};
|