@@ -384,6 +384,18 @@ function validateExpectations(commandEvents, spec, savedSessionData) {
384
384
385
385
const actualCommand = actual . command ;
386
386
const expectedCommand = expected . command ;
387
+ if ( expectedCommand . sort ) {
388
+ // TODO: This is a workaround that works because all sorts in the specs
389
+ // are objects with one key; ideally we'd want to adjust the spec definitions
390
+ // to indicate whether order matters for any given key and set general
391
+ // expectations accordingly (see NODE-3235)
392
+ expect ( Object . keys ( expectedCommand . sort ) ) . to . have . lengthOf ( 1 ) ;
393
+ expect ( actualCommand . sort ) . to . be . instanceOf ( Map ) ;
394
+ expect ( actualCommand . sort . size ) . to . equal ( 1 ) ;
395
+ const expectedKey = Object . keys ( expectedCommand . sort ) [ 0 ] ;
396
+ expect ( actualCommand . sort ) . to . have . all . keys ( expectedKey ) ;
397
+ actualCommand . sort = { [ expectedKey ] : actualCommand . sort . get ( expectedKey ) } ;
398
+ }
387
399
388
400
expect ( actualCommand )
389
401
. withSessionData ( savedSessionData )
@@ -392,18 +404,23 @@ function validateExpectations(commandEvents, spec, savedSessionData) {
392
404
}
393
405
394
406
function normalizeCommandShapes ( commands ) {
395
- return commands . map ( command =>
396
- JSON . parse (
407
+ return commands . map ( def => {
408
+ const output = JSON . parse (
397
409
EJSON . stringify (
398
410
{
399
- command : command . command ,
400
- commandName : command . command_name ? command . command_name : command . commandName ,
401
- databaseName : command . database_name ? command . database_name : command . databaseName
411
+ command : def . command ,
412
+ commandName : def . command_name ? def . command_name : def . commandName ,
413
+ databaseName : def . database_name ? def . database_name : def . databaseName
402
414
} ,
403
415
{ relaxed : true }
404
416
)
405
- )
406
- ) ;
417
+ ) ;
418
+ // TODO: this is a workaround to preserve sort Map type until NODE-3235 is completed
419
+ if ( def . command . sort ) {
420
+ output . command . sort = def . command . sort ;
421
+ }
422
+ return output ;
423
+ } ) ;
407
424
}
408
425
409
426
function extractCrudResult ( result , operation ) {
0 commit comments