@@ -1653,6 +1653,8 @@ test('original various tests', function (t) {
16531653 t . deepEqual ( result , expected , 'override sku' ) ;
16541654
16551655 obj [ "inventory" ] = null ;
1656+ map [ "inventory.onHandQty" ] = { key : [ "Envelope.Request.Item.Inventory?" , null , null ] } ;
1657+ map [ "inventory.replenishQty" ] = { key : [ "Envelope.Request.Item.RelpenishQuantity?" , null , null ] } ;
16561658 expected . Envelope . Request . Item . Inventory = null ;
16571659
16581660 result = merge ( obj , { } , map ) ;
@@ -1718,3 +1720,57 @@ test('map array inside array to property', function (t) {
17181720 t . deepEqual ( result , expect ) ;
17191721 t . end ( ) ;
17201722} ) ;
1723+
1724+ test ( 'do not map when a property not present in source and default is not given in map' , function ( t ) {
1725+ var expect = {
1726+ mapThis : 'defaultVal' ,
1727+ mapThisToo : [ {
1728+ property : 'defaultVal' ,
1729+ subArray : [ { property : null } ]
1730+ } ] ,
1731+ other : 'otherVal'
1732+ } ;
1733+
1734+ var map = {
1735+ "doNotMapThis" : {
1736+ "key" : "doNotMapThis" ,
1737+ "transform" : function ( val ) {
1738+ return "_" + val ;
1739+ }
1740+ } ,
1741+ "doNotMapThisToo[].property" : {
1742+ "key" : "doNotMapThisToo[].property" ,
1743+ "transform" : function ( val ) {
1744+ return "_" + val ;
1745+ }
1746+ } ,
1747+ "doNotMapThisToo[].subArray[].property" : {
1748+ "key" : "doNotMapThisToo[].subArray[].property" ,
1749+ "transform" : function ( val ) {
1750+ return "_" + val ;
1751+ }
1752+ } ,
1753+ "mapThis" : {
1754+ "key" : "mapThis" ,
1755+ "default" : "defaultVal"
1756+ } ,
1757+ "mapThisToo[].property" : {
1758+ "key" : "mapThisToo[].property" ,
1759+ "default" : "defaultVal"
1760+ } ,
1761+ "mapThisToo[].subArray[].property" : {
1762+ "key" : "mapThisToo[].subArray[].property?" ,
1763+ "default" : null
1764+ } ,
1765+ "other" : "other"
1766+ } ;
1767+
1768+ var obj = {
1769+ "other" : "otherVal"
1770+ } ;
1771+
1772+ var result = om ( obj , map ) ;
1773+
1774+ t . deepEqual ( result , expect ) ;
1775+ t . end ( ) ;
1776+ } ) ;
0 commit comments