@@ -1932,6 +1932,74 @@ describe('Onyx', () => {
19321932 expect ( await StorageMock . getItem ( `${ ONYX_KEYS . COLLECTION . TEST_UPDATE } entry1` ) ) . toEqual ( entry1ExpectedResult ) ;
19331933 } ) ;
19341934
1935+ it ( 'replacing nested object during updates' , async ( ) => {
1936+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1937+ const entry1 : DeepRecord < string , any > | undefined = {
1938+ id : 'entry1' ,
1939+ someKey : 'someValue' ,
1940+ } ;
1941+ await Onyx . multiSet ( {
1942+ [ `${ ONYX_KEYS . COLLECTION . TEST_UPDATE } entry1` ] : {
1943+ id : 'entry1' ,
1944+ someKey : 'someValue' ,
1945+ } ,
1946+ } ) ;
1947+
1948+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1949+ let entry1ExpectedResult = lodashCloneDeep ( entry1 ) as DeepRecord < string , any > | undefined ;
1950+ const queuedUpdates : OnyxUpdate [ ] = [ ] ;
1951+
1952+ queuedUpdates . push ( {
1953+ key : `${ ONYX_KEYS . COLLECTION . TEST_UPDATE } entry1` ,
1954+ onyxMethod : 'merge' ,
1955+ // Removing the entire object in this update.
1956+ // Any subsequent changes to this key should completely replace the old value.
1957+ value : null ,
1958+ } ) ;
1959+ entry1ExpectedResult = undefined ;
1960+
1961+ queuedUpdates . push ( {
1962+ key : `${ ONYX_KEYS . COLLECTION . TEST_UPDATE } entry1` ,
1963+ onyxMethod : 'merge' ,
1964+ // This change should completely replace `${ONYX_KEYS.COLLECTION.TEST_UPDATE}entry1` old value.
1965+ value : {
1966+ someKey : 'someValueChanged' ,
1967+ someNestedObject : {
1968+ someNestedKey : 'someNestedValue' ,
1969+ } ,
1970+ } ,
1971+ } ) ;
1972+ entry1ExpectedResult = { someKey : 'someValueChanged' , someNestedObject : { someNestedKey : 'someNestedValue' } } ;
1973+
1974+ queuedUpdates . push ( {
1975+ key : `${ ONYX_KEYS . COLLECTION . TEST_UPDATE } entry1` ,
1976+ onyxMethod : 'merge' ,
1977+ value : {
1978+ // Removing the "sub_entry1" object in this update.
1979+ // Any subsequent changes to this key should completely replace the old update's value.
1980+ someNestedObject : null ,
1981+ } ,
1982+ } ) ;
1983+ delete entry1ExpectedResult . someNestedObject ;
1984+
1985+ queuedUpdates . push ( {
1986+ key : `${ ONYX_KEYS . COLLECTION . TEST_UPDATE } entry1` ,
1987+ onyxMethod : 'merge' ,
1988+ // This change should completely replace `someNestedObject` old update's value.
1989+ value : {
1990+ someNestedObject : {
1991+ someNestedKeyChanged : 'someNestedValueChange' ,
1992+ } ,
1993+ } ,
1994+ } ) ;
1995+ entry1ExpectedResult . someNestedObject = { someNestedKeyChanged : 'someNestedValueChange' } ;
1996+
1997+ await Onyx . update ( queuedUpdates ) ;
1998+
1999+ expect ( result ) . toEqual ( { [ `${ ONYX_KEYS . COLLECTION . TEST_UPDATE } entry1` ] : entry1ExpectedResult } ) ;
2000+ expect ( await StorageMock . getItem ( `${ ONYX_KEYS . COLLECTION . TEST_UPDATE } entry1` ) ) . toEqual ( entry1ExpectedResult ) ;
2001+ } ) ;
2002+
19352003 describe ( 'mergeCollection' , ( ) => {
19362004 it ( 'replacing old object after null merge' , async ( ) => {
19372005 // eslint-disable-next-line @typescript-eslint/no-explicit-any
0 commit comments