Skip to content

Commit 18fa053

Browse files
committed
refactor: improve import structure and enhance MongoClient options
1 parent 0e7430d commit 18fa053

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

test/unit/client-side-encryption/auto_encrypter.test.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import * as fs from 'fs';
33
import * as net from 'net';
44
import * as sinon from 'sinon';
55

6-
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
7-
import { AutoEncrypter } from '../../../src/client-side-encryption/auto_encrypter';
8-
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
9-
import { MongocryptdManager } from '../../../src/client-side-encryption/mongocryptd_manager';
10-
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
11-
import { StateMachine } from '../../../src/client-side-encryption/state_machine';
12-
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
13-
import { MongoClient } from '../../../src/mongo_client';
14-
import { BSON, type DataKey } from '../../mongodb';
6+
import {
7+
AutoEncrypter,
8+
type AutoEncryptionOptions,
9+
BSON,
10+
type DataKey,
11+
MongoClient,
12+
MongocryptdManager,
13+
StateMachine
14+
} from '../../mongodb';
1515
import * as requirements from './requirements.helper';
1616

1717
const bson = BSON;
@@ -92,8 +92,7 @@ describe('AutoEncrypter', function () {
9292
describe('#constructor', function () {
9393
context('when using mongocryptd', function () {
9494
const client = new MockClient() as MongoClient;
95-
const autoEncrypterOptions = {
96-
mongocryptdBypassSpawn: true,
95+
const autoEncrypterOptions: AutoEncryptionOptions = {
9796
keyVaultNamespace: 'admin.datakeys',
9897
options: {
9998
// eslint-disable-next-line @typescript-eslint/no-empty-function
@@ -102,6 +101,9 @@ describe('AutoEncrypter', function () {
102101
kmsProviders: {
103102
aws: { accessKeyId: 'example', secretAccessKey: 'example' },
104103
local: { key: Buffer.alloc(96) }
104+
},
105+
extraOptions: {
106+
mongocryptdBypassSpawn: true
105107
}
106108
};
107109
const autoEncrypter = new AutoEncrypter(client, autoEncrypterOptions);

test/unit/mongo_client.test.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ import {
2525

2626
describe('MongoClient', function () {
2727
const client: MongoClient = {
28-
listeners: () => []
29-
} as MongoClient;
28+
listeners: () => [],
29+
on() {
30+
return this;
31+
}
32+
} as unknown as MongoClient;
3033

3134
it('programmatic options should override URI options', function () {
3235
const options = parseOptions('mongodb://localhost:27017/test?directConnection=true', client, {
@@ -76,34 +79,30 @@ describe('MongoClient', function () {
7679
expect(options).has.property('tls', true);
7780
});
7881

79-
const ALL_OPTIONS = {
82+
const ALL_OPTIONS: MongoClientOptions = {
8083
appName: 'cats',
8184
auth: { username: 'username', password: 'password' },
8285
authMechanism: 'SCRAM-SHA-1',
8386
authMechanismProperties: { SERVICE_NAME: 'service name here' },
8487
authSource: 'refer to dbName',
85-
autoEncryption: { bypassAutoEncryption: true },
88+
autoEncryption: { bypassAutoEncryption: true, kmsProviders: { aws: {} } },
8689
checkKeys: true,
87-
checkServerIdentity: false,
90+
checkServerIdentity: () => undefined,
8891
compressors: 'snappy,zlib',
8992
connectTimeoutMS: 123,
9093
directConnection: true,
91-
dbName: 'test',
9294
driverInfo: { name: 'MyDriver', platform: 'moonOS' },
9395
family: 6,
9496
fieldsAsRaw: { rawField: true },
9597
forceServerObjectId: true,
96-
fsync: true,
9798
heartbeatFrequencyMS: 3,
9899
ignoreUndefined: false,
99-
j: true,
100-
journal: false,
100+
journal: true,
101101
localThresholdMS: 3,
102102
maxConnecting: 5,
103103
maxIdleTimeMS: 3,
104104
maxPoolSize: 2,
105105
maxStalenessSeconds: 3,
106-
minInternalBufferSize: 0,
107106
minPoolSize: 1,
108107
monitorCommands: true,
109108
noDelay: true,
@@ -136,7 +135,6 @@ describe('MongoClient', function () {
136135
w: 'majority',
137136
waitQueueTimeoutMS: 3,
138137
writeConcern: new WriteConcern(2),
139-
wtimeout: 5,
140138
wtimeoutMS: 6,
141139
zlibCompressionLevel: 2
142140
};
@@ -150,7 +148,7 @@ describe('MongoClient', function () {
150148
// Check consolidated options
151149
expect(options).has.property('writeConcern');
152150
expect(options.writeConcern).has.property('w', 2);
153-
expect(options.writeConcern).has.property('j', true);
151+
expect(options.writeConcern).has.property('journal', true);
154152
});
155153

156154
const allURIOptions =

0 commit comments

Comments
 (0)