Skip to content

Commit

Permalink
test: add additional ways of specifying dbName
Browse files Browse the repository at this point in the history
  • Loading branch information
nbbeeken committed Nov 29, 2021
1 parent a217def commit 22db220
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/unit/mongo_client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -796,18 +796,42 @@ 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();
expect(db.databaseName).to.equal('myDb');
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');
});
});
});

0 comments on commit 22db220

Please sign in to comment.