3
3
const parseConnectionString = require ( '../../../lib/uri_parser' ) ;
4
4
const fs = require ( 'fs' ) ;
5
5
const f = require ( 'util' ) . format ;
6
- const expect = require ( 'chai' ) . expect ;
7
6
const punycode = require ( 'punycode' ) ;
8
7
const MongoParseError = require ( '../../../lib/error' ) . MongoParseError ;
8
+ const chai = require ( 'chai' ) ;
9
+ const expect = chai . expect ;
10
+ chai . use ( require ( 'chai-subset' ) ) ;
9
11
10
12
// NOTE: These are cases we could never check for unless we write out own
11
13
// url parser. The node parser simply won't let these through, so we
@@ -22,6 +24,14 @@ const skipTests = [
22
24
] ;
23
25
24
26
describe ( 'Connection String (spec)' , function ( ) {
27
+ it ( 'should provide a default port if one is not provided' , function ( done ) {
28
+ parseConnectionString ( 'mongodb://hostname' , function ( err , result ) {
29
+ expect ( err ) . to . not . exist ;
30
+ expect ( result . hosts [ 0 ] . port ) . to . equal ( 27017 ) ;
31
+ done ( ) ;
32
+ } ) ;
33
+ } ) ;
34
+
25
35
const testFiles = fs
26
36
. readdirSync ( f ( '%s/../spec/connection-string' , __dirname ) )
27
37
. filter ( x => x . indexOf ( '.json' ) !== - 1 )
@@ -63,7 +73,14 @@ describe('Connection String (spec)', function() {
63
73
return host ;
64
74
} ) ;
65
75
66
- expect ( result . hosts ) . to . eql ( test . hosts ) ;
76
+ // remove values that require no validation
77
+ test . hosts . forEach ( host => {
78
+ Object . keys ( host ) . forEach ( key => {
79
+ if ( host [ key ] == null ) delete host [ key ] ;
80
+ } ) ;
81
+ } ) ;
82
+
83
+ expect ( result . hosts ) . to . containSubset ( test . hosts ) ;
67
84
expect ( result . auth ) . to . eql ( test . auth ) ;
68
85
expect ( result . options ) . to . eql ( test . options ) ;
69
86
}
0 commit comments