diff --git a/src/libs/actions/Search.ts b/src/libs/actions/Search.ts index 8e34bdd702bb..c54e60de1dbc 100644 --- a/src/libs/actions/Search.ts +++ b/src/libs/actions/Search.ts @@ -1427,7 +1427,7 @@ function handleBulkPayItemSelected(params: { return; } - if (!isUserValidated) { + if (!isUserValidated && item.key !== CONST.IOU.PAYMENT_TYPE.ELSEWHERE) { Navigation.navigate(createDynamicRoute(DYNAMIC_ROUTES.VERIFY_ACCOUNT.path)); return; } diff --git a/tests/unit/Search/handleActionButtonPressTest.ts b/tests/unit/Search/handleActionButtonPressTest.ts index b32202b5b2a6..03ad47d2c64c 100644 --- a/tests/unit/Search/handleActionButtonPressTest.ts +++ b/tests/unit/Search/handleActionButtonPressTest.ts @@ -2,10 +2,11 @@ import type {OnyxEntry} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; import type {TransactionReportGroupListItemType} from '@components/Search/SearchList/ListItem/types'; import {handleActionButtonPress, handleBulkPayItemSelected} from '@libs/actions/Search'; +import createDynamicRoute from '@libs/Navigation/helpers/dynamicRoutesUtils/createDynamicRoute'; import Navigation from '@libs/Navigation/Navigation'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import ROUTES from '@src/ROUTES'; +import ROUTES, {DYNAMIC_ROUTES} from '@src/ROUTES'; import type {LastPaymentMethod, Policy, Report, SearchResults} from '@src/types/onyx'; import createRandomPolicy from '../../utils/collections/policies'; @@ -498,4 +499,46 @@ describe('handleBulkPayItemSelected', () => { expect(baseParams.confirmPayment).toHaveBeenCalled(); }); + + it('should not navigate to verify account and should call confirmPayment when user is unvalidated and item is Mark as paid (ELSEWHERE)', async () => { + const policy = { + ...createRandomPolicy(Number(policyID)), + id: policyID, + ownerAccountID, + } as Policy; + + await Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, policy); + + handleBulkPayItemSelected({ + ...baseParams, + policy, + amountOwed: 0, + isUserValidated: false, + item: {key: CONST.IOU.PAYMENT_TYPE.ELSEWHERE, text: 'Pay elsewhere', icon: () => null}, + }); + + expect(Navigation.navigate).not.toHaveBeenCalledWith(createDynamicRoute(DYNAMIC_ROUTES.VERIFY_ACCOUNT.path)); + expect(baseParams.confirmPayment).toHaveBeenCalled(); + }); + + it('should navigate to verify account when user is unvalidated and item is a bank-funded payment type (VBBA)', async () => { + const policy = { + ...createRandomPolicy(Number(policyID)), + id: policyID, + ownerAccountID, + } as Policy; + + await Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, policy); + + handleBulkPayItemSelected({ + ...baseParams, + policy, + amountOwed: 0, + isUserValidated: false, + item: {key: CONST.IOU.PAYMENT_TYPE.VBBA, text: 'Pay with bank account', icon: () => null}, + }); + + expect(Navigation.navigate).toHaveBeenCalledWith(createDynamicRoute(DYNAMIC_ROUTES.VERIFY_ACCOUNT.path)); + expect(baseParams.confirmPayment).not.toHaveBeenCalled(); + }); });