From 0e07520100780643a85047bfdc0e5ef4145b2cd1 Mon Sep 17 00:00:00 2001 From: Carlos Alvarez Date: Tue, 12 Nov 2024 14:19:52 -0700 Subject: [PATCH] Revert "Move RBR to workspace chats instead of transaction threads" --- .../LHNOptionsList/OptionRowLHNData.tsx | 2 +- .../MoneyRequestPreviewContent.tsx | 4 +- .../ReportActionItem/ReportPreview.tsx | 5 +- src/libs/DebugUtils.ts | 2 +- src/libs/OptionsListUtils.ts | 2 +- src/libs/ReportUtils.ts | 90 ++++++++++++------- src/libs/SidebarUtils.ts | 21 +++-- src/libs/TransactionUtils/index.ts | 33 ++++--- src/libs/WorkspacesSettingsUtils.ts | 8 +- src/pages/Debug/Report/DebugReportPage.tsx | 6 +- src/types/onyx/TransactionViolation.ts | 3 - tests/unit/DebugUtilsTest.ts | 79 ++++++++++++---- 12 files changed, 177 insertions(+), 78 deletions(-) diff --git a/src/components/LHNOptionsList/OptionRowLHNData.tsx b/src/components/LHNOptionsList/OptionRowLHNData.tsx index 0fe2a1542ca3..3c40210a5d99 100644 --- a/src/components/LHNOptionsList/OptionRowLHNData.tsx +++ b/src/components/LHNOptionsList/OptionRowLHNData.tsx @@ -37,7 +37,7 @@ function OptionRowLHNData({ const optionItemRef = useRef(); - const shouldDisplayViolations = ReportUtils.shouldDisplayViolationsRBRInLHN(fullReport, transactionViolations); + const shouldDisplayViolations = ReportUtils.shouldDisplayTransactionThreadViolations(fullReport, transactionViolations, parentReportAction); const shouldDisplayReportViolations = ReportUtils.isReportOwner(fullReport) && ReportUtils.hasReportViolations(reportID); const optionItem = useMemo(() => { diff --git a/src/components/ReportActionItem/MoneyRequestPreview/MoneyRequestPreviewContent.tsx b/src/components/ReportActionItem/MoneyRequestPreview/MoneyRequestPreviewContent.tsx index 8d9def814549..336b7dea9654 100644 --- a/src/components/ReportActionItem/MoneyRequestPreview/MoneyRequestPreviewContent.tsx +++ b/src/components/ReportActionItem/MoneyRequestPreview/MoneyRequestPreviewContent.tsx @@ -115,8 +115,8 @@ function MoneyRequestPreviewContent({ const isOnHold = TransactionUtils.isOnHold(transaction); const isSettlementOrApprovalPartial = !!iouReport?.pendingFields?.partial; const isPartialHold = isSettlementOrApprovalPartial && isOnHold; - const hasViolations = TransactionUtils.hasViolation(transaction?.transactionID ?? '-1', transactionViolations, true); - const hasNoticeTypeViolations = TransactionUtils.hasNoticeTypeViolation(transaction?.transactionID ?? '-1', transactionViolations, true) && ReportUtils.isPaidGroupPolicy(iouReport); + const hasViolations = TransactionUtils.hasViolation(transaction?.transactionID ?? '-1', transactionViolations); + const hasNoticeTypeViolations = TransactionUtils.hasNoticeTypeViolation(transaction?.transactionID ?? '-1', transactionViolations) && ReportUtils.isPaidGroupPolicy(iouReport); const hasFieldErrors = TransactionUtils.hasMissingSmartscanFields(transaction); const isDistanceRequest = TransactionUtils.isDistanceRequest(transaction); const isFetchingWaypointsFromServer = TransactionUtils.isFetchingWaypointsFromServer(transaction); diff --git a/src/components/ReportActionItem/ReportPreview.tsx b/src/components/ReportActionItem/ReportPreview.tsx index 1edb6fe9fc9f..d476d1198808 100644 --- a/src/components/ReportActionItem/ReportPreview.tsx +++ b/src/components/ReportActionItem/ReportPreview.tsx @@ -157,9 +157,8 @@ function ReportPreview({ const hasErrors = (hasMissingSmartscanFields && !iouSettled) || // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - ReportUtils.hasViolations(iouReportID, transactionViolations, true) || - ReportUtils.hasNoticeTypeViolations(iouReportID, transactionViolations, true) || - ReportUtils.hasWarningTypeViolations(iouReportID, transactionViolations, true) || + ReportUtils.hasViolations(iouReportID, transactionViolations) || + ReportUtils.hasWarningTypeViolations(iouReportID, transactionViolations) || (ReportUtils.isReportOwner(iouReport) && ReportUtils.hasReportViolations(iouReportID)) || ReportUtils.hasActionsWithErrors(iouReportID); const lastThreeTransactionsWithReceipts = transactionsWithReceipts.slice(-3); diff --git a/src/libs/DebugUtils.ts b/src/libs/DebugUtils.ts index 223c04df4eac..6b3b2a70ede0 100644 --- a/src/libs/DebugUtils.ts +++ b/src/libs/DebugUtils.ts @@ -588,7 +588,7 @@ function getReasonForShowingRowInLHN(report: OnyxEntry, hasRBR = false): return null; } - const doesReportHaveViolations = ReportUtils.shouldDisplayViolationsRBRInLHN(report, transactionViolations); + const doesReportHaveViolations = ReportUtils.shouldShowViolations(report, transactionViolations); const reason = ReportUtils.reasonForReportToBeInOptionList({ report, diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 8d1084b5342f..6bcb353cf065 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1704,7 +1704,7 @@ function getOptions( // Filter out all the reports that shouldn't be displayed const filteredReportOptions = options.reports.filter((option) => { const report = option.item; - const doesReportHaveViolations = ReportUtils.shouldDisplayViolationsRBRInLHN(report, transactionViolations); + const doesReportHaveViolations = ReportUtils.shouldShowViolations(report, transactionViolations); return ReportUtils.shouldReportBeInOptionList({ report, diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 1cd37cf94ffe..73721d094ebe 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -6324,53 +6324,65 @@ function shouldHideReport(report: OnyxEntry, currentReportId: string): b } /** - * Should we display a RBR on the LHN on this report due to violations? + * Checks to see if a report's parentAction is an expense that contains a violation type of either violation or warning */ -function shouldDisplayViolationsRBRInLHN(report: OnyxEntry, transactionViolations: OnyxCollection): boolean { - // We only show the RBR in the highest level, which is the workspace chat - if (!report || !isPolicyExpenseChat(report)) { +function doesTransactionThreadHaveViolations( + report: OnyxInputOrEntry, + transactionViolations: OnyxCollection, + parentReportAction: OnyxInputOrEntry, +): boolean { + if (!ReportActionsUtils.isMoneyRequestAction(parentReportAction)) { return false; } - - // We only show the RBR to the submitter - if (!isCurrentUserSubmitter(report.reportID ?? '')) { + const {IOUTransactionID, IOUReportID} = ReportActionsUtils.getOriginalMessage(parentReportAction) ?? {}; + if (!IOUTransactionID || !IOUReportID) { return false; } - - // Get all potential reports, which are the ones that are: - // - Owned by the same user - // - Are either open or submitted - // - Belong to the same workspace - // And if any have a violation, then it should have a RBR - const allReports = Object.values(ReportConnection.getAllReports() ?? {}) as Report[]; - const potentialReports = allReports.filter((r) => r.ownerAccountID === currentUserAccountID && (r.stateNum ?? 0) <= 1 && r.policyID === report.policyID); - return potentialReports.some( - (potentialReport) => hasViolations(potentialReport.reportID, transactionViolations) || hasWarningTypeViolations(potentialReport.reportID, transactionViolations), + if (!isCurrentUserSubmitter(IOUReportID)) { + return false; + } + if (report?.stateNum !== CONST.REPORT.STATE_NUM.OPEN && report?.stateNum !== CONST.REPORT.STATE_NUM.SUBMITTED) { + return false; + } + return ( + TransactionUtils.hasViolation(IOUTransactionID, transactionViolations) || + TransactionUtils.hasWarningTypeViolation(IOUTransactionID, transactionViolations) || + (isPaidGroupPolicy(report) && TransactionUtils.hasModifiedAmountOrDateViolation(IOUTransactionID, transactionViolations)) ); } /** - * Checks to see if a report contains a violation + * Checks if we should display violation - we display violations when the expense has violation and it is not settled */ -function hasViolations(reportID: string, transactionViolations: OnyxCollection, shouldShowInReview?: boolean): boolean { - const transactions = reportsTransactions[reportID] ?? []; - return transactions.some((transaction) => TransactionUtils.hasViolation(transaction.transactionID, transactionViolations, shouldShowInReview)); +function shouldDisplayTransactionThreadViolations( + report: OnyxEntry, + transactionViolations: OnyxCollection, + parentReportAction: OnyxEntry, +): boolean { + if (!ReportActionsUtils.isMoneyRequestAction(parentReportAction)) { + return false; + } + const {IOUReportID} = ReportActionsUtils.getOriginalMessage(parentReportAction) ?? {}; + if (isSettled(IOUReportID) || isReportApproved(IOUReportID?.toString())) { + return false; + } + return doesTransactionThreadHaveViolations(report, transactionViolations, parentReportAction); } /** - * Checks to see if a report contains a violation of type `warning` + * Checks to see if a report contains a violation */ -function hasWarningTypeViolations(reportID: string, transactionViolations: OnyxCollection, shouldShowInReview?: boolean): boolean { +function hasViolations(reportID: string, transactionViolations: OnyxCollection): boolean { const transactions = reportsTransactions[reportID] ?? []; - return transactions.some((transaction) => TransactionUtils.hasWarningTypeViolation(transaction.transactionID, transactionViolations, shouldShowInReview)); + return transactions.some((transaction) => TransactionUtils.hasViolation(transaction.transactionID, transactionViolations)); } /** - * Checks to see if a report contains a violation of type `notice` + * Checks to see if a report contains a violation of type `warning` */ -function hasNoticeTypeViolations(reportID: string, transactionViolations: OnyxCollection, shouldShowInReview?: boolean): boolean { +function hasWarningTypeViolations(reportID: string, transactionViolations: OnyxCollection): boolean { const transactions = reportsTransactions[reportID] ?? []; - return transactions.some((transaction) => TransactionUtils.hasNoticeTypeViolation(transaction.transactionID, transactionViolations, shouldShowInReview)); + return transactions.some((transaction) => TransactionUtils.hasWarningTypeViolation(transaction.transactionID, transactionViolations)); } function hasReportViolations(reportID: string) { @@ -6392,6 +6404,23 @@ function shouldAdminsRoomBeVisible(report: OnyxEntry): boolean { return true; } +/** + * Check whether report has violations + */ +function shouldShowViolations(report: Report, transactionViolations: OnyxCollection) { + const {parentReportID, parentReportActionID} = report ?? {}; + const canGetParentReport = parentReportID && parentReportActionID && allReportActions; + if (!canGetParentReport) { + return false; + } + const parentReportActions = allReportActions ? allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`] ?? {} : {}; + const parentReportAction = parentReportActions[parentReportActionID] ?? null; + if (!parentReportAction) { + return false; + } + return shouldDisplayTransactionThreadViolations(report, transactionViolations, parentReportAction); +} + type ReportErrorsAndReportActionThatRequiresAttention = { errors: ErrorFields; reportAction?: OnyxEntry; @@ -6474,7 +6503,7 @@ function hasReportErrorsOtherThanFailedReceipt(report: Report, doesReportHaveVio let doesTransactionThreadReportHasViolations = false; if (oneTransactionThreadReportID) { const transactionReport = getReport(oneTransactionThreadReportID); - doesTransactionThreadReportHasViolations = !!transactionReport && shouldDisplayViolationsRBRInLHN(transactionReport, transactionViolations); + doesTransactionThreadReportHasViolations = !!transactionReport && shouldShowViolations(transactionReport, transactionViolations); } return ( doesTransactionThreadReportHasViolations || @@ -8468,6 +8497,7 @@ export { chatIncludesConcierge, createDraftTransactionAndNavigateToParticipantSelector, doesReportBelongToWorkspace, + doesTransactionThreadHaveViolations, findLastAccessedReport, findSelfDMReportID, formatReportLastMessageText, @@ -8571,7 +8601,6 @@ export { hasUpdatedTotal, hasViolations, hasWarningTypeViolations, - hasNoticeTypeViolations, isActionCreator, isAdminRoom, isAdminsOnlyPostingRoom, @@ -8673,7 +8702,7 @@ export { shouldDisableRename, shouldDisableThread, shouldDisplayThreadReplies, - shouldDisplayViolationsRBRInLHN, + shouldDisplayTransactionThreadViolations, shouldReportBeInOptionList, shouldReportShowSubscript, shouldShowFlagComment, @@ -8721,6 +8750,7 @@ export { buildOptimisticChangeFieldAction, isPolicyRelatedReport, hasReportErrorsOtherThanFailedReceipt, + shouldShowViolations, getAllReportErrors, getAllReportActionsErrorsAndReportActionThatRequiresAttention, hasInvoiceReports, diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index b8acec00af05..d47cee3745a0 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -110,7 +110,7 @@ function getOrderedReportIDs( return; } const parentReportAction = ReportActionsUtils.getReportAction(report?.parentReportID ?? '-1', report?.parentReportActionID ?? '-1'); - const doesReportHaveViolations = ReportUtils.shouldDisplayViolationsRBRInLHN(report, transactionViolations); + const doesReportHaveViolations = ReportUtils.shouldShowViolations(report, transactionViolations); const isHidden = ReportUtils.getReportNotificationPreference(report) === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN; const isFocused = report.reportID === currentReportId; const hasErrorsOtherThanFailedReceipt = ReportUtils.hasReportErrorsOtherThanFailedReceipt(report, doesReportHaveViolations, transactionViolations); @@ -239,11 +239,22 @@ function getReasonAndReportActionThatHasRedBrickRoad( ): ReasonAndReportActionThatHasRedBrickRoad | null { const {errors, reportAction} = ReportUtils.getAllReportActionsErrorsAndReportActionThatRequiresAttention(report, reportActions); const hasErrors = Object.keys(errors).length !== 0; + const oneTransactionThreadReportID = ReportActionsUtils.getOneTransactionThreadReportID(report.reportID, ReportActionsUtils.getAllReportActions(report.reportID)); - if (ReportUtils.shouldDisplayViolationsRBRInLHN(report, transactionViolations)) { - return { - reason: CONST.RBR_REASONS.HAS_TRANSACTION_THREAD_VIOLATIONS, - }; + if (oneTransactionThreadReportID) { + const oneTransactionThreadReport = ReportUtils.getReport(oneTransactionThreadReportID); + + if ( + ReportUtils.shouldDisplayTransactionThreadViolations( + oneTransactionThreadReport, + transactionViolations, + ReportActionsUtils.getAllReportActions(report.reportID)[oneTransactionThreadReport?.parentReportActionID ?? '-1'], + ) + ) { + return { + reason: CONST.RBR_REASONS.HAS_TRANSACTION_THREAD_VIOLATIONS, + }; + } } if (hasErrors) { diff --git a/src/libs/TransactionUtils/index.ts b/src/libs/TransactionUtils/index.ts index 1fc7cad2f456..25d0d93c99c7 100644 --- a/src/libs/TransactionUtils/index.ts +++ b/src/libs/TransactionUtils/index.ts @@ -866,37 +866,41 @@ function isOnHoldByTransactionID(transactionID: string): boolean { /** * Checks if any violations for the provided transaction are of type 'violation' */ -function hasViolation(transactionID: string, transactionViolations: OnyxCollection, showInReview?: boolean): boolean { +function hasViolation(transactionID: string, transactionViolations: OnyxCollection): boolean { return !!transactionViolations?.[ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS + transactionID]?.some( - (violation: TransactionViolation) => violation.type === CONST.VIOLATION_TYPES.VIOLATION && (showInReview === undefined || showInReview === (violation.showInReview ?? false)), + (violation: TransactionViolation) => violation.type === CONST.VIOLATION_TYPES.VIOLATION, ); } /** * Checks if any violations for the provided transaction are of type 'notice' */ -function hasNoticeTypeViolation(transactionID: string, transactionViolations: OnyxCollection, showInReview?: boolean): boolean { - return !!transactionViolations?.[ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS + transactionID]?.some( - (violation: TransactionViolation) => violation.type === CONST.VIOLATION_TYPES.NOTICE && (showInReview === undefined || showInReview === (violation.showInReview ?? false)), - ); +function hasNoticeTypeViolation(transactionID: string, transactionViolations: OnyxCollection): boolean { + return !!transactionViolations?.[ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS + transactionID]?.some((violation: TransactionViolation) => violation.type === CONST.VIOLATION_TYPES.NOTICE); } /** * Checks if any violations for the provided transaction are of type 'warning' */ -function hasWarningTypeViolation(transactionID: string, transactionViolations: OnyxCollection, showInReview?: boolean | null): boolean { - const violations = transactionViolations?.[ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS + transactionID]; - const warningTypeViolations = - violations?.filter( - (violation: TransactionViolation) => violation.type === CONST.VIOLATION_TYPES.WARNING && (showInReview === null || showInReview === (violation.showInReview ?? false)), - ) ?? []; - +function hasWarningTypeViolation(transactionID: string, transactionViolations: OnyxCollection): boolean { + const warningTypeViolations = transactionViolations?.[ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS + transactionID]?.filter( + (violation: TransactionViolation) => violation.type === CONST.VIOLATION_TYPES.WARNING, + ); const hasOnlyDupeDetectionViolation = warningTypeViolations?.every((violation: TransactionViolation) => violation.name === CONST.VIOLATIONS.DUPLICATED_TRANSACTION); if (!Permissions.canUseDupeDetection(allBetas ?? []) && hasOnlyDupeDetectionViolation) { return false; } - return warningTypeViolations.length > 0; + return !!warningTypeViolations && warningTypeViolations.length > 0; +} + +/** + * Checks if any violations for the provided transaction are of modifiedAmount or modifiedDate + */ +function hasModifiedAmountOrDateViolation(transactionID: string, transactionViolations: OnyxCollection): boolean { + return !!transactionViolations?.[ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS + transactionID]?.some( + (violation: TransactionViolation) => violation.name === CONST.VIOLATIONS.MODIFIED_AMOUNT || violation.name === CONST.VIOLATIONS.MODIFIED_DATE, + ); } /** @@ -1288,6 +1292,7 @@ export { shouldShowBrokenConnectionViolation, hasNoticeTypeViolation, hasWarningTypeViolation, + hasModifiedAmountOrDateViolation, isCustomUnitRateIDForP2P, getRateID, getTransaction, diff --git a/src/libs/WorkspacesSettingsUtils.ts b/src/libs/WorkspacesSettingsUtils.ts index 18e2fa179764..eb03d8b6def9 100644 --- a/src/libs/WorkspacesSettingsUtils.ts +++ b/src/libs/WorkspacesSettingsUtils.ts @@ -78,7 +78,13 @@ const getBrickRoadForPolicy = (report: Report, altReportActions?: OnyxCollection if (oneTransactionThreadReportID && !doesReportContainErrors) { const oneTransactionThreadReport = ReportUtils.getReport(oneTransactionThreadReportID); - if (ReportUtils.shouldDisplayViolationsRBRInLHN(oneTransactionThreadReport, allTransactionViolations)) { + if ( + ReportUtils.shouldDisplayTransactionThreadViolations( + oneTransactionThreadReport, + allTransactionViolations, + reportActions[oneTransactionThreadReport?.parentReportActionID ?? '-1'], + ) + ) { doesReportContainErrors = CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR; } } diff --git a/src/pages/Debug/Report/DebugReportPage.tsx b/src/pages/Debug/Report/DebugReportPage.tsx index 67fa0a6c5113..5fa26cbf1835 100644 --- a/src/pages/Debug/Report/DebugReportPage.tsx +++ b/src/pages/Debug/Report/DebugReportPage.tsx @@ -53,13 +53,15 @@ function DebugReportPage({ const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`); const [reportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`); const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS); + const [parentReportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report?.parentReportID ?? '-1'}`); + const parentReportAction = parentReportActions && report?.parentReportID ? parentReportActions[report?.parentReportActionID ?? '-1'] : undefined; const metadata = useMemo(() => { if (!report) { return []; } - const shouldDisplayViolations = ReportUtils.shouldDisplayViolationsRBRInLHN(report, transactionViolations); + const shouldDisplayViolations = ReportUtils.shouldDisplayTransactionThreadViolations(report, transactionViolations, parentReportAction); const shouldDisplayReportViolations = ReportUtils.isReportOwner(report) && ReportUtils.hasReportViolations(reportID); const hasViolations = !!shouldDisplayViolations || shouldDisplayReportViolations; const {reason: reasonGBR, reportAction: reportActionGBR} = DebugUtils.getReasonAndReportActionForGBRInLHNRow(report) ?? {}; @@ -111,7 +113,7 @@ function DebugReportPage({ : undefined, }, ]; - }, [report, reportActions, reportID, transactionViolations, translate]); + }, [parentReportAction, report, reportActions, reportID, transactionViolations, translate]); if (!report) { return ; diff --git a/src/types/onyx/TransactionViolation.ts b/src/types/onyx/TransactionViolation.ts index bfb215a1bbdb..bf8ecc7ebdde 100644 --- a/src/types/onyx/TransactionViolation.ts +++ b/src/types/onyx/TransactionViolation.ts @@ -92,9 +92,6 @@ type TransactionViolation = { /** Additional violation information to provide the user */ data?: TransactionViolationData; - - /** Indicates if this violation should be shown in review */ - showInReview?: boolean; }; /** Collection of transaction violations */ diff --git a/tests/unit/DebugUtilsTest.ts b/tests/unit/DebugUtilsTest.ts index abeaff971194..c5d84341deee 100644 --- a/tests/unit/DebugUtilsTest.ts +++ b/tests/unit/DebugUtilsTest.ts @@ -693,6 +693,46 @@ describe('DebugUtils', () => { }); expect(reason).toBe('debug.reasonVisibleInLHN.pinnedByUser'); }); + it('returns correct reason when report has IOU violations', async () => { + const threadReport = { + ...baseReport, + stateNum: CONST.REPORT.STATE_NUM.OPEN, + statusNum: CONST.REPORT.STATUS_NUM.OPEN, + parentReportID: '0', + parentReportActionID: '0', + }; + await Onyx.multiSet({ + [ONYXKEYS.SESSION]: { + accountID: 1234, + }, + [`${ONYXKEYS.COLLECTION.REPORT}0` as const]: { + reportID: '0', + type: CONST.REPORT.TYPE.EXPENSE, + ownerAccountID: 1234, + }, + [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}0` as const]: { + // eslint-disable-next-line @typescript-eslint/naming-convention + '0': { + reportActionID: '0', + actionName: CONST.REPORT.ACTIONS.TYPE.IOU, + message: { + type: CONST.IOU.REPORT_ACTION_TYPE.CREATE, + IOUTransactionID: '0', + IOUReportID: '0', + }, + }, + }, + [`${ONYXKEYS.COLLECTION.REPORT}1` as const]: threadReport, + [`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}0` as const]: [ + { + type: CONST.VIOLATION_TYPES.VIOLATION, + name: CONST.VIOLATIONS.MODIFIED_AMOUNT, + }, + ], + }); + const reason = DebugUtils.getReasonForShowingRowInLHN(threadReport); + expect(reason).toBe('debug.reasonVisibleInLHN.hasIOUViolations'); + }); it('returns correct reason when report has add workspace room errors', () => { const reason = DebugUtils.getReasonForShowingRowInLHN({ ...baseReport, @@ -1490,13 +1530,28 @@ describe('DebugUtils', () => { ) ?? {}; expect(reason).toBe('debug.reasonRBR.hasViolations'); }); - it('returns correct reason when there are reports on the workspace chat with violations', async () => { + it('returns correct reason when there are transaction thread violations', async () => { const report: Report = { reportID: '0', - type: CONST.REPORT.TYPE.CHAT, + type: CONST.REPORT.TYPE.EXPENSE, ownerAccountID: 1234, - policyID: '1', - chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, + }; + const reportActions: ReportActions = { + // eslint-disable-next-line @typescript-eslint/naming-convention + '0': { + reportActionID: '0', + actionName: CONST.REPORT.ACTIONS.TYPE.IOU, + message: { + type: CONST.IOU.REPORT_ACTION_TYPE.CREATE, + IOUTransactionID: '0', + IOUReportID: '0', + amount: 10, + currency: CONST.CURRENCY.USD, + text: '', + }, + created: '2024-07-13 06:02:11.111', + childReportID: '1', + }, }; await Onyx.multiSet({ [ONYXKEYS.SESSION]: { @@ -1507,23 +1562,17 @@ describe('DebugUtils', () => { reportID: '1', parentReportActionID: '0', stateNum: CONST.REPORT.STATE_NUM.OPEN, - ownerAccountID: 1234, - policyID: '1', - }, - [`${ONYXKEYS.COLLECTION.TRANSACTION}1` as const]: { - transactionID: '1', - amount: 10, - modifiedAmount: 10, - reportID: '0', + statusNum: CONST.REPORT.STATE_NUM.SUBMITTED, }, - [`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}1` as const]: [ + [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}0` as const]: reportActions, + [`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}0` as const]: [ { type: CONST.VIOLATION_TYPES.VIOLATION, - name: CONST.VIOLATIONS.MISSING_CATEGORY, + name: CONST.VIOLATIONS.MODIFIED_AMOUNT, }, ], }); - const {reason} = DebugUtils.getReasonAndReportActionForRBRInLHNRow(report, {}, false) ?? {}; + const {reason} = DebugUtils.getReasonAndReportActionForRBRInLHNRow(report, reportActions, false) ?? {}; expect(reason).toBe('debug.reasonRBR.hasTransactionThreadViolations'); }); });