@@ -449,6 +449,81 @@ describe('mongodb connector', function() {
449449 } ) ;
450450 } ) ;
451451 } ) ;
452+
453+ it ( "should honor the settings database if url doesn't have db" , function ( done ) {
454+ const cfg = JSON . parse ( JSON . stringify ( global . config ) ) ;
455+ const testDb = cfg . database ;
456+ cfg . url = 'mongodb://' + cfg . host + ':' + cfg . port ;
457+ const ds = global . getDataSource ( cfg ) ;
458+ ds . once ( 'connected' , function ( ) {
459+ const db = ds . connector . db ;
460+ let validationError = null ;
461+ try {
462+ db . should . have . property ( 'databaseName' , testDb ) ; // check the db name in the db instance
463+ } catch ( err ) {
464+ // async error
465+ validationError = err ;
466+ }
467+ ds . ping ( function ( err ) {
468+ if ( err && ! validationError ) validationError = err ;
469+ ds . disconnect ( function ( disconnectError ) {
470+ if ( disconnectError && ! validationError )
471+ validationError = disconnectError ;
472+ done ( validationError ) ;
473+ } ) ;
474+ } ) ;
475+ } ) ;
476+ } ) ;
477+
478+ it ( 'should honor the url database if both replicaset url and settings has db' , function ( done ) {
479+ const cfg = JSON . parse ( JSON . stringify ( global . config ) ) ;
480+ const testDb = 'lb-ds-overriden-test-1' ;
481+ cfg . url = 'mongodb://' + cfg . host + ':' + cfg . port + ',' + cfg . host + ':' + cfg . port + '/' + testDb ;
482+ const ds = global . getDataSource ( cfg ) ;
483+ ds . once ( 'connected' , function ( ) {
484+ const db = ds . connector . db ;
485+ let validationError = null ;
486+ try {
487+ db . should . have . property ( 'databaseName' , testDb ) ; // check the db name in the db instance
488+ } catch ( err ) {
489+ // async error
490+ validationError = err ;
491+ }
492+ ds . ping ( function ( err ) {
493+ if ( err && ! validationError ) validationError = err ;
494+ ds . disconnect ( function ( disconnectError ) {
495+ if ( disconnectError && ! validationError )
496+ validationError = disconnectError ;
497+ done ( validationError ) ;
498+ } ) ;
499+ } ) ;
500+ } ) ;
501+ } ) ;
502+
503+ it ( "should honor the settings database if replicaset url doesn't have db has slash" , function ( done ) {
504+ const cfg = JSON . parse ( JSON . stringify ( global . config ) ) ;
505+ const testDb = cfg . database ;
506+ cfg . url = 'mongodb://' + cfg . host + ':' + cfg . port + ',' + cfg . host + ':' + cfg . port + '/' ;
507+ const ds = global . getDataSource ( cfg ) ;
508+ ds . once ( 'connected' , function ( ) {
509+ const db = ds . connector . db ;
510+ let validationError = null ;
511+ try {
512+ db . should . have . property ( 'databaseName' , testDb ) ; // check the db name in the db instance
513+ } catch ( err ) {
514+ // async error
515+ validationError = err ;
516+ }
517+ ds . ping ( function ( err ) {
518+ if ( err && ! validationError ) validationError = err ;
519+ ds . disconnect ( function ( disconnectError ) {
520+ if ( disconnectError && ! validationError )
521+ validationError = disconnectError ;
522+ done ( validationError ) ;
523+ } ) ;
524+ } ) ;
525+ } ) ;
526+ } ) ;
452527 } ) ;
453528
454529 describe ( 'order filters' , function ( ) {
0 commit comments