@@ -1045,10 +1045,13 @@ describe('MongoOptions', function () {
1045
1045
} ) ;
1046
1046
1047
1047
context ( 'when invalid environment option is provided' , function ( ) {
1048
+ afterEach ( function ( ) {
1049
+ process . env [ 'MONGODB_LOG_ALL' ] = 'undefined' ;
1050
+ } ) ;
1051
+
1048
1052
it ( 'should still throw error at construction' , function ( ) {
1049
1053
process . env [ 'MONGODB_LOG_ALL' ] = 'imFakeToo' ;
1050
1054
expect ( badClientCreator ) . to . throw ( MongoAPIError ) ;
1051
- process . env [ 'MONGODB_LOG_ALL' ] = 'undefined' ;
1052
1055
} ) ;
1053
1056
} ) ;
1054
1057
} ) ;
@@ -1099,14 +1102,14 @@ describe('MongoOptions', function () {
1099
1102
describe ( 'mongodbLogMaxDocumentLength' , function ( ) {
1100
1103
context ( 'when mongodbLogMaxDocumentLength is in options' , function ( ) {
1101
1104
context ( 'when env option for MONGODB_LOG_MAX_DOCUMENT_LENGTH is not provided' , function ( ) {
1102
- it ( 'it stores value for maxDocumentLength correctly' , function ( ) {
1105
+ it ( 'should store value for maxDocumentLength correctly' , function ( ) {
1103
1106
const client = new MongoClient ( 'mongodb://a/' , {
1104
1107
[ loggerFeatureFlag ] : true ,
1105
1108
mongodbLogMaxDocumentLength : 290
1106
1109
} ) ;
1107
1110
expect ( client . options . mongoLoggerOptions . maxDocumentLength ) . to . equal ( 290 ) ;
1108
1111
} ) ;
1109
- it ( 'it throws error for negative input' , function ( ) {
1112
+ it ( 'should throw error for negative input' , function ( ) {
1110
1113
expect (
1111
1114
( ) =>
1112
1115
new MongoClient ( 'mongodb://a/' , {
@@ -1117,23 +1120,61 @@ describe('MongoOptions', function () {
1117
1120
} ) ;
1118
1121
} ) ;
1119
1122
context ( 'when env option for MONGODB_LOG_MAX_DOCUMENT_LENGTH is provided' , function ( ) {
1120
- it ( 'it stores value for maxDocumentLength correctly (client option value takes precedence)' , function ( ) {
1123
+ beforeEach ( function ( ) {
1121
1124
process . env [ 'MONGODB_LOG_MAX_DOCUMENT_LENGTH' ] = '155' ;
1125
+ } ) ;
1126
+
1127
+ afterEach ( function ( ) {
1128
+ process . env [ 'MONGODB_LOG_MAX_DOCUMENT_LENGTH' ] = undefined ;
1129
+ } ) ;
1130
+
1131
+ it ( 'should store value for maxDocumentLength correctly (client option value takes precedence)' , function ( ) {
1122
1132
const client = new MongoClient ( 'mongodb://a/' , {
1123
1133
[ loggerFeatureFlag ] : true ,
1124
1134
mongodbLogMaxDocumentLength : 290
1125
1135
} ) ;
1126
1136
expect ( client . options . mongoLoggerOptions . maxDocumentLength ) . to . equal ( 290 ) ;
1127
- process . env [ 'MONGODB_LOG_MAX_DOCUMENT_LENGTH' ] = undefined ;
1137
+ } ) ;
1138
+ it ( 'should throw error for negative input' , function ( ) {
1139
+ expect (
1140
+ ( ) =>
1141
+ new MongoClient ( 'mongodb://a/' , {
1142
+ [ loggerFeatureFlag ] : true ,
1143
+ mongodbLogMaxDocumentLength : - 290
1144
+ } )
1145
+ ) . to . throw ( MongoParseError ) ;
1128
1146
} ) ;
1129
1147
} ) ;
1130
1148
} ) ;
1131
1149
context ( 'when mongodbLogMaxDocumentLength is not in options' , function ( ) {
1132
- it ( 'it stores value for default maxDocumentLength correctly' , function ( ) {
1133
- const client = new MongoClient ( 'mongodb://a/' , {
1134
- [ loggerFeatureFlag ] : true
1150
+ context ( 'when env option for MONGODB_LOG_MAX_DOCUMENT_LENGTH is not provided' , function ( ) {
1151
+ it ( 'should store value for default maxDocumentLength correctly' , function ( ) {
1152
+ const client = new MongoClient ( 'mongodb://a/' , {
1153
+ [ loggerFeatureFlag ] : true
1154
+ } ) ;
1155
+ expect ( client . options . mongoLoggerOptions . maxDocumentLength ) . to . equal ( 1000 ) ;
1156
+ } ) ;
1157
+ } ) ;
1158
+ context ( 'when env option for MONGODB_LOG_MAX_DOCUMENT_LENGTH is provided' , function ( ) {
1159
+ afterEach ( function ( ) {
1160
+ process . env [ 'MONGODB_LOG_MAX_DOCUMENT_LENGTH' ] = undefined ;
1161
+ } ) ;
1162
+
1163
+ it ( 'should store value for maxDocumentLength correctly' , function ( ) {
1164
+ process . env [ 'MONGODB_LOG_MAX_DOCUMENT_LENGTH' ] = '155' ;
1165
+ const client = new MongoClient ( 'mongodb://a/' , {
1166
+ [ loggerFeatureFlag ] : true
1167
+ } ) ;
1168
+ expect ( client . options . mongoLoggerOptions . maxDocumentLength ) . to . equal ( 155 ) ;
1169
+ } ) ;
1170
+
1171
+ it ( 'should not throw error for negative MONGODB_MAX_DOCUMENT_LENGTH and set to default' , function ( ) {
1172
+ process . env [ 'MONGODB_LOG_MAX_DOCUMENT_LENGTH' ] = '-14' ;
1173
+ const client = new MongoClient ( 'mongodb://a/' , {
1174
+ [ loggerFeatureFlag ] : true
1175
+ } ) ;
1176
+ expect ( client . options . mongoLoggerOptions . maxDocumentLength ) . to . equal ( 1000 ) ;
1135
1177
} ) ;
1136
- expect ( client . options . mongoLoggerOptions . maxDocumentLength ) . to . equal ( 1000 ) ;
1137
1178
} ) ;
1138
1179
} ) ;
1139
1180
} ) ;
0 commit comments