-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathrun_command.test.ts
52 lines (46 loc) · 1.8 KB
/
run_command.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { expect } from 'chai';
import {
type CommandStartedEvent,
type Db,
type MongoClient,
ReadConcern,
ReadPreference,
WriteConcern
} from '../../mongodb';
describe('RunCommand API', () => {
let client: MongoClient;
let db: Db;
let commandsStarted: CommandStartedEvent[];
beforeEach(async function () {
const options = {
serverApi: { version: '1', strict: true, deprecationErrors: false },
monitorCommands: true
};
client = this.configuration.newClient({}, options);
db = client.db();
commandsStarted = [];
client.on('commandStarted', started => commandsStarted.push(started));
});
afterEach(async function () {
commandsStarted = [];
await client.close();
});
it('does not modify user input', { requires: { mongodb: '>=5.0' } }, async () => {
const command = Object.freeze({ ping: 1 });
// will throw if it tries to modify command
await db.command(command, { readPreference: ReadPreference.nearest });
});
it('does not support writeConcern in options', { requires: { mongodb: '>=5.0' } }, async () => {
const command = Object.freeze({ insert: 'test', documents: [{ x: 1 }] });
await db.command(command, { writeConcern: new WriteConcern('majority') });
expect(commandsStarted).to.not.have.nested.property('[0].command.writeConcern');
expect(command).to.not.have.property('writeConcern');
});
it('does not support readConcern in options', { requires: { mongodb: '>=5.0' } }, async () => {
const command = Object.freeze({ find: 'test', filter: {} });
const res = await db.command(command, { readConcern: ReadConcern.MAJORITY });
expect(res).to.have.property('ok', 1);
expect(commandsStarted).to.not.have.nested.property('[0].command.readConcern');
expect(command).to.not.have.property('readConcern');
});
});