From 22db220f1925ee975941cf81c35cb0ff223a4b09 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Mon, 29 Nov 2021 14:26:21 -0500 Subject: [PATCH] test: add additional ways of specifying dbName --- test/unit/mongo_client.test.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/unit/mongo_client.test.js b/test/unit/mongo_client.test.js index 09ba1ed79b..91600d4dee 100644 --- a/test/unit/mongo_client.test.js +++ b/test/unit/mongo_client.test.js @@ -796,6 +796,13 @@ describe('MongoOptions', function () { expect(client).to.have.nested.property('options.credentials.source', 'myDb'); }); + it('in the options object', function () { + const client = new MongoClient('mongodb://u:p@host', { dbName: 'myDb' }); + const db = client.db(); + expect(db).to.have.property('databaseName', 'myDb'); + expect(client).to.have.nested.property('options.credentials.source', 'myDb'); + }); + it('in the URI as a pathname with authSource option', function () { const client = new MongoClient('mongodb://u:p@host/myDb?authSource=myAuthDb'); const db = client.db(); @@ -803,11 +810,28 @@ describe('MongoOptions', function () { expect(client).to.have.nested.property('options.credentials.source', 'myAuthDb'); }); + it('in the options object with authSource option', function () { + const client = new MongoClient('mongodb://u:p@host?authSource=myAuthDb', { dbName: 'myDb' }); + const db = client.db(); + expect(db).to.have.property('databaseName', 'myDb'); + expect(client).to.have.nested.property('options.credentials.source', 'myAuthDb'); + }); + it('in the URI as a pathname with authSource option in options object', function () { const client = new MongoClient('mongodb://u:p@host/myDb', { authSource: 'myAuthDb' }); const db = client.db(); expect(db.databaseName).to.equal('myDb'); expect(client).to.have.nested.property('options.credentials.source', 'myAuthDb'); }); + + it('in the options object with authSource option in options object', function () { + const client = new MongoClient('mongodb://u:p@host', { + dbName: 'myDb', + authSource: 'myAuthDb' + }); + const db = client.db(); + expect(db.databaseName).to.equal('myDb'); + expect(client).to.have.nested.property('options.credentials.source', 'myAuthDb'); + }); }); });