-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51093 from gedu/gedu/open_report_de_dupe
Replace duplicated openReports
- Loading branch information
Showing
6 changed files
with
93 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ import {afterEach, beforeAll, beforeEach, describe, expect, it} from '@jest/glob | |
import {toZonedTime} from 'date-fns-tz'; | ||
import Onyx from 'react-native-onyx'; | ||
import type {OnyxCollection, OnyxEntry, OnyxUpdate} from 'react-native-onyx'; | ||
import {WRITE_COMMANDS} from '@libs/API/types'; | ||
import CONST from '@src/CONST'; | ||
import OnyxUpdateManager from '@src/libs/actions/OnyxUpdateManager'; | ||
import * as PersistedRequests from '@src/libs/actions/PersistedRequests'; | ||
|
@@ -757,4 +758,54 @@ describe('actions/Report', () => { | |
expect(reportActionReaction?.[EMOJI.name].users[TEST_USER_ACCOUNT_ID]).toBeUndefined(); | ||
}); | ||
}); | ||
|
||
it.only('should send only one OpenReport, replacing any extra ones with same reportIDs', async () => { | ||
global.fetch = TestHelper.getGlobalFetchMock(); | ||
|
||
const REPORT_ID = '1'; | ||
|
||
await Onyx.set(ONYXKEYS.NETWORK, {isOffline: true}); | ||
await waitForBatchedUpdates(); | ||
|
||
for (let i = 0; i < 5; i++) { | ||
Report.openReport(REPORT_ID, undefined, ['[email protected]'], { | ||
isOptimisticReport: true, | ||
reportID: REPORT_ID, | ||
}); | ||
} | ||
|
||
expect(PersistedRequests.getAll().length).toBe(1); | ||
|
||
await Onyx.set(ONYXKEYS.NETWORK, {isOffline: false}); | ||
await waitForBatchedUpdates(); | ||
|
||
TestHelper.expectAPICommandToHaveBeenCalled(WRITE_COMMANDS.OPEN_REPORT, 1); | ||
}); | ||
|
||
it.only('should replace duplicate OpenReport commands with the same reportID', async () => { | ||
global.fetch = TestHelper.getGlobalFetchMock(); | ||
|
||
const REPORT_ID = '1'; | ||
|
||
await Onyx.set(ONYXKEYS.NETWORK, {isOffline: true}); | ||
await waitForBatchedUpdates(); | ||
|
||
for (let i = 0; i < 8; i++) { | ||
let reportID = REPORT_ID; | ||
if (i > 4) { | ||
reportID = `${i}`; | ||
} | ||
Report.openReport(reportID, undefined, ['[email protected]'], { | ||
isOptimisticReport: true, | ||
reportID: REPORT_ID, | ||
}); | ||
} | ||
|
||
expect(PersistedRequests.getAll().length).toBe(4); | ||
|
||
await Onyx.set(ONYXKEYS.NETWORK, {isOffline: false}); | ||
await waitForBatchedUpdates(); | ||
|
||
TestHelper.expectAPICommandToHaveBeenCalled(WRITE_COMMANDS.OPEN_REPORT, 4); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters