@@ -214,88 +214,118 @@ describe('Connection String', function () {
214
214
} ) ;
215
215
216
216
describe ( 'spec tests' , function ( ) {
217
+ /** @type {import('../../spec/connection-string/valid-auth.json')[] } */
217
218
const suites = loadSpecTests ( 'connection-string' ) . concat ( loadSpecTests ( 'auth' ) ) ;
218
219
219
220
suites . forEach ( suite => {
220
221
describe ( suite . name , function ( ) {
221
222
suite . tests . forEach ( test => {
222
- it ( test . description , {
223
- metadata : { requires : { topology : 'single' } } ,
224
- test : function ( done ) {
225
- if ( skipTests . indexOf ( test . description ) !== - 1 ) {
226
- return this . skip ( ) ;
227
- }
228
-
229
- const valid = test . valid ;
230
- parseConnectionString ( test . uri , { caseTranslate : false } , function ( err , result ) {
231
- if ( valid === false ) {
232
- expect ( err ) . to . exist ;
233
- expect ( err ) . to . be . instanceOf ( MongoParseError ) ;
234
- expect ( result ) . to . not . exist ;
235
- } else {
236
- expect ( err ) . to . not . exist ;
237
- expect ( result ) . to . exist ;
238
-
239
- // remove data we don't track
240
- if ( test . auth && test . auth . password === '' ) {
241
- test . auth . password = null ;
242
- }
243
-
244
- if ( test . hosts != null ) {
245
- test . hosts = test . hosts . map ( host => {
246
- delete host . type ;
247
- host . host = punycode . toASCII ( host . host ) ;
248
- return host ;
249
- } ) ;
250
-
251
- // remove values that require no validation
252
- test . hosts . forEach ( host => {
253
- Object . keys ( host ) . forEach ( key => {
254
- if ( host [ key ] == null ) delete host [ key ] ;
255
- } ) ;
256
- } ) ;
257
-
258
- expect ( result . hosts ) . to . containSubset ( test . hosts ) ;
259
- }
260
-
261
- if ( test . auth ) {
262
- if ( test . auth . db != null ) {
263
- expect ( result . auth ) . to . have . property ( 'db' ) ;
264
- expect ( result . auth . db ) . to . eql ( test . auth . db ) ;
265
- }
266
-
267
- if ( test . auth . username != null ) {
268
- expect ( result . auth ) . to . have . property ( 'username' ) ;
269
- expect ( result . auth . username ) . to . eql ( test . auth . username ) ;
270
- }
271
-
272
- if ( test . auth . password != null ) {
273
- expect ( result . auth ) . to . have . property ( 'password' ) ;
274
- expect ( result . auth . password ) . to . eql ( test . auth . password ) ;
275
- }
276
- }
277
-
278
- if ( test . options != null ) {
279
- // it's possible we have options which are not explicitly included in the spec test
280
- expect ( result . options ) . to . deep . include ( test . options ) ;
281
- }
282
- }
283
-
284
- done ( ) ;
285
- } ) ;
286
- }
287
- } ) ;
223
+ // it(test.description, {
224
+ // metadata: { requires: { topology: 'single' } },
225
+ // test: function (done) {
226
+ // if (skipTests.indexOf(test.description) !== -1) {
227
+ // return this.skip();
228
+ // }
229
+
230
+ // const valid = test.valid;
231
+ // parseConnectionString(test.uri, { caseTranslate: false }, function (err, result) {
232
+ // if (valid === false) {
233
+ // expect(err).to.exist;
234
+ // expect(err).to.be.instanceOf(MongoParseError);
235
+ // expect(result).to.not.exist;
236
+ // } else {
237
+ // expect(err).to.not.exist;
238
+ // expect(result).to.exist;
239
+
240
+ // // remove data we don't track
241
+ // if (test.auth && test.auth.password === '') {
242
+ // test.auth.password = null;
243
+ // }
244
+
245
+ // if (test.hosts != null) {
246
+ // test.hosts = test.hosts.map(host => {
247
+ // delete host.type;
248
+ // host.host = punycode.toASCII(host.host);
249
+ // return host;
250
+ // });
251
+
252
+ // // remove values that require no validation
253
+ // test.hosts.forEach(host => {
254
+ // Object.keys(host).forEach(key => {
255
+ // if (host[key] == null) delete host[key];
256
+ // });
257
+ // });
258
+
259
+ // expect(result.hosts).to.containSubset(test.hosts);
260
+ // }
261
+
262
+ // if (test.auth) {
263
+ // if (test.auth.db != null) {
264
+ // expect(result.auth).to.have.property('db');
265
+ // expect(result.auth.db).to.eql(test.auth.db);
266
+ // }
267
+
268
+ // if (test.auth.username != null) {
269
+ // expect(result.auth).to.have.property('username');
270
+ // expect(result.auth.username).to.eql(test.auth.username);
271
+ // }
272
+
273
+ // if (test.auth.password != null) {
274
+ // expect(result.auth).to.have.property('password');
275
+ // expect(result.auth.password).to.eql(test.auth.password);
276
+ // }
277
+ // }
278
+
279
+ // if (test.options != null) {
280
+ // // it's possible we have options which are not explicitly included in the spec test
281
+ // expect(result.options).to.deep.include(test.options);
282
+ // }
283
+ // }
284
+
285
+ // done();
286
+ // });
287
+ // }
288
+ // });
288
289
289
290
it ( `${ test . description } -- new MongoOptions parser` , function ( ) {
290
291
if ( skipTests . includes ( test . description ) ) {
291
292
return this . skip ( ) ;
292
293
}
293
294
295
+ const message = `"${ test . uri } "` ;
296
+
294
297
const valid = test . valid ;
295
298
if ( valid ) {
296
- expect ( parseOptions ( test . uri ) , `"${ test . uri } "` ) . to . be . ok ;
299
+ const options = parseOptions ( test . uri ) ;
300
+ expect ( options , message ) . to . be . ok ;
301
+
302
+ if ( test . hosts ) {
303
+ for ( const [ index , { host, port } ] of test . hosts . entries ( ) ) {
304
+ expect ( options . hosts [ index ] . host , message ) . to . equal ( host ) ;
305
+ if ( typeof port === 'number' ) expect ( options . hosts [ index ] . port ) . to . equal ( port ) ;
306
+ }
307
+ }
308
+
309
+ if ( test . auth ) {
310
+ if ( test . auth . db != null ) {
311
+ expect ( options . credentials . source , message ) . to . equal ( test . auth . db ) ;
312
+ }
313
+
314
+ if ( test . auth . username != null ) {
315
+ expect ( options . credentials . username , message ) . to . equal ( test . auth . username ) ;
316
+ }
317
+
318
+ if ( test . auth . password != null ) {
319
+ expect ( options . credentials . password , message ) . to . equal ( test . auth . password ) ;
320
+ }
321
+ }
322
+
323
+ // Going to have to get clever here...
324
+ // if (test.options) {
325
+ // expect(options, message).to.deep.include(test.options);
326
+ // }
297
327
} else {
298
- expect ( ( ) => parseOptions ( test . uri ) , `" ${ test . uri } "` ) . to . throw ( ) ;
328
+ expect ( ( ) => parseOptions ( test . uri ) , message ) . to . throw ( ) ;
299
329
}
300
330
} ) ;
301
331
} ) ;
0 commit comments