From 4468cb2a719511355dbabcf750dfe9e051e35829 Mon Sep 17 00:00:00 2001 From: situchan Date: Tue, 18 Nov 2025 23:33:19 +0600 Subject: [PATCH] Revert "Merge pull request #72413 from Expensify/mollfpr-create-optimistic-ioureport-action-and-transaction-thread" This reverts commit 147676d5d9ab602f8ac5bdd90f77dfa2a1f3deb2, reversing changes made to 169c509200894cc43adbeebf8b68275bcd2e4b6a. --- .../MoneyRequestReportTransactionList.tsx | 3 +- .../MoneyRequestReportView.tsx | 2 +- src/libs/MoneyRequestReportUtils.ts | 5 +- src/libs/SearchUIUtils.ts | 67 +------ src/libs/actions/Report.ts | 175 ++++++------------ src/pages/home/ReportScreen.tsx | 7 +- tests/actions/ReportTest.ts | 8 +- tests/unit/Search/SearchUIUtilsTest.ts | 62 +------ tests/unit/libs/MoneyRequestReportUtils.ts | 42 +---- 9 files changed, 72 insertions(+), 299 deletions(-) diff --git a/src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx b/src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx index 5deddd7c1d6b..c7a1a4d8d55e 100644 --- a/src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx +++ b/src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx @@ -272,8 +272,7 @@ function MoneyRequestReportTransactionList({ } as ReportScreenNavigationProps; if (!reportIDToNavigate) { - const transaction = sortedTransactions.find((t) => t.transactionID === activeTransactionID); - const transactionThreadReport = createTransactionThreadReport(report, iouAction, transaction); + const transactionThreadReport = createTransactionThreadReport(report, iouAction); if (transactionThreadReport) { reportIDToNavigate = transactionThreadReport.reportID; routeParams.reportID = reportIDToNavigate; diff --git a/src/components/MoneyRequestReportView/MoneyRequestReportView.tsx b/src/components/MoneyRequestReportView/MoneyRequestReportView.tsx index c99d57461594..9e816cf999ec 100644 --- a/src/components/MoneyRequestReportView/MoneyRequestReportView.tsx +++ b/src/components/MoneyRequestReportView/MoneyRequestReportView.tsx @@ -98,7 +98,7 @@ function MoneyRequestReportView({report, policy, reportMetadata, shouldDisplayRe const {transactions: reportTransactions, violations: allReportViolations} = useTransactionsAndViolationsForReport(reportID); const hasPendingDeletionTransaction = Object.values(reportTransactions ?? {}).some((transaction) => transaction.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE); - const transactions = useMemo(() => getAllNonDeletedTransactions(reportTransactions, reportActions, isOffline, true), [reportTransactions, reportActions, isOffline]); + const transactions = useMemo(() => getAllNonDeletedTransactions(reportTransactions, reportActions), [reportTransactions, reportActions]); const visibleTransactions = transactions?.filter((transaction) => isOffline || transaction.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE); const reportTransactionIDs = visibleTransactions?.map((transaction) => transaction.transactionID); diff --git a/src/libs/MoneyRequestReportUtils.ts b/src/libs/MoneyRequestReportUtils.ts index dee1bb2640d5..248c2ea890b2 100644 --- a/src/libs/MoneyRequestReportUtils.ts +++ b/src/libs/MoneyRequestReportUtils.ts @@ -71,7 +71,7 @@ function getReportIDForTransaction(transactionItem: TransactionListItemType) { /** * Filters all available transactions and returns the ones that belong to not removed action and not removed parent action. */ -function getAllNonDeletedTransactions(transactions: OnyxCollection, reportActions: ReportAction[], isOffline = false, includeOrphanedTransactions = false) { +function getAllNonDeletedTransactions(transactions: OnyxCollection, reportActions: ReportAction[], isOffline = false) { return Object.values(transactions ?? {}).filter((transaction): transaction is Transaction => { if (!transaction) { return false; @@ -82,9 +82,6 @@ function getAllNonDeletedTransactions(transactions: OnyxCollection, } const action = getIOUActionForTransactionID(reportActions, transaction.transactionID); - if (!action && includeOrphanedTransactions) { - return true; - } if (action?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE && isOffline) { return true; } diff --git a/src/libs/SearchUIUtils.ts b/src/libs/SearchUIUtils.ts index b59ecb0a5f2e..30ab92ca71b3 100644 --- a/src/libs/SearchUIUtils.ts +++ b/src/libs/SearchUIUtils.ts @@ -1371,69 +1371,14 @@ function getTaskSections( ); } -/** - * @private - * - * Extracts the core Transaction fields from a TransactionListItemType - * This removes UI-specific fields like formattedFrom, hash, violations, etc. - */ -function getTransactionFromTransactionListItem(item: TransactionListItemType): OnyxTypes.Transaction { - // Extract only the core Transaction fields, excluding UI-specific and search-specific fields - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const { - // Remove UI-specific fields - keyForList, - action, - allActions, - report, - from, - to, - formattedFrom, - formattedTo, - formattedTotal, - formattedMerchant, - date, - shouldShowMerchant, - shouldShowYear: shouldTransactionShowYear, - isAmountColumnWide, - isTaxAmountColumnWide, - violations, - hash, - moneyRequestReportActionID, - canDelete, - convertedAmount, - convertedCurrency, - transactionThreadReportID, - isFromOneTransactionReport, - accountID, - policyID, - transactionType, - // Keep all other fields (core Transaction fields) - ...transaction - } = item; - - return transaction as OnyxTypes.Transaction; -} - /** Creates transaction thread report and navigates to it from the search page */ function createAndOpenSearchTransactionThread(item: TransactionListItemType, hash: number, backTo: string, transactionPreviewData?: TransactionPreviewData, shouldNavigate = true) { - // Treat '0' as empty for reportActionID (0 means no IOU action exists in the backend) - const reportActionID = item.moneyRequestReportActionID === '0' ? '' : item.moneyRequestReportActionID; - - // If the IOU action exists in the backend, populate Onyx with data from the search snapshot - // This shows the transaction thread immediately while waiting for OpenReport to return the real data - if (reportActionID) { - const previewData = transactionPreviewData - ? {...transactionPreviewData, hasTransactionThreadReport: true} - : {hasTransaction: false, hasParentReport: false, hasParentReportAction: false, hasTransactionThreadReport: true}; - setOptimisticDataForTransactionThreadPreview(item, previewData); - } - - // For legacy transactions without an IOU action in the backend, pass transaction data - // This allows OpenReport to create the IOU action and transaction thread on the backend - const transaction = !reportActionID ? getTransactionFromTransactionListItem(item) : undefined; - const transactionViolations = !reportActionID ? item.violations : undefined; - const transactionThreadReport = createTransactionThreadReport(item.report, {reportActionID} as OnyxTypes.ReportAction, transaction, transactionViolations); + const previewData = transactionPreviewData + ? {...transactionPreviewData, hasTransactionThreadReport: true} + : {hasTransaction: false, hasParentReport: false, hasParentReportAction: false, hasTransactionThreadReport: true}; + setOptimisticDataForTransactionThreadPreview(item, previewData); + + const transactionThreadReport = createTransactionThreadReport(item.report, {reportActionID: item.moneyRequestReportActionID} as OnyxTypes.ReportAction); if (transactionThreadReport?.reportID) { updateSearchResultsWithTransactionThreadReportID(hash, item.transactionID, transactionThreadReport?.reportID); } diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 1d517345552d..56602078f432 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -974,13 +974,7 @@ function clearAvatarErrors(reportID: string) { * @param parentReportActionID The parent report action that a thread was created from (only passed for new threads) * @param isFromDeepLink Whether or not this report is being opened from a deep link * @param participantAccountIDList The list of accountIDs that are included in a new chat, not including the user creating it - * @param avatar The avatar file to upload for a new group chat - * @param isNewThread Whether this is a new thread being created - * @param transaction The transaction object for legacy transactions that don't have a transaction thread or money request preview yet - * @param transactionViolations The violations for the transaction, if any - * @param parentReportID The parent report ID for the transaction thread (optional, defaults to transaction.reportID) */ -// eslint-disable-next-line @typescript-eslint/max-params function openReport( reportID: string | undefined, reportActionID?: string, @@ -990,10 +984,8 @@ function openReport( isFromDeepLink = false, participantAccountIDList: number[] = [], avatar?: File | CustomRNImageManipulatorResult, + transactionID?: string, isNewThread = false, - transaction?: Transaction, - transactionViolations?: TransactionViolations, - parentReportID?: string, ) { if (!reportID) { return; @@ -1074,92 +1066,59 @@ function openReport( emailList: participantLoginList ? participantLoginList.join(',') : '', accountIDList: participantAccountIDList ? participantAccountIDList.join(',') : '', parentReportActionID, - transactionID: transaction?.transactionID, + transactionID, }; - // This is a legacy transaction that doesn't have either a transaction thread or a money request preview - if (transaction && !parentReportActionID) { - const transactionParentReportID = parentReportID ?? transaction?.reportID; - const iouReportActionID = rand64(); - - const optimisticIOUAction = buildOptimisticIOUReportAction({ - type: CONST.IOU.REPORT_ACTION_TYPE.CREATE, - amount: Math.abs(transaction.amount), - currency: transaction.currency, - comment: transaction.comment?.comment ?? '', - participants: [{accountID: currentUserAccountID, login: currentUserEmail ?? ''}], - transactionID: transaction.transactionID, - isOwnPolicyExpenseChat: true, - reportActionID: iouReportActionID, - iouReportID: transactionParentReportID, - }); - - // We have a case where the transaction data is only available from the snapshot - // So we need to add the transaction data to Onyx so it's available when opening the report - optimisticData.push({ - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`, - value: transaction, - }); - - // Add violations if they exist. This is needed when opening from search results where - // violations are in the snapshot but not yet synced to the main collections, so we need - // to add them to Onyx to ensure they show up in the transaction thread - if (transactionViolations) { - optimisticData.push({ - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transaction.transactionID}`, - value: transactionViolations, - }); - } + // This is a legacy transactions that doesn't have either a transaction thread or a money request preview + if (transactionID && !parentReportActionID) { + const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]; + + if (transaction) { + const selfDMReportID = findSelfDMReportID(); + + if (selfDMReportID) { + const generatedReportActionID = rand64(); + const optimisticParentAction = buildOptimisticIOUReportAction({ + type: CONST.IOU.REPORT_ACTION_TYPE.CREATE, + amount: Math.abs(transaction.amount), + currency: transaction.currency, + comment: transaction.comment?.comment ?? '', + participants: [{accountID: currentUserAccountID, login: currentUserEmail ?? ''}], + transactionID, + isOwnPolicyExpenseChat: true, + }); - // Attach the optimistic IOU report action created for the transaction to the transaction thread - optimisticData.push({ - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, - value: { - parentReportActionID: iouReportActionID, - }, - }); + optimisticData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, + value: { + parentReportID: selfDMReportID, + parentReportActionID: generatedReportActionID, + }, + }); - optimisticData.push({ - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionParentReportID}`, - value: { - [iouReportActionID]: { - ...optimisticIOUAction, - childReportID: reportID, - }, - }, - }); + // Log how often the legacy transaction fallback path is taken + Log.info('[Report] Legacy transaction fallback: creating money request preview in self DM', false, { + selfDMReportID, + transactionID, + reportID, + }); - // Update the snapshot with the new transactionThreadReportID and moneyRequestReportActionID if we're coming from search - // preventing duplicate reportActionID when moneyRequestReportActionID still empty - const currentSearchQueryJSON = getCurrentSearchQueryJSON(); - if (currentSearchQueryJSON?.hash) { - // @ts-expect-error - will be solved in https://github.com/Expensify/App/issues/73830 - optimisticData.push({ - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.SNAPSHOT}${currentSearchQueryJSON.hash}`, - value: { - data: { - [`${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`]: { - transactionThreadReportID: reportID, - moneyRequestReportActionID: iouReportActionID, + optimisticData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${selfDMReportID}`, + value: { + [generatedReportActionID]: { + ...optimisticParentAction, + reportActionID: generatedReportActionID, + childReportID: reportID, }, }, - }, - }); - } - - parameters.moneyRequestPreviewReportActionID = iouReportActionID; + }); - // Log how often the legacy transaction fallback path is taken - Log.info('[Report] Legacy transaction fallback: creating money request preview', false, { - transactionParentReportID, - transactionID: transaction.transactionID, - reportID, - }); + parameters.moneyRequestPreviewReportActionID = generatedReportActionID; + } + } } const isInviteOnboardingComplete = introSelected?.isInviteOnboardingComplete ?? false; @@ -1396,20 +1355,16 @@ function getOptimisticChatReport(accountID: number): OptimisticChatReport { }); } -function createTransactionThreadReport( - iouReport?: OnyxEntry, - iouReportAction?: OnyxEntry, - transaction?: Transaction, - transactionViolations?: TransactionViolations, -): OptimisticChatReport | undefined { - // Determine if we need selfDM report (for track expenses or unreported transactions) - const isTrackExpense = !iouReport && ReportActionsUtils.isTrackExpenseAction(iouReportAction); - const isUnreportedTransaction = transaction?.reportID === CONST.REPORT.UNREPORTED_REPORT_ID; - const selfDMReportID = isTrackExpense || isUnreportedTransaction ? findSelfDMReportID() : undefined; +function createTransactionThreadReport(iouReport: OnyxEntry, iouReportAction: OnyxEntry): OptimisticChatReport | undefined { + if (!iouReportAction) { + Log.warn('Cannot build transaction thread report without iouReportAction parameter'); + return; + } let reportToUse = iouReport; // For track expenses without iouReport, get the selfDM report - if (isTrackExpense && selfDMReportID) { + if (!iouReport && ReportActionsUtils.isTrackExpenseAction(iouReportAction)) { + const selfDMReportID = findSelfDMReportID(); reportToUse = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${selfDMReportID}`]; } @@ -1418,29 +1373,9 @@ function createTransactionThreadReport( return; } - // Sync fresh report data from snapshot to allReports. When navigating from search, - // allReports may be stale and missing parentReportID/parentReportActionID, causing - // getAllAncestorReportActionIDs() to fail when adding comments optimistically. - if (iouReport?.reportID && reportToUse.reportID === iouReport.reportID) { - Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`, iouReport); - } - const optimisticTransactionThreadReportID = generateReportID(); const optimisticTransactionThread = buildTransactionThread(iouReportAction, reportToUse, undefined, optimisticTransactionThreadReportID); - openReport( - optimisticTransactionThreadReportID, - undefined, - currentUserEmail ? [currentUserEmail] : [], - optimisticTransactionThread, - iouReportAction?.reportActionID, - false, - [], - undefined, - false, - transaction, - transactionViolations, - selfDMReportID, - ); + openReport(optimisticTransactionThreadReportID, undefined, currentUserEmail ? [currentUserEmail] : [], optimisticTransactionThread, iouReportAction?.reportActionID); return optimisticTransactionThread; } @@ -1555,7 +1490,7 @@ function navigateToAndOpenChildReport(childReportID: string | undefined, parentR if (!childReportID) { const participantLogins = PersonalDetailsUtils.getLoginsByAccountIDs(Object.keys(newChat.participants ?? {}).map(Number)); - openReport(newChat.reportID, '', participantLogins, newChat, parentReportAction.reportActionID, undefined, undefined, undefined, true); + openReport(newChat.reportID, '', participantLogins, newChat, parentReportAction.reportActionID, undefined, undefined, undefined, undefined, true); } else { Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${childReportID}`, newChat); } diff --git a/src/pages/home/ReportScreen.tsx b/src/pages/home/ReportScreen.tsx index d227919db11c..f3cb1c39af19 100644 --- a/src/pages/home/ReportScreen.tsx +++ b/src/pages/home/ReportScreen.tsx @@ -322,7 +322,7 @@ function ReportScreen({route, navigation}: ReportScreenProps) { const {transactions: allReportTransactions, violations: allReportViolations} = useTransactionsAndViolationsForReport(reportIDFromRoute); const hasPendingDeletionTransaction = Object.values(allReportTransactions ?? {}).some((transaction) => transaction.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE); - const reportTransactions = useMemo(() => getAllNonDeletedTransactions(allReportTransactions, reportActions, isOffline, true), [allReportTransactions, reportActions, isOffline]); + const reportTransactions = useMemo(() => getAllNonDeletedTransactions(allReportTransactions, reportActions, isOffline), [allReportTransactions, reportActions, isOffline]); // wrapping in useMemo because this is array operation and can cause performance issues const visibleTransactions = useMemo( () => reportTransactions?.filter((transaction) => isOffline || transaction.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE), @@ -507,7 +507,7 @@ function ReportScreen({route, navigation}: ReportScreenProps) { const currentReportTransaction = getReportTransactions(reportID).filter((transaction) => transaction.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE); const oneTransactionID = currentReportTransaction.at(0)?.transactionID; const iouAction = getIOUActionForReportID(reportID, oneTransactionID); - createTransactionThreadReport(report, iouAction, currentReportTransaction.at(0)); + createTransactionThreadReport(report, iouAction); }, [report, reportID]); const isInviteOnboardingComplete = introSelected?.isInviteOnboardingComplete ?? false; @@ -523,7 +523,7 @@ function ReportScreen({route, navigation}: ReportScreenProps) { } // If there is one transaction thread that has not yet been created, we should create it. - if ((transactionThreadReportID === CONST.FAKE_REPORT_ID && !transactionThreadReport) || (visibleTransactions.length === 1 && !transactionThreadReportID)) { + if (transactionThreadReportID === CONST.FAKE_REPORT_ID && !transactionThreadReport) { createOneTransactionThreadReport(); return; } @@ -549,7 +549,6 @@ function ReportScreen({route, navigation}: ReportScreenProps) { isOffline, transactionThreadReportID, transactionThreadReport, - visibleTransactions.length, reportIDFromRoute, reportActionIDFromRoute, createOneTransactionThreadReport, diff --git a/tests/actions/ReportTest.ts b/tests/actions/ReportTest.ts index 6a339277c315..50d05167bc26 100644 --- a/tests/actions/ReportTest.ts +++ b/tests/actions/ReportTest.ts @@ -915,12 +915,8 @@ describe('actions/Report', () => { comment: {comment: 'Legacy expense'}, } as unknown as OnyxTypes.Transaction); - // Get the transaction object from Onyx - const transaction = await getOnyxValue(`${ONYXKEYS.COLLECTION.TRANSACTION}${TXN_ID}` as const); - expect(transaction).toBeTruthy(); - - // Call openReport with transaction object to trigger the legacy preview flow - Report.openReport(CHILD_REPORT_ID, undefined, [], undefined, undefined, false, [], undefined, false, transaction ?? undefined, undefined, SELF_DM_ID); + // Call openReport with transactionID to trigger the legacy preview flow + Report.openReport(CHILD_REPORT_ID, undefined, [], undefined, undefined, false, [], undefined, TXN_ID); await waitForBatchedUpdates(); // Validate the correct Onyx key received the new action and existing one is preserved diff --git a/tests/unit/Search/SearchUIUtilsTest.ts b/tests/unit/Search/SearchUIUtilsTest.ts index 24cee484ae98..0dd018053943 100644 --- a/tests/unit/Search/SearchUIUtilsTest.ts +++ b/tests/unit/Search/SearchUIUtilsTest.ts @@ -2846,21 +2846,14 @@ describe('SearchUIUtils', () => { const hash = 12345; const backTo = '/search/all'; - beforeEach(() => { - jest.clearAllMocks(); - }); - - test('Should create transaction thread report and set optimistic data when IOU action exists (moneyRequestReportActionID is not "0")', () => { + test('Should create transaction thread report and set optimistic data necessary for its preview', () => { const setOptimisticDataForTransactionThreadMock = jest.spyOn(require('@userActions/Search'), 'setOptimisticDataForTransactionThreadPreview'); (createTransactionThreadReport as jest.Mock).mockReturnValue(threadReport); SearchUIUtils.createAndOpenSearchTransactionThread(transactionListItem, hash, backTo, undefined, false); - // Should call setOptimisticDataForTransactionThreadPreview to populate Onyx with snapshot data expect(setOptimisticDataForTransactionThreadMock).toHaveBeenCalled(); - - // Should pass reportActionID but NOT transaction/violations since IOU action exists in backend - expect(createTransactionThreadReport).toHaveBeenCalledWith(report1, iouReportAction, undefined, undefined); + expect(createTransactionThreadReport).toHaveBeenCalledWith(report1, iouReportAction); expect(updateSearchResultsWithTransactionThreadReportID).toHaveBeenCalledWith(hash, transactionID, threadReportID); }); @@ -2873,57 +2866,6 @@ describe('SearchUIUtils', () => { SearchUIUtils.createAndOpenSearchTransactionThread(transactionListItem, hash, backTo, undefined, true); expect(Navigation.navigate).toHaveBeenCalledWith(ROUTES.SEARCH_REPORT.getRoute({reportID: threadReportID, backTo})); }); - - test('Should create transaction thread report for legacy transactions without IOU action (moneyRequestReportActionID = "0")', () => { - const setOptimisticDataForTransactionThreadMock = jest.spyOn(require('@userActions/Search'), 'setOptimisticDataForTransactionThreadPreview'); - (createTransactionThreadReport as jest.Mock).mockReturnValue(threadReport); - - // Create a legacy transaction item with moneyRequestReportActionID = '0' - const legacyTransactionItem = { - ...transactionListItem, - moneyRequestReportActionID: '0', - }; - - SearchUIUtils.createAndOpenSearchTransactionThread(legacyTransactionItem, hash, backTo); - - // Should NOT call setOptimisticDataForTransactionThreadPreview for legacy transactions - expect(setOptimisticDataForTransactionThreadMock).not.toHaveBeenCalled(); - - // Extract the transaction by removing UI-specific and search-specific fields - const { - keyForList, - action, - allActions, - report, - from, - to, - formattedFrom, - formattedTo, - formattedTotal, - formattedMerchant, - date, - shouldShowMerchant, - shouldShowYear, - isAmountColumnWide, - isTaxAmountColumnWide, - violations, - hash: itemHash, - moneyRequestReportActionID, - canDelete, - convertedAmount, - convertedCurrency, - transactionThreadReportID, - isFromOneTransactionReport, - accountID, - policyID: searchPolicyID, - transactionType, - ...expectedTransaction - } = legacyTransactionItem; - - // For legacy transactions (moneyRequestReportActionID = '0'), should pass transaction and violations - // '0' is treated as empty string for reportActionID - expect(createTransactionThreadReport).toHaveBeenCalledWith(report, {reportActionID: ''}, expect.objectContaining(expectedTransaction), violations); - }); }); describe('setOptimisticDataForTransactionThreadPreview', () => { diff --git a/tests/unit/libs/MoneyRequestReportUtils.ts b/tests/unit/libs/MoneyRequestReportUtils.ts index 56bf6d944742..c8eafb6c8f93 100644 --- a/tests/unit/libs/MoneyRequestReportUtils.ts +++ b/tests/unit/libs/MoneyRequestReportUtils.ts @@ -1,4 +1,4 @@ -import {getAllNonDeletedTransactions, getThreadReportIDsForTransactions} from '@libs/MoneyRequestReportUtils'; +import {getThreadReportIDsForTransactions} from '@libs/MoneyRequestReportUtils'; import type {ReportAction, Transaction} from '@src/types/onyx'; import {actionR14932, actionR98765} from '../../../__mocks__/reportData/actions'; import {transactionR14932, transactionR98765} from '../../../__mocks__/reportData/transactions'; @@ -31,43 +31,3 @@ describe('getThreadReportIDsForTransactions', () => { expect(result).toEqual([]); }); }); - -describe('getAllNonDeletedTransactions', () => { - test('should return all transactions that have IOU actions', () => { - const transactions = { - [transactionR14932.transactionID]: transactionR14932, - [transactionR98765.transactionID]: transactionR98765, - }; - const reportActions = [actionR14932, actionR98765]; - - const result = getAllNonDeletedTransactions(transactions, reportActions); - expect(result).toHaveLength(2); - }); - - test('should filter out transactions without IOU actions by default', () => { - const orphanedTransaction = {...transactionR98765, transactionID: 'orphaned123'}; - const transactions = { - [transactionR14932.transactionID]: transactionR14932, - [orphanedTransaction.transactionID]: orphanedTransaction, - }; - const reportActions = [actionR14932]; // Only has action for transactionR14932 - - const result = getAllNonDeletedTransactions(transactions, reportActions, false, false); - expect(result).toHaveLength(1); - expect(result.at(0)?.transactionID).toBe(transactionR14932.transactionID); - }); - - test('should include transactions without IOU actions when includeOrphanedTransactions is true', () => { - const orphanedTransaction = {...transactionR98765, transactionID: 'orphaned123'}; - const transactions = { - [transactionR14932.transactionID]: transactionR14932, - [orphanedTransaction.transactionID]: orphanedTransaction, - }; - const reportActions = [actionR14932]; // Only has action for transactionR14932 - - const result = getAllNonDeletedTransactions(transactions, reportActions, false, true); - expect(result).toHaveLength(2); - expect(result.map((t) => t.transactionID)).toContain(transactionR14932.transactionID); - expect(result.map((t) => t.transactionID)).toContain(orphanedTransaction.transactionID); - }); -});