|
1 | 1 | import type {OnyxKey} from 'react-native-onyx'; |
2 | 2 | import Onyx from 'react-native-onyx'; |
| 3 | +import {SIDE_EFFECT_REQUEST_COMMANDS} from '@libs/API/types'; |
3 | 4 | import CONST from '@src/CONST'; |
4 | 5 | import * as OnyxUpdates from '@src/libs/actions/OnyxUpdates'; |
5 | 6 | import DateUtils from '@src/libs/DateUtils'; |
@@ -64,6 +65,41 @@ describe('OnyxUpdatesTest', () => { |
64 | 65 | expect(reportAction).toStrictEqual(reportActionValue); |
65 | 66 | }); |
66 | 67 | }); |
| 68 | + |
| 69 | + it('applies full ReconnectApp Onyx updates even if they appear old', async () => { |
| 70 | + // Given the current lastUpdateIDAppliedToClient is merged |
| 71 | + const currentUpdateID = 100; |
| 72 | + await Onyx.merge(ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT, currentUpdateID); |
| 73 | + |
| 74 | + // And we received onyx updates from a full ReconnectApp request with the same lastUpdateID |
| 75 | + const reportID = NumberUtils.rand64(); |
| 76 | + const reportValue = {reportID}; |
| 77 | + const fullReconnectUpdates: OnyxUpdatesFromServer = { |
| 78 | + type: CONST.ONYX_UPDATE_TYPES.HTTPS, |
| 79 | + request: { |
| 80 | + command: SIDE_EFFECT_REQUEST_COMMANDS.RECONNECT_APP, |
| 81 | + data: { |
| 82 | + updateIDFrom: null, |
| 83 | + }, |
| 84 | + }, |
| 85 | + response: { |
| 86 | + onyxData: [ |
| 87 | + { |
| 88 | + onyxMethod: 'merge', |
| 89 | + key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, |
| 90 | + value: reportValue, |
| 91 | + }, |
| 92 | + ], |
| 93 | + }, |
| 94 | + previousUpdateID: currentUpdateID - 2, |
| 95 | + lastUpdateID: currentUpdateID - 1, |
| 96 | + }; |
| 97 | + |
| 98 | + // When we apply the updates, then they are still applied even if the lastUpdateID is old |
| 99 | + await OnyxUpdates.apply(fullReconnectUpdates); |
| 100 | + const report = await getOnyxValue(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`); |
| 101 | + expect(report).toStrictEqual(reportValue); |
| 102 | + }); |
67 | 103 | }); |
68 | 104 |
|
69 | 105 | function getOnyxValues<TKey extends OnyxKey>(...keys: TKey[]) { |
|
0 commit comments