From 2c67158cf9ffffc3a9e5499d2b3c490093790981 Mon Sep 17 00:00:00 2001 From: rory Date: Mon, 24 Apr 2023 12:13:00 -0400 Subject: [PATCH 1/3] Clear cache in Onyx.clear() --- lib/Onyx.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Onyx.js b/lib/Onyx.js index 266775443..203351332 100644 --- a/lib/Onyx.js +++ b/lib/Onyx.js @@ -1100,6 +1100,8 @@ function clear(keysToPreserve = []) { const defaultKeyValuePairs = _.pairs(_.omit(defaultKeyStates, keysToPreserve)); // Remove only the items that we want cleared from storage, and reset others to default + _.each(keysToBeClearedFromStorage, key => cache.drop(key)); + _.each(defaultKeyValuePairs, ([key, value]) => cache.set(key, value)); return Storage.removeItems(keysToBeClearedFromStorage).then(() => Storage.multiSet(defaultKeyValuePairs)); }); } From 3571dfbea5c828a7f6cc559f04981f12bff0cec7 Mon Sep 17 00:00:00 2001 From: rory Date: Mon, 24 Apr 2023 12:38:53 -0400 Subject: [PATCH 2/3] Remove unnecessary calls to cache.set --- lib/Onyx.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Onyx.js b/lib/Onyx.js index 203351332..43427aefa 100644 --- a/lib/Onyx.js +++ b/lib/Onyx.js @@ -1101,7 +1101,6 @@ function clear(keysToPreserve = []) { // Remove only the items that we want cleared from storage, and reset others to default _.each(keysToBeClearedFromStorage, key => cache.drop(key)); - _.each(defaultKeyValuePairs, ([key, value]) => cache.set(key, value)); return Storage.removeItems(keysToBeClearedFromStorage).then(() => Storage.multiSet(defaultKeyValuePairs)); }); } From 14ded820d428a7637abe623e220473d32776fa00 Mon Sep 17 00:00:00 2001 From: rory Date: Mon, 24 Apr 2023 12:39:56 -0400 Subject: [PATCH 3/3] Update tests --- tests/unit/onyxTest.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/unit/onyxTest.js b/tests/unit/onyxTest.js index 09d46e52c..cf2694946 100644 --- a/tests/unit/onyxTest.js +++ b/tests/unit/onyxTest.js @@ -117,8 +117,12 @@ describe('Onyx', () => { return Onyx.clear().then(waitForPromisesToResolve); }) .then(() => { + // Test key should be cleared expect(testKeyValue).toBeNull(); - expect(otherTestValue).toBe(null); + + // Other test key should be returned to its default state + expect(otherTestValue).toBe(42); + return Onyx.disconnect(otherTestConnectionID); }); }); @@ -596,7 +600,7 @@ describe('Onyx', () => { expect(mockCallback).toHaveBeenCalledTimes(2); // AND the value for the first call should be null since the collection was not initialized at that point - expect(mockCallback).toHaveBeenNthCalledWith(1, null, 'testPolicy_1'); + expect(mockCallback).toHaveBeenNthCalledWith(1, null, undefined); // AND the value for the second call should be collectionUpdate since the collection was updated expect(mockCallback).toHaveBeenNthCalledWith(2, collectionUpdate.testPolicy_1, 'testPolicy_1');