@@ -415,6 +415,14 @@ describe('DataSource', function() {
415415 it ( 'supports shorthand version (cmd)' , async ( ) => {
416416 let called = 'not called' ;
417417 ds . connector . execute = function ( command , args , options , callback ) {
418+ // copied from loopback-connector/lib/sql.js
419+ if ( typeof args === 'function' && options === undefined && callback === undefined ) {
420+ // execute(sql, callback)
421+ options = { } ;
422+ callback = args ;
423+ args = [ ] ;
424+ }
425+
418426 called = { command, args, options} ;
419427 callback ( null , 'a-result' ) ;
420428 } ;
@@ -431,6 +439,13 @@ describe('DataSource', function() {
431439 it ( 'supports shorthand version (cmd, args)' , async ( ) => {
432440 let called = 'not called' ;
433441 ds . connector . execute = function ( command , args , options , callback ) {
442+ // copied from loopback-connector/lib/sql.js
443+ if ( typeof options === 'function' && callback === undefined ) {
444+ // execute(sql, params, callback)
445+ callback = options ;
446+ options = { } ;
447+ }
448+
434449 called = { command, args, options} ;
435450 callback ( null , 'a-result' ) ;
436451 } ;
@@ -444,7 +459,8 @@ describe('DataSource', function() {
444459 } ) ;
445460
446461 it ( 'converts multiple callbacks arguments into a promise resolved with an array' , async ( ) => {
447- ds . connector . execute = function ( command , args , options , callback ) {
462+ ds . connector . execute = function ( ) {
463+ const callback = arguments [ arguments . length - 1 ] ;
448464 callback ( null , 'result1' , 'result2' ) ;
449465 } ;
450466 const result = await ds . execute ( 'command' ) ;
@@ -460,14 +476,64 @@ describe('DataSource', function() {
460476
461477 // See https://www.npmjs.com/package/loopback-connector-neo4j-graph
462478 const command = 'MATCH (u:User {email: {email}}) RETURN u' ;
463- await ds . execute ( command , { email :
'[email protected] ' } ) ; 479+ await ds . execute ( command , { email :
'[email protected] ' } , { options : true } ) ; 464480 called . should . be . eql ( {
465481 command,
466482 args :
{ email :
'[email protected] ' } , 467- options : { } ,
483+ options : { options : true } ,
468484 } ) ;
469485 } ) ;
470486
487+ it ( 'supports MongoDB version (collection, cmd, args, options)' , async ( ) => {
488+ let called = 'not called' ;
489+ ds . connector . execute = function ( ...params ) {
490+ const callback = params . pop ( ) ;
491+ called = params ;
492+ callback ( null , 'a-result' ) ;
493+ } ;
494+
495+ const result = await ds . execute (
496+ 'collection' ,
497+ 'command' ,
498+ [ 'arg1' , 'arg2' ] ,
499+ { options : true } ,
500+ ) ;
501+
502+ result . should . equal ( 'a-result' ) ;
503+ called . should . be . eql ( [
504+ 'collection' ,
505+ 'command' ,
506+ [ 'arg1' , 'arg2' ] ,
507+ { options : true } ,
508+ ] ) ;
509+ } ) ;
510+
511+ it ( 'supports free-form version (...params)' , async ( ) => {
512+ let called = 'not called' ;
513+ ds . connector . execute = function ( ...params ) {
514+ const callback = params . pop ( ) ;
515+ called = params ;
516+ callback ( null , 'a-result' ) ;
517+ } ;
518+
519+ const result = await ds . execute (
520+ 'arg1' ,
521+ 'arg2' ,
522+ 'arg3' ,
523+ 'arg4' ,
524+ { options : true } ,
525+ ) ;
526+
527+ result . should . equal ( 'a-result' ) ;
528+ called . should . be . eql ( [
529+ 'arg1' ,
530+ 'arg2' ,
531+ 'arg3' ,
532+ 'arg4' ,
533+ { options : true } ,
534+ ] ) ;
535+ } ) ;
536+
471537 it ( 'throws NOT_IMPLEMENTED when no connector is provided' , ( ) => {
472538 ds . connector = undefined ;
473539 return ds . execute ( 'command' ) . should . be . rejectedWith ( {
0 commit comments