import { generateMapTransform } from '../mapTransform' ; describe ( 'mapTransform' , ( ) => { const keyMap = { oldId : 'newId' , veryOldKey : 'muchNewerKey' , oldArray : 'newArray' , } ; const transformMap = { muchNewerKey : ( value ) => value . slice ( 0 , 3 ) , newArray : ( value ) => value . slice ( 0 , 1 ) , } ; const testMapTransform = generateMapTransform ( keyMap , transformMap ) ; it ( 'maps keys to new values' , ( ) => { const oldObject = { oldId : 1 , veryOldKey : '123456' , nestedObject : { veryOldKey : '123456' , nestedObject : { veryOldKey : '123456' , } , } , oldArray : [ { veryOldKey : '123456' , doNotTransform : 'nope' , } , { veryOldKey : '123456' , doNotTransform : 'nope' , } , { veryOldKey : '123456' , doNotTransform : 'nope' , } , ] , } ; const clone = JSON . parse ( JSON . stringify ( oldObject ) ) ; const newObject = testMapTransform ( oldObject ) ; expect ( oldObject ) . toMatchObject ( clone ) ; expect ( newObject ) . toMatchSnapshot ( ) ; } ) ; } ) ;