|
1 | 1 | import { expect } from 'chai';
|
| 2 | +import { once } from 'events'; |
2 | 3 |
|
3 | 4 | import { type AddUserOptions, type MongoClient, MongoServerError } from '../mongodb';
|
4 | 5 | import { TestBuilder, UnifiedTestSuiteBuilder } from '../tools/utils';
|
@@ -141,6 +142,53 @@ describe('listDatabases()', function () {
|
141 | 142 | );
|
142 | 143 | });
|
143 | 144 |
|
| 145 | + describe('nameOnly option', function () { |
| 146 | + let client: MongoClient; |
| 147 | + const nameOnlyOptions = [true, false, undefined]; |
| 148 | + const optionToExpectation = { |
| 149 | + true: 'with nameOnly = true', |
| 150 | + false: 'with nameOnly = false', |
| 151 | + undefined: 'without nameOnly field' |
| 152 | + }; |
| 153 | + |
| 154 | + beforeEach(async function () { |
| 155 | + client = await this.configuration.newClient({}, { monitorCommands: true }).connect(); |
| 156 | + await client.db('test').createCollection('test'); |
| 157 | + }); |
| 158 | + |
| 159 | + afterEach(async function () { |
| 160 | + if (client) { |
| 161 | + await client.db(`test`).dropDatabase(); |
| 162 | + await client.close(); |
| 163 | + } |
| 164 | + }); |
| 165 | + |
| 166 | + for (const nameOnly of nameOnlyOptions) { |
| 167 | + context(`when options.nameOnly is ${nameOnly ?? 'not defined'}`, function () { |
| 168 | + it(`sends command ${optionToExpectation[String(nameOnly)]}`, async function () { |
| 169 | + const promise = once(client, 'commandStarted'); |
| 170 | + await client.db().admin().listDatabases({ nameOnly }); |
| 171 | + |
| 172 | + const commandStarted = (await promise)[0]; |
| 173 | + expect(commandStarted.command).to.haveOwnProperty('listDatabases', 1); |
| 174 | + |
| 175 | + switch (nameOnly) { |
| 176 | + case true: |
| 177 | + expect(commandStarted.command).to.have.property('nameOnly', true); |
| 178 | + break; |
| 179 | + case false: |
| 180 | + expect(commandStarted.command).to.have.property('nameOnly', false); |
| 181 | + break; |
| 182 | + case undefined: |
| 183 | + expect(commandStarted.command).to.not.have.property('nameOnly'); |
| 184 | + break; |
| 185 | + default: |
| 186 | + expect.fail(`Unrecognized nameOnly value: ${nameOnly}`); |
| 187 | + } |
| 188 | + }); |
| 189 | + }); |
| 190 | + } |
| 191 | + }); |
144 | 192 | UnifiedTestSuiteBuilder.describe('comment option')
|
145 | 193 | .createEntities(UnifiedTestSuiteBuilder.defaultEntities)
|
146 | 194 | .initialData({
|
|
0 commit comments