diff --git a/src/components/LHNOptionsList/OptionRowLHNData.tsx b/src/components/LHNOptionsList/OptionRowLHNData.tsx index 3c40210a5d99..0fe2a1542ca3 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.shouldDisplayTransactionThreadViolations(fullReport, transactionViolations, parentReportAction); + const shouldDisplayViolations = ReportUtils.shouldDisplayViolationsRBRInLHN(fullReport, transactionViolations); 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 336b7dea9654..8d9def814549 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); - const hasNoticeTypeViolations = TransactionUtils.hasNoticeTypeViolation(transaction?.transactionID ?? '-1', transactionViolations) && ReportUtils.isPaidGroupPolicy(iouReport); + const hasViolations = TransactionUtils.hasViolation(transaction?.transactionID ?? '-1', transactionViolations, true); + const hasNoticeTypeViolations = TransactionUtils.hasNoticeTypeViolation(transaction?.transactionID ?? '-1', transactionViolations, true) && 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 d476d1198808..1edb6fe9fc9f 100644 --- a/src/components/ReportActionItem/ReportPreview.tsx +++ b/src/components/ReportActionItem/ReportPreview.tsx @@ -157,8 +157,9 @@ function ReportPreview({ const hasErrors = (hasMissingSmartscanFields && !iouSettled) || // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - ReportUtils.hasViolations(iouReportID, transactionViolations) || - ReportUtils.hasWarningTypeViolations(iouReportID, transactionViolations) || + ReportUtils.hasViolations(iouReportID, transactionViolations, true) || + ReportUtils.hasNoticeTypeViolations(iouReportID, transactionViolations, true) || + ReportUtils.hasWarningTypeViolations(iouReportID, transactionViolations, true) || (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 6b3b2a70ede0..223c04df4eac 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.shouldShowViolations(report, transactionViolations); + const doesReportHaveViolations = ReportUtils.shouldDisplayViolationsRBRInLHN(report, transactionViolations); const reason = ReportUtils.reasonForReportToBeInOptionList({ report, diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 6bcb353cf065..8d1084b5342f 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.shouldShowViolations(report, transactionViolations); + const doesReportHaveViolations = ReportUtils.shouldDisplayViolationsRBRInLHN(report, transactionViolations); return ReportUtils.shouldReportBeInOptionList({ report, diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 28e3a0144141..60fc39d513c2 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -6320,65 +6320,53 @@ function shouldHideReport(report: OnyxEntry, currentReportId: string): b } /** - * Checks to see if a report's parentAction is an expense that contains a violation type of either violation or warning + * Should we display a RBR on the LHN on this report due to violations? */ -function doesTransactionThreadHaveViolations( - report: OnyxInputOrEntry, - transactionViolations: OnyxCollection, - parentReportAction: OnyxInputOrEntry, -): boolean { - if (!ReportActionsUtils.isMoneyRequestAction(parentReportAction)) { - return false; - } - const {IOUTransactionID, IOUReportID} = ReportActionsUtils.getOriginalMessage(parentReportAction) ?? {}; - if (!IOUTransactionID || !IOUReportID) { +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)) { return false; } - if (!isCurrentUserSubmitter(IOUReportID)) { - return false; - } - if (report?.stateNum !== CONST.REPORT.STATE_NUM.OPEN && report?.stateNum !== CONST.REPORT.STATE_NUM.SUBMITTED) { + + // We only show the RBR to the submitter + if (!isCurrentUserSubmitter(report.reportID ?? '')) { return false; } - return ( - TransactionUtils.hasViolation(IOUTransactionID, transactionViolations) || - TransactionUtils.hasWarningTypeViolation(IOUTransactionID, transactionViolations) || - (isPaidGroupPolicy(report) && TransactionUtils.hasModifiedAmountOrDateViolation(IOUTransactionID, transactionViolations)) + + // 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), ); } /** - * Checks if we should display violation - we display violations when the expense has violation and it is not settled + * Checks to see if a report contains a violation */ -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); +function hasViolations(reportID: string, transactionViolations: OnyxCollection, shouldShowInReview?: boolean): boolean { + const transactions = reportsTransactions[reportID] ?? []; + return transactions.some((transaction) => TransactionUtils.hasViolation(transaction.transactionID, transactionViolations, shouldShowInReview)); } /** - * Checks to see if a report contains a violation + * Checks to see if a report contains a violation of type `warning` */ -function hasViolations(reportID: string, transactionViolations: OnyxCollection): boolean { +function hasWarningTypeViolations(reportID: string, transactionViolations: OnyxCollection, shouldShowInReview?: boolean): boolean { const transactions = reportsTransactions[reportID] ?? []; - return transactions.some((transaction) => TransactionUtils.hasViolation(transaction.transactionID, transactionViolations)); + return transactions.some((transaction) => TransactionUtils.hasWarningTypeViolation(transaction.transactionID, transactionViolations, shouldShowInReview)); } /** - * Checks to see if a report contains a violation of type `warning` + * Checks to see if a report contains a violation of type `notice` */ -function hasWarningTypeViolations(reportID: string, transactionViolations: OnyxCollection): boolean { +function hasNoticeTypeViolations(reportID: string, transactionViolations: OnyxCollection, shouldShowInReview?: boolean): boolean { const transactions = reportsTransactions[reportID] ?? []; - return transactions.some((transaction) => TransactionUtils.hasWarningTypeViolation(transaction.transactionID, transactionViolations)); + return transactions.some((transaction) => TransactionUtils.hasNoticeTypeViolation(transaction.transactionID, transactionViolations, shouldShowInReview)); } function hasReportViolations(reportID: string) { @@ -6400,23 +6388,6 @@ 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; @@ -6499,7 +6470,7 @@ function hasReportErrorsOtherThanFailedReceipt(report: Report, doesReportHaveVio let doesTransactionThreadReportHasViolations = false; if (oneTransactionThreadReportID) { const transactionReport = getReport(oneTransactionThreadReportID); - doesTransactionThreadReportHasViolations = !!transactionReport && shouldShowViolations(transactionReport, transactionViolations); + doesTransactionThreadReportHasViolations = !!transactionReport && shouldDisplayViolationsRBRInLHN(transactionReport, transactionViolations); } return ( doesTransactionThreadReportHasViolations || @@ -8493,7 +8464,6 @@ export { chatIncludesConcierge, createDraftTransactionAndNavigateToParticipantSelector, doesReportBelongToWorkspace, - doesTransactionThreadHaveViolations, findLastAccessedReport, findSelfDMReportID, formatReportLastMessageText, @@ -8597,6 +8567,7 @@ export { hasUpdatedTotal, hasViolations, hasWarningTypeViolations, + hasNoticeTypeViolations, isActionCreator, isAdminRoom, isAdminsOnlyPostingRoom, @@ -8698,7 +8669,7 @@ export { shouldDisableRename, shouldDisableThread, shouldDisplayThreadReplies, - shouldDisplayTransactionThreadViolations, + shouldDisplayViolationsRBRInLHN, shouldReportBeInOptionList, shouldReportShowSubscript, shouldShowFlagComment, @@ -8746,7 +8717,6 @@ export { buildOptimisticChangeFieldAction, isPolicyRelatedReport, hasReportErrorsOtherThanFailedReceipt, - shouldShowViolations, getAllReportErrors, getAllReportActionsErrorsAndReportActionThatRequiresAttention, hasInvoiceReports, diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index d47cee3745a0..b8acec00af05 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.shouldShowViolations(report, transactionViolations); + const doesReportHaveViolations = ReportUtils.shouldDisplayViolationsRBRInLHN(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,22 +239,11 @@ 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 (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 (ReportUtils.shouldDisplayViolationsRBRInLHN(report, transactionViolations)) { + 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 aa46d28e6899..cb2c1a52e2d2 100644 --- a/src/libs/TransactionUtils/index.ts +++ b/src/libs/TransactionUtils/index.ts @@ -865,41 +865,37 @@ function isOnHoldByTransactionID(transactionID: string): boolean { /** * Checks if any violations for the provided transaction are of type 'violation' */ -function hasViolation(transactionID: string, transactionViolations: OnyxCollection): boolean { +function hasViolation(transactionID: string, transactionViolations: OnyxCollection, showInReview?: boolean): boolean { return !!transactionViolations?.[ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS + transactionID]?.some( - (violation: TransactionViolation) => violation.type === CONST.VIOLATION_TYPES.VIOLATION, + (violation: TransactionViolation) => violation.type === CONST.VIOLATION_TYPES.VIOLATION && (showInReview === undefined || showInReview === (violation.showInReview ?? false)), ); } /** * Checks if any violations for the provided transaction are of type 'notice' */ -function hasNoticeTypeViolation(transactionID: string, transactionViolations: OnyxCollection): boolean { - return !!transactionViolations?.[ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS + transactionID]?.some((violation: TransactionViolation) => violation.type === CONST.VIOLATION_TYPES.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)), + ); } /** * Checks if any violations for the provided transaction are of type 'warning' */ -function hasWarningTypeViolation(transactionID: string, transactionViolations: OnyxCollection): boolean { - const warningTypeViolations = transactionViolations?.[ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS + transactionID]?.filter( - (violation: TransactionViolation) => violation.type === CONST.VIOLATION_TYPES.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)), + ) ?? []; + const hasOnlyDupeDetectionViolation = warningTypeViolations?.every((violation: TransactionViolation) => violation.name === CONST.VIOLATIONS.DUPLICATED_TRANSACTION); if (!Permissions.canUseDupeDetection(allBetas ?? []) && hasOnlyDupeDetectionViolation) { return false; } - 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, - ); + return warningTypeViolations.length > 0; } /** @@ -1291,7 +1287,6 @@ export { shouldShowBrokenConnectionViolation, hasNoticeTypeViolation, hasWarningTypeViolation, - hasModifiedAmountOrDateViolation, isCustomUnitRateIDForP2P, getRateID, getTransaction, diff --git a/src/libs/WorkspacesSettingsUtils.ts b/src/libs/WorkspacesSettingsUtils.ts index eb03d8b6def9..f1b79402f86f 100644 --- a/src/libs/WorkspacesSettingsUtils.ts +++ b/src/libs/WorkspacesSettingsUtils.ts @@ -65,9 +65,7 @@ const getBrickRoadForPolicy = (report: Report, altReportActions?: OnyxCollection let doesReportContainErrors = Object.keys(reportErrors ?? {}).length !== 0 ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined; if (!doesReportContainErrors) { - const parentReportActions = (altReportActions ?? allReportActions)?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report?.parentReportID}`]; - const parentReportAction = parentReportActions?.[report?.parentReportActionID ?? '-1']; - const shouldDisplayViolations = ReportUtils.shouldDisplayTransactionThreadViolations(report, allTransactionViolations, parentReportAction); + const shouldDisplayViolations = ReportUtils.shouldDisplayViolationsRBRInLHN(report, allTransactionViolations); const shouldDisplayReportViolations = ReportUtils.isReportOwner(report) && ReportUtils.hasReportViolations(report.reportID); const hasViolations = shouldDisplayViolations || shouldDisplayReportViolations; if (hasViolations) { @@ -78,13 +76,7 @@ const getBrickRoadForPolicy = (report: Report, altReportActions?: OnyxCollection if (oneTransactionThreadReportID && !doesReportContainErrors) { const oneTransactionThreadReport = ReportUtils.getReport(oneTransactionThreadReportID); - if ( - ReportUtils.shouldDisplayTransactionThreadViolations( - oneTransactionThreadReport, - allTransactionViolations, - reportActions[oneTransactionThreadReport?.parentReportActionID ?? '-1'], - ) - ) { + if (ReportUtils.shouldDisplayViolationsRBRInLHN(oneTransactionThreadReport, allTransactionViolations)) { doesReportContainErrors = CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR; } } diff --git a/src/pages/Debug/Report/DebugReportPage.tsx b/src/pages/Debug/Report/DebugReportPage.tsx index 5fa26cbf1835..67fa0a6c5113 100644 --- a/src/pages/Debug/Report/DebugReportPage.tsx +++ b/src/pages/Debug/Report/DebugReportPage.tsx @@ -53,15 +53,13 @@ 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.shouldDisplayTransactionThreadViolations(report, transactionViolations, parentReportAction); + const shouldDisplayViolations = ReportUtils.shouldDisplayViolationsRBRInLHN(report, transactionViolations); const shouldDisplayReportViolations = ReportUtils.isReportOwner(report) && ReportUtils.hasReportViolations(reportID); const hasViolations = !!shouldDisplayViolations || shouldDisplayReportViolations; const {reason: reasonGBR, reportAction: reportActionGBR} = DebugUtils.getReasonAndReportActionForGBRInLHNRow(report) ?? {}; @@ -113,7 +111,7 @@ function DebugReportPage({ : undefined, }, ]; - }, [parentReportAction, report, reportActions, reportID, transactionViolations, translate]); + }, [report, reportActions, reportID, transactionViolations, translate]); if (!report) { return ; diff --git a/src/types/onyx/TransactionViolation.ts b/src/types/onyx/TransactionViolation.ts index bf8ecc7ebdde..bfb215a1bbdb 100644 --- a/src/types/onyx/TransactionViolation.ts +++ b/src/types/onyx/TransactionViolation.ts @@ -92,6 +92,9 @@ 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 c5d84341deee..abeaff971194 100644 --- a/tests/unit/DebugUtilsTest.ts +++ b/tests/unit/DebugUtilsTest.ts @@ -693,46 +693,6 @@ 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, @@ -1530,28 +1490,13 @@ describe('DebugUtils', () => { ) ?? {}; expect(reason).toBe('debug.reasonRBR.hasViolations'); }); - it('returns correct reason when there are transaction thread violations', async () => { + it('returns correct reason when there are reports on the workspace chat with violations', async () => { const report: Report = { reportID: '0', - type: CONST.REPORT.TYPE.EXPENSE, + type: CONST.REPORT.TYPE.CHAT, ownerAccountID: 1234, - }; - 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', - }, + policyID: '1', + chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, }; await Onyx.multiSet({ [ONYXKEYS.SESSION]: { @@ -1562,17 +1507,23 @@ describe('DebugUtils', () => { reportID: '1', parentReportActionID: '0', stateNum: CONST.REPORT.STATE_NUM.OPEN, - statusNum: CONST.REPORT.STATE_NUM.SUBMITTED, + ownerAccountID: 1234, + policyID: '1', + }, + [`${ONYXKEYS.COLLECTION.TRANSACTION}1` as const]: { + transactionID: '1', + amount: 10, + modifiedAmount: 10, + reportID: '0', }, - [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}0` as const]: reportActions, - [`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}0` as const]: [ + [`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}1` as const]: [ { type: CONST.VIOLATION_TYPES.VIOLATION, - name: CONST.VIOLATIONS.MODIFIED_AMOUNT, + name: CONST.VIOLATIONS.MISSING_CATEGORY, }, ], }); - const {reason} = DebugUtils.getReasonAndReportActionForRBRInLHNRow(report, reportActions, false) ?? {}; + const {reason} = DebugUtils.getReasonAndReportActionForRBRInLHNRow(report, {}, false) ?? {}; expect(reason).toBe('debug.reasonRBR.hasTransactionThreadViolations'); }); }); diff --git a/tests/unit/WorkspaceSettingsUtilsTest.json b/tests/unit/WorkspaceSettingsUtilsTest.json index ff83fe078adf..52048f5efccb 100644 --- a/tests/unit/WorkspaceSettingsUtilsTest.json +++ b/tests/unit/WorkspaceSettingsUtilsTest.json @@ -5,8 +5,9 @@ "reports": { "report_4286515777714555": { "type": "chat", + "chatType": "policyExpenseChat", "isOwnPolicyExpenseChat": false, - "ownerAccountID": 0, + "ownerAccountID": 18634488, "parentReportActionID": "8722650843049927838", "parentReportID": "6955627196303088", "policyID": "57D0F454E0BCE54B", @@ -26,6 +27,17 @@ "parentReportActionID": "7978085421707288417" } }, + "transactions": { + "transactions_3106135972713435169": { + "transactionID": "3106135972713435169", + "created": "2024-11-13", + "currency": "USD", + "merchant": "test", + "amount": 10, + "modifiedAmount": 10, + "reportID": "4286515777714555" + } + }, "transactionViolations": { "transactionViolations_3106135972713435169": [ { diff --git a/tests/unit/WorkspaceSettingsUtilsTest.ts b/tests/unit/WorkspaceSettingsUtilsTest.ts index 9ee2b511379f..37f235eb73f9 100644 --- a/tests/unit/WorkspaceSettingsUtilsTest.ts +++ b/tests/unit/WorkspaceSettingsUtilsTest.ts @@ -2,7 +2,7 @@ import type {OnyxCollection} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; import {getBrickRoadForPolicy} from '@libs/WorkspacesSettingsUtils'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {Report, ReportActions, TransactionViolations} from '@src/types/onyx'; +import type {Report, ReportActions, Transaction, TransactionViolations} from '@src/types/onyx'; import type {ReportCollectionDataSet} from '@src/types/onyx/Report'; import * as TestHelper from '../utils/TestHelper'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; @@ -27,11 +27,13 @@ describe('WorkspacesSettingsUtils', () => { const reports = mockData.reports; const session = mockData.session; const reportActions = mockData.reportActions; + const transactions = mockData.transactions; await Onyx.multiSet({ ...(reports as ReportCollectionDataSet), ...(reportActions as OnyxCollection), ...(transactionViolations as OnyxCollection), + ...(transactions as OnyxCollection), session, });