From bf12516635eaa1c91c03c56013f04e5069775a29 Mon Sep 17 00:00:00 2001 From: KJ21-ENG Date: Thu, 18 Jun 2026 01:41:29 +0530 Subject: [PATCH 1/8] Fix report preview approval policy flow --- .../ApproveActionButton.tsx | 5 +- .../PayActionButton.tsx | 2 +- src/hooks/useHoldMenuSubmit.ts | 2 +- src/libs/actions/IOU/ReportWorkflow.ts | 39 +++++++-- tests/actions/IOUTest/ReportWorkflowTest.ts | 86 +++++++++++++++++++ 5 files changed, 122 insertions(+), 12 deletions(-) diff --git a/src/components/ReportActionItem/MoneyRequestReportPreview/ApproveActionButton.tsx b/src/components/ReportActionItem/MoneyRequestReportPreview/ApproveActionButton.tsx index cc95da70b48c..10ae0c6a4c26 100644 --- a/src/components/ReportActionItem/MoneyRequestReportPreview/ApproveActionButton.tsx +++ b/src/components/ReportActionItem/MoneyRequestReportPreview/ApproveActionButton.tsx @@ -6,7 +6,6 @@ import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails' import useLocalize from '@hooks/useLocalize'; import useOnyx from '@hooks/useOnyx'; import usePermissions from '@hooks/usePermissions'; -import usePolicy from '@hooks/usePolicy'; import useTransactionsAndViolationsForReport from '@hooks/useTransactionsAndViolationsForReport'; import {hasHeldExpensesFromTransactions as hasHeldExpensesReportUtils, hasViolations as hasViolationsReportUtils} from '@libs/ReportUtils'; import {approveMoneyRequest} from '@userActions/IOU/ReportWorkflow'; @@ -30,8 +29,6 @@ function ApproveActionButton({iouReportID, startApprovedAnimation, onHoldMenuOpe const {isDelegateAccessRestricted} = useDelegateNoAccessState(); const {showDelegateNoAccessModal} = useDelegateNoAccessActions(); - const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID); - const activePolicy = usePolicy(activePolicyID); const [iouReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${iouReportID}`); const [expenseReportPolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${iouReport?.policyID}`); const [userBillingGracePeriodEnds] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END); @@ -59,7 +56,7 @@ function ApproveActionButton({iouReportID, startApprovedAnimation, onHoldMenuOpe approveMoneyRequest({ expenseReport: iouReport, expenseReportPolicy, - policy: activePolicy, + policy: expenseReportPolicy, currentUserAccountIDParam: currentUserAccountID, currentUserEmailParam: currentUserEmail, hasViolations, diff --git a/src/components/ReportActionItem/MoneyRequestReportPreview/PayActionButton.tsx b/src/components/ReportActionItem/MoneyRequestReportPreview/PayActionButton.tsx index 2fd9e05b0ccf..c3559c906f5e 100644 --- a/src/components/ReportActionItem/MoneyRequestReportPreview/PayActionButton.tsx +++ b/src/components/ReportActionItem/MoneyRequestReportPreview/PayActionButton.tsx @@ -143,7 +143,7 @@ function PayActionButton({ approveMoneyRequest({ expenseReport: iouReport, expenseReportPolicy: policy, - policy: activePolicy, + policy, currentUserAccountIDParam: currentUserAccountID, currentUserEmailParam: currentUserEmail, hasViolations, diff --git a/src/hooks/useHoldMenuSubmit.ts b/src/hooks/useHoldMenuSubmit.ts index f5082038cfdd..94e89d2244e2 100644 --- a/src/hooks/useHoldMenuSubmit.ts +++ b/src/hooks/useHoldMenuSubmit.ts @@ -62,7 +62,7 @@ function useHoldMenuSubmit({moneyRequestReport, chatReport, requestType, payment if (isApprove) { approveMoneyRequest({ expenseReport: moneyRequestReport, - policy: activePolicy, + policy, currentUserAccountIDParam: currentUserDetails.accountID, currentUserEmailParam: currentUserDetails.email ?? '', hasViolations, diff --git a/src/libs/actions/IOU/ReportWorkflow.ts b/src/libs/actions/IOU/ReportWorkflow.ts index 4b1855dfa9e3..87ef6aa31353 100644 --- a/src/libs/actions/IOU/ReportWorkflow.ts +++ b/src/libs/actions/IOU/ReportWorkflow.ts @@ -409,18 +409,19 @@ function approveMoneyRequest(params: ApproveMoneyRequestFunctionParams) { return; } + const workflowPolicy = expenseReportPolicy ?? policy; const reportTransactions = getReportTransactions(expenseReport.reportID); let total = expenseReport.total ?? 0; const hasHeldExpenses = hasHeldExpensesReportUtils(reportTransactions); // TODO: https://github.com/Expensify/App/issues/66512 // eslint-disable-next-line @typescript-eslint/no-deprecated - const hasDuplicates = hasDuplicateTransactions(currentUserEmailParam, currentUserAccountIDParam, expenseReport, policy, getAllTransactionViolations()); + const hasDuplicates = hasDuplicateTransactions(currentUserEmailParam, currentUserAccountIDParam, expenseReport, workflowPolicy, getAllTransactionViolations()); if (hasHeldExpenses && !full && !!expenseReport.unheldTotal) { total = expenseReport.unheldTotal; } const optimisticApprovedReportAction = buildOptimisticApprovedReportAction(total, expenseReport.currency ?? '', expenseReport.reportID, currentUserAccountIDParam, delegateEmail); - const isDEWPolicy = hasDynamicExternalWorkflow(policy); + const isDEWPolicy = hasDynamicExternalWorkflow(workflowPolicy); const shouldAddOptimisticApproveAction = !isDEWPolicy || getIsOffline(); const nextApproverAccountID = getNextApproverAccountID(expenseReport); @@ -433,7 +434,7 @@ function approveMoneyRequest(params: ApproveMoneyRequestFunctionParams) { ? null : buildNextStepNew({ report: expenseReport, - policy, + policy: workflowPolicy, currentUserAccountIDParam, currentUserEmailParam, hasViolations, @@ -444,7 +445,7 @@ function approveMoneyRequest(params: ApproveMoneyRequestFunctionParams) { ? null : buildOptimisticNextStep({ report: expenseReport, - policy, + policy: workflowPolicy, currentUserAccountIDParam, currentUserEmailParam, hasViolations, @@ -620,6 +621,32 @@ function approveMoneyRequest(params: ApproveMoneyRequestFunctionParams) { }); } + if (!isDEWPolicy && expenseReport.parentReportID && expenseReport.parentReportActionID) { + optimisticData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.parentReportID}`, + value: { + [expenseReport.parentReportActionID]: { + childStateNum: predictedNextState, + childStatusNum: predictedNextStatus, + ...(nextApproverAccountID ? {childManagerAccountID: managerID} : {}), + }, + }, + }); + + failureData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.parentReportID}`, + value: { + [expenseReport.parentReportActionID]: { + childStateNum: expenseReport.stateNum, + childStatusNum: expenseReport.statusNum, + ...(nextApproverAccountID ? {childManagerAccountID: expenseReport.managerID} : {}), + }, + }, + }); + } + if (shouldAddOptimisticApproveAction) { if (isDEWPolicy) { failureData.push({ @@ -688,7 +715,7 @@ function approveMoneyRequest(params: ApproveMoneyRequestFunctionParams) { chatReport, iouReport: expenseReport, recipient: {accountID: expenseReport.ownerAccountID}, - policy, + policy: workflowPolicy, createdTimestamp: originalCreated, isApprovalFlow: true, betas, @@ -712,7 +739,7 @@ function approveMoneyRequest(params: ApproveMoneyRequestFunctionParams) { currentUserEmailParam, currentUserAccountIDParam, expenseReport, - policy, + workflowPolicy, // TODO: https://github.com/Expensify/App/issues/66512 // eslint-disable-next-line @typescript-eslint/no-deprecated getAllTransactionViolations()?.[ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS + transaction.transactionID], diff --git a/tests/actions/IOUTest/ReportWorkflowTest.ts b/tests/actions/IOUTest/ReportWorkflowTest.ts index b343b622ead6..0373145552fb 100644 --- a/tests/actions/IOUTest/ReportWorkflowTest.ts +++ b/tests/actions/IOUTest/ReportWorkflowTest.ts @@ -23,6 +23,7 @@ import initOnyxDerivedValues from '@libs/actions/OnyxDerived'; import {createWorkspace, deleteWorkspace, generatePolicyID, setWorkspaceApprovalMode} from '@libs/actions/Policy/Policy'; import {submitMoneyRequestOnSearch} from '@libs/actions/Search'; import Navigation from '@libs/Navigation/Navigation'; +import getReportPreviewAction from '@libs/ReportPreviewActionUtils'; import CONST from '@src/CONST'; import IntlStore from '@src/languages/IntlStore'; import OnyxUpdateManager from '@src/libs/actions/OnyxUpdateManager'; @@ -3021,6 +3022,91 @@ describe('actions/IOU/ReportWorkflow', () => { expect(updatedReport?.stateNum).toBe(CONST.REPORT.STATE_NUM.APPROVED); expect(updatedReport?.statusNum).toBe(CONST.REPORT.STATUS_NUM.APPROVED); }); + + it('uses the expense report policy for approval optimism when active policy is DEW', () => { + const activeDEWPolicy: Policy = { + ...policy, + id: '2', + approvalMode: CONST.POLICY.APPROVAL_MODE.DYNAMICEXTERNAL, + }; + const reportPreviewActionID = 'preview-action-1'; + const parentReportID = 'parent-report-1'; + const normalReport: Report = { + ...expenseReport, + reportID: '789', + parentReportID, + parentReportActionID: reportPreviewActionID, + managerID: managerAccountID, + }; + const transaction = { + ...createRandomTransaction(1), + reportID: normalReport.reportID, + }; + + return Onyx.multiSet({ + [ONYXKEYS.SESSION]: { + email: managerEmail, + accountID: managerAccountID, + }, + [ONYXKEYS.NVP_ACTIVE_POLICY_ID]: activeDEWPolicy.id, + [`${ONYXKEYS.COLLECTION.POLICY}${activeDEWPolicy.id}`]: activeDEWPolicy, + [`${ONYXKEYS.COLLECTION.REPORT}${normalReport.reportID}`]: normalReport, + [`${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`]: transaction, + [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`]: { + [reportPreviewActionID]: { + reportActionID: reportPreviewActionID, + actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW, + childReportID: normalReport.reportID, + childStateNum: normalReport.stateNum, + childStatusNum: normalReport.statusNum, + childManagerAccountID: normalReport.managerID, + }, + }, + }) + .then(() => { + approveMoneyRequest({ + expenseReport: normalReport, + expenseReportPolicy: policy, + policy: activeDEWPolicy, + currentUserAccountIDParam: managerAccountID, + currentUserEmailParam: managerEmail, + hasViolations: false, + isASAPSubmitBetaEnabled: false, + expenseReportCurrentNextStepDeprecated: undefined, + betas: [CONST.BETAS.ALL], + userBillingGracePeriodEnds: undefined, + amountOwed: 0, + ownerBillingGracePeriodEnd: undefined, + delegateEmail: undefined, + }); + return waitForBatchedUpdates(); + }) + .then(() => getOnyxValue(`${ONYXKEYS.COLLECTION.REPORT}${normalReport.reportID}`)) + .then((updatedReport) => { + expect(updatedReport?.stateNum).toBe(CONST.REPORT.STATE_NUM.SUBMITTED); + expect(updatedReport?.statusNum).toBe(CONST.REPORT.STATUS_NUM.SUBMITTED); + expect(updatedReport?.managerID).toBe(adminAccountID); + + const previewAction = getReportPreviewAction({ + isReportArchived: false, + currentUserAccountID: managerAccountID, + currentUserLogin: managerEmail, + report: updatedReport, + policy, + transactions: [transaction], + bankAccountList: {}, + reportMetadata: undefined, + }); + expect(previewAction).not.toBe(CONST.REPORT.REPORT_PREVIEW_ACTIONS.APPROVE); + + return getOnyxValue(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`); + }) + .then((parentReportActions) => { + expect(parentReportActions?.[reportPreviewActionID]?.childStateNum).toBe(CONST.REPORT.STATE_NUM.SUBMITTED); + expect(parentReportActions?.[reportPreviewActionID]?.childStatusNum).toBe(CONST.REPORT.STATUS_NUM.SUBMITTED); + expect(parentReportActions?.[reportPreviewActionID]?.childManagerAccountID).toBe(adminAccountID); + }); + }); }); describe('approveMoneyRequest partially', () => { From 2254baf3c5560db9221a315fa3d6b707495a2171 Mon Sep 17 00:00:00 2001 From: KJ21-ENG Date: Tue, 23 Jun 2026 19:15:59 +0530 Subject: [PATCH 2/8] Remove stale approval policy fallback --- .../useConfirmApproval.ts | 1 - .../ApproveActionButton.tsx | 1 - .../MoneyRequestReportPreview/PayActionButton.tsx | 1 - src/components/SettlementButton/index.tsx | 1 - src/hooks/useHoldMenuSubmit.ts | 1 - src/hooks/useLifecycleActions.tsx | 1 - src/hooks/useSelectionModeReportActions.ts | 1 - src/libs/PaymentUtils.ts | 1 - src/libs/actions/IOU/ReportWorkflow.ts | 15 ++++++--------- tests/actions/IOUTest/ReportWorkflowTest.ts | 13 +------------ 10 files changed, 7 insertions(+), 29 deletions(-) diff --git a/src/components/MoneyReportHeaderPrimaryAction/useConfirmApproval.ts b/src/components/MoneyReportHeaderPrimaryAction/useConfirmApproval.ts index 5e2129a52dd9..ef6f76eb858d 100644 --- a/src/components/MoneyReportHeaderPrimaryAction/useConfirmApproval.ts +++ b/src/components/MoneyReportHeaderPrimaryAction/useConfirmApproval.ts @@ -46,7 +46,6 @@ function useConfirmApproval(reportID: string | undefined, startApprovedAnimation approveMoneyRequest({ expenseReport: moneyRequestReport, expenseReportPolicy: policy, - policy, currentUserAccountIDParam: accountID, currentUserEmailParam: email ?? '', hasViolations, diff --git a/src/components/ReportActionItem/MoneyRequestReportPreview/ApproveActionButton.tsx b/src/components/ReportActionItem/MoneyRequestReportPreview/ApproveActionButton.tsx index 10ae0c6a4c26..06429974112a 100644 --- a/src/components/ReportActionItem/MoneyRequestReportPreview/ApproveActionButton.tsx +++ b/src/components/ReportActionItem/MoneyRequestReportPreview/ApproveActionButton.tsx @@ -56,7 +56,6 @@ function ApproveActionButton({iouReportID, startApprovedAnimation, onHoldMenuOpe approveMoneyRequest({ expenseReport: iouReport, expenseReportPolicy, - policy: expenseReportPolicy, currentUserAccountIDParam: currentUserAccountID, currentUserEmailParam: currentUserEmail, hasViolations, diff --git a/src/components/ReportActionItem/MoneyRequestReportPreview/PayActionButton.tsx b/src/components/ReportActionItem/MoneyRequestReportPreview/PayActionButton.tsx index c3559c906f5e..6e6c446ab91f 100644 --- a/src/components/ReportActionItem/MoneyRequestReportPreview/PayActionButton.tsx +++ b/src/components/ReportActionItem/MoneyRequestReportPreview/PayActionButton.tsx @@ -143,7 +143,6 @@ function PayActionButton({ approveMoneyRequest({ expenseReport: iouReport, expenseReportPolicy: policy, - policy, currentUserAccountIDParam: currentUserAccountID, currentUserEmailParam: currentUserEmail, hasViolations, diff --git a/src/components/SettlementButton/index.tsx b/src/components/SettlementButton/index.tsx index d14530dc800e..6b818b8bfba6 100644 --- a/src/components/SettlementButton/index.tsx +++ b/src/components/SettlementButton/index.tsx @@ -508,7 +508,6 @@ function SettlementButton({ approveMoneyRequest({ expenseReport: iouReport, expenseReportPolicy, - policy, currentUserAccountIDParam: accountID, currentUserEmailParam: email ?? '', hasViolations, diff --git a/src/hooks/useHoldMenuSubmit.ts b/src/hooks/useHoldMenuSubmit.ts index 94e89d2244e2..934b1addff11 100644 --- a/src/hooks/useHoldMenuSubmit.ts +++ b/src/hooks/useHoldMenuSubmit.ts @@ -62,7 +62,6 @@ function useHoldMenuSubmit({moneyRequestReport, chatReport, requestType, payment if (isApprove) { approveMoneyRequest({ expenseReport: moneyRequestReport, - policy, currentUserAccountIDParam: currentUserDetails.accountID, currentUserEmailParam: currentUserDetails.email ?? '', hasViolations, diff --git a/src/hooks/useLifecycleActions.tsx b/src/hooks/useLifecycleActions.tsx index af868c5c5ff9..847cf658cb59 100644 --- a/src/hooks/useLifecycleActions.tsx +++ b/src/hooks/useLifecycleActions.tsx @@ -156,7 +156,6 @@ function useLifecycleActions({reportID, startApprovedAnimation, startAnimation, approveMoneyRequest({ expenseReport: moneyRequestReport, expenseReportPolicy: policy, - policy, currentUserAccountIDParam: accountID, currentUserEmailParam: email ?? '', hasViolations, diff --git a/src/hooks/useSelectionModeReportActions.ts b/src/hooks/useSelectionModeReportActions.ts index 2f0a90af1d63..97f18fef2646 100644 --- a/src/hooks/useSelectionModeReportActions.ts +++ b/src/hooks/useSelectionModeReportActions.ts @@ -337,7 +337,6 @@ function useSelectionModeReportActions({ } else { approveMoneyRequest({ expenseReport: report, - policy, currentUserAccountIDParam: currentUserAccountID, currentUserEmailParam: currentUserEmail ?? '', hasViolations, diff --git a/src/libs/PaymentUtils.ts b/src/libs/PaymentUtils.ts index e4f90c33fda9..ebe3b7c5a6f4 100644 --- a/src/libs/PaymentUtils.ts +++ b/src/libs/PaymentUtils.ts @@ -270,7 +270,6 @@ const selectPaymentType = (params: SelectPaymentTypeParams) => { approveMoneyRequest({ expenseReport: iouReport, expenseReportPolicy, - policy, currentUserAccountIDParam: currentAccountID, currentUserEmailParam: currentEmail, hasViolations, diff --git a/src/libs/actions/IOU/ReportWorkflow.ts b/src/libs/actions/IOU/ReportWorkflow.ts index 87ef6aa31353..b44823c72f92 100644 --- a/src/libs/actions/IOU/ReportWorkflow.ts +++ b/src/libs/actions/IOU/ReportWorkflow.ts @@ -77,7 +77,6 @@ import {getReportFromHoldRequestsOnyxData} from './Hold'; type ApproveMoneyRequestFunctionParams = { expenseReport: OnyxEntry; expenseReportPolicy: OnyxEntry; - policy: OnyxEntry; currentUserAccountIDParam: number; currentUserEmailParam: string; hasViolations: boolean; @@ -385,7 +384,6 @@ function getReportOriginalCreationTimestamp(expenseReport?: OnyxEntry { approveMoneyRequest({ expenseReport, expenseReportPolicy: createRandomPolicy(Number(expenseReport.policyID)), - policy: {} as Policy, currentUserAccountIDParam: CARLOS_ACCOUNT_ID, currentUserEmailParam: CARLOS_EMAIL, hasViolations: false, @@ -2061,7 +2060,6 @@ describe('actions/IOU/ReportWorkflow', () => { approveMoneyRequest({ expenseReport, expenseReportPolicy: createRandomPolicy(Number(expenseReport.policyID)), - policy: {} as Policy, currentUserAccountIDParam: CARLOS_ACCOUNT_ID, currentUserEmailParam: CARLOS_EMAIL, hasViolations: false, @@ -2660,7 +2658,6 @@ describe('actions/IOU/ReportWorkflow', () => { approveMoneyRequest({ expenseReport, expenseReportPolicy: policy, - policy, currentUserAccountIDParam: adminAccountID, currentUserEmailParam: adminEmail, hasViolations: false, @@ -2712,7 +2709,6 @@ describe('actions/IOU/ReportWorkflow', () => { approveMoneyRequest({ expenseReport, expenseReportPolicy: policy, - policy, currentUserAccountIDParam: managerAccountID, currentUserEmailParam: managerEmail, hasViolations: false, @@ -2760,7 +2756,6 @@ describe('actions/IOU/ReportWorkflow', () => { approveMoneyRequest({ expenseReport, expenseReportPolicy: policy, - policy, currentUserAccountIDParam: adminAccountID, currentUserEmailParam: adminEmail, hasViolations: false, @@ -2884,7 +2879,6 @@ describe('actions/IOU/ReportWorkflow', () => { approveMoneyRequest({ expenseReport, expenseReportPolicy: policy, - policy, currentUserAccountIDParam: managerAccountID, currentUserEmailParam: managerEmail, hasViolations: false, @@ -2915,7 +2909,6 @@ describe('actions/IOU/ReportWorkflow', () => { approveMoneyRequest({ expenseReport, expenseReportPolicy: policy, - policy, currentUserAccountIDParam: managerAccountID, currentUserEmailParam: managerEmail, hasViolations: false, @@ -2944,7 +2937,6 @@ describe('actions/IOU/ReportWorkflow', () => { approveMoneyRequest({ expenseReport: updatedReport, expenseReportPolicy: policy, - policy, currentUserAccountIDParam: adminAccountID, currentUserEmailParam: adminEmail, hasViolations: false, @@ -3003,7 +2995,6 @@ describe('actions/IOU/ReportWorkflow', () => { approveMoneyRequest({ expenseReport: singleApproverReport, expenseReportPolicy: singleApproverPolicy, - policy: singleApproverPolicy, currentUserAccountIDParam: managerAccountID, currentUserEmailParam: managerEmail, hasViolations: false, @@ -3062,12 +3053,11 @@ describe('actions/IOU/ReportWorkflow', () => { childManagerAccountID: normalReport.managerID, }, }, - }) + } as unknown as OnyxMultiSetInput) .then(() => { approveMoneyRequest({ expenseReport: normalReport, expenseReportPolicy: policy, - policy: activeDEWPolicy, currentUserAccountIDParam: managerAccountID, currentUserEmailParam: managerEmail, hasViolations: false, @@ -3203,7 +3193,6 @@ describe('actions/IOU/ReportWorkflow', () => { const newExpenseReportID = approveMoneyRequest({ expenseReport, expenseReportPolicy: policy, - policy, currentUserAccountIDParam: adminAccountID, currentUserEmailParam: adminEmail, hasViolations: false, From 71d081ee7ce431e5e97bbe4799f05508ff2620f9 Mon Sep 17 00:00:00 2001 From: KJ21-ENG Date: Tue, 23 Jun 2026 20:54:13 +0530 Subject: [PATCH 3/8] Align approval upgrade policy after merge --- src/libs/actions/IOU/ReportWorkflow.ts | 5 ++--- tests/actions/IOUTest/ReportWorkflowTest.ts | 25 +++++++-------------- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/src/libs/actions/IOU/ReportWorkflow.ts b/src/libs/actions/IOU/ReportWorkflow.ts index fba1d54d1307..c2d7dbb0ccf4 100644 --- a/src/libs/actions/IOU/ReportWorkflow.ts +++ b/src/libs/actions/IOU/ReportWorkflow.ts @@ -417,9 +417,8 @@ function approveMoneyRequest(params: ApproveMoneyRequestFunctionParams) { } // If this is a Submit workspace, approving requires upgrading first. - // IMPORTANT: gate by the workspace that owns the expense report (`expenseReportPolicy`) instead of `policy`, - // since some call sites pass `policy` as the active/personal policy rather than the report's workspace policy. - const policyToUpgrade = expenseReportPolicy ?? policy; + // IMPORTANT: gate by the workspace that owns the expense report. + const policyToUpgrade = expenseReportPolicy; if (isSubmitPolicy(policyToUpgrade) && policyToUpgrade?.id) { const upgradeFeatureAlias = CONST.UPGRADE_FEATURE_INTRO_MAPPING.approvalSubmitReport.alias; const backTo = Navigation.getActiveRoute() || ROUTES.REPORT_WITH_ID.getRoute(expenseReport.reportID); diff --git a/tests/actions/IOUTest/ReportWorkflowTest.ts b/tests/actions/IOUTest/ReportWorkflowTest.ts index 0fcfdbfa0d85..f3a1212ab7b0 100644 --- a/tests/actions/IOUTest/ReportWorkflowTest.ts +++ b/tests/actions/IOUTest/ReportWorkflowTest.ts @@ -2691,10 +2691,9 @@ describe('actions/IOU/ReportWorkflow', () => { policyID, }); - const createApproveMoneyRequestParams = (expenseReport: Report, expenseReportPolicy: Policy, policy: Policy = teamPolicy) => ({ + const createApproveMoneyRequestParams = (expenseReport: Report, expenseReportPolicy: OnyxEntry) => ({ expenseReport, expenseReportPolicy, - policy, currentUserAccountIDParam: CARLOS_ACCOUNT_ID, currentUserEmailParam: CARLOS_EMAIL, hasViolations: false, @@ -2722,28 +2721,20 @@ describe('actions/IOU/ReportWorkflow', () => { expect(Navigation.navigate).toHaveBeenCalledWith(expectedRoute); }); - it('gates upgrade by expenseReportPolicy instead of the policy param', () => { - const expenseReport = createSubmittedExpenseReport(); - const expectedRoute = ROUTES.WORKSPACE_UPGRADE.getRoute(submitPolicyID, upgradeFeatureAlias, ROUTES.REPORT_WITH_ID.getRoute(expenseReport.reportID), expenseReport.reportID); + it('gates upgrade by expenseReportPolicy even when the report policyID is Submit', () => { + const expenseReport = createSubmittedExpenseReport(submitPolicyID); - approveMoneyRequest(createApproveMoneyRequestParams(expenseReport, submitPolicy, teamPolicy)); + approveMoneyRequest(createApproveMoneyRequestParams(expenseReport, teamPolicy)); - expect(Navigation.navigate).toHaveBeenCalledTimes(1); - expect(Navigation.navigate).toHaveBeenCalledWith(expectedRoute); + expect(Navigation.navigate).not.toHaveBeenCalled(); }); - it('falls back to policy when expenseReportPolicy is undefined', () => { + it('does not fall back to another policy when expenseReportPolicy is undefined', () => { const expenseReport = createSubmittedExpenseReport(submitPolicyID); - const expectedRoute = ROUTES.WORKSPACE_UPGRADE.getRoute(submitPolicyID, upgradeFeatureAlias, ROUTES.REPORT_WITH_ID.getRoute(expenseReport.reportID), expenseReport.reportID); - approveMoneyRequest({ - ...createApproveMoneyRequestParams(expenseReport, submitPolicy), - expenseReportPolicy: undefined, - policy: submitPolicy, - }); + approveMoneyRequest(createApproveMoneyRequestParams(expenseReport, undefined)); - expect(Navigation.navigate).toHaveBeenCalledTimes(1); - expect(Navigation.navigate).toHaveBeenCalledWith(expectedRoute); + expect(Navigation.navigate).not.toHaveBeenCalled(); }); it('uses Navigation.getActiveRoute as backTo when available', () => { From 9ee78d44991432cee96c33cb6360ee42d84aa7b0 Mon Sep 17 00:00:00 2001 From: KJ21-ENG Date: Tue, 23 Jun 2026 22:49:27 +0530 Subject: [PATCH 4/8] Fix approval policy test expectations --- tests/actions/IOUTest/ReportWorkflowTest.ts | 80 ++++++--------------- tests/unit/PaymentUtilsTest.ts | 2 - 2 files changed, 20 insertions(+), 62 deletions(-) diff --git a/tests/actions/IOUTest/ReportWorkflowTest.ts b/tests/actions/IOUTest/ReportWorkflowTest.ts index f3a1212ab7b0..27123df2fc86 100644 --- a/tests/actions/IOUTest/ReportWorkflowTest.ts +++ b/tests/actions/IOUTest/ReportWorkflowTest.ts @@ -2021,6 +2021,20 @@ describe('actions/IOU/ReportWorkflow', () => { await waitForBatchedUpdates(); }); + const getOptimisticReportAction = (reportID: string) => { + // eslint-disable-next-line rulesdir/no-multiple-api-calls -- Inspecting mock call args to verify optimistic data structure + const calls = (API.write as jest.Mock).mock.calls; + const optimisticData = calls.flatMap((call) => { + const [, , onyxData] = call as [unknown, unknown, OnyxData | undefined]; + return onyxData?.optimisticData ?? []; + }); + + const reportActionsUpdate = optimisticData.find((update: {key: string}) => update.key === `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`); + expect(reportActionsUpdate).toBeDefined(); + + return Object.values(reportActionsUpdate?.value as Record).at(0); + }; + it('submitReport includes delegateAccountID when delegateEmail is provided', () => { const expenseReport: Report = { ...createRandomReport(1, undefined), @@ -2044,16 +2058,7 @@ describe('actions/IOU/ReportWorkflow', () => { delegateEmail: DELEGATE_EMAIL, }); - // eslint-disable-next-line rulesdir/no-multiple-api-calls -- Inspecting mock call args to verify optimistic data structure - const calls = (API.write as jest.Mock).mock.calls; - const [, , onyxData] = calls.at(0) as [unknown, unknown, OnyxData]; - const optimisticData = onyxData.optimisticData ?? []; - - const reportActionsUpdate = optimisticData.find((update: {key: string}) => update.key === `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.reportID}`); - expect(reportActionsUpdate).toBeDefined(); - - const reportAction = Object.values(reportActionsUpdate?.value as Record).at(0); - expect(reportAction?.delegateAccountID).toBe(DELEGATE_ACCOUNT_ID); + expect(getOptimisticReportAction(expenseReport.reportID)?.delegateAccountID).toBe(DELEGATE_ACCOUNT_ID); }); it('submitReport sets delegateAccountID to undefined when delegateEmail is undefined', () => { @@ -2079,16 +2084,7 @@ describe('actions/IOU/ReportWorkflow', () => { delegateEmail: undefined, }); - // eslint-disable-next-line rulesdir/no-multiple-api-calls -- Inspecting mock call args to verify optimistic data structure - const calls = (API.write as jest.Mock).mock.calls; - const [, , onyxData] = calls.at(0) as [unknown, unknown, OnyxData]; - const optimisticData = onyxData.optimisticData ?? []; - - const reportActionsUpdate = optimisticData.find((update: {key: string}) => update.key === `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.reportID}`); - expect(reportActionsUpdate).toBeDefined(); - - const reportAction = Object.values(reportActionsUpdate?.value as Record).at(0); - expect(reportAction?.delegateAccountID).toBeUndefined(); + expect(getOptimisticReportAction(expenseReport.reportID)?.delegateAccountID).toBeUndefined(); }); it('unapproveExpenseReport includes delegateAccountID when delegateEmail is provided', () => { @@ -2102,16 +2098,7 @@ describe('actions/IOU/ReportWorkflow', () => { unapproveExpenseReport(expenseReport, {} as Policy, CARLOS_ACCOUNT_ID, CARLOS_EMAIL, false, false, undefined, DELEGATE_EMAIL); - // eslint-disable-next-line rulesdir/no-multiple-api-calls -- Inspecting mock call args to verify optimistic data structure - const calls = (API.write as jest.Mock).mock.calls; - const [, , onyxData] = calls.at(0) as [unknown, unknown, OnyxData]; - const optimisticData = onyxData.optimisticData ?? []; - - const reportActionsUpdate = optimisticData.find((update: {key: string}) => update.key === `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.reportID}`); - expect(reportActionsUpdate).toBeDefined(); - - const reportAction = Object.values(reportActionsUpdate?.value as Record).at(0); - expect(reportAction?.delegateAccountID).toBe(DELEGATE_ACCOUNT_ID); + expect(getOptimisticReportAction(expenseReport.reportID)?.delegateAccountID).toBe(DELEGATE_ACCOUNT_ID); }); it('retractReport includes delegateAccountID when delegateEmail is provided', () => { @@ -2128,16 +2115,7 @@ describe('actions/IOU/ReportWorkflow', () => { retractReport(expenseReport, chatReport, {} as Policy, CARLOS_ACCOUNT_ID, CARLOS_EMAIL, false, false, undefined, DELEGATE_EMAIL); - // eslint-disable-next-line rulesdir/no-multiple-api-calls -- Inspecting mock call args to verify optimistic data structure - const calls = (API.write as jest.Mock).mock.calls; - const [, , onyxData] = calls.at(0) as [unknown, unknown, OnyxData]; - const optimisticData = onyxData.optimisticData ?? []; - - const reportActionsUpdate = optimisticData.find((update: {key: string}) => update.key === `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.reportID}`); - expect(reportActionsUpdate).toBeDefined(); - - const reportAction = Object.values(reportActionsUpdate?.value as Record).at(0); - expect(reportAction?.delegateAccountID).toBe(DELEGATE_ACCOUNT_ID); + expect(getOptimisticReportAction(expenseReport.reportID)?.delegateAccountID).toBe(DELEGATE_ACCOUNT_ID); }); it('approveMoneyRequest includes delegateAccountID when delegateEmail is provided', () => { @@ -2164,16 +2142,7 @@ describe('actions/IOU/ReportWorkflow', () => { delegateEmail: DELEGATE_EMAIL, }); - // eslint-disable-next-line rulesdir/no-multiple-api-calls -- Inspecting mock call args to verify optimistic data structure - const calls = (API.write as jest.Mock).mock.calls; - const [, , onyxData] = calls.at(0) as [unknown, unknown, OnyxData]; - const optimisticData = onyxData.optimisticData ?? []; - - const reportActionsUpdate = optimisticData.find((update: {key: string}) => update.key === `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.reportID}`); - expect(reportActionsUpdate).toBeDefined(); - - const reportAction = Object.values(reportActionsUpdate?.value as Record).at(0); - expect(reportAction?.delegateAccountID).toBe(DELEGATE_ACCOUNT_ID); + expect(getOptimisticReportAction(expenseReport.reportID)?.delegateAccountID).toBe(DELEGATE_ACCOUNT_ID); }); it('approveMoneyRequest sets delegateAccountID to undefined when delegateEmail is undefined', () => { @@ -2200,16 +2169,7 @@ describe('actions/IOU/ReportWorkflow', () => { delegateEmail: undefined, }); - // eslint-disable-next-line rulesdir/no-multiple-api-calls -- Inspecting mock call args to verify optimistic data structure - const calls = (API.write as jest.Mock).mock.calls; - const [, , onyxData] = calls.at(0) as [unknown, unknown, OnyxData]; - const optimisticData = onyxData.optimisticData ?? []; - - const reportActionsUpdate = optimisticData.find((update: {key: string}) => update.key === `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.reportID}`); - expect(reportActionsUpdate).toBeDefined(); - - const reportAction = Object.values(reportActionsUpdate?.value as Record).at(0); - expect(reportAction?.delegateAccountID).toBeUndefined(); + expect(getOptimisticReportAction(expenseReport.reportID)?.delegateAccountID).toBeUndefined(); }); }); diff --git a/tests/unit/PaymentUtilsTest.ts b/tests/unit/PaymentUtilsTest.ts index 2903ed53503a..2da8e89e59df 100644 --- a/tests/unit/PaymentUtilsTest.ts +++ b/tests/unit/PaymentUtilsTest.ts @@ -271,7 +271,6 @@ describe('PaymentUtils', () => { expect(approveMoneyRequest).toHaveBeenCalledWith({ expenseReport: params.iouReport, expenseReportPolicy: params.expenseReportPolicy, - policy: params.policy, currentUserAccountIDParam: params.currentAccountID, currentUserEmailParam: params.currentEmail, hasViolations: params.hasViolations, @@ -294,7 +293,6 @@ describe('PaymentUtils', () => { expect(approveMoneyRequest).toHaveBeenCalledWith({ expenseReport: params.iouReport, expenseReportPolicy: params.expenseReportPolicy, - policy: params.policy, currentUserAccountIDParam: params.currentAccountID, currentUserEmailParam: params.currentEmail, hasViolations: params.hasViolations, From 7ad21f7b74ab7af86086858fcaba0f7f37fd5b56 Mon Sep 17 00:00:00 2001 From: KJ21-ENG Date: Tue, 23 Jun 2026 23:51:07 +0530 Subject: [PATCH 5/8] Stabilize approval delegate policy test --- tests/actions/IOUTest/ReportWorkflowTest.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/actions/IOUTest/ReportWorkflowTest.ts b/tests/actions/IOUTest/ReportWorkflowTest.ts index 27123df2fc86..f6ac7d44b1f7 100644 --- a/tests/actions/IOUTest/ReportWorkflowTest.ts +++ b/tests/actions/IOUTest/ReportWorkflowTest.ts @@ -2126,10 +2126,14 @@ describe('actions/IOU/ReportWorkflow', () => { currency: CONST.CURRENCY.USD, statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, }; + const expenseReportPolicy = { + ...createRandomPolicy(Number(expenseReport.policyID), CONST.POLICY.TYPE.TEAM), + approvalMode: CONST.POLICY.APPROVAL_MODE.BASIC, + }; approveMoneyRequest({ expenseReport, - expenseReportPolicy: createRandomPolicy(Number(expenseReport.policyID), CONST.POLICY.TYPE.TEAM), + expenseReportPolicy, currentUserAccountIDParam: CARLOS_ACCOUNT_ID, currentUserEmailParam: CARLOS_EMAIL, hasViolations: false, @@ -2153,10 +2157,14 @@ describe('actions/IOU/ReportWorkflow', () => { currency: CONST.CURRENCY.USD, statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, }; + const expenseReportPolicy = { + ...createRandomPolicy(Number(expenseReport.policyID), CONST.POLICY.TYPE.TEAM), + approvalMode: CONST.POLICY.APPROVAL_MODE.BASIC, + }; approveMoneyRequest({ expenseReport, - expenseReportPolicy: createRandomPolicy(Number(expenseReport.policyID), CONST.POLICY.TYPE.TEAM), + expenseReportPolicy, currentUserAccountIDParam: CARLOS_ACCOUNT_ID, currentUserEmailParam: CARLOS_EMAIL, hasViolations: false, From b82a2717ff8634226b906ca5845d1116c9397670 Mon Sep 17 00:00:00 2001 From: KJ21-ENG Date: Wed, 24 Jun 2026 22:24:54 +0530 Subject: [PATCH 6/8] Address approval workflow review comments --- src/libs/actions/IOU/ReportWorkflow.ts | 6 +- tests/actions/IOUTest/ReportWorkflowTest.ts | 82 +++++++++++++++------ 2 files changed, 63 insertions(+), 25 deletions(-) diff --git a/src/libs/actions/IOU/ReportWorkflow.ts b/src/libs/actions/IOU/ReportWorkflow.ts index c2d7dbb0ccf4..a4c3389e5b08 100644 --- a/src/libs/actions/IOU/ReportWorkflow.ts +++ b/src/libs/actions/IOU/ReportWorkflow.ts @@ -417,13 +417,11 @@ function approveMoneyRequest(params: ApproveMoneyRequestFunctionParams) { } // If this is a Submit workspace, approving requires upgrading first. - // IMPORTANT: gate by the workspace that owns the expense report. - const policyToUpgrade = expenseReportPolicy; - if (isSubmitPolicy(policyToUpgrade) && policyToUpgrade?.id) { + if (isSubmitPolicy(expenseReportPolicy) && expenseReportPolicy?.id) { const upgradeFeatureAlias = CONST.UPGRADE_FEATURE_INTRO_MAPPING.approvalSubmitReport.alias; const backTo = Navigation.getActiveRoute() || ROUTES.REPORT_WITH_ID.getRoute(expenseReport.reportID); - Navigation.navigate(ROUTES.WORKSPACE_UPGRADE.getRoute(policyToUpgrade.id, upgradeFeatureAlias, backTo, expenseReport.reportID)); + Navigation.navigate(ROUTES.WORKSPACE_UPGRADE.getRoute(expenseReportPolicy.id, upgradeFeatureAlias, backTo, expenseReport.reportID)); return; } diff --git a/tests/actions/IOUTest/ReportWorkflowTest.ts b/tests/actions/IOUTest/ReportWorkflowTest.ts index f6ac7d44b1f7..bf8ea5978ca4 100644 --- a/tests/actions/IOUTest/ReportWorkflowTest.ts +++ b/tests/actions/IOUTest/ReportWorkflowTest.ts @@ -2021,20 +2021,6 @@ describe('actions/IOU/ReportWorkflow', () => { await waitForBatchedUpdates(); }); - const getOptimisticReportAction = (reportID: string) => { - // eslint-disable-next-line rulesdir/no-multiple-api-calls -- Inspecting mock call args to verify optimistic data structure - const calls = (API.write as jest.Mock).mock.calls; - const optimisticData = calls.flatMap((call) => { - const [, , onyxData] = call as [unknown, unknown, OnyxData | undefined]; - return onyxData?.optimisticData ?? []; - }); - - const reportActionsUpdate = optimisticData.find((update: {key: string}) => update.key === `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`); - expect(reportActionsUpdate).toBeDefined(); - - return Object.values(reportActionsUpdate?.value as Record).at(0); - }; - it('submitReport includes delegateAccountID when delegateEmail is provided', () => { const expenseReport: Report = { ...createRandomReport(1, undefined), @@ -2058,7 +2044,16 @@ describe('actions/IOU/ReportWorkflow', () => { delegateEmail: DELEGATE_EMAIL, }); - expect(getOptimisticReportAction(expenseReport.reportID)?.delegateAccountID).toBe(DELEGATE_ACCOUNT_ID); + // eslint-disable-next-line rulesdir/no-multiple-api-calls -- Inspecting mock call args to verify optimistic data structure + const calls = (API.write as jest.Mock).mock.calls; + const [, , onyxData] = calls.at(0) as [unknown, unknown, OnyxData]; + const optimisticData = onyxData.optimisticData ?? []; + + const reportActionsUpdate = optimisticData.find((update: {key: string}) => update.key === `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.reportID}`); + expect(reportActionsUpdate).toBeDefined(); + + const reportAction = Object.values(reportActionsUpdate?.value as Record).at(0); + expect(reportAction?.delegateAccountID).toBe(DELEGATE_ACCOUNT_ID); }); it('submitReport sets delegateAccountID to undefined when delegateEmail is undefined', () => { @@ -2084,7 +2079,16 @@ describe('actions/IOU/ReportWorkflow', () => { delegateEmail: undefined, }); - expect(getOptimisticReportAction(expenseReport.reportID)?.delegateAccountID).toBeUndefined(); + // eslint-disable-next-line rulesdir/no-multiple-api-calls -- Inspecting mock call args to verify optimistic data structure + const calls = (API.write as jest.Mock).mock.calls; + const [, , onyxData] = calls.at(0) as [unknown, unknown, OnyxData]; + const optimisticData = onyxData.optimisticData ?? []; + + const reportActionsUpdate = optimisticData.find((update: {key: string}) => update.key === `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.reportID}`); + expect(reportActionsUpdate).toBeDefined(); + + const reportAction = Object.values(reportActionsUpdate?.value as Record).at(0); + expect(reportAction?.delegateAccountID).toBeUndefined(); }); it('unapproveExpenseReport includes delegateAccountID when delegateEmail is provided', () => { @@ -2098,7 +2102,16 @@ describe('actions/IOU/ReportWorkflow', () => { unapproveExpenseReport(expenseReport, {} as Policy, CARLOS_ACCOUNT_ID, CARLOS_EMAIL, false, false, undefined, DELEGATE_EMAIL); - expect(getOptimisticReportAction(expenseReport.reportID)?.delegateAccountID).toBe(DELEGATE_ACCOUNT_ID); + // eslint-disable-next-line rulesdir/no-multiple-api-calls -- Inspecting mock call args to verify optimistic data structure + const calls = (API.write as jest.Mock).mock.calls; + const [, , onyxData] = calls.at(0) as [unknown, unknown, OnyxData]; + const optimisticData = onyxData.optimisticData ?? []; + + const reportActionsUpdate = optimisticData.find((update: {key: string}) => update.key === `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.reportID}`); + expect(reportActionsUpdate).toBeDefined(); + + const reportAction = Object.values(reportActionsUpdate?.value as Record).at(0); + expect(reportAction?.delegateAccountID).toBe(DELEGATE_ACCOUNT_ID); }); it('retractReport includes delegateAccountID when delegateEmail is provided', () => { @@ -2115,7 +2128,16 @@ describe('actions/IOU/ReportWorkflow', () => { retractReport(expenseReport, chatReport, {} as Policy, CARLOS_ACCOUNT_ID, CARLOS_EMAIL, false, false, undefined, DELEGATE_EMAIL); - expect(getOptimisticReportAction(expenseReport.reportID)?.delegateAccountID).toBe(DELEGATE_ACCOUNT_ID); + // eslint-disable-next-line rulesdir/no-multiple-api-calls -- Inspecting mock call args to verify optimistic data structure + const calls = (API.write as jest.Mock).mock.calls; + const [, , onyxData] = calls.at(0) as [unknown, unknown, OnyxData]; + const optimisticData = onyxData.optimisticData ?? []; + + const reportActionsUpdate = optimisticData.find((update: {key: string}) => update.key === `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.reportID}`); + expect(reportActionsUpdate).toBeDefined(); + + const reportAction = Object.values(reportActionsUpdate?.value as Record).at(0); + expect(reportAction?.delegateAccountID).toBe(DELEGATE_ACCOUNT_ID); }); it('approveMoneyRequest includes delegateAccountID when delegateEmail is provided', () => { @@ -2146,7 +2168,16 @@ describe('actions/IOU/ReportWorkflow', () => { delegateEmail: DELEGATE_EMAIL, }); - expect(getOptimisticReportAction(expenseReport.reportID)?.delegateAccountID).toBe(DELEGATE_ACCOUNT_ID); + // eslint-disable-next-line rulesdir/no-multiple-api-calls -- Inspecting mock call args to verify optimistic data structure + const calls = (API.write as jest.Mock).mock.calls; + const [, , onyxData] = calls.at(0) as [unknown, unknown, OnyxData]; + const optimisticData = onyxData.optimisticData ?? []; + + const reportActionsUpdate = optimisticData.find((update: {key: string}) => update.key === `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.reportID}`); + expect(reportActionsUpdate).toBeDefined(); + + const reportAction = Object.values(reportActionsUpdate?.value as Record).at(0); + expect(reportAction?.delegateAccountID).toBe(DELEGATE_ACCOUNT_ID); }); it('approveMoneyRequest sets delegateAccountID to undefined when delegateEmail is undefined', () => { @@ -2177,7 +2208,16 @@ describe('actions/IOU/ReportWorkflow', () => { delegateEmail: undefined, }); - expect(getOptimisticReportAction(expenseReport.reportID)?.delegateAccountID).toBeUndefined(); + // eslint-disable-next-line rulesdir/no-multiple-api-calls -- Inspecting mock call args to verify optimistic data structure + const calls = (API.write as jest.Mock).mock.calls; + const [, , onyxData] = calls.at(0) as [unknown, unknown, OnyxData]; + const optimisticData = onyxData.optimisticData ?? []; + + const reportActionsUpdate = optimisticData.find((update: {key: string}) => update.key === `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.reportID}`); + expect(reportActionsUpdate).toBeDefined(); + + const reportAction = Object.values(reportActionsUpdate?.value as Record).at(0); + expect(reportAction?.delegateAccountID).toBeUndefined(); }); }); @@ -3220,7 +3260,7 @@ describe('actions/IOU/ReportWorkflow', () => { expect(updatedReport?.statusNum).toBe(CONST.REPORT.STATUS_NUM.APPROVED); }); - it('uses the expense report policy for approval optimism when active policy is DEW', () => { + it('uses the expense report policy (not the activePolicy) to determine if it is a DEW approval', () => { const activeDEWPolicy: Policy = { ...policy, id: '2', From c03056bd5f7cadd636bf2fa6a59ebb12fb2f111a Mon Sep 17 00:00:00 2001 From: KJ21-ENG Date: Wed, 24 Jun 2026 23:14:19 +0530 Subject: [PATCH 7/8] Remove parent preview approval mirror --- src/libs/actions/IOU/ReportWorkflow.ts | 26 --------------------- tests/actions/IOUTest/ReportWorkflowTest.ts | 21 ----------------- 2 files changed, 47 deletions(-) diff --git a/src/libs/actions/IOU/ReportWorkflow.ts b/src/libs/actions/IOU/ReportWorkflow.ts index 049addb571b5..d1c18135bdd9 100644 --- a/src/libs/actions/IOU/ReportWorkflow.ts +++ b/src/libs/actions/IOU/ReportWorkflow.ts @@ -626,32 +626,6 @@ function approveMoneyRequest(params: ApproveMoneyRequestFunctionParams) { }); } - if (!isDEWPolicy && expenseReport.parentReportID && expenseReport.parentReportActionID) { - optimisticData.push({ - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.parentReportID}`, - value: { - [expenseReport.parentReportActionID]: { - childStateNum: predictedNextState, - childStatusNum: predictedNextStatus, - ...(nextApproverAccountID ? {childManagerAccountID: managerID} : {}), - }, - }, - }); - - failureData.push({ - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.parentReportID}`, - value: { - [expenseReport.parentReportActionID]: { - childStateNum: expenseReport.stateNum, - childStatusNum: expenseReport.statusNum, - ...(nextApproverAccountID ? {childManagerAccountID: expenseReport.managerID} : {}), - }, - }, - }); - } - if (shouldAddOptimisticApproveAction) { if (isDEWPolicy) { failureData.push({ diff --git a/tests/actions/IOUTest/ReportWorkflowTest.ts b/tests/actions/IOUTest/ReportWorkflowTest.ts index 0bdf8379ee21..41f51ce547f0 100644 --- a/tests/actions/IOUTest/ReportWorkflowTest.ts +++ b/tests/actions/IOUTest/ReportWorkflowTest.ts @@ -3138,13 +3138,9 @@ describe('actions/IOU/ReportWorkflow', () => { id: '2', approvalMode: CONST.POLICY.APPROVAL_MODE.DYNAMICEXTERNAL, }; - const reportPreviewActionID = 'preview-action-1'; - const parentReportID = 'parent-report-1'; const normalReport: Report = { ...expenseReport, reportID: '789', - parentReportID, - parentReportActionID: reportPreviewActionID, managerID: managerAccountID, }; const transaction = { @@ -3161,16 +3157,6 @@ describe('actions/IOU/ReportWorkflow', () => { [`${ONYXKEYS.COLLECTION.POLICY}${activeDEWPolicy.id}`]: activeDEWPolicy, [`${ONYXKEYS.COLLECTION.REPORT}${normalReport.reportID}`]: normalReport, [`${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`]: transaction, - [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`]: { - [reportPreviewActionID]: { - reportActionID: reportPreviewActionID, - actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW, - childReportID: normalReport.reportID, - childStateNum: normalReport.stateNum, - childStatusNum: normalReport.statusNum, - childManagerAccountID: normalReport.managerID, - }, - }, } as unknown as OnyxMultiSetInput) .then(() => { approveMoneyRequest({ @@ -3206,13 +3192,6 @@ describe('actions/IOU/ReportWorkflow', () => { reportMetadata: undefined, }); expect(previewAction).not.toBe(CONST.REPORT.REPORT_PREVIEW_ACTIONS.APPROVE); - - return getOnyxValue(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`); - }) - .then((parentReportActions) => { - expect(parentReportActions?.[reportPreviewActionID]?.childStateNum).toBe(CONST.REPORT.STATE_NUM.SUBMITTED); - expect(parentReportActions?.[reportPreviewActionID]?.childStatusNum).toBe(CONST.REPORT.STATUS_NUM.SUBMITTED); - expect(parentReportActions?.[reportPreviewActionID]?.childManagerAccountID).toBe(adminAccountID); }); }); }); From e00239eb5c81e40270b622e9d9b2da6aaefa5e3e Mon Sep 17 00:00:00 2001 From: KJ21-ENG Date: Thu, 25 Jun 2026 23:04:39 +0530 Subject: [PATCH 8/8] Remove obsolete approval policy fallback tests --- tests/actions/IOUTest/ReportWorkflowTest.ts | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/tests/actions/IOUTest/ReportWorkflowTest.ts b/tests/actions/IOUTest/ReportWorkflowTest.ts index 41f51ce547f0..e1d61ff8ca4b 100644 --- a/tests/actions/IOUTest/ReportWorkflowTest.ts +++ b/tests/actions/IOUTest/ReportWorkflowTest.ts @@ -2601,22 +2601,6 @@ describe('actions/IOU/ReportWorkflow', () => { expect(Navigation.navigate).toHaveBeenCalledWith(expectedRoute); }); - it('gates upgrade by expenseReportPolicy even when the report policyID is Submit', () => { - const expenseReport = createSubmittedExpenseReport(submitPolicyID); - - approveMoneyRequest(createApproveMoneyRequestParams(expenseReport, teamPolicy)); - - expect(Navigation.navigate).not.toHaveBeenCalled(); - }); - - it('does not fall back to another policy when expenseReportPolicy is undefined', () => { - const expenseReport = createSubmittedExpenseReport(submitPolicyID); - - approveMoneyRequest(createApproveMoneyRequestParams(expenseReport, undefined)); - - expect(Navigation.navigate).not.toHaveBeenCalled(); - }); - it('uses Navigation.getActiveRoute as backTo when available', () => { const expenseReport = createSubmittedExpenseReport(); const activeRoute = `search?q=reportID%3A${expenseReport.reportID}`;