From b76e8b1f9e24847b36507d3079f28135bfc9ab40 Mon Sep 17 00:00:00 2001 From: Zaid Humayun Date: Fri, 23 Jun 2023 23:03:31 +0530 Subject: [PATCH 1/7] fix(NODE-5102): coercing the nameOnly option for listDatabases to a boolean. Also assigning that directly to the cmd object in execute. Added tests for listDatabases --- src/operations/command.ts | 2 +- src/operations/list_databases.ts | 6 ++-- test/unit/operations/list_databases.test.js | 36 +++++++++++++++++++++ 3 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 test/unit/operations/list_databases.test.js diff --git a/src/operations/command.ts b/src/operations/command.ts index 8804762df41..8454986a4af 100644 --- a/src/operations/command.ts +++ b/src/operations/command.ts @@ -86,7 +86,7 @@ export abstract class CommandOperation extends AbstractOperation { this.ns = new MongoDBNamespace(dbNameOverride, '$cmd'); } else { this.ns = parent - ? parent.s.namespace.withCollection('$cmd') + ? parent.s?.namespace.withCollection('$cmd') : new MongoDBNamespace('admin', '$cmd'); } diff --git a/src/operations/list_databases.ts b/src/operations/list_databases.ts index 807616c3cf9..f222b7f626e 100644 --- a/src/operations/list_databases.ts +++ b/src/operations/list_databases.ts @@ -31,6 +31,7 @@ export class ListDatabasesOperation extends CommandOperation ): void { - const cmd: Document = { listDatabases: 1 }; - if (this.options.nameOnly) { - cmd.nameOnly = Number(cmd.nameOnly); - } + const cmd: Document = { listDatabases: 1, nameOnly: this.options.nameOnly }; if (this.options.filter) { cmd.filter = this.options.filter; diff --git a/test/unit/operations/list_databases.test.js b/test/unit/operations/list_databases.test.js new file mode 100644 index 00000000000..bce1420ef74 --- /dev/null +++ b/test/unit/operations/list_databases.test.js @@ -0,0 +1,36 @@ +'use strict'; + +const { expect } = require('chai'); + +const { ListDatabasesOperation } = require('../../mongodb'); + +describe('ListDatabasesOperation', function () { + const db = 'test'; + + describe('#constructor', function () { + context('when nameOnly is provided', function () { + context('when nameOnly is true', function () { + const operation = new ListDatabasesOperation(db, { nameOnly: true }); + it('sets nameOnly to true', function () { + expect(operation.options).to.have.property('nameOnly', true); + }); + }); + + context('when nameOnly is false', function () { + const operation = new ListDatabasesOperation({}, { nameOnly: false }); + + it('sets nameOnly to false', function () { + expect(operation.options).to.have.property('nameOnly', false); + }); + }); + }); + + context('when no options are provided', function () { + const operation = new ListDatabasesOperation(db, {}); + + it('sets nameOnly to false', function () { + expect(operation.options).to.have.property('nameOnly', false); + }); + }); + }); +}); From 2d9ad3bb80c35815c283c2bdb02e7728f2284f57 Mon Sep 17 00:00:00 2001 From: Warren James Date: Thu, 29 Jun 2023 14:01:00 -0400 Subject: [PATCH 2/7] fix(NODE-5102): Fix review suggestions and add int tests --- src/operations/command.ts | 2 +- src/operations/list_databases.ts | 7 +- test/integration/enumerate_databases.test.ts | 77 ++++++++++++++++++-- test/unit/operations/list_databases.test.js | 36 --------- test/unit/operations/list_databases.test.ts | 31 ++++++++ 5 files changed, 106 insertions(+), 47 deletions(-) delete mode 100644 test/unit/operations/list_databases.test.js create mode 100644 test/unit/operations/list_databases.test.ts diff --git a/src/operations/command.ts b/src/operations/command.ts index 8454986a4af..8804762df41 100644 --- a/src/operations/command.ts +++ b/src/operations/command.ts @@ -86,7 +86,7 @@ export abstract class CommandOperation extends AbstractOperation { this.ns = new MongoDBNamespace(dbNameOverride, '$cmd'); } else { this.ns = parent - ? parent.s?.namespace.withCollection('$cmd') + ? parent.s.namespace.withCollection('$cmd') : new MongoDBNamespace('admin', '$cmd'); } diff --git a/src/operations/list_databases.ts b/src/operations/list_databases.ts index f222b7f626e..c4029d808a7 100644 --- a/src/operations/list_databases.ts +++ b/src/operations/list_databases.ts @@ -31,7 +31,6 @@ export class ListDatabasesOperation extends CommandOperation ): void { - const cmd: Document = { listDatabases: 1, nameOnly: this.options.nameOnly }; + const cmd: Document = { listDatabases: 1 }; + + if (typeof this.options.nameOnly === 'boolean') { + cmd.nameOnly = this.options.nameOnly; + } if (this.options.filter) { cmd.filter = this.options.filter; diff --git a/test/integration/enumerate_databases.test.ts b/test/integration/enumerate_databases.test.ts index 9234973eb6d..7229988deab 100644 --- a/test/integration/enumerate_databases.test.ts +++ b/test/integration/enumerate_databases.test.ts @@ -14,7 +14,7 @@ const metadata: MongoDBMetadataUI = { } }; -describe('listDatabases()', function () { +describe('listDatabases()', function() { describe('authorizedDatabases option', () => { const username = 'a'; const password = 'b'; @@ -28,7 +28,7 @@ describe('listDatabases()', function () { roles: [{ role: 'read', db: mockAuthorizedDb }] }; - beforeEach(async function () { + beforeEach(async function() { adminClient = this.configuration.newClient(); await adminClient @@ -43,7 +43,7 @@ describe('listDatabases()', function () { }); }); - afterEach(async function () { + afterEach(async function() { await adminClient?.db('admin').removeUser(username); await adminClient?.db(mockAuthorizedDb).dropDatabase(); await adminClient?.close(); @@ -53,7 +53,7 @@ describe('listDatabases()', function () { it( 'should list all databases when admin client sets authorizedDatabases to true', metadata, - async function () { + async function() { const adminListDbs = await adminClient .db() .admin() @@ -70,7 +70,7 @@ describe('listDatabases()', function () { it( 'should list all databases when admin client sets authorizedDatabases to false', metadata, - async function () { + async function() { const adminListDbs = await adminClient .db() .admin() @@ -87,7 +87,7 @@ describe('listDatabases()', function () { it( 'should list authorized databases with authorizedDatabases set to true', metadata, - async function () { + async function() { const adminListDbs = await adminClient.db().admin().listDatabases(); const authorizedListDbs = await authorizedClient .db() @@ -108,7 +108,7 @@ describe('listDatabases()', function () { it( 'should list authorized databases by default with authorizedDatabases unspecified', metadata, - async function () { + async function() { const adminListDbs = await adminClient.db().admin().listDatabases(); const authorizedListDbs = await authorizedClient.db().admin().listDatabases(); const adminDbs = adminListDbs.databases; @@ -126,7 +126,7 @@ describe('listDatabases()', function () { it( 'should not show authorized databases with authorizedDatabases set to false', metadata, - async function () { + async function() { let thrownError; try { await authorizedClient.db().admin().listDatabases({ authorizedDatabases: false }); @@ -141,6 +141,67 @@ describe('listDatabases()', function () { ); }); + describe('nameOnly option', function() { + let client: MongoClient; + const DBS = 10; + const nameOnlyOptions = [true, false, undefined]; + + beforeEach(async function() { + client = await this.configuration.newClient().connect(); + for (let i = 0; i < DBS; i++) { + const db = client.db(`testDb_${i}`); + await db.collection('test').insertOne({ a: 1 }); + } + }); + + afterEach(async function() { + if (client) { + for (let i = 0; i < DBS; i++) { + await client.db(`testDb_${i}`).dropDatabase(); + } + + await client.close(); + } + }); + + for (const nameOnly of nameOnlyOptions) { + context(`when options.nameOnly is ${nameOnly ?? 'not defined'}`, function() { + it(`returns ${optionToExpecation(nameOnly)}`, async function() { + const response = await client.db().admin().listDatabases({ nameOnly }); + + expect(response).to.have.property('databases'); + expect(response.databases).to.have.length.gte(DBS); + switch (nameOnly) { + case true: + for (const db of response.databases) { + expect(db).property('name').to.exist; + expect(db).to.not.have.property('sizeOnDisk'); + expect(db).to.not.have.property('empty'); + } + break; + case false: + case undefined: + for (const db of response.databases) { + expect(db.name).to.exist; + expect(db).property('sizeOnDisk').to.exist; + expect(db).property('empty').to.exist; + } + break; + } + }); + }); + } + + function optionToExpecation(nameOnly?: boolean): string { + switch (nameOnly) { + case true: + return 'list of only database names'; + case false: + case undefined: + return 'list of entire listDatabases responses'; + } + } + }); UnifiedTestSuiteBuilder.describe('comment option') .createEntities(UnifiedTestSuiteBuilder.defaultEntities) .initialData({ diff --git a/test/unit/operations/list_databases.test.js b/test/unit/operations/list_databases.test.js deleted file mode 100644 index bce1420ef74..00000000000 --- a/test/unit/operations/list_databases.test.js +++ /dev/null @@ -1,36 +0,0 @@ -'use strict'; - -const { expect } = require('chai'); - -const { ListDatabasesOperation } = require('../../mongodb'); - -describe('ListDatabasesOperation', function () { - const db = 'test'; - - describe('#constructor', function () { - context('when nameOnly is provided', function () { - context('when nameOnly is true', function () { - const operation = new ListDatabasesOperation(db, { nameOnly: true }); - it('sets nameOnly to true', function () { - expect(operation.options).to.have.property('nameOnly', true); - }); - }); - - context('when nameOnly is false', function () { - const operation = new ListDatabasesOperation({}, { nameOnly: false }); - - it('sets nameOnly to false', function () { - expect(operation.options).to.have.property('nameOnly', false); - }); - }); - }); - - context('when no options are provided', function () { - const operation = new ListDatabasesOperation(db, {}); - - it('sets nameOnly to false', function () { - expect(operation.options).to.have.property('nameOnly', false); - }); - }); - }); -}); diff --git a/test/unit/operations/list_databases.test.ts b/test/unit/operations/list_databases.test.ts new file mode 100644 index 00000000000..f189d7b7fb8 --- /dev/null +++ b/test/unit/operations/list_databases.test.ts @@ -0,0 +1,31 @@ +import { expect } from 'chai'; +import { ListDatabasesOperation, Db } from '../../mongodb'; + +describe('ListDatabasesOperation', function() { + describe('#constructor', function() { + context('when nameOnly is provided', function() { + context('when nameOnly is true', function() { + const operation = new ListDatabasesOperation({} as Db, { nameOnly: true }); + it('sets nameOnly to true', function() { + expect(operation.options).to.have.property('nameOnly', true); + }); + }); + + context('when nameOnly is false', function() { + const operation = new ListDatabasesOperation({} as Db, { nameOnly: false }); + + it('sets nameOnly to false', function() { + expect(operation.options).to.have.property('nameOnly', false); + }); + }); + }); + + context('when no options are provided', function() { + const operation = new ListDatabasesOperation({} as Db, {}); + + it('nameOnly is undefined', function() { + expect(operation.options).not.to.have.property('nameOnly'); + }); + }); + }); +}); From 36d3cdbf05d4f334b08920943b6c89436e7a2c93 Mon Sep 17 00:00:00 2001 From: Warren James Date: Thu, 29 Jun 2023 14:19:28 -0400 Subject: [PATCH 3/7] style(NODE-5102): eslint --- test/integration/enumerate_databases.test.ts | 26 ++++++++++---------- test/unit/operations/list_databases.test.ts | 21 ++++++++-------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/test/integration/enumerate_databases.test.ts b/test/integration/enumerate_databases.test.ts index 7229988deab..5b3c2cd1756 100644 --- a/test/integration/enumerate_databases.test.ts +++ b/test/integration/enumerate_databases.test.ts @@ -14,7 +14,7 @@ const metadata: MongoDBMetadataUI = { } }; -describe('listDatabases()', function() { +describe('listDatabases()', function () { describe('authorizedDatabases option', () => { const username = 'a'; const password = 'b'; @@ -28,7 +28,7 @@ describe('listDatabases()', function() { roles: [{ role: 'read', db: mockAuthorizedDb }] }; - beforeEach(async function() { + beforeEach(async function () { adminClient = this.configuration.newClient(); await adminClient @@ -43,7 +43,7 @@ describe('listDatabases()', function() { }); }); - afterEach(async function() { + afterEach(async function () { await adminClient?.db('admin').removeUser(username); await adminClient?.db(mockAuthorizedDb).dropDatabase(); await adminClient?.close(); @@ -53,7 +53,7 @@ describe('listDatabases()', function() { it( 'should list all databases when admin client sets authorizedDatabases to true', metadata, - async function() { + async function () { const adminListDbs = await adminClient .db() .admin() @@ -70,7 +70,7 @@ describe('listDatabases()', function() { it( 'should list all databases when admin client sets authorizedDatabases to false', metadata, - async function() { + async function () { const adminListDbs = await adminClient .db() .admin() @@ -87,7 +87,7 @@ describe('listDatabases()', function() { it( 'should list authorized databases with authorizedDatabases set to true', metadata, - async function() { + async function () { const adminListDbs = await adminClient.db().admin().listDatabases(); const authorizedListDbs = await authorizedClient .db() @@ -108,7 +108,7 @@ describe('listDatabases()', function() { it( 'should list authorized databases by default with authorizedDatabases unspecified', metadata, - async function() { + async function () { const adminListDbs = await adminClient.db().admin().listDatabases(); const authorizedListDbs = await authorizedClient.db().admin().listDatabases(); const adminDbs = adminListDbs.databases; @@ -126,7 +126,7 @@ describe('listDatabases()', function() { it( 'should not show authorized databases with authorizedDatabases set to false', metadata, - async function() { + async function () { let thrownError; try { await authorizedClient.db().admin().listDatabases({ authorizedDatabases: false }); @@ -141,12 +141,12 @@ describe('listDatabases()', function() { ); }); - describe('nameOnly option', function() { + describe('nameOnly option', function () { let client: MongoClient; const DBS = 10; const nameOnlyOptions = [true, false, undefined]; - beforeEach(async function() { + beforeEach(async function () { client = await this.configuration.newClient().connect(); for (let i = 0; i < DBS; i++) { const db = client.db(`testDb_${i}`); @@ -154,7 +154,7 @@ describe('listDatabases()', function() { } }); - afterEach(async function() { + afterEach(async function () { if (client) { for (let i = 0; i < DBS; i++) { await client.db(`testDb_${i}`).dropDatabase(); @@ -165,8 +165,8 @@ describe('listDatabases()', function() { }); for (const nameOnly of nameOnlyOptions) { - context(`when options.nameOnly is ${nameOnly ?? 'not defined'}`, function() { - it(`returns ${optionToExpecation(nameOnly)}`, async function() { + context(`when options.nameOnly is ${nameOnly ?? 'not defined'}`, function () { + it(`returns ${optionToExpecation(nameOnly)}`, async function () { const response = await client.db().admin().listDatabases({ nameOnly }); expect(response).to.have.property('databases'); diff --git a/test/unit/operations/list_databases.test.ts b/test/unit/operations/list_databases.test.ts index f189d7b7fb8..f2b9937e72e 100644 --- a/test/unit/operations/list_databases.test.ts +++ b/test/unit/operations/list_databases.test.ts @@ -1,29 +1,30 @@ import { expect } from 'chai'; -import { ListDatabasesOperation, Db } from '../../mongodb'; -describe('ListDatabasesOperation', function() { - describe('#constructor', function() { - context('when nameOnly is provided', function() { - context('when nameOnly is true', function() { +import { type Db, ListDatabasesOperation } from '../../mongodb'; + +describe('ListDatabasesOperation', function () { + describe('#constructor', function () { + context('when nameOnly is provided', function () { + context('when nameOnly is true', function () { const operation = new ListDatabasesOperation({} as Db, { nameOnly: true }); - it('sets nameOnly to true', function() { + it('sets nameOnly to true', function () { expect(operation.options).to.have.property('nameOnly', true); }); }); - context('when nameOnly is false', function() { + context('when nameOnly is false', function () { const operation = new ListDatabasesOperation({} as Db, { nameOnly: false }); - it('sets nameOnly to false', function() { + it('sets nameOnly to false', function () { expect(operation.options).to.have.property('nameOnly', false); }); }); }); - context('when no options are provided', function() { + context('when no options are provided', function () { const operation = new ListDatabasesOperation({} as Db, {}); - it('nameOnly is undefined', function() { + it('nameOnly is undefined', function () { expect(operation.options).not.to.have.property('nameOnly'); }); }); From ec976069580cb4f70f7c0a6a5a35638ea2e90aa5 Mon Sep 17 00:00:00 2001 From: Warren James Date: Thu, 29 Jun 2023 14:46:35 -0400 Subject: [PATCH 4/7] test(NODE-5102): fix unit tests --- test/unit/operations/list_databases.test.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/test/unit/operations/list_databases.test.ts b/test/unit/operations/list_databases.test.ts index f2b9937e72e..609cae15879 100644 --- a/test/unit/operations/list_databases.test.ts +++ b/test/unit/operations/list_databases.test.ts @@ -1,19 +1,29 @@ import { expect } from 'chai'; -import { type Db, ListDatabasesOperation } from '../../mongodb'; +import { ListDatabasesOperation, MongoDBNamespace } from '../../mongodb'; + +const mockDB = { + s: { + namespace: { + withCollection() { + return new MongoDBNamespace('test', 'test'); + } + } + } +}; describe('ListDatabasesOperation', function () { describe('#constructor', function () { context('when nameOnly is provided', function () { context('when nameOnly is true', function () { - const operation = new ListDatabasesOperation({} as Db, { nameOnly: true }); + const operation = new ListDatabasesOperation(mockDB, { nameOnly: true }); it('sets nameOnly to true', function () { expect(operation.options).to.have.property('nameOnly', true); }); }); context('when nameOnly is false', function () { - const operation = new ListDatabasesOperation({} as Db, { nameOnly: false }); + const operation = new ListDatabasesOperation(mockDB, { nameOnly: false }); it('sets nameOnly to false', function () { expect(operation.options).to.have.property('nameOnly', false); @@ -21,8 +31,8 @@ describe('ListDatabasesOperation', function () { }); }); - context('when no options are provided', function () { - const operation = new ListDatabasesOperation({} as Db, {}); + context('when nameOnly is not specified', function () { + const operation = new ListDatabasesOperation(mockDB, {}); it('nameOnly is undefined', function () { expect(operation.options).not.to.have.property('nameOnly'); From 426d04bb1c0a310131eb2b6025cd3a8c2554130b Mon Sep 17 00:00:00 2001 From: Warren James Date: Thu, 29 Jun 2023 15:11:06 -0400 Subject: [PATCH 5/7] test(NODE-5102): update int tests and fix unit test nit --- test/integration/enumerate_databases.test.ts | 32 +++++++++----------- test/unit/operations/list_databases.test.ts | 8 ++--- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/test/integration/enumerate_databases.test.ts b/test/integration/enumerate_databases.test.ts index 5b3c2cd1756..2065bccdd0e 100644 --- a/test/integration/enumerate_databases.test.ts +++ b/test/integration/enumerate_databases.test.ts @@ -1,4 +1,5 @@ import { expect } from 'chai'; +import { once } from 'events'; import { type AddUserOptions, type MongoClient, MongoServerError } from '../mongodb'; import { TestBuilder, UnifiedTestSuiteBuilder } from '../tools/utils'; @@ -147,7 +148,7 @@ describe('listDatabases()', function () { const nameOnlyOptions = [true, false, undefined]; beforeEach(async function () { - client = await this.configuration.newClient().connect(); + client = await this.configuration.newClient({}, { monitorCommands: true }).connect(); for (let i = 0; i < DBS; i++) { const db = client.db(`testDb_${i}`); await db.collection('test').insertOne({ a: 1 }); @@ -166,26 +167,22 @@ describe('listDatabases()', function () { for (const nameOnly of nameOnlyOptions) { context(`when options.nameOnly is ${nameOnly ?? 'not defined'}`, function () { - it(`returns ${optionToExpecation(nameOnly)}`, async function () { - const response = await client.db().admin().listDatabases({ nameOnly }); + it(`sends command ${optionToExpecation(nameOnly)}`, async function () { + const promise = once(client, 'commandStarted'); + await client.db().admin().listDatabases({ nameOnly }); + + const commandStarted = (await promise)[0]; + expect(commandStarted.command).to.haveOwnProperty('listDatabases', 1); - expect(response).to.have.property('databases'); - expect(response.databases).to.have.length.gte(DBS); switch (nameOnly) { case true: - for (const db of response.databases) { - expect(db).property('name').to.exist; - expect(db).to.not.have.property('sizeOnDisk'); - expect(db).to.not.have.property('empty'); - } + expect(commandStarted.command).to.have.property('nameOnly', true); break; case false: + expect(commandStarted.command).to.have.property('nameOnly', false); + break; case undefined: - for (const db of response.databases) { - expect(db.name).to.exist; - expect(db).property('sizeOnDisk').to.exist; - expect(db).property('empty').to.exist; - } + expect(commandStarted.command).to.not.have.property('nameOnly'); break; } }); @@ -195,10 +192,11 @@ describe('listDatabases()', function () { function optionToExpecation(nameOnly?: boolean): string { switch (nameOnly) { case true: - return 'list of only database names'; + return 'with nameOnly = true'; case false: + return 'with nameOnly = false'; case undefined: - return 'list of entire listDatabases responses'; + return 'without nameOnly field'; } } }); diff --git a/test/unit/operations/list_databases.test.ts b/test/unit/operations/list_databases.test.ts index 609cae15879..b5f49f4b0aa 100644 --- a/test/unit/operations/list_databases.test.ts +++ b/test/unit/operations/list_databases.test.ts @@ -16,25 +16,23 @@ describe('ListDatabasesOperation', function () { describe('#constructor', function () { context('when nameOnly is provided', function () { context('when nameOnly is true', function () { - const operation = new ListDatabasesOperation(mockDB, { nameOnly: true }); it('sets nameOnly to true', function () { + const operation = new ListDatabasesOperation(mockDB, { nameOnly: true }); expect(operation.options).to.have.property('nameOnly', true); }); }); context('when nameOnly is false', function () { - const operation = new ListDatabasesOperation(mockDB, { nameOnly: false }); - it('sets nameOnly to false', function () { + const operation = new ListDatabasesOperation(mockDB, { nameOnly: false }); expect(operation.options).to.have.property('nameOnly', false); }); }); }); context('when nameOnly is not specified', function () { - const operation = new ListDatabasesOperation(mockDB, {}); - it('nameOnly is undefined', function () { + const operation = new ListDatabasesOperation(mockDB, {}); expect(operation.options).not.to.have.property('nameOnly'); }); }); From b2dbc3c6ecf5792b36413aaae6815ff21febbeeb Mon Sep 17 00:00:00 2001 From: Warren James Date: Thu, 29 Jun 2023 15:55:35 -0400 Subject: [PATCH 6/7] test(NODE-5102): streamline tests --- test/integration/enumerate_databases.test.ts | 29 ++++++-------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/test/integration/enumerate_databases.test.ts b/test/integration/enumerate_databases.test.ts index 2065bccdd0e..1c2b65dbccf 100644 --- a/test/integration/enumerate_databases.test.ts +++ b/test/integration/enumerate_databases.test.ts @@ -144,30 +144,28 @@ describe('listDatabases()', function () { describe('nameOnly option', function () { let client: MongoClient; - const DBS = 10; const nameOnlyOptions = [true, false, undefined]; + const optionToExpectation = { + true: 'with nameOnly = true', + false: 'with nameOnly = false', + undefined: 'without nameOnly field' + }; beforeEach(async function () { client = await this.configuration.newClient({}, { monitorCommands: true }).connect(); - for (let i = 0; i < DBS; i++) { - const db = client.db(`testDb_${i}`); - await db.collection('test').insertOne({ a: 1 }); - } + await client.db('test').createCollection('test'); }); afterEach(async function () { if (client) { - for (let i = 0; i < DBS; i++) { - await client.db(`testDb_${i}`).dropDatabase(); - } - + await client.db(`test`).dropDatabase(); await client.close(); } }); for (const nameOnly of nameOnlyOptions) { context(`when options.nameOnly is ${nameOnly ?? 'not defined'}`, function () { - it(`sends command ${optionToExpecation(nameOnly)}`, async function () { + it(`sends command ${optionToExpectation[String(nameOnly)]}`, async function () { const promise = once(client, 'commandStarted'); await client.db().admin().listDatabases({ nameOnly }); @@ -188,17 +186,6 @@ describe('listDatabases()', function () { }); }); } - - function optionToExpecation(nameOnly?: boolean): string { - switch (nameOnly) { - case true: - return 'with nameOnly = true'; - case false: - return 'with nameOnly = false'; - case undefined: - return 'without nameOnly field'; - } - } }); UnifiedTestSuiteBuilder.describe('comment option') .createEntities(UnifiedTestSuiteBuilder.defaultEntities) From 41ea030dd763e537ed9c324a7f6e44df6503dde1 Mon Sep 17 00:00:00 2001 From: Warren James Date: Fri, 30 Jun 2023 09:24:03 -0400 Subject: [PATCH 7/7] test(NODE-5102): add default case --- test/integration/enumerate_databases.test.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/integration/enumerate_databases.test.ts b/test/integration/enumerate_databases.test.ts index 1c2b65dbccf..decb0ac892c 100644 --- a/test/integration/enumerate_databases.test.ts +++ b/test/integration/enumerate_databases.test.ts @@ -182,6 +182,8 @@ describe('listDatabases()', function () { case undefined: expect(commandStarted.command).to.not.have.property('nameOnly'); break; + default: + expect.fail(`Unrecognized nameOnly value: ${nameOnly}`); } }); });