Repository navigation
Read Pay button reports and actions at press time #108230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
luacmartins
merged 4 commits into
Expensify:main
from
callstack-internal:perf/3405-pay-action-cell-reads
Dec 1, 2026
+343
−29
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a63bbdf
Read Pay button reports and actions at press time
sosek108 c8b99ab
Merge remote-tracking branch 'exfy/main' into perf/3405-pay-action-ce…
sosek108 f4b4281
Type requireActual in KYCWall test mock
sosek108 65ea87b
Keep snapshot invoice room lookup and scope KYCWall chat subscriptions
sosek108 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import {isPolicyExpenseChat, isThread} from '@libs/ReportUtils'; | ||
|
|
||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import type {ReportActions} from '@src/types/onyx'; | ||
|
|
||
| import type {OnyxCollection} from 'react-native-onyx'; | ||
|
|
||
| import useOnyx from './useOnyx'; | ||
|
|
||
| /** Report actions of the submitter's workspace chats, keyed like the REPORT_ACTIONS collection. Empty when `submitterAccountID` is undefined. */ | ||
| function useSubmitterWorkspaceChatActions(submitterAccountID: number | undefined): OnyxCollection<ReportActions> { | ||
| const [submitterWorkspaceChatIDs] = useOnyx(ONYXKEYS.COLLECTION.REPORT, { | ||
| selector: (reports) => { | ||
| if (submitterAccountID === undefined) { | ||
| return undefined; | ||
| } | ||
| const reportIDs: string[] = []; | ||
| for (const report of Object.values(reports ?? {})) { | ||
| if (report?.reportID && report.ownerAccountID === submitterAccountID && isPolicyExpenseChat(report) && !isThread(report)) { | ||
| reportIDs.push(report.reportID); | ||
| } | ||
| } | ||
| return reportIDs; | ||
| }, | ||
| }); | ||
| const [submitterWorkspaceChatActions] = useOnyx(ONYXKEYS.COLLECTION.REPORT_ACTIONS, { | ||
| selector: (allReportActions) => { | ||
| const reportActions: OnyxCollection<ReportActions> = {}; | ||
| for (const reportID of submitterWorkspaceChatIDs ?? []) { | ||
| const key = `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}` as const; | ||
| const actions = allReportActions?.[key]; | ||
| if (actions) { | ||
| reportActions[key] = actions; | ||
| } | ||
| } | ||
| return reportActions; | ||
| }, | ||
| }); | ||
|
|
||
| return submitterWorkspaceChatActions; | ||
| } | ||
|
|
||
| export default useSubmitterWorkspaceChatActions; |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| import {act, render} from '@testing-library/react-native'; | ||
|
|
||
| import ComposeProviders from '@components/ComposeProviders'; | ||
| import {CurrentUserPersonalDetailsProvider} from '@components/CurrentUserPersonalDetailsProvider'; | ||
| import KYCWall from '@components/KYCWall'; | ||
| import type {ContinueActionParams, KYCWallRef} from '@components/KYCWall/types'; | ||
| import {LocaleContextProvider} from '@components/LocaleContextProvider'; | ||
| import OnyxListItemProvider from '@components/OnyxListItemProvider'; | ||
|
|
||
| import type * as ReportActionsModule from '@libs/actions/Report'; | ||
| import {moveIOUReportToPolicyAndInviteSubmitter} from '@libs/actions/Report'; | ||
|
|
||
| import CONST from '@src/CONST'; | ||
| import IntlStore from '@src/languages/IntlStore'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import ROUTES from '@src/ROUTES'; | ||
| import type {Policy, Report, ReportActions} from '@src/types/onyx'; | ||
|
|
||
| import React from 'react'; | ||
| import Onyx from 'react-native-onyx'; | ||
|
|
||
| import createRandomPolicy from '../../utils/collections/policies'; | ||
| import createRandomReportAction from '../../utils/collections/reportActions'; | ||
| import waitForBatchedUpdatesWithAct from '../../utils/waitForBatchedUpdatesWithAct'; | ||
|
|
||
| jest.mock('@libs/Navigation/Navigation', () => ({ | ||
| __esModule: true, | ||
| default: { | ||
| navigate: jest.fn(), | ||
| goBack: jest.fn(), | ||
| getActiveRoute: jest.fn(() => ''), | ||
| }, | ||
| })); | ||
|
|
||
| jest.mock('@libs/actions/Report', () => { | ||
| const actual = jest.requireActual<typeof ReportActionsModule>('@libs/actions/Report'); | ||
| return { | ||
| ...actual, | ||
| __esModule: true, | ||
| moveIOUReportToPolicy: jest.fn(() => undefined), | ||
| moveIOUReportToPolicyAndInviteSubmitter: jest.fn(() => undefined), | ||
| }; | ||
| }); | ||
|
|
||
| const mockedMoveIOUReportToPolicyAndInviteSubmitter = jest.mocked(moveIOUReportToPolicyAndInviteSubmitter); | ||
|
|
||
| const POLICY_ID = 'kyc-wall-policy'; | ||
| const WORKSPACE_CHAT_ID = '300'; | ||
|
|
||
| const iouReport = { | ||
| reportID: '100', | ||
| chatReportID: '200', | ||
| type: CONST.REPORT.TYPE.IOU, | ||
| ownerAccountID: 2, | ||
| managerID: 1, | ||
| currency: CONST.CURRENCY.USD, | ||
| } as Report; | ||
|
|
||
| const adminPolicy: Policy = { | ||
| ...createRandomPolicy(1, CONST.POLICY.TYPE.TEAM, 'Admin workspace'), | ||
| id: POLICY_ID, | ||
| role: CONST.POLICY.ROLE.ADMIN, | ||
| outputCurrency: CONST.CURRENCY.USD, | ||
| }; | ||
|
|
||
| const workspaceChat = { | ||
| reportID: WORKSPACE_CHAT_ID, | ||
| type: CONST.REPORT.TYPE.CHAT, | ||
| chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, | ||
| policyID: POLICY_ID, | ||
| ownerAccountID: iouReport.ownerAccountID, | ||
| } as Report; | ||
|
|
||
| const workspaceChatAction = createRandomReportAction(1); | ||
| const workspaceChatActions: ReportActions = {[workspaceChatAction.reportActionID]: workspaceChatAction}; | ||
|
|
||
| describe('KYCWall', () => { | ||
| beforeAll(() => { | ||
| Onyx.init({keys: ONYXKEYS}); | ||
| IntlStore.load(CONST.LOCALES.EN); | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| jest.clearAllMocks(); | ||
| await Onyx.clear(); | ||
| }); | ||
|
|
||
| it('should pass the submitter workspace chat actions when moving an IOU report to a workspace', async () => { | ||
| // Given an IOU report payer without a payment method who administers a workspace | ||
| await Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${POLICY_ID}`, adminPolicy); | ||
| let continueAction: ((params?: ContinueActionParams) => void) | undefined; | ||
| render( | ||
| <ComposeProviders components={[OnyxListItemProvider, LocaleContextProvider, CurrentUserPersonalDetailsProvider]}> | ||
| <KYCWall | ||
| ref={React.createRef<KYCWallRef>()} | ||
| iouReport={iouReport} | ||
| chatReportID={iouReport.chatReportID} | ||
| enablePaymentsRoute={ROUTES.ENABLE_PAYMENTS} | ||
| onSuccessfulKYC={jest.fn()} | ||
| > | ||
| {(triggerKYCFlow) => { | ||
| continueAction = triggerKYCFlow; | ||
| }} | ||
| </KYCWall> | ||
| </ComposeProviders>, | ||
| ); | ||
| await waitForBatchedUpdatesWithAct(); | ||
|
|
||
| // And the workspace chat and its actions land in Onyx after the wall rendered | ||
| await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${WORKSPACE_CHAT_ID}`, workspaceChat); | ||
| await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${WORKSPACE_CHAT_ID}`, workspaceChatActions); | ||
| await waitForBatchedUpdatesWithAct(); | ||
|
|
||
| // When the payer picks the workspace to pay through | ||
| act(() => { | ||
| continueAction?.({policy: adminPolicy}); | ||
| }); | ||
| await waitForBatchedUpdatesWithAct(); | ||
|
|
||
| // Then the move should get those actions, because the wall subscribes to the submitter's workspace chats so the report joins the existing chat | ||
| expect(mockedMoveIOUReportToPolicyAndInviteSubmitter.mock.calls.at(0)?.at(2)).toEqual({[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${WORKSPACE_CHAT_ID}`]: workspaceChatActions}); | ||
| }); | ||
|
|
||
| it('should not pass workspace chats of other members when moving an IOU report to a workspace', async () => { | ||
| // Given an IOU report payer who administers a workspace where only another member has a workspace chat | ||
| await Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${POLICY_ID}`, adminPolicy); | ||
| await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${WORKSPACE_CHAT_ID}`, {...workspaceChat, ownerAccountID: 3}); | ||
| await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${WORKSPACE_CHAT_ID}`, workspaceChatActions); | ||
| let continueAction: ((params?: ContinueActionParams) => void) | undefined; | ||
| render( | ||
| <ComposeProviders components={[OnyxListItemProvider, LocaleContextProvider, CurrentUserPersonalDetailsProvider]}> | ||
| <KYCWall | ||
| ref={React.createRef<KYCWallRef>()} | ||
| iouReport={iouReport} | ||
| chatReportID={iouReport.chatReportID} | ||
| enablePaymentsRoute={ROUTES.ENABLE_PAYMENTS} | ||
| onSuccessfulKYC={jest.fn()} | ||
| > | ||
| {(triggerKYCFlow) => { | ||
| continueAction = triggerKYCFlow; | ||
| }} | ||
| </KYCWall> | ||
| </ComposeProviders>, | ||
| ); | ||
| await waitForBatchedUpdatesWithAct(); | ||
|
|
||
| // When the payer picks the workspace to pay through | ||
| act(() => { | ||
| continueAction?.({policy: adminPolicy}); | ||
| }); | ||
| await waitForBatchedUpdatesWithAct(); | ||
|
|
||
| // Then the move should get no workspace chat actions, because only the submitter's own workspace chat can receive the report | ||
| expect(mockedMoveIOUReportToPolicyAndInviteSubmitter.mock.calls.at(0)?.at(2)).toEqual({}); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.