@@ -787,4 +787,63 @@ describe('MongoOptions', function () {
787787 // Nothing wrong with the name, just DNE
788788 expect ( thrownError ) . to . have . property ( 'code' , 'ENOTFOUND' ) ;
789789 } ) ;
790+
791+ describe ( 'dbName and authSource' , ( ) => {
792+ describe ( 'in the URI' , ( ) => {
793+ it ( 'should set the database name to the dbName in the uri' , ( ) => {
794+ const client = new MongoClient ( 'mongodb://u:p@host/myDb' ) ;
795+ const db = client . db ( ) ;
796+ expect ( db ) . to . have . property ( 'databaseName' , 'myDb' ) ;
797+ expect ( client ) . to . have . nested . property ( 'options.credentials.source' , 'myDb' ) ;
798+ } ) ;
799+ it ( 'should set the database name to the uri pathname and respect the authSource option' , ( ) => {
800+ const client = new MongoClient ( 'mongodb://u:p@host/myDb?authSource=myAuthDb' ) ;
801+ const db = client . db ( ) ;
802+ expect ( db ) . to . have . property ( 'databaseName' , 'myDb' ) ;
803+ expect ( client ) . to . have . nested . property ( 'options.credentials.source' , 'myAuthDb' ) ;
804+ } ) ;
805+ it ( 'should set the database name to the uri pathname and respect the authSource option in options object' , ( ) => {
806+ const client = new MongoClient ( 'mongodb://u:p@host/myDb' , { authSource : 'myAuthDb' } ) ;
807+ const db = client . db ( ) ;
808+ expect ( db ) . to . have . property ( 'databaseName' , 'myDb' ) ;
809+ expect ( client ) . to . have . nested . property ( 'options.credentials.source' , 'myAuthDb' ) ;
810+ } ) ;
811+ } ) ;
812+
813+ describe ( 'in the options object' , ( ) => {
814+ it ( 'should set the database name to the dbName in the options object' , ( ) => {
815+ const client = new MongoClient ( 'mongodb://u:p@host' , { dbName : 'myDb' } ) ;
816+ const db = client . db ( ) ;
817+ expect ( db ) . to . have . property ( 'databaseName' , 'myDb' ) ;
818+ expect ( client ) . to . have . nested . property ( 'options.credentials.source' , 'myDb' ) ;
819+ } ) ;
820+ it ( 'should set the database name to dbName and respect the authSource option' , ( ) => {
821+ const client = new MongoClient ( 'mongodb://u:p@host?authSource=myAuthDb' , {
822+ dbName : 'myDb'
823+ } ) ;
824+ const db = client . db ( ) ;
825+ expect ( db ) . to . have . property ( 'databaseName' , 'myDb' ) ;
826+ expect ( client ) . to . have . nested . property ( 'options.credentials.source' , 'myAuthDb' ) ;
827+ } ) ;
828+ it ( 'should set the database name to dbName and respect the authSource option in options object' , ( ) => {
829+ const client = new MongoClient ( 'mongodb://u:p@host' , {
830+ dbName : 'myDb' ,
831+ authSource : 'myAuthDb'
832+ } ) ;
833+ const db = client . db ( ) ;
834+ expect ( db ) . to . have . property ( 'databaseName' , 'myDb' ) ;
835+ expect ( client ) . to . have . nested . property ( 'options.credentials.source' , 'myAuthDb' ) ;
836+ } ) ;
837+
838+ it ( 'should set the database name to dbName in options object and respect the authSource option in options object' , ( ) => {
839+ const client = new MongoClient ( 'mongodb://u:p@host/myIgnoredDb' , {
840+ dbName : 'myDb' ,
841+ authSource : 'myAuthDb'
842+ } ) ;
843+ const db = client . db ( ) ;
844+ expect ( db ) . to . have . property ( 'databaseName' , 'myDb' ) ;
845+ expect ( client ) . to . have . nested . property ( 'options.credentials.source' , 'myAuthDb' ) ;
846+ } ) ;
847+ } ) ;
848+ } ) ;
790849} ) ;
0 commit comments