diff --git a/src/CONST.ts b/src/CONST.ts index 6de65ae74f63..0204558aa83d 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -1000,6 +1000,7 @@ const CONST = { EMPTY_ARRAY, EMPTY_OBJECT, DEFAULT_NUMBER_ID, + FAKE_REPORT_ID: 'FAKE_REPORT_ID', USE_EXPENSIFY_URL, EXPENSIFY_URL, GOOGLE_MEET_URL_ANDROID: 'https://meet.google.com', diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 89f39c8e5510..52abe61774cd 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -343,7 +343,7 @@ const ROUTES = { REPORT: 'r', REPORT_WITH_ID: { route: 'r/:reportID?/:reportActionID?', - getRoute: (reportID: string | undefined, reportActionID?: string, referrer?: string, moneyRequestReportActionID?: string, transactionID?: string) => { + getRoute: (reportID: string | undefined, reportActionID?: string, referrer?: string, moneyRequestReportActionID?: string, transactionID?: string, iouReportID?: string) => { if (!reportID) { Log.warn('Invalid reportID is used to build the REPORT_WITH_ID route'); } @@ -360,6 +360,10 @@ const ROUTES = { queryParams.push(`transactionID=${transactionID}`); } + if (iouReportID) { + queryParams.push(`iouReportID=${iouReportID}`); + } + const queryString = queryParams.length > 0 ? `?${queryParams.join('&')}` : ''; return `${baseRoute}${queryString}` as const; diff --git a/src/components/ReportActionItem/MoneyRequestAction.tsx b/src/components/ReportActionItem/MoneyRequestAction.tsx index e6cdba15948c..4e46244f0268 100644 --- a/src/components/ReportActionItem/MoneyRequestAction.tsx +++ b/src/components/ReportActionItem/MoneyRequestAction.tsx @@ -98,7 +98,7 @@ function MoneyRequestAction({ const transactionID = isMoneyRequestAction(action) ? getOriginalMessage(action)?.IOUTransactionID : CONST.DEFAULT_NUMBER_ID; if (!action?.childReportID && transactionID && action.reportActionID) { const optimisticReportID = generateReportID(); - Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(optimisticReportID, undefined, undefined, action.reportActionID, transactionID)); + Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(optimisticReportID, undefined, undefined, action.reportActionID, transactionID, requestReportID)); return; } diff --git a/src/libs/API/parameters/CreatePerDiemRequestParams.ts b/src/libs/API/parameters/CreatePerDiemRequestParams.ts index b2fe0b541cc5..a33b586719dc 100644 --- a/src/libs/API/parameters/CreatePerDiemRequestParams.ts +++ b/src/libs/API/parameters/CreatePerDiemRequestParams.ts @@ -17,7 +17,7 @@ type CreatePerDiemRequestParams = { createdChatReportActionID?: string; createdIOUReportActionID?: string; reportPreviewReportActionID: string; - transactionThreadReportID: string; + transactionThreadReportID?: string; createdReportActionIDForThread: string | undefined; billable?: boolean; }; diff --git a/src/libs/API/parameters/RequestMoneyParams.ts b/src/libs/API/parameters/RequestMoneyParams.ts index ea375f32fe0d..30f2347fe24c 100644 --- a/src/libs/API/parameters/RequestMoneyParams.ts +++ b/src/libs/API/parameters/RequestMoneyParams.ts @@ -25,8 +25,8 @@ type RequestMoneyParams = { taxAmount: number; billable?: boolean; receiptGpsPoints?: string; - transactionThreadReportID: string; - createdReportActionIDForThread: string | undefined; + transactionThreadReportID?: string; + createdReportActionIDForThread?: string; reimbursible?: boolean; description?: string; }; diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index b6521a75b998..323c6a212a5f 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -1619,6 +1619,7 @@ type ReportsSplitNavigatorParamList = { referrer?: string; moneyRequestReportActionID?: string; transactionID?: string; + iouReportID?: string; }; }; diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 9bfdfafb0c46..c676a7ec178b 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -1175,7 +1175,6 @@ function getOneTransactionThreadReportID( if ( actionType && iouRequestTypes.has(actionType) && - action.childReportID && // Include deleted IOU reportActions if: // - they have an assocaited IOU transaction ID or // - they have visibile childActions (like comments) that we'd want to display @@ -1203,8 +1202,8 @@ function getOneTransactionThreadReportID( return; } - // Ensure we have a childReportID associated with the IOU report action - return singleAction?.childReportID; + // Since we don't always create transaction thread optimistically, we return CONST.FAKE_REPORT_ID + return singleAction?.childReportID ?? CONST.FAKE_REPORT_ID; } /** diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 8d421fca3ea9..b4aa1659781c 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -560,7 +560,7 @@ type OptimisticModifiedExpenseReportAction = Pick< | 'delegateAccountID' > & {reportID?: string}; -type OptimisticMoneyRequestEntities = { +type BaseOptimisticMoneyRequestEntities = { iouReport: Report; type: ValueOf; amount: number; @@ -578,6 +578,10 @@ type OptimisticMoneyRequestEntities = { linkedTrackedExpenseReportAction?: ReportAction; }; +type OptimisticMoneyRequestEntities = BaseOptimisticMoneyRequestEntities & {shouldGenerateOptimisticTransactionThread?: boolean}; +type OptimisticMoneyRequestEntitiesWithTransactionThreadFlag = BaseOptimisticMoneyRequestEntities & {shouldGenerateOptimisticTransactionThread: boolean}; +type OptimisticMoneyRequestEntitiesWithoutTransactionThreadFlag = BaseOptimisticMoneyRequestEntities; + type OptimisticTaskReport = SetRequired< Pick< Report, @@ -6982,6 +6986,7 @@ function buildTransactionThread( reportAction: OnyxEntry, moneyRequestReport: OnyxEntry, existingTransactionThreadReportID?: string, + optimisticTransactionThreadReportID?: string, ): OptimisticChatReport { const participantAccountIDs = [...new Set([currentUserAccountID, Number(reportAction?.actorAccountID)])].filter(Boolean) as number[]; const existingTransactionThreadReport = getReportOrDraftReport(existingTransactionThreadReportID); @@ -7004,6 +7009,7 @@ function buildTransactionThread( notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, parentReportActionID: reportAction?.reportActionID, parentReportID: moneyRequestReport?.reportID, + optimisticReportID: optimisticTransactionThreadReportID, }); } @@ -7016,6 +7022,12 @@ function buildTransactionThread( * 4. Transaction Thread linked to the IOU action via `parentReportActionID` * 5. CREATED action for the Transaction Thread */ +function buildOptimisticMoneyRequestEntities( + optimisticMoneyRequestEntities: OptimisticMoneyRequestEntitiesWithoutTransactionThreadFlag, +): [OptimisticCreatedReportAction, OptimisticCreatedReportAction, OptimisticIOUReportAction, OptimisticChatReport, OptimisticCreatedReportAction | null]; +function buildOptimisticMoneyRequestEntities( + optimisticMoneyRequestEntities: OptimisticMoneyRequestEntitiesWithTransactionThreadFlag, +): [OptimisticCreatedReportAction, OptimisticCreatedReportAction, OptimisticIOUReportAction, OptimisticChatReport | undefined, OptimisticCreatedReportAction | null]; function buildOptimisticMoneyRequestEntities({ iouReport, type, @@ -7029,10 +7041,17 @@ function buildOptimisticMoneyRequestEntities({ isSettlingUp = false, isSendMoneyFlow = false, isOwnPolicyExpenseChat = false, + shouldGenerateOptimisticTransactionThread = true, isPersonalTrackingExpense, existingTransactionThreadReportID, linkedTrackedExpenseReportAction, -}: OptimisticMoneyRequestEntities): [OptimisticCreatedReportAction, OptimisticCreatedReportAction, OptimisticIOUReportAction, OptimisticChatReport, OptimisticCreatedReportAction | null] { +}: OptimisticMoneyRequestEntities): [ + OptimisticCreatedReportAction, + OptimisticCreatedReportAction, + OptimisticIOUReportAction, + OptimisticChatReport | undefined, + OptimisticCreatedReportAction | null, +] { const createdActionForChat = buildOptimisticCreatedReportAction(payeeEmail); // The `CREATED` action must be optimistically generated before the IOU action so that it won't appear after the IOU action in the chat. @@ -7056,11 +7075,11 @@ function buildOptimisticMoneyRequestEntities({ }); // Create optimistic transactionThread and the `CREATED` action for it, if existingTransactionThreadReportID is undefined - const transactionThread = buildTransactionThread(iouAction, iouReport, existingTransactionThreadReportID); - const createdActionForTransactionThread = existingTransactionThreadReportID ? null : buildOptimisticCreatedReportAction(payeeEmail); + const transactionThread = shouldGenerateOptimisticTransactionThread ? buildTransactionThread(iouAction, iouReport, existingTransactionThreadReportID) : undefined; + const createdActionForTransactionThread = !!existingTransactionThreadReportID || !shouldGenerateOptimisticTransactionThread ? null : buildOptimisticCreatedReportAction(payeeEmail); // The IOU action and the transactionThread are co-dependent as parent-child, so we need to link them together - iouAction.childReportID = existingTransactionThreadReportID ?? transactionThread.reportID; + iouAction.childReportID = existingTransactionThreadReportID ?? transactionThread?.reportID; return [createdActionForChat, createdActionForIOUReport, iouAction, transactionThread, createdActionForTransactionThread]; } diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 75ff2de9766d..955eb5d65f1d 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -230,7 +230,7 @@ type MoneyRequestInformation = { createdChatReportActionID?: string; createdIOUReportActionID?: string; reportPreviewAction: OnyxTypes.ReportAction; - transactionThreadReportID: string; + transactionThreadReportID?: string; createdReportActionIDForThread: string | undefined; onyxData: OnyxData; billable?: boolean; @@ -397,6 +397,7 @@ type MoneyRequestInformationParams = { existingTransactionID?: string; existingTransaction?: OnyxEntry; retryParams?: StartSplitBilActionParams | CreateTrackExpenseParams | RequestMoneyInformation | ReplaceReceipt; + shouldGenerateOptimisticTransactionThread?: boolean; }; type MoneyRequestOptimisticParams = { @@ -412,8 +413,8 @@ type MoneyRequestOptimisticParams = { }; transactionParams: { transaction: OnyxTypes.Transaction; - transactionThreadReport: OptimisticChatReport | null; - transactionThreadCreatedReportAction: OptimisticCreatedReportAction | null; + transactionThreadReport?: OptimisticChatReport | null; + transactionThreadCreatedReportAction?: OptimisticCreatedReportAction | null; }; policyRecentlyUsed: { categories?: string[]; @@ -2880,6 +2881,7 @@ function getMoneyRequestInformation(moneyRequestInformation: MoneyRequestInforma existingTransactionID, moneyRequestReportID = '', retryParams, + shouldGenerateOptimisticTransactionThread = true, } = moneyRequestInformation; const {payeeAccountID = userAccountID, payeeEmail = currentUserEmail, participant} = participantParams; const {policy, policyCategories, policyTagList} = policyParams; @@ -2997,9 +2999,9 @@ function getMoneyRequestInformation(moneyRequestInformation: MoneyRequestInforma participants: [participant], transactionID: optimisticTransaction.transactionID, paymentType: isSelectedManagerMcTest(participant.login) ? CONST.IOU.PAYMENT_TYPE.ELSEWHERE : undefined, - existingTransactionThreadReportID: linkedTrackedExpenseReportAction?.childReportID, linkedTrackedExpenseReportAction, + shouldGenerateOptimisticTransactionThread, }); let reportPreviewAction = shouldCreateNewMoneyRequestReport ? null : getReportPreviewAction(chatReport.reportID, iouReport.reportID); @@ -4454,30 +4456,32 @@ const getConvertTrackedExpenseInformation = ( // Build modified expense report action with the transaction changes const modifiedExpenseReportAction = buildOptimisticMovedTrackedExpenseModifiedReportAction(transactionThreadReportID, moneyRequestReportID); - optimisticData?.push({ - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReportID}`, - value: { - [modifiedExpenseReportAction.reportActionID]: modifiedExpenseReportAction as OnyxTypes.ReportAction, - }, - }); - successData?.push({ - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReportID}`, - value: { - [modifiedExpenseReportAction.reportActionID]: {pendingAction: null}, - }, - }); - failureData?.push({ - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReportID}`, - value: { - [modifiedExpenseReportAction.reportActionID]: { - ...(modifiedExpenseReportAction as OnyxTypes.ReportAction), - errors: getMicroSecondOnyxErrorWithTranslationKey('iou.error.genericEditFailureMessage'), + if (transactionThreadReportID) { + optimisticData?.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReportID}`, + value: { + [modifiedExpenseReportAction.reportActionID]: modifiedExpenseReportAction as OnyxTypes.ReportAction, }, - }, - }); + }); + successData?.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReportID}`, + value: { + [modifiedExpenseReportAction.reportActionID]: {pendingAction: null}, + }, + }); + failureData?.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReportID}`, + value: { + [modifiedExpenseReportAction.reportActionID]: { + ...(modifiedExpenseReportAction as OnyxTypes.ReportAction), + errors: getMicroSecondOnyxErrorWithTranslationKey('iou.error.genericEditFailureMessage'), + }, + }, + }); + } return {optimisticData, successData, failureData, modifiedExpenseReportActionID: modifiedExpenseReportAction.reportActionID}; }; @@ -4526,7 +4530,7 @@ type ConvertTrackedExpenseToRequestParams = { merchant: string; created: string; attendees?: Attendee[]; - transactionThreadReportID: string; + transactionThreadReportID?: string; }; chatParams: { reportID: string; @@ -4791,29 +4795,18 @@ function requestMoney(requestMoneyInformation: RequestMoneyInformation) { }, }; - const { - payerAccountID, - payerEmail, - iouReport, - chatReport, - transaction, - iouAction, - createdChatReportActionID, - createdIOUReportActionID, - reportPreviewAction, - transactionThreadReportID, - createdReportActionIDForThread, - onyxData, - } = getMoneyRequestInformation({ - parentChatReport: isMovingTransactionFromTrackExpense ? undefined : currentChatReport, - participantParams, - policyParams, - transactionParams, - moneyRequestReportID, - existingTransactionID, - existingTransaction: isDistanceRequestTransactionUtils(existingTransaction) ? existingTransaction : undefined, - retryParams, - }); + const {payerAccountID, payerEmail, iouReport, chatReport, transaction, iouAction, createdChatReportActionID, createdIOUReportActionID, reportPreviewAction, onyxData} = + getMoneyRequestInformation({ + parentChatReport: isMovingTransactionFromTrackExpense ? undefined : currentChatReport, + participantParams, + policyParams, + transactionParams, + moneyRequestReportID, + existingTransactionID, + existingTransaction: isDistanceRequestTransactionUtils(existingTransaction) ? existingTransaction : undefined, + retryParams, + shouldGenerateOptimisticTransactionThread: false, + }); const activeReportID = isMoneyRequestReport ? report?.reportID : chatReport.reportID; switch (action) { @@ -4851,7 +4844,6 @@ function requestMoney(requestMoneyInformation: RequestMoneyInformation) { actionableWhisperReportActionID, linkedTrackedExpenseReportAction, linkedTrackedExpenseReportID, - transactionThreadReportID, }, chatParams: { reportID: chatReport.reportID, @@ -4893,8 +4885,6 @@ function requestMoney(requestMoneyInformation: RequestMoneyInformation) { billable, // This needs to be a string of JSON because of limitations with the fetch() API and nested objects receiptGpsPoints: gpsPoints ? JSON.stringify(gpsPoints) : undefined, - transactionThreadReportID, - createdReportActionIDForThread, reimbursible, description: parsedComment, }; diff --git a/src/pages/home/ReportScreen.tsx b/src/pages/home/ReportScreen.tsx index 60653a69ece2..9a8e05745ad8 100644 --- a/src/pages/home/ReportScreen.tsx +++ b/src/pages/home/ReportScreen.tsx @@ -39,7 +39,9 @@ import {getPersonalDetailsForAccountIDs} from '@libs/OptionsListUtils'; import {getDisplayNameOrDefault} from '@libs/PersonalDetailsUtils'; import { getCombinedReportActions, + getIOUActionForReportID, getOneTransactionThreadReportID, + getReportAction, isCreatedAction, isDeletedParentAction, isMoneyRequestAction, @@ -47,11 +49,15 @@ import { shouldReportActionBeVisible, } from '@libs/ReportActionsUtils'; import { + buildTransactionThread, canEditReportAction, canUserPerformWriteAction, findLastAccessedReport, + generateReportID, getParticipantsAccountIDsForDisplay, getReportOfflinePendingActionAndErrors, + getReportOrDraftReport, + getReportTransactions, isChatThread, isConciergeChatReport, isGroupChat, @@ -289,6 +295,7 @@ function ReportScreen({route, navigation}: ReportScreenProps) { const isLinkedMessagePageReady = isLinkedMessageAvailable && (reportActions.length - indexOfLinkedMessage >= CONST.REPORT.MIN_INITIAL_REPORT_ACTION_COUNT || doesCreatedActionExists()); const transactionThreadReportID = getOneTransactionThreadReportID(reportID, reportActions ?? [], isOffline); + const [transactionThreadReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`); const [transactionThreadReportActions = {}] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReportID}`); const combinedReportActions = getCombinedReportActions(reportActions, transactionThreadReportID ?? null, Object.values(transactionThreadReportActions)); const lastReportAction = [...combinedReportActions, parentReportAction].find((action) => canEditReportAction(action) && !isMoneyRequestAction(action)); @@ -428,17 +435,30 @@ function ReportScreen({route, navigation}: ReportScreenProps) { ); const fetchReport = useCallback(() => { - const moneyRequestReportActionID: string | undefined = route.params?.moneyRequestReportActionID; - const transactionID: string | undefined = route.params?.transactionID; + const {moneyRequestReportActionID, transactionID, iouReportID} = route.params; - // When we get here with a moneyRequestReportActionID and a transactionID from the route it means we don't have the trasaction thread created yet + // When we get here with a moneyRequestReportActionID and a transactionID from the route it means we don't have the transaction thread created yet // so we have to call OpenReport in a way that the transaction thread will be created and attached to the parentReportAction - if (moneyRequestReportActionID && transactionID && currentUserEmail) { - openReport(reportIDFromRoute, '', [currentUserEmail], undefined, moneyRequestReportActionID); + if (moneyRequestReportActionID && transactionID && currentUserEmail && !report) { + const iouReport = getReportOrDraftReport(iouReportID); + const iouAction = getReportAction(iouReportID, moneyRequestReportActionID); + const optimisticTransactionThread = buildTransactionThread(iouAction, iouReport, undefined, reportIDFromRoute); + openReport(reportIDFromRoute, undefined, [currentUserEmail], optimisticTransactionThread, moneyRequestReportActionID); return; } + + // If there is one transaction thread that has not yet been created, we should create it. + if (transactionThreadReportID === CONST.FAKE_REPORT_ID && !transactionThreadReport && currentUserEmail) { + const optimisticTransactionThreadReportID = generateReportID(); + const transactions = getReportTransactions(reportID); + const oneTransactionID = transactions.at(0)?.transactionID; + const iouAction = getIOUActionForReportID(reportID, oneTransactionID); + const optimisticTransactionThread = buildTransactionThread(iouAction, report, undefined, optimisticTransactionThreadReportID); + openReport(optimisticTransactionThreadReportID, undefined, [currentUserEmail], optimisticTransactionThread, iouAction?.reportActionID); + } + openReport(reportIDFromRoute, reportActionIDFromRoute); - }, [route.params?.moneyRequestReportActionID, route.params?.transactionID, reportIDFromRoute, reportActionIDFromRoute, currentUserEmail]); + }, [route.params, reportIDFromRoute, reportActionIDFromRoute, currentUserEmail, report, reportID, transactionThreadReport, transactionThreadReportID]); useEffect(() => { if (!reportID || !isFocused) { diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index 297849e3620d..6d80b5279e70 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -368,8 +368,6 @@ describe('actions/IOU', () => { let createdAction: OnyxEntry; let iouAction: OnyxEntry>; let transactionID: string | undefined; - let transactionThread: OnyxEntry; - let transactionThreadCreatedAction: OnyxEntry; mockFetch?.pause?.(); requestMoney({ report: {reportID: ''}, @@ -397,16 +395,14 @@ describe('actions/IOU', () => { callback: (allReports) => { Onyx.disconnect(connection); - // A chat report, a transaction thread, and an iou report should be created + // A chat report and an iou report should be created const chatReports = Object.values(allReports ?? {}).filter((report) => report?.type === CONST.REPORT.TYPE.CHAT); const iouReports = Object.values(allReports ?? {}).filter((report) => report?.type === CONST.REPORT.TYPE.IOU); - expect(Object.keys(chatReports).length).toBe(2); + expect(Object.keys(chatReports).length).toBe(1); expect(Object.keys(iouReports).length).toBe(1); const chatReport = chatReports.at(0); - const transactionThreadReport = chatReports.at(1); const iouReport = iouReports.at(0); iouReportID = iouReport?.reportID; - transactionThread = transactionThreadReport; expect(iouReport?.participants).toEqual({ [RORY_ACCOUNT_ID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN}, @@ -469,29 +465,6 @@ describe('actions/IOU', () => { }); }), ) - .then( - () => - new Promise((resolve) => { - const connection = Onyx.connect({ - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThread?.reportID}`, - waitForCollectionCallback: false, - callback: (reportActionsForTransactionThread) => { - Onyx.disconnect(connection); - - // The transaction thread should have a CREATED action - expect(Object.values(reportActionsForTransactionThread ?? {}).length).toBe(1); - const createdActions = Object.values(reportActionsForTransactionThread ?? {}).filter( - (reportAction) => reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED, - ); - expect(Object.values(createdActions).length).toBe(1); - transactionThreadCreatedAction = createdActions.at(0); - - expect(transactionThreadCreatedAction?.pendingAction).toBe(CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); - resolve(); - }, - }); - }), - ) .then( () => new Promise((resolve) => { @@ -954,8 +927,6 @@ describe('actions/IOU', () => { let createdAction: OnyxEntry; let iouAction: OnyxEntry>; let transactionID: string | undefined; - let transactionThreadReport: OnyxEntry; - let transactionThreadAction: OnyxEntry; mockFetch?.pause?.(); requestMoney({ report: {reportID: ''}, @@ -984,14 +955,13 @@ describe('actions/IOU', () => { callback: (allReports) => { Onyx.disconnect(connection); - // A chat report, transaction thread and an iou report should be created + // A chat report and an iou report should be created const chatReports = Object.values(allReports ?? {}).filter((report) => report?.type === CONST.REPORT.TYPE.CHAT); const iouReports = Object.values(allReports ?? {}).filter((report) => report?.type === CONST.REPORT.TYPE.IOU); - expect(Object.values(chatReports).length).toBe(2); + expect(Object.values(chatReports).length).toBe(1); expect(Object.values(iouReports).length).toBe(1); const chatReport = chatReports.at(0); chatReportID = chatReport?.reportID; - transactionThreadReport = chatReports.at(1); const iouReport = iouReports.at(0); iouReportID = iouReport?.reportID; @@ -1104,24 +1074,6 @@ describe('actions/IOU', () => { }); }), ) - .then( - () => - new Promise((resolve) => { - const connection = Onyx.connect({ - key: ONYXKEYS.COLLECTION.REPORT_ACTIONS, - waitForCollectionCallback: true, - callback: (reportActionsForTransactionThread) => { - Onyx.disconnect(connection); - expect(Object.values(reportActionsForTransactionThread ?? {}).length).toBe(3); - transactionThreadAction = Object.values( - reportActionsForTransactionThread?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReport?.reportID}`] ?? {}, - ).find((reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED); - expect(transactionThreadAction?.pendingAction).toBe(CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); - resolve(); - }, - }); - }), - ) .then( () => new Promise((resolve) => { @@ -1188,22 +1140,6 @@ describe('actions/IOU', () => { }), ) - // Then the reportAction from transaction report should be removed from Onyx - .then( - () => - new Promise((resolve) => { - const connection = Onyx.connect({ - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReport?.reportID}`, - waitForCollectionCallback: false, - callback: (reportActionsForReport) => { - Onyx.disconnect(connection); - expect(reportActionsForReport).toMatchObject({}); - resolve(); - }, - }); - }), - ) - // Along with the associated transaction .then( () => @@ -1227,9 +1163,6 @@ describe('actions/IOU', () => { if (chatReportID) { deleteReport(chatReportID); } - if (transactionThreadReport?.reportID) { - deleteReport(transactionThreadReport?.reportID); - } resolve(); }), )