Skip to content

Commit

Permalink
test: default name with no argument client.db()
Browse files Browse the repository at this point in the history
  • Loading branch information
nbbeeken committed Nov 29, 2021
1 parent 8027af4 commit a217def
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/unit/mongo_client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -787,4 +787,27 @@ describe('MongoOptions', function () {
// Nothing wrong with the name, just DNE
expect(thrownError).to.have.property('code', 'ENOTFOUND');
});

describe('specifying dbName', () => {
it('in the URI as a pathname', function () {
const client = new MongoClient('mongodb://u:p@host/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 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');
});
});
});

0 comments on commit a217def

Please sign in to comment.