@@ -1216,22 +1216,47 @@ describe('class MongoLogger', function () {
1216
1216
} ) ;
1217
1217
1218
1218
describe ( 'maybeTruncate' , function ( ) {
1219
- const largeDoc = { } ;
1219
+ let largeEjsonString : string ;
1220
+ let smallEjsonString : string ;
1220
1221
before ( function ( ) {
1221
- for ( let i = 0 ; i < 1000 ; i ++ ) {
1222
+ const largeDoc = { } ;
1223
+ for ( let i = 0 ; i < DEFAULT_MAX_DOCUMENT_LENGTH ; i ++ ) {
1222
1224
largeDoc [ `test${ i } ` ] = `Hello_${ i } ` ;
1223
1225
}
1226
+ largeEjsonString = EJSON . stringify ( largeDoc ) ;
1227
+ const smallDoc = { test : 'Hello' } ;
1228
+ smallEjsonString = EJSON . stringify ( smallDoc ) ;
1224
1229
} ) ;
1225
1230
1226
1231
context ( 'when maxDocumentLength = 0' , function ( ) {
1227
1232
it ( 'does not truncate document' , function ( ) {
1228
- const ejson = EJSON . stringify ( largeDoc ) ;
1229
- expect ( ejson ) . to . equal ( maybeTruncate ( ejson , 0 ) ) ;
1233
+ expect ( maybeTruncate ( largeEjsonString , 0 ) ) . to . equal ( largeEjsonString ) ;
1230
1234
} ) ;
1231
1235
} ) ;
1232
1236
1233
1237
context ( 'when maxDocumentLength is non-zero' , function ( ) {
1234
- context ( 'when document has length greater than maxDocumentLength' , function ( ) { } ) ;
1235
- context ( 'when document has length less than or equal to maxDocumentLength' , function ( ) { } ) ;
1238
+ context ( 'when document has length greater than maxDocumentLength' , function ( ) {
1239
+ it ( 'truncates ejson string to length of maxDocumentLength + 3' , function ( ) {
1240
+ expect ( maybeTruncate ( largeEjsonString ) ) . to . have . lengthOf ( DEFAULT_MAX_DOCUMENT_LENGTH + 3 ) ;
1241
+ } ) ;
1242
+ it ( 'ends with "..."' , function ( ) {
1243
+ expect ( maybeTruncate ( largeEjsonString ) ) . to . match ( / ^ .* \. \. \. $ / ) ;
1244
+ } ) ;
1245
+ } ) ;
1246
+
1247
+ context ( 'when document has length less than or equal to maxDocumentLength' , function ( ) {
1248
+ it ( 'does not truncate document' , function ( ) {
1249
+ expect ( maybeTruncate ( smallEjsonString ) ) . to . equal ( smallEjsonString ) ;
1250
+ } ) ;
1251
+ it ( 'does not end with "..."' , function ( ) {
1252
+ expect ( maybeTruncate ( smallEjsonString ) ) . to . not . match ( / ^ .* \. \. \. / ) ;
1253
+ } ) ;
1254
+
1255
+ it ( 'produces valid relaxed EJSON' , function ( ) {
1256
+ expect ( ( ) => {
1257
+ EJSON . parse ( maybeTruncate ( smallEjsonString ) ) ;
1258
+ } ) . to . not . throw ( ) ;
1259
+ } ) ;
1260
+ } ) ;
1236
1261
} ) ;
1237
1262
} ) ;
0 commit comments