From da190cf16880de7b152f7de16849c86fcdaa3a4f Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Mon, 23 Nov 2026 20:23:51 +0530 Subject: [PATCH 1/4] Refactor RNVP pairs for MoneyRequest update functions --- src/libs/actions/IOU/MoneyRequestBuilder.ts | 7 +- src/libs/actions/IOU/UpdateMoneyRequest.ts | 17 ++ .../step/DynamicIOURequestStepDate.tsx | 2 + .../step/DynamicIOURequestStepDescription.tsx | 2 + .../step/DynamicIOURequestStepMerchant.tsx | 4 +- .../GetUpdateMoneyRequestParamsTest.ts | 106 +++++++++++++ .../actions/IOUTest/UpdateMoneyRequestTest.ts | 149 ++++++++++++++++++ 7 files changed, 283 insertions(+), 4 deletions(-) diff --git a/src/libs/actions/IOU/MoneyRequestBuilder.ts b/src/libs/actions/IOU/MoneyRequestBuilder.ts index 2d2593202a7d..0aa70c70c71a 100644 --- a/src/libs/actions/IOU/MoneyRequestBuilder.ts +++ b/src/libs/actions/IOU/MoneyRequestBuilder.ts @@ -1292,9 +1292,9 @@ function maybeUpdateReportNameForFormulaTitle( policy: OnyxEntry, getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals'], optimisticTransactions: Record = {}, + iouReportNameValuePairs?: OnyxEntry, ): OnyxTypes.Report { - const allReportNameValuePairs = getAllReportNameValuePairs(); - const reportNameValuePairs = allReportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${iouReport.reportID}`]; + const reportNameValuePairs = iouReportNameValuePairs ?? getAllReportNameValuePairs()?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${iouReport.reportID}`]; const titleField = reportNameValuePairs?.expensify_text_title; // Manual renames null out expensify_text_title in RNVP; if RNVP isn't loaded, skip rather than overwrite. @@ -1903,6 +1903,7 @@ function getUpdatedMoneyRequestReportData( transactionChanges?: TransactionChanges, // Overlaid on Onyx in the formula context — search snapshots, prior bulk-edit iterations, etc. additionalTransactionsForFormula: Record = {}, + iouReportNameValuePairs?: OnyxEntry, ) { const calculatedDiffAmount = calculateDiffAmount(iouReport, updatedTransaction, transaction); // Once a prior iteration made the total pending, later ones must not recompute against a stale base. @@ -1963,7 +1964,7 @@ function getUpdatedMoneyRequestReportData( if (updatedTransaction?.transactionID) { optimisticTransactions[updatedTransaction.transactionID] = updatedTransaction; } - updatedMoneyRequestReport = maybeUpdateReportNameForFormulaTitle(updatedMoneyRequestReport, policy, getCurrencyDecimals, optimisticTransactions); + updatedMoneyRequestReport = maybeUpdateReportNameForFormulaTitle(updatedMoneyRequestReport, policy, getCurrencyDecimals, optimisticTransactions, iouReportNameValuePairs); } } else { updatedMoneyRequestReport = updateIOUOwnerAndTotal(iouReport, actorAccountID ?? CONST.DEFAULT_NUMBER_ID, diff, getCurrency(transaction), false, true, isTransactionOnHold); diff --git a/src/libs/actions/IOU/UpdateMoneyRequest.ts b/src/libs/actions/IOU/UpdateMoneyRequest.ts index c22ca51fc8e6..f81c8d20e905 100644 --- a/src/libs/actions/IOU/UpdateMoneyRequest.ts +++ b/src/libs/actions/IOU/UpdateMoneyRequest.ts @@ -99,6 +99,8 @@ type UpdateMoneyRequestDateParams = { getCurrencySymbol: CurrencyListActionsContextType['getCurrencySymbol']; rules: OnyxCollection; isVendorMatchingBetaEnabled: boolean | undefined; + /** RNVP of `parentReport`. Falls back to the module-level Onyx cache when omitted */ + parentReportNameValuePairs?: OnyxEntry; }; type SearchSnapshotOnyxData = { @@ -256,6 +258,7 @@ function updateMoneyRequestDate({ getCurrencySymbol, rules, isVendorMatchingBetaEnabled, + parentReportNameValuePairs, }: UpdateMoneyRequestDateParams) { const isTrackExpense = isTrackExpenseReport(transactionThreadReport) && isSelfDM(parentReport); const effectivePolicy = isTrackExpense ? policyForTrackExpense : policy; @@ -355,6 +358,7 @@ function updateMoneyRequestDate({ getCurrencyDecimals, getCurrencySymbol, rules, + iouReportNameValuePairs: parentReportNameValuePairs, }); removeTransactionFromDuplicateTransactionViolation(data.onyxData, transactionID, transactions, transactionViolations); } @@ -556,6 +560,7 @@ function updateMoneyRequestMerchant({ getCurrencySymbol, rules, isVendorMatchingBetaEnabled, + parentReportNameValuePairs, }: { isVendorMatchingBetaEnabled: boolean | undefined; transactionID: string; @@ -579,6 +584,8 @@ function updateMoneyRequestMerchant({ getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; getCurrencySymbol: CurrencyListActionsContextType['getCurrencySymbol']; rules: OnyxCollection; + /** RNVP of `parentReport`. Falls back to the module-level Onyx cache when omitted */ + parentReportNameValuePairs?: OnyxEntry; }) { const transactionChanges: TransactionChanges = { merchant: value, @@ -622,6 +629,7 @@ function updateMoneyRequestMerchant({ getCurrencyDecimals, getCurrencySymbol, rules, + iouReportNameValuePairs: parentReportNameValuePairs, }); } const {params, onyxData} = data; @@ -1437,6 +1445,7 @@ function updateMoneyRequestDescription({ rules, isVendorMatchingBetaEnabled, policyVendors, + parentReportNameValuePairs, }: { isVendorMatchingBetaEnabled: boolean | undefined; transactionID: string; @@ -1460,6 +1469,8 @@ function updateMoneyRequestDescription({ getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals']; getCurrencySymbol: CurrencyListActionsContextType['getCurrencySymbol']; rules: OnyxCollection; + /** RNVP of `parentReport`. Falls back to the module-level Onyx cache when omitted */ + parentReportNameValuePairs?: OnyxEntry; }) { const parsedComment = getParsedComment(comment); const transactionChanges: TransactionChanges = { @@ -1504,6 +1515,7 @@ function updateMoneyRequestDescription({ getCurrencyDecimals, getCurrencySymbol, rules, + iouReportNameValuePairs: parentReportNameValuePairs, }); } const {params, onyxData} = data; @@ -1817,6 +1829,8 @@ type GetUpdateMoneyRequestParamsType = { rules: OnyxCollection; isVendorMatchingBetaEnabled: boolean | undefined; policyVendors?: OnyxEntry; + /** RNVP of `iouReport`. Falls back to the module-level Onyx cache when omitted */ + iouReportNameValuePairs?: OnyxEntry; }; type UpdateMoneyRequestDataKeys = @@ -1871,6 +1885,7 @@ function getUpdateMoneyRequestParams(params: GetUpdateMoneyRequestParamsType): U rules, isVendorMatchingBetaEnabled, policyVendors: policyVendorsParam, + iouReportNameValuePairs, } = params; const optimisticData: Array< OnyxUpdate< @@ -2129,6 +2144,8 @@ function getUpdateMoneyRequestParams(params: GetUpdateMoneyRequestParamsType): U getCurrencyDecimals, updatedReportAction?.actorAccountID, transactionChanges, + undefined, + iouReportNameValuePairs, ); optimisticData.push( diff --git a/src/pages/iou/request/step/DynamicIOURequestStepDate.tsx b/src/pages/iou/request/step/DynamicIOURequestStepDate.tsx index 526a412c7af0..4de436ea92bf 100644 --- a/src/pages/iou/request/step/DynamicIOURequestStepDate.tsx +++ b/src/pages/iou/request/step/DynamicIOURequestStepDate.tsx @@ -84,6 +84,7 @@ function DynamicIOURequestStepDate({ const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${report?.policyID}`); const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${report?.policyID}`); const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(report?.parentReportID)}`); + const [parentReportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${getNonEmptyStringOnyxID(report?.parentReportID)}`); const [iouReportOwnerLogin] = usePersonalDetail(parentReport?.ownerAccountID, loginSelector); const [reportPolicyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${getNonEmptyStringOnyxID(parentReport?.policyID)}`); @@ -162,6 +163,7 @@ function DynamicIOURequestStepDate({ getCurrencyDecimals, getCurrencySymbol, rules, + parentReportNameValuePairs, }); } else { setMoneyRequestCreated(transactionID, newCreated, isTransactionDraft, hasReceipt(transaction)); diff --git a/src/pages/iou/request/step/DynamicIOURequestStepDescription.tsx b/src/pages/iou/request/step/DynamicIOURequestStepDescription.tsx index a3154eebcc0a..8452a6cec5ff 100644 --- a/src/pages/iou/request/step/DynamicIOURequestStepDescription.tsx +++ b/src/pages/iou/request/step/DynamicIOURequestStepDescription.tsx @@ -77,6 +77,7 @@ function DynamicIOURequestStepDescription({ const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${report?.policyID}`); const [policyVendors] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_VENDORS}${report?.policyID}`); const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(report?.parentReportID)}`); + const [parentReportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${getNonEmptyStringOnyxID(report?.parentReportID)}`); const [iouReportOwnerLogin] = usePersonalDetail(parentReport?.ownerAccountID, loginSelector); const [reportPolicyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${getNonEmptyStringOnyxID(parentReport?.policyID)}`); @@ -178,6 +179,7 @@ function DynamicIOURequestStepDescription({ getCurrencyDecimals, getCurrencySymbol, rules, + parentReportNameValuePairs, }); } else { setMoneyRequestDescription(transaction?.transactionID, newComment, isTransactionDraft, hasReceipt(transaction)); diff --git a/src/pages/iou/request/step/DynamicIOURequestStepMerchant.tsx b/src/pages/iou/request/step/DynamicIOURequestStepMerchant.tsx index 10c4cd935f16..d2f65ef03dfc 100644 --- a/src/pages/iou/request/step/DynamicIOURequestStepMerchant.tsx +++ b/src/pages/iou/request/step/DynamicIOURequestStepMerchant.tsx @@ -137,12 +137,13 @@ function DynamicIOURequestStepMerchant({ // also calling setMoneyRequestMerchant would trigger a redundant Onyx commit and // re-render every subscriber of that key for nothing. if (isEditing) { - const [rules, policyCategories, policyTags, reportPolicyTags, introSelected] = await Onyx.multiGet([ + const [rules, policyCategories, policyTags, reportPolicyTags, introSelected, parentReportNameValuePairs] = await Onyx.multiGet([ ONYXKEYS.COLLECTION.RULE, `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${report?.policyID}`, `${ONYXKEYS.COLLECTION.POLICY_TAGS}${report?.policyID}`, `${ONYXKEYS.COLLECTION.POLICY_TAGS}${getNonEmptyStringOnyxID(parentReport?.policyID)}`, ONYXKEYS.NVP_INTRO_SELECTED, + `${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${getNonEmptyStringOnyxID(parentReport?.reportID)}`, ]); updateMoneyRequestMerchant({ isVendorMatchingBetaEnabled, @@ -166,6 +167,7 @@ function DynamicIOURequestStepMerchant({ getCurrencyDecimals, getCurrencySymbol, rules, + parentReportNameValuePairs, }); } else if (!newMerchant) { clearMoneyRequestMerchant(transactionID); diff --git a/tests/actions/IOUTest/GetUpdateMoneyRequestParamsTest.ts b/tests/actions/IOUTest/GetUpdateMoneyRequestParamsTest.ts index 7717dd611c89..5a9699622a1a 100644 --- a/tests/actions/IOUTest/GetUpdateMoneyRequestParamsTest.ts +++ b/tests/actions/IOUTest/GetUpdateMoneyRequestParamsTest.ts @@ -651,3 +651,109 @@ describe('getUpdateMoneyRequestParams — next step of a submitted report', () = expect(hasOptimisticNextStep(approvedReport, policy, {reimbursable: false})).toBe(false); }); }); + +describe('getUpdateMoneyRequestParams — formula report title', () => { + const TRIP_TITLE_FORMULA = 'Trip from {report:autoreporting:start:MMM dd} to {report:autoreporting:end:MMM dd, yyyy}'; + const ORIGINAL_REPORT_NAME = 'Original report name'; + + const titleField = { + fieldID: CONST.REPORT_FIELD_TITLE_FIELD_ID, + name: 'Title', + type: CONST.REPORT_FIELD_TYPES.FORMULA, + defaultValue: TRIP_TITLE_FORMULA, + deletable: false, + target: CONST.POLICY.DEFAULT_FIELD_LIST_TARGET, + values: [], + keys: [], + externalIDs: [], + disabledOptions: [], + orderWeight: 1, + isTax: false, + }; + + const policy: Policy = { + ...createRandomPolicy(0, CONST.POLICY.TYPE.TEAM), + id: POLICY_ID, + autoReportingFrequency: CONST.POLICY.AUTO_REPORTING_FREQUENCIES.TRIP, + fieldList: {[CONST.POLICY.FIELDS.FIELD_LIST_TITLE]: titleField}, + }; + + const expenseReport: Report = { + reportID: IOU_REPORT_ID, + reportName: ORIGINAL_REPORT_NAME, + type: CONST.REPORT.TYPE.EXPENSE, + policyID: POLICY_ID, + total: -1000, + currency: CONST.CURRENCY.USD, + ownerAccountID: RORY_ACCOUNT_ID, + }; + + const transaction: Transaction = { + transactionID: TRANSACTION_ID, + reportID: IOU_REPORT_ID, + amount: -1000, + currency: CONST.CURRENCY.USD, + created: '2025-01-10', + merchant: 'Merchant', + }; + + function getOptimisticReportName(iouReportNameValuePairs: Parameters[0]['iouReportNameValuePairs']): unknown { + const {onyxData} = getUpdateMoneyRequestParams({ + isVendorMatchingBetaEnabled: false, + rules: undefined, + iouReportOwnerLogin: undefined, + transactionID: TRANSACTION_ID, + transaction, + transactionThreadReport, + iouReport: expenseReport, + delegateAccountID: undefined, + transactionChanges: {created: '2025-01-15'}, + policy, + policyTagList: undefined, + reportPolicyTags: undefined, + policyCategories: undefined, + currentUserAccountIDParam: RORY_ACCOUNT_ID, + currentUserEmailParam: RORY_EMAIL, + isASAPSubmitBetaEnabled: false, + isTrackIntentUser: false, + getCurrencyDecimals: getCurrencyDecimalsLocal, + getCurrencySymbol: getCurrencySymbolLocal, + iouReportNameValuePairs, + }); + + const reportUpdate = onyxData.optimisticData?.find((entry) => entry.key === `${ONYXKEYS.COLLECTION.REPORT}${IOU_REPORT_ID}` && isRecord(entry.value) && 'reportName' in entry.value); + const reportUpdateValue: unknown = reportUpdate?.value; + return isRecord(reportUpdateValue) ? reportUpdateValue.reportName : undefined; + } + + beforeEach(async () => { + await Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${POLICY_ID}`, policy); + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${IOU_REPORT_ID}`, expenseReport); + await Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION}${TRANSACTION_ID}`, transaction); + await waitForBatchedUpdates(); + }); + + it('should recalculate the title from the passed RNVP entry when Onyx has no RNVP for the report', () => { + // Given the report's RNVP, which marks its title as a formula, is passed in by the caller and isn't in Onyx, + // so the title can only be recalculated if the passed entry is used + // eslint-disable-next-line @typescript-eslint/naming-convention + const iouReportNameValuePairs = {expensify_text_title: titleField}; + + // When the expense date changes + // Then the title is recalculated with the new date + expect(getOptimisticReportName(iouReportNameValuePairs)).toBe('Trip from Jan 15 to Jan 15, 2025'); + }); + + it('should keep the title when the passed RNVP entry has no formula title, even if Onyx has one', async () => { + // Given Onyx still holds a formula title for the report, but the caller passes an RNVP entry without one, + // as happens after the user renames the report manually + // eslint-disable-next-line @typescript-eslint/naming-convention + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${IOU_REPORT_ID}`, {expensify_text_title: titleField}); + await waitForBatchedUpdates(); + const iouReportNameValuePairs = {}; + + // When the expense date changes + // Then the passed entry wins over the module-level cache and the title isn't recalculated + expect(getOptimisticReportName(iouReportNameValuePairs)).toBe(ORIGINAL_REPORT_NAME); + }); +}); diff --git a/tests/actions/IOUTest/UpdateMoneyRequestTest.ts b/tests/actions/IOUTest/UpdateMoneyRequestTest.ts index 57c7a3909a1f..b167919cc222 100644 --- a/tests/actions/IOUTest/UpdateMoneyRequestTest.ts +++ b/tests/actions/IOUTest/UpdateMoneyRequestTest.ts @@ -3400,4 +3400,153 @@ describe('actions/IOU/UpdateMoneyRequest', () => { expect(storedTransaction?.receipt?.state).not.toBe(CONST.IOU.RECEIPT_STATE.SCAN_COMPLETE); }); }); + + describe('formula report title from the passed parent report RNVP', () => { + const transactionID = 'formulaTitleTransaction'; + const transactionThreadReportID = 'formulaTitleThread'; + const parentReportID = 'formulaTitleExpenseReport'; + const policyID = 'formulaTitlePolicy'; + + const titleField = { + fieldID: CONST.REPORT_FIELD_TITLE_FIELD_ID, + name: 'Title', + type: CONST.REPORT_FIELD_TYPES.FORMULA, + defaultValue: 'Trip from {report:autoreporting:start:MMM dd} to {report:autoreporting:end:MMM dd, yyyy}', + deletable: false, + target: CONST.POLICY.DEFAULT_FIELD_LIST_TARGET, + values: [], + keys: [], + externalIDs: [], + disabledOptions: [], + orderWeight: 1, + isTax: false, + }; + const policy: Policy = { + ...createRandomPolicy(1, CONST.POLICY.TYPE.TEAM), + id: policyID, + autoReportingFrequency: CONST.POLICY.AUTO_REPORTING_FREQUENCIES.TRIP, + fieldList: {[CONST.POLICY.FIELDS.FIELD_LIST_TITLE]: titleField}, + }; + const parentReport: Report = { + ...createRandomReport(1, undefined), + reportID: parentReportID, + reportName: 'Original report name', + type: CONST.REPORT.TYPE.EXPENSE, + policyID, + ownerAccountID: RORY_ACCOUNT_ID, + total: -1000, + currency: CONST.CURRENCY.USD, + }; + const transactionThreadReport: Report = { + ...createRandomReport(2, undefined), + reportID: transactionThreadReportID, + parentReportID, + type: CONST.REPORT.TYPE.CHAT, + }; + const transaction: Transaction = { + transactionID, + reportID: parentReportID, + amount: -1000, + currency: CONST.CURRENCY.USD, + created: '2025-01-10', + merchant: 'Old merchant', + }; + // eslint-disable-next-line @typescript-eslint/naming-convention + const parentReportNameValuePairs = {expensify_text_title: titleField}; + + const sharedParams = { + isVendorMatchingBetaEnabled: false, + rules: undefined, + transactionID, + transaction, + transactionThreadReport, + parentReport, + iouReportOwnerLogin: undefined, + policy, + policyCategories: {}, + reportPolicyTags: undefined, + currentUserAccountIDParam: RORY_ACCOUNT_ID, + currentUserEmailParam: RORY_EMAIL, + isASAPSubmitBetaEnabled: false, + delegateAccountID: undefined, + isTrackIntentUser: false, + getCurrencyDecimals: getCurrencyDecimalsLocal, + getCurrencySymbol: getCurrencySymbolLocal, + parentReportNameValuePairs, + }; + + beforeEach(async () => { + await Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, policy); + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${parentReportID}`, parentReport); + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`, transactionThreadReport); + await Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, transaction); + await waitForBatchedUpdates(); + }); + + it.each([ + { + name: 'updateMoneyRequestDate', + command: WRITE_COMMANDS.UPDATE_MONEY_REQUEST_DATE, + expectedReportName: 'Trip from Jan 15 to Jan 15, 2025', + update: () => + updateMoneyRequestDate({ + ...sharedParams, + transactions: {}, + transactionViolations: {}, + value: '2025-01-15', + policyTags: {}, + isOffline: false, + personalPolicyOutputCurrency: undefined, + }), + }, + { + name: 'updateMoneyRequestMerchant', + command: WRITE_COMMANDS.UPDATE_MONEY_REQUEST_MERCHANT, + expectedReportName: 'Trip from Jan 10 to Jan 10, 2025', + update: () => + updateMoneyRequestMerchant({ + ...sharedParams, + value: 'New merchant', + policyTagList: {}, + isOffline: false, + violations: undefined, + }), + }, + { + name: 'updateMoneyRequestDescription', + command: WRITE_COMMANDS.UPDATE_MONEY_REQUEST_DESCRIPTION, + expectedReportName: 'Trip from Jan 10 to Jan 10, 2025', + update: () => + updateMoneyRequestDescription({ + ...sharedParams, + comment: 'New description', + policyTagList: {}, + violations: undefined, + }), + }, + ])('$name recalculates the formula title from the passed parent report RNVP', ({command, expectedReportName, update}) => { + // Given the expense report's RNVP marks its title as a formula, but only the caller has it and Onyx doesn't, + // so the title can only be recalculated if the wrapper passes the entry on + const writeSpy = jest.spyOn(API, 'write').mockImplementation(jest.fn()); + + // When the expense is edited + update(); + + // Then the optimistic report update carries the recalculated title + expect(writeSpy).toHaveBeenCalledWith( + command, + expect.anything(), + expect.objectContaining({ + optimisticData: expect.arrayContaining([ + expect.objectContaining({ + key: `${ONYXKEYS.COLLECTION.REPORT}${parentReportID}`, + value: expect.objectContaining({reportName: expectedReportName}), + }), + ]), + }), + ); + + writeSpy.mockRestore(); + }); + }); }); From e51289d8a19462561ead64224b09474289878743 Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Sat, 28 Nov 2026 15:59:41 +0530 Subject: [PATCH 2/4] fix unit tests --- tests/actions/IOUTest/UpdateMoneyRequestTest.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/actions/IOUTest/UpdateMoneyRequestTest.ts b/tests/actions/IOUTest/UpdateMoneyRequestTest.ts index 71b1f98be06f..fc515e5fea1f 100644 --- a/tests/actions/IOUTest/UpdateMoneyRequestTest.ts +++ b/tests/actions/IOUTest/UpdateMoneyRequestTest.ts @@ -3779,6 +3779,7 @@ describe('actions/IOU/UpdateMoneyRequest', () => { const parentReportNameValuePairs = {expensify_text_title: titleField}; const sharedParams = { + translate: translateLocal, isVendorMatchingBetaEnabled: false, rules: undefined, transactionID, From 9a788ba5c96e83801e42e29b5017aff31a8590d8 Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Mon, 30 Nov 2026 15:35:18 +0530 Subject: [PATCH 3/4] fixes --- src/libs/actions/IOU/UpdateMoneyRequest.ts | 2 +- src/pages/iou/request/step/DynamicIOURequestStepDate.tsx | 4 ++-- .../request/step/DynamicIOURequestStepDescription.tsx | 4 ++-- .../iou/request/step/DynamicIOURequestStepMerchant.tsx | 2 +- tests/actions/IOUTest/GetUpdateMoneyRequestParamsTest.ts | 9 ++++++--- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/libs/actions/IOU/UpdateMoneyRequest.ts b/src/libs/actions/IOU/UpdateMoneyRequest.ts index a640b53f94d9..16671fc78cea 100644 --- a/src/libs/actions/IOU/UpdateMoneyRequest.ts +++ b/src/libs/actions/IOU/UpdateMoneyRequest.ts @@ -2297,7 +2297,7 @@ function getUpdateMoneyRequestParams(params: GetUpdateMoneyRequestParamsType): U getCurrencyDecimals, updatedReportAction?.actorAccountID, transactionChanges, - undefined, + undefined, // additionalTransactionsForFormula iouReportNameValuePairs, ); diff --git a/src/pages/iou/request/step/DynamicIOURequestStepDate.tsx b/src/pages/iou/request/step/DynamicIOURequestStepDate.tsx index 2747dc878fd5..6e7a53dcdccd 100644 --- a/src/pages/iou/request/step/DynamicIOURequestStepDate.tsx +++ b/src/pages/iou/request/step/DynamicIOURequestStepDate.tsx @@ -83,7 +83,6 @@ function DynamicIOURequestStepDate({ const distanceOriginalPolicy = useDistanceRateOriginalPolicy(customUnitRateID, shouldLookupDistancePolicy); const {duplicateTransactions, duplicateTransactionViolations} = useDuplicateTransactionsAndViolations(transactionID ? [transactionID] : []); const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(report?.parentReportID)}`); - const [parentReportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${getNonEmptyStringOnyxID(report?.parentReportID)}`); const [iouReportOwnerLogin] = usePersonalDetail(parentReport?.ownerAccountID, loginSelector); const [splitDraftTransaction] = useOnyx(`${ONYXKEYS.COLLECTION.SPLIT_TRANSACTION_DRAFT}${transactionID}`); @@ -129,13 +128,14 @@ function DynamicIOURequestStepDate({ return; } - const [rules, lastSelectedDistanceRates, policyCategories, policyTags, reportPolicyTags, introSelected] = await Onyx.multiGet([ + const [rules, lastSelectedDistanceRates, policyCategories, policyTags, reportPolicyTags, introSelected, parentReportNameValuePairs] = await Onyx.multiGet([ ONYXKEYS.COLLECTION.RULE, ONYXKEYS.NVP_LAST_SELECTED_DISTANCE_RATES, `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${report?.policyID}`, `${ONYXKEYS.COLLECTION.POLICY_TAGS}${report?.policyID}`, `${ONYXKEYS.COLLECTION.POLICY_TAGS}${getNonEmptyStringOnyxID(parentReport?.policyID)}`, ONYXKEYS.NVP_INTRO_SELECTED, + `${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${getNonEmptyStringOnyxID(report?.parentReportID)}`, ]); const isTransactionDraft = shouldUseTransactionDraft(action); diff --git a/src/pages/iou/request/step/DynamicIOURequestStepDescription.tsx b/src/pages/iou/request/step/DynamicIOURequestStepDescription.tsx index 35660cc3f5b0..bd058606e39a 100644 --- a/src/pages/iou/request/step/DynamicIOURequestStepDescription.tsx +++ b/src/pages/iou/request/step/DynamicIOURequestStepDescription.tsx @@ -77,7 +77,6 @@ function DynamicIOURequestStepDescription({ const allTransactionViolations = useAllTransactionViolations(transaction?.transactionID); const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${report?.policyID}`); const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(report?.parentReportID)}`); - const [parentReportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${getNonEmptyStringOnyxID(report?.parentReportID)}`); const [iouReportOwnerLogin] = usePersonalDetail(parentReport?.ownerAccountID, loginSelector); const [personalPolicyID] = useOnyx(ONYXKEYS.PERSONAL_POLICY_ID); @@ -150,12 +149,13 @@ function DynamicIOURequestStepDescription({ } if (action === CONST.IOU.ACTION.EDIT) { - const [rules, policyTags, policyVendors, reportPolicyTags, introSelected] = await Onyx.multiGet([ + const [rules, policyTags, policyVendors, reportPolicyTags, introSelected, parentReportNameValuePairs] = await Onyx.multiGet([ ONYXKEYS.COLLECTION.RULE, `${ONYXKEYS.COLLECTION.POLICY_TAGS}${report?.policyID}`, `${ONYXKEYS.COLLECTION.POLICY_VENDORS}${report?.policyID}`, `${ONYXKEYS.COLLECTION.POLICY_TAGS}${getNonEmptyStringOnyxID(parentReport?.policyID)}`, ONYXKEYS.NVP_INTRO_SELECTED, + `${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${getNonEmptyStringOnyxID(report?.parentReportID)}`, ]); updateMoneyRequestDescription({ translate, diff --git a/src/pages/iou/request/step/DynamicIOURequestStepMerchant.tsx b/src/pages/iou/request/step/DynamicIOURequestStepMerchant.tsx index ca5b500043d1..60885267c0aa 100644 --- a/src/pages/iou/request/step/DynamicIOURequestStepMerchant.tsx +++ b/src/pages/iou/request/step/DynamicIOURequestStepMerchant.tsx @@ -143,7 +143,7 @@ function DynamicIOURequestStepMerchant({ `${ONYXKEYS.COLLECTION.POLICY_TAGS}${report?.policyID}`, `${ONYXKEYS.COLLECTION.POLICY_TAGS}${getNonEmptyStringOnyxID(parentReport?.policyID)}`, ONYXKEYS.NVP_INTRO_SELECTED, - `${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${getNonEmptyStringOnyxID(parentReport?.reportID)}`, + `${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${getNonEmptyStringOnyxID(report?.parentReportID)}`, ]); updateMoneyRequestMerchant({ translate, diff --git a/tests/actions/IOUTest/GetUpdateMoneyRequestParamsTest.ts b/tests/actions/IOUTest/GetUpdateMoneyRequestParamsTest.ts index 7b71975cdbb7..8d03b5abf8df 100644 --- a/tests/actions/IOUTest/GetUpdateMoneyRequestParamsTest.ts +++ b/tests/actions/IOUTest/GetUpdateMoneyRequestParamsTest.ts @@ -5,7 +5,9 @@ import {isRecord} from '@libs/ObjectUtils'; import CONST from '@src/CONST'; import IntlStore from '@src/languages/IntlStore'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {Policy, PolicyTagLists, RecentlyUsedTags, Report, Transaction} from '@src/types/onyx'; +import type {Policy, PolicyTagLists, RecentlyUsedTags, Report, ReportNameValuePairs, Transaction} from '@src/types/onyx'; + +import type {OnyxEntry} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; @@ -706,7 +708,7 @@ describe('getUpdateMoneyRequestParams — formula report title', () => { merchant: 'Merchant', }; - function getOptimisticReportName(iouReportNameValuePairs: Parameters[0]['iouReportNameValuePairs']): unknown { + function getOptimisticReportName(iouReportNameValuePairs: OnyxEntry): string | undefined { const {onyxData} = getUpdateMoneyRequestParams({ isVendorMatchingBetaEnabled: false, rules: undefined, @@ -732,7 +734,8 @@ describe('getUpdateMoneyRequestParams — formula report title', () => { const reportUpdate = onyxData.optimisticData?.find((entry) => entry.key === `${ONYXKEYS.COLLECTION.REPORT}${IOU_REPORT_ID}` && isRecord(entry.value) && 'reportName' in entry.value); const reportUpdateValue: unknown = reportUpdate?.value; - return isRecord(reportUpdateValue) ? reportUpdateValue.reportName : undefined; + const reportName = isRecord(reportUpdateValue) ? reportUpdateValue.reportName : undefined; + return typeof reportName === 'string' ? reportName : undefined; } beforeEach(async () => { From fa1e7562556aed170bd953172e6578bd3545d9ec Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Mon, 30 Nov 2026 15:50:09 +0530 Subject: [PATCH 4/4] Fixes --- src/pages/iou/request/step/DynamicIOURequestStepDate.tsx | 1 + src/pages/iou/request/step/DynamicIOURequestStepDescription.tsx | 1 + src/pages/iou/request/step/DynamicIOURequestStepMerchant.tsx | 1 + tests/actions/IOUTest/UpdateMoneyRequestTest.ts | 1 + 4 files changed, 4 insertions(+) diff --git a/src/pages/iou/request/step/DynamicIOURequestStepDate.tsx b/src/pages/iou/request/step/DynamicIOURequestStepDate.tsx index 6e7a53dcdccd..47d33d2ac7f2 100644 --- a/src/pages/iou/request/step/DynamicIOURequestStepDate.tsx +++ b/src/pages/iou/request/step/DynamicIOURequestStepDate.tsx @@ -128,6 +128,7 @@ function DynamicIOURequestStepDate({ return; } + // eslint-disable-next-line rulesdir/no-onyx-get-snapshot-key -- replaces maybeUpdateReportNameForFormulaTitle's module-level Onyx.connect fallback, which never read a Search snapshot const [rules, lastSelectedDistanceRates, policyCategories, policyTags, reportPolicyTags, introSelected, parentReportNameValuePairs] = await Onyx.multiGet([ ONYXKEYS.COLLECTION.RULE, ONYXKEYS.NVP_LAST_SELECTED_DISTANCE_RATES, diff --git a/src/pages/iou/request/step/DynamicIOURequestStepDescription.tsx b/src/pages/iou/request/step/DynamicIOURequestStepDescription.tsx index bd058606e39a..f6496d09c44d 100644 --- a/src/pages/iou/request/step/DynamicIOURequestStepDescription.tsx +++ b/src/pages/iou/request/step/DynamicIOURequestStepDescription.tsx @@ -149,6 +149,7 @@ function DynamicIOURequestStepDescription({ } if (action === CONST.IOU.ACTION.EDIT) { + // eslint-disable-next-line rulesdir/no-onyx-get-snapshot-key -- replaces maybeUpdateReportNameForFormulaTitle's module-level Onyx.connect fallback, which never read a Search snapshot const [rules, policyTags, policyVendors, reportPolicyTags, introSelected, parentReportNameValuePairs] = await Onyx.multiGet([ ONYXKEYS.COLLECTION.RULE, `${ONYXKEYS.COLLECTION.POLICY_TAGS}${report?.policyID}`, diff --git a/src/pages/iou/request/step/DynamicIOURequestStepMerchant.tsx b/src/pages/iou/request/step/DynamicIOURequestStepMerchant.tsx index 60885267c0aa..e2279a8f3e9e 100644 --- a/src/pages/iou/request/step/DynamicIOURequestStepMerchant.tsx +++ b/src/pages/iou/request/step/DynamicIOURequestStepMerchant.tsx @@ -137,6 +137,7 @@ function DynamicIOURequestStepMerchant({ // also calling setMoneyRequestMerchant would trigger a redundant Onyx commit and // re-render every subscriber of that key for nothing. if (isEditing) { + // eslint-disable-next-line rulesdir/no-onyx-get-snapshot-key -- replaces maybeUpdateReportNameForFormulaTitle's module-level Onyx.connect fallback, which never read a Search snapshot const [rules, policyCategories, policyTags, reportPolicyTags, introSelected, parentReportNameValuePairs] = await Onyx.multiGet([ ONYXKEYS.COLLECTION.RULE, `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${report?.policyID}`, diff --git a/tests/actions/IOUTest/UpdateMoneyRequestTest.ts b/tests/actions/IOUTest/UpdateMoneyRequestTest.ts index fc515e5fea1f..d7bc06c66ad8 100644 --- a/tests/actions/IOUTest/UpdateMoneyRequestTest.ts +++ b/tests/actions/IOUTest/UpdateMoneyRequestTest.ts @@ -3852,6 +3852,7 @@ describe('actions/IOU/UpdateMoneyRequest', () => { ])('$name recalculates the formula title from the passed parent report RNVP', ({command, expectedReportName, update}) => { // Given the expense report's RNVP marks its title as a formula, but only the caller has it and Onyx doesn't, // so the title can only be recalculated if the wrapper passes the entry on + // eslint-disable-next-line rulesdir/no-multiple-api-calls const writeSpy = jest.spyOn(API, 'write').mockImplementation(jest.fn()); // When the expense is edited