@@ -347,64 +347,105 @@ describe("convertToAttr", () => {
347
347
( { input, output } ) => {
348
348
[ true , false ] . forEach ( ( useObjectCreate ) => {
349
349
const inputObject = useObjectCreate ? Object . create ( input ) : input ;
350
- it ( `testing object: ${ inputObject } ` , ( ) => {
350
+ it ( `testing object: ${ inputObject } ${ useObjectCreate && " with Object.create()" } ` , ( ) => {
351
351
expect ( convertToAttr ( inputObject ) ) . toEqual ( { M : output } ) ;
352
352
} ) ;
353
353
} ) ;
354
+
355
+ const inputMap = new Map ( Object . entries ( input ) ) ;
356
+ it ( `testing map: ${ inputMap } ` , ( ) => {
357
+ expect ( convertToAttr ( inputMap ) ) . toEqual ( { M : output } ) ;
358
+ } ) ;
354
359
}
355
360
) ;
356
361
357
- [ true , false ] . forEach ( ( useObjectCreate ) => {
358
- it ( `testing object with options.convertEmptyValues=true` , ( ) => {
359
- const input = { stringKey : "" , binaryKey : new Uint8Array ( ) , setKey : new Set ( [ ] ) } ;
362
+ describe ( `with options.convertEmptyValues=true` , ( ) => {
363
+ const input = { stringKey : "" , binaryKey : new Uint8Array ( ) , setKey : new Set ( [ ] ) } ;
364
+ const output = { stringKey : { NULL : true } , binaryKey : { NULL : true } , setKey : { NULL : true } } ;
365
+
366
+ [ true , false ] . forEach ( ( useObjectCreate ) => {
360
367
const inputObject = useObjectCreate ? Object . create ( input ) : input ;
361
- expect ( convertToAttr ( inputObject , { convertEmptyValues : true } ) ) . toEqual ( {
362
- M : { stringKey : { NULL : true } , binaryKey : { NULL : true } , setKey : { NULL : true } } ,
368
+ it ( `testing object ${ useObjectCreate && " with Object.create()" } ` , ( ) => {
369
+ expect ( convertToAttr ( inputObject , { convertEmptyValues : true } ) ) . toEqual ( { M : output } ) ;
363
370
} ) ;
364
371
} ) ;
372
+
373
+ const inputMap = new Map ( Object . entries ( input ) ) ;
374
+ it ( `testing map` , ( ) => {
375
+ expect ( convertToAttr ( inputMap , { convertEmptyValues : true } ) ) . toEqual ( { M : output } ) ;
376
+ } ) ;
365
377
} ) ;
366
378
367
- [ true , false ] . forEach ( ( useObjectCreate ) => {
368
- describe ( `testing object with options.removeUndefinedValues` , ( ) => {
369
- describe ( "throws error" , ( ) => {
370
- const testErrorMapWithUndefinedValues = ( useObjectCreate : boolean , options ?: marshallOptions ) => {
371
- const input = { definedKey : "definedKey" , undefinedKey : undefined } ;
372
- const inputObject = useObjectCreate ? Object . create ( input ) : input ;
373
- expect ( ( ) => {
374
- convertToAttr ( inputObject , options ) ;
375
- } ) . toThrowError ( `Pass options.removeUndefinedValues=true to remove undefined values from map/array/set.` ) ;
376
- } ;
379
+ describe ( `with options.removeUndefinedValues=true` , ( ) => {
380
+ describe ( "throws error" , ( ) => {
381
+ const testErrorMapWithUndefinedValues = ( input : any , options ?: marshallOptions ) => {
382
+ expect ( ( ) => {
383
+ convertToAttr ( input , options ) ;
384
+ } ) . toThrowError ( `Pass options.removeUndefinedValues=true to remove undefined values from map/array/set.` ) ;
385
+ } ;
377
386
378
- [ undefined , { } , { convertEmptyValues : false } ] . forEach ( ( options ) => {
379
- it ( `when options=${ options } ` , ( ) => {
380
- testErrorMapWithUndefinedValues ( useObjectCreate , options ) ;
387
+ [ undefined , { } , { convertEmptyValues : false } ] . forEach ( ( options ) => {
388
+ const input = { definedKey : "definedKey" , undefinedKey : undefined } ;
389
+ [ true , false ] . forEach ( ( useObjectCreate ) => {
390
+ const inputObject = useObjectCreate ? Object . create ( input ) : input ;
391
+ it ( `testing object${ useObjectCreate && " with Object.create()" } when options=${ options } ` , ( ) => {
392
+ testErrorMapWithUndefinedValues ( inputObject , options ) ;
381
393
} ) ;
382
394
} ) ;
395
+
396
+ const inputMap = new Map ( Object . entries ( input ) ) ;
397
+ it ( `testing map when options=${ options } ` , ( ) => {
398
+ testErrorMapWithUndefinedValues ( inputMap , options ) ;
399
+ } ) ;
383
400
} ) ;
401
+ } ) ;
384
402
385
- it ( `returns when options.removeUndefinedValues=true` , ( ) => {
386
- const input = { definedKey : "definedKey" , undefinedKey : undefined } ;
403
+ describe ( `returns when options.removeUndefinedValues=true` , ( ) => {
404
+ const input = { definedKey : "definedKey" , undefinedKey : undefined } ;
405
+ const output = { definedKey : { S : "definedKey" } } ;
406
+ [ true , false ] . forEach ( ( useObjectCreate ) => {
387
407
const inputObject = useObjectCreate ? Object . create ( input ) : input ;
388
- expect ( convertToAttr ( inputObject , { removeUndefinedValues : true } ) ) . toEqual ( {
389
- M : { definedKey : { S : "definedKey" } } ,
408
+ it ( `testing object ${ useObjectCreate && " with Object.create()" } ` , ( ) => {
409
+ expect ( convertToAttr ( inputObject , { removeUndefinedValues : true } ) ) . toEqual ( { M : output } ) ;
390
410
} ) ;
391
411
} ) ;
412
+
413
+ const inputMap = new Map ( Object . entries ( input ) ) ;
414
+ it ( `testing map` , ( ) => {
415
+ expect ( convertToAttr ( inputMap , { removeUndefinedValues : true } ) ) . toEqual ( { M : output } ) ;
416
+ } ) ;
392
417
} ) ;
393
418
} ) ;
394
419
395
- it ( `testing Object.create with function` , ( ) => {
396
- const person = {
397
- isHuman : true ,
398
- printIntroduction : function ( ) {
399
- console . log ( `Am I human? ${ this . isHuman } ` ) ;
420
+ describe ( `testing with function` , ( ) => {
421
+ const input = {
422
+ bool : true ,
423
+ func : function ( ) {
424
+ console . log ( `bool: ${ this . bool } ` ) ;
400
425
} ,
401
426
} ;
402
- expect ( convertToAttr ( Object . create ( person ) ) ) . toEqual ( { M : { isHuman : { BOOL : true } } } ) ;
427
+ const output = { bool : { BOOL : true } } ;
428
+
429
+ [ true , false ] . forEach ( ( useObjectCreate ) => {
430
+ const inputObject = useObjectCreate ? Object . create ( input ) : input ;
431
+ it ( `testing object${ useObjectCreate && " with Object.create()" } ` , ( ) => {
432
+ expect ( convertToAttr ( inputObject ) ) . toEqual ( { M : output } ) ;
433
+ } ) ;
434
+ } ) ;
435
+
436
+ const inputMap = new Map ( Object . entries ( input ) ) ;
437
+ it ( `testing map` , ( ) => {
438
+ expect ( convertToAttr ( inputMap ) ) . toEqual ( { M : output } ) ;
439
+ } ) ;
403
440
} ) ;
404
441
405
442
it ( `testing Object.create(null)` , ( ) => {
406
443
expect ( convertToAttr ( Object . create ( null ) ) ) . toEqual ( { M : { } } ) ;
407
444
} ) ;
445
+
446
+ it ( `testing empty Map` , ( ) => {
447
+ expect ( convertToAttr ( new Map ( ) ) ) . toEqual ( { M : { } } ) ;
448
+ } ) ;
408
449
} ) ;
409
450
410
451
describe ( "string" , ( ) => {
0 commit comments