File tree 4 files changed +16
-13
lines changed
4 files changed +16
-13
lines changed Original file line number Diff line number Diff line change @@ -19,10 +19,12 @@ try {
19
19
const ServerApiVersion = Object . freeze ( {
20
20
v1 : '1'
21
21
} ) ;
22
+ const ValidServerApiVersions = Object . keys ( ServerApiVersion ) . map ( key => ServerApiVersion [ key ] ) ;
22
23
23
24
module . exports = {
24
25
// Versioned API
25
26
ServerApiVersion,
27
+ ValidServerApiVersions,
26
28
// Errors
27
29
MongoError : require ( './error' ) . MongoError ,
28
30
MongoNetworkError : require ( './error' ) . MongoNetworkError ,
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ const Db = require('./db');
5
5
const EventEmitter = require ( 'events' ) . EventEmitter ;
6
6
const inherits = require ( 'util' ) . inherits ;
7
7
const MongoError = require ( './core' ) . MongoError ;
8
- const ServerApiVersion = require ( './core' ) . ServerApiVersion ;
8
+ const ValidServerApiVersions = require ( './core' ) . ValidServerApiVersions ;
9
9
const deprecate = require ( 'util' ) . deprecate ;
10
10
const WriteConcern = require ( './write_concern' ) ;
11
11
const MongoDBNamespace = require ( './utils' ) . MongoDBNamespace ;
@@ -206,16 +206,16 @@ function MongoClient(url, options) {
206
206
const versionToValidate = serverApiToValidate && serverApiToValidate . version ;
207
207
if ( ! versionToValidate ) {
208
208
throw new MongoError (
209
- `Invalid \`serverApi\` property; must specify a version from the following enum: ["${ Object . values (
210
- ServerApiVersion
211
- ) . join ( '", "' ) } "]`
209
+ `Invalid \`serverApi\` property; must specify a version from the following enum: ["${ ValidServerApiVersions . join (
210
+ '", "'
211
+ ) } "]`
212
212
) ;
213
213
}
214
- if ( ! Object . values ( ServerApiVersion ) . some ( v => v === versionToValidate ) ) {
214
+ if ( ! ValidServerApiVersions . some ( v => v === versionToValidate ) ) {
215
215
throw new MongoError (
216
- `Invalid server API version=${ versionToValidate } ; must be in the following enum: ["${ Object . values (
217
- ServerApiVersion
218
- ) . join ( '", "' ) } "]`
216
+ `Invalid server API version=${ versionToValidate } ; must be in the following enum: ["${ ValidServerApiVersions . join (
217
+ '", "'
218
+ ) } "]`
219
219
) ;
220
220
}
221
221
options . serverApi = serverApiToValidate ;
Original file line number Diff line number Diff line change @@ -2,7 +2,6 @@ import { expect } from 'chai';
2
2
import type { CollectionOrDatabaseOptions , RunOnRequirement , Document } from './schema' ;
3
3
import { gte as semverGte , lte as semverLte } from 'semver' ;
4
4
import { MongoClient } from '../../../index' ;
5
- import { isDeepStrictEqual } from 'util' ;
6
5
import { TestConfiguration } from './runner' ;
7
6
8
7
export async function topologySatisfies (
@@ -41,7 +40,11 @@ export async function topologySatisfies(
41
40
if ( ! config . parameters ) throw new Error ( 'Configuration does not have server parameters' ) ;
42
41
for ( const [ name , value ] of Object . entries ( r . serverParameters ) ) {
43
42
if ( name in config . parameters ) {
44
- ok &&= isDeepStrictEqual ( config . parameters [ name ] , value ) ;
43
+ try {
44
+ expect ( config . parameters [ name ] ) . to . deep . equal ( value ) ;
45
+ } catch ( _err ) {
46
+ ok = false ;
47
+ }
45
48
}
46
49
}
47
50
}
Original file line number Diff line number Diff line change 3
3
const expect = require ( 'chai' ) . expect ;
4
4
const loadSpecTests = require ( '../spec/index' ) . loadSpecTests ;
5
5
const runUnifiedTest = require ( './unified-spec-runner/runner' ) . runUnifiedTest ;
6
- const ServerApiVersion = require ( '../../lib/core' ) . ServerApiVersion ;
6
+ const validVersions = require ( '../../lib/core' ) . ValidServerApiVersions ;
7
7
8
8
describe ( 'Versioned API' , function ( ) {
9
9
describe ( 'client option validation' , function ( ) {
10
10
it ( 'is supported as a client option when it is a valid ServerApiVersion string' , function ( ) {
11
- const validVersions = Object . values ( ServerApiVersion ) ;
12
11
expect ( validVersions . length ) . to . be . at . least ( 1 ) ;
13
12
for ( const version of validVersions ) {
14
13
const client = this . configuration . newClient ( 'mongodb://localhost/' , {
@@ -21,7 +20,6 @@ describe('Versioned API', function() {
21
20
} ) ;
22
21
23
22
it ( 'is supported as a client option when it is an object with a valid version property' , function ( ) {
24
- const validVersions = Object . values ( ServerApiVersion ) ;
25
23
expect ( validVersions . length ) . to . be . at . least ( 1 ) ;
26
24
for ( const version of validVersions ) {
27
25
const client = this . configuration . newClient ( 'mongodb://localhost/' , {
You can’t perform that action at this time.
0 commit comments