diff --git a/src/components/MoneyReportHeader.tsx b/src/components/MoneyReportHeader.tsx index 3102252b539b..90639d9812e1 100644 --- a/src/components/MoneyReportHeader.tsx +++ b/src/components/MoneyReportHeader.tsx @@ -255,8 +255,8 @@ function MoneyReportHeader({ }, [reportTransactions]); const shouldBlockSubmit = useMemo(() => { - return shouldBlockSubmitDueToStrictPolicyRules(moneyRequestReport?.reportID, violations, areStrictPolicyRulesEnabled, transactions); - }, [moneyRequestReport?.reportID, violations, areStrictPolicyRulesEnabled, transactions]); + return shouldBlockSubmitDueToStrictPolicyRules(moneyRequestReport?.reportID, violations, areStrictPolicyRulesEnabled, accountID, email ?? '', transactions); + }, [moneyRequestReport?.reportID, violations, areStrictPolicyRulesEnabled, accountID, email, transactions]); const iouTransactionID = isMoneyRequestAction(requestParentReportAction) ? getOriginalMessage(requestParentReportAction)?.IOUTransactionID : undefined; const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${getNonEmptyStringOnyxID(iouTransactionID)}`, { @@ -292,7 +292,7 @@ function MoneyReportHeader({ const [allTransactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true}); const {isBetaEnabled} = usePermissions(); const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT); - const hasViolations = hasViolationsReportUtils(moneyRequestReport?.reportID, allTransactionViolations); + const hasViolations = hasViolationsReportUtils(moneyRequestReport?.reportID, allTransactionViolations, accountID, email ?? ''); const [exportModalStatus, setExportModalStatus] = useState(null); const {showConfirmModal} = useConfirmModal(); @@ -327,11 +327,11 @@ function MoneyReportHeader({ // Check if there is pending rter violation in all transactionViolations with given transactionIDs. // wrapped in useMemo to avoid unnecessary re-renders and for better performance (array operation inside of function) const hasAllPendingRTERViolations = useMemo( - () => allHavePendingRTERViolation(transactions, violations, email ?? '', moneyRequestReport, policy), - [transactions, violations, email, moneyRequestReport, policy], + () => allHavePendingRTERViolation(transactions, violations, email ?? '', accountID, moneyRequestReport, policy), + [transactions, violations, email, accountID, moneyRequestReport, policy], ); // Check if user should see broken connection violation warning. - const shouldShowBrokenConnectionViolation = shouldShowBrokenConnectionViolationForMultipleTransactions(transactions, moneyRequestReport, policy, violations, email ?? ''); + const shouldShowBrokenConnectionViolation = shouldShowBrokenConnectionViolationForMultipleTransactions(transactions, moneyRequestReport, policy, violations, email ?? '', accountID); const hasOnlyHeldExpenses = hasOnlyHeldExpensesReportUtils(moneyRequestReport?.reportID); const isPayAtEndExpense = isPayAtEndExpenseTransactionUtils(transaction); const isArchivedReport = useReportIsArchived(moneyRequestReport?.reportID); @@ -420,7 +420,7 @@ function MoneyReportHeader({ const isFromPaidPolicy = policyType === CONST.POLICY.TYPE.TEAM || policyType === CONST.POLICY.TYPE.CORPORATE; - const hasDuplicates = hasDuplicateTransactions(email ?? '', moneyRequestReport, policy); + const hasDuplicates = hasDuplicateTransactions(email ?? '', accountID, moneyRequestReport, policy); const shouldShowMarkAsResolved = isMarkAsResolvedAction(moneyRequestReport, transactionViolations); const shouldShowStatusBar = hasAllPendingRTERViolations || @@ -606,7 +606,7 @@ function MoneyReportHeader({ }; const getFirstDuplicateThreadID = (transactionsList: OnyxTypes.Transaction[], allReportActions: OnyxTypes.ReportAction[]) => { - const duplicateTransaction = transactionsList.find((reportTransaction) => isDuplicate(reportTransaction, email ?? '', moneyRequestReport, policy)); + const duplicateTransaction = transactionsList.find((reportTransaction) => isDuplicate(reportTransaction, email ?? '', accountID, moneyRequestReport, policy)); if (!duplicateTransaction) { return null; } @@ -642,6 +642,7 @@ function MoneyReportHeader({ const primaryAction = useMemo(() => { return getReportPrimaryAction({ currentUserEmail: currentUserLogin ?? '', + currentUserAccountID: accountID, report: moneyRequestReport, chatReport, reportTransactions: transactions, @@ -669,6 +670,7 @@ function MoneyReportHeader({ isChatReportArchived, invoiceReceiverPolicy, currentUserLogin, + accountID, ]); const confirmExport = useCallback(() => { @@ -898,7 +900,7 @@ function MoneyReportHeader({ onPress={() => { let threadID = transactionThreadReportID ?? getFirstDuplicateThreadID(transactions, reportActions); if (!threadID) { - const duplicateTransaction = transactions.find((reportTransaction) => isDuplicate(reportTransaction, email ?? '', moneyRequestReport, policy)); + const duplicateTransaction = transactions.find((reportTransaction) => isDuplicate(reportTransaction, email ?? '', accountID, moneyRequestReport, policy)); const transactionID = duplicateTransaction?.transactionID; const iouAction = getIOUActionForReportID(moneyRequestReport?.reportID, transactionID); const createdTransactionThreadReport = createTransactionThreadReport(moneyRequestReport, iouAction); @@ -921,6 +923,7 @@ function MoneyReportHeader({ } return getSecondaryReportActions({ currentUserEmail: currentUserLogin ?? '', + currentUserAccountID: accountID, report: moneyRequestReport, chatReport, reportTransactions: transactions, @@ -932,7 +935,20 @@ function MoneyReportHeader({ policies, isChatReportArchived, }); - }, [moneyRequestReport, currentUserLogin, chatReport, transactions, originalIOUTransaction, violations, policy, reportNameValuePairs, reportActions, policies, isChatReportArchived]); + }, [ + moneyRequestReport, + currentUserLogin, + accountID, + chatReport, + transactions, + originalIOUTransaction, + violations, + policy, + reportNameValuePairs, + reportActions, + policies, + isChatReportArchived, + ]); const secondaryExportActions = useMemo(() => { if (!moneyRequestReport) { diff --git a/src/components/MoneyRequestHeader.tsx b/src/components/MoneyRequestHeader.tsx index 7ed574501906..99ddb5611089 100644 --- a/src/components/MoneyRequestHeader.tsx +++ b/src/components/MoneyRequestHeader.tsx @@ -112,9 +112,9 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre const styles = useThemeStyles(); const theme = useTheme(); const {translate} = useLocalize(); - const {login: currentUserLogin, email} = useCurrentUserPersonalDetails(); + const {login: currentUserLogin, email, accountID} = useCurrentUserPersonalDetails(); const isOnHold = isOnHoldTransactionUtils(transaction); - const isDuplicate = isDuplicateTransactionUtils(transaction, email ?? '', report, policy); + const isDuplicate = isDuplicateTransactionUtils(transaction, email ?? '', accountID, report, policy); const reportID = report?.reportID; const {removeTransaction, currentSearchHash} = useSearchContext(); const {isExpenseSplit} = getOriginalTransactionWithSplitInfo(transaction, originalTransaction); @@ -195,8 +195,8 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre if (!report || !parentReport || !transaction) { return ''; } - return getTransactionThreadPrimaryAction(currentUserLogin ?? '', report, parentReport, transaction, transactionViolations, policy, isFromReviewDuplicates); - }, [parentReport, policy, report, transaction, transactionViolations, isFromReviewDuplicates, currentUserLogin]); + return getTransactionThreadPrimaryAction(currentUserLogin ?? '', accountID, report, parentReport, transaction, transactionViolations, policy, isFromReviewDuplicates); + }, [parentReport, policy, report, transaction, transactionViolations, isFromReviewDuplicates, currentUserLogin, accountID]); const primaryActionImplementation = { [CONST.REPORT.TRANSACTION_PRIMARY_ACTIONS.REMOVE_HOLD]: ( diff --git a/src/components/ProcessMoneyReportHoldMenu.tsx b/src/components/ProcessMoneyReportHoldMenu.tsx index 96289496fd29..8f5d98d377df 100644 --- a/src/components/ProcessMoneyReportHoldMenu.tsx +++ b/src/components/ProcessMoneyReportHoldMenu.tsx @@ -72,8 +72,8 @@ function ProcessMoneyReportHoldMenu({ const {isBetaEnabled} = usePermissions(); const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true}); const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT); - const hasViolations = hasViolationsReportUtils(moneyRequestReport?.reportID, transactionViolations); const currentUserDetails = useCurrentUserPersonalDetails(); + const hasViolations = hasViolationsReportUtils(moneyRequestReport?.reportID, transactionViolations, currentUserDetails.accountID, currentUserDetails.email ?? ''); const onSubmit = (full: boolean) => { if (isApprove) { diff --git a/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx b/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx index 97b8d43cf094..35e80d2bf2c4 100644 --- a/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx +++ b/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx @@ -167,7 +167,7 @@ function MoneyRequestReportPreviewContent({ const {isBetaEnabled} = usePermissions(); const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true}); const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT); - const hasViolations = hasViolationsReportUtils(iouReport?.reportID, transactionViolations); + const hasViolations = hasViolationsReportUtils(iouReport?.reportID, transactionViolations, currentUserDetails.accountID, currentUserDetails.email ?? ''); const getCanIOUBePaid = useCallback( (shouldShowOnlyPayElsewhere = false, shouldCheckApprovedState = true) => @@ -495,6 +495,7 @@ function MoneyRequestReportPreviewContent({ violations, isIouReportArchived || isChatReportArchived, currentUserDetails.email ?? '', + currentUserDetails.accountID, iouReport, policy, transactions, @@ -517,6 +518,7 @@ function MoneyRequestReportPreviewContent({ isChatReportArchived, areStrictPolicyRulesEnabled, currentUserDetails.email, + currentUserDetails.accountID, ]); const addExpenseDropdownOptions = useMemo( diff --git a/src/components/ReportActionItem/TransactionPreview/TransactionPreviewContent.tsx b/src/components/ReportActionItem/TransactionPreview/TransactionPreviewContent.tsx index 93dee4191b99..d9d887e750ef 100644 --- a/src/components/ReportActionItem/TransactionPreview/TransactionPreviewContent.tsx +++ b/src/components/ReportActionItem/TransactionPreview/TransactionPreviewContent.tsx @@ -103,8 +103,9 @@ function TransactionPreviewContent({ areThereDuplicates, isReportAPolicyExpenseChat, currentUserEmail: currentUserDetails.email ?? '', + currentUserAccountID: currentUserDetails.accountID, }), - [areThereDuplicates, transactionPreviewCommonArguments, isReportAPolicyExpenseChat, currentUserDetails.email], + [areThereDuplicates, transactionPreviewCommonArguments, isReportAPolicyExpenseChat, currentUserDetails.email, currentUserDetails.accountID], ); const {shouldShowRBR, shouldShowMerchant, shouldShowSplitShare, shouldShowTag, shouldShowCategory, shouldShowSkeleton, shouldShowDescription} = conditionals; @@ -123,9 +124,10 @@ function TransactionPreviewContent({ violationMessage, reportActions, currentUserEmail: currentUserDetails.email ?? '', + currentUserAccountID: currentUserDetails.accountID, originalTransaction, }), - [transactionPreviewCommonArguments, shouldShowRBR, violationMessage, reportActions, currentUserDetails.email, originalTransaction], + [transactionPreviewCommonArguments, shouldShowRBR, violationMessage, reportActions, currentUserDetails.email, currentUserDetails.accountID, originalTransaction], ); const getTranslatedText = (item: TranslationPathOrText) => (item.translationPath ? translate(item.translationPath) : (item.text ?? '')); diff --git a/src/components/SelectionListWithSections/Search/TransactionGroupListExpanded.tsx b/src/components/SelectionListWithSections/Search/TransactionGroupListExpanded.tsx index 3a31e59d70e1..2267ca5948f8 100644 --- a/src/components/SelectionListWithSections/Search/TransactionGroupListExpanded.tsx +++ b/src/components/SelectionListWithSections/Search/TransactionGroupListExpanded.tsx @@ -190,7 +190,14 @@ function TransactionGroupListExpanded({ ({ const transactionViolations = useMemo(() => { return (violations?.[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionItem.transactionID}`] ?? []).filter( (violation: TransactionViolation) => - !isViolationDismissed(transactionItem, violation, currentUserDetails.email ?? '', snapshotReport, snapshotPolicy) && + !isViolationDismissed(transactionItem, violation, currentUserDetails.email ?? '', currentUserDetails.accountID, snapshotReport, snapshotPolicy) && shouldShowViolation(snapshotReport, snapshotPolicy, violation.name, currentUserDetails.email ?? '', false), ); - }, [snapshotPolicy, snapshotReport, transactionItem, violations, currentUserDetails.email]); + }, [snapshotPolicy, snapshotReport, transactionItem, violations, currentUserDetails.email, currentUserDetails.accountID]); const handleActionButtonPress = useCallback(() => { handleActionButtonPressUtil( diff --git a/src/components/SettlementButton/index.tsx b/src/components/SettlementButton/index.tsx index 55f94691eed2..a9f8f3bd5b18 100644 --- a/src/components/SettlementButton/index.tsx +++ b/src/components/SettlementButton/index.tsx @@ -146,7 +146,7 @@ function SettlementButton({ const {isBetaEnabled} = usePermissions(); const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true}); const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT); - const hasViolations = hasViolationsReportUtils(iouReport?.reportID, transactionViolations); + const hasViolations = hasViolationsReportUtils(iouReport?.reportID, transactionViolations, accountID, email ?? ''); const isInvoiceReport = (!isEmptyObject(iouReport) && isInvoiceReportUtil(iouReport)) || false; diff --git a/src/hooks/useSearchTypeMenuSections.ts b/src/hooks/useSearchTypeMenuSections.ts index bccb282f0429..af424b8f8fe1 100644 --- a/src/hooks/useSearchTypeMenuSections.ts +++ b/src/hooks/useSearchTypeMenuSections.ts @@ -58,7 +58,12 @@ const useSearchTypeMenuSections = () => { const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true}); const {isBetaEnabled} = usePermissions(); const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT); - const hasViolations = hasViolationsReportUtils(undefined, transactionViolations); + const hasViolations = hasViolationsReportUtils( + undefined, + transactionViolations, + currentUserLoginAndAccountID?.accountID ?? CONST.DEFAULT_NUMBER_ID, + currentUserLoginAndAccountID?.email ?? '', + ); const [pendingReportCreation, setPendingReportCreation] = useState<{policyID: string; policyName?: string; onConfirm: () => void} | null>(null); const handlePendingConfirm = useCallback(() => { diff --git a/src/hooks/useTransactionViolations.ts b/src/hooks/useTransactionViolations.ts index f5854f182ec1..f633e0abee80 100644 --- a/src/hooks/useTransactionViolations.ts +++ b/src/hooks/useTransactionViolations.ts @@ -27,11 +27,11 @@ function useTransactionViolations(transactionID?: string, shouldShowRterForSettl mergeProhibitedViolations( transactionViolations.filter( (violation: TransactionViolation) => - !isViolationDismissed(transaction, violation, currentUserDetails.email ?? '', iouReport, policy) && + !isViolationDismissed(transaction, violation, currentUserDetails.email ?? '', currentUserDetails.accountID, iouReport, policy) && shouldShowViolation(iouReport, policy, violation.name, currentUserDetails.email ?? '', shouldShowRterForSettledReport), ), ), - [transaction, transactionViolations, iouReport, policy, shouldShowRterForSettledReport, currentUserDetails.email], + [transaction, transactionViolations, iouReport, policy, shouldShowRterForSettledReport, currentUserDetails.email, currentUserDetails.accountID], ); } diff --git a/src/hooks/useTransactionsAndViolationsForReport.ts b/src/hooks/useTransactionsAndViolationsForReport.ts index c25ca002d4c3..d92ec801bdd4 100644 --- a/src/hooks/useTransactionsAndViolationsForReport.ts +++ b/src/hooks/useTransactionsAndViolationsForReport.ts @@ -25,14 +25,15 @@ function useTransactionsAndViolationsForReport(reportID?: string) { // This is our accumulator, it's okay to reassign // eslint-disable-next-line no-param-reassign - filteredTransactionViolations[transactionViolationKey] = getTransactionViolations(transaction, violations, currentUserDetails.email ?? '', report, policy) ?? []; + filteredTransactionViolations[transactionViolationKey] = + getTransactionViolations(transaction, violations, currentUserDetails.email ?? '', currentUserDetails.accountID, report, policy) ?? []; return filteredTransactionViolations; }, {} as Record, ); return {transactions, violations: filteredViolations}; - }, [transactions, violations, currentUserDetails?.email, report, policy]); + }, [transactions, violations, currentUserDetails?.email, currentUserDetails?.accountID, report, policy]); return transactionsAndViolations; } diff --git a/src/libs/NextStepUtils.ts b/src/libs/NextStepUtils.ts index ce4456cf8a5e..6f05b32aa6f6 100644 --- a/src/libs/NextStepUtils.ts +++ b/src/libs/NextStepUtils.ts @@ -395,7 +395,7 @@ function buildNextStep( const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`] ?? ({} as Policy); const {harvesting, autoReportingOffset} = policy; const autoReportingFrequency = getCorrectedAutoReportingFrequency(policy); - const hasViolations = hasViolationsReportUtils(report?.reportID, transactionViolations); + const hasViolations = hasViolationsReportUtils(report?.reportID, transactionViolations, currentUserAccountID, currentUserEmail); const isASAPSubmitBetaEnabled = Permissions.isBetaEnabled(CONST.BETAS.ASAP_SUBMIT, allBetas); const isInstantSubmitEnabled = autoReportingFrequency === CONST.POLICY.AUTO_REPORTING_FREQUENCIES.INSTANT; const shouldShowFixMessage = hasViolations && isInstantSubmitEnabled && !isASAPSubmitBetaEnabled; diff --git a/src/libs/ReportPreviewActionUtils.ts b/src/libs/ReportPreviewActionUtils.ts index 2b37a1936a0c..3268e18fe6a8 100644 --- a/src/libs/ReportPreviewActionUtils.ts +++ b/src/libs/ReportPreviewActionUtils.ts @@ -2,7 +2,6 @@ import type {OnyxCollection} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; import CONST from '@src/CONST'; import type {Policy, Report, Transaction, TransactionViolation} from '@src/types/onyx'; -import {getCurrentUserAccountID} from './actions/Report'; import {arePaymentsEnabled, getSubmitToAccountID, getValidConnectedIntegration, hasIntegrationAutoSync, isPolicyAdmin, isPreferredExporter} from './PolicyUtils'; import {isAddExpenseAction} from './ReportPrimaryActionUtils'; import { @@ -29,7 +28,15 @@ import {getSession} from './SessionUtils'; import {allHavePendingRTERViolation, isPending, isScanning, shouldShowBrokenConnectionViolationForMultipleTransactions} from './TransactionUtils'; import ViolationsUtils from './Violations/ViolationsUtils'; -function canSubmit(report: Report, violations: OnyxCollection, isReportArchived: boolean, policy?: Policy, transactions?: Transaction[]) { +function canSubmit( + report: Report, + violations: OnyxCollection, + isReportArchived: boolean, + currentUserEmail: string, + currentUserAccountID: number, + policy?: Policy, + transactions?: Transaction[], +) { if (isReportArchived) { return false; } @@ -37,14 +44,14 @@ function canSubmit(report: Report, violations: OnyxCollection 0 && transactions.every((transaction) => isPending(transaction))) { return false; } - const hasAnyViolations = hasMissingSmartscanFields(report.reportID, transactions) || hasAnyViolationsUtil(report.reportID, violations); + const hasAnyViolations = hasMissingSmartscanFields(report.reportID, transactions) || hasAnyViolationsUtil(report.reportID, violations, currentUserAccountID, currentUserEmail); const isAnyReceiptBeingScanned = transactions?.some((transaction) => isScanning(transaction)); @@ -61,21 +68,22 @@ function canApprove( report: Report, violations: OnyxCollection, currentUserEmail: string, + currentUserAccountID: number, policy: Policy | undefined, transactions: Transaction[], shouldConsiderViolations = true, ) { - const currentUserID = getCurrentUserAccountID(); const isExpense = isExpenseReport(report); const isProcessing = isProcessingReport(report); const isApprovalEnabled = policy?.approvalMode && policy.approvalMode !== CONST.POLICY.APPROVAL_MODE.OPTIONAL; const managerID = report.managerID ?? CONST.DEFAULT_NUMBER_ID; - const isCurrentUserManager = managerID === currentUserID; + const isCurrentUserManager = managerID === currentUserAccountID; // We should consider only visible violations for the approver, invisible violations should not block approval const reportTransactions = transactions.length ? transactions : getReportTransactions(report?.reportID); const hasAnyVisibleViolations = - hasMissingSmartscanFields(report.reportID, reportTransactions) || ViolationsUtils.hasVisibleViolationsForUser(report, violations, currentUserEmail, policy, reportTransactions); + hasMissingSmartscanFields(report.reportID, reportTransactions) || + ViolationsUtils.hasVisibleViolationsForUser(report, violations, currentUserEmail, currentUserAccountID, policy, reportTransactions); const isAnyReceiptBeingScanned = reportTransactions?.some((transaction) => isScanning(transaction)); if (isAnyReceiptBeingScanned) { @@ -100,6 +108,8 @@ function canPay( report: Report, violations: OnyxCollection, isReportArchived: boolean, + currentUserAccountID: number, + currentUserEmail: string, policy?: Policy, invoiceReceiverPolicy?: Policy, shouldConsiderViolations = true, @@ -120,7 +130,7 @@ function canPay( const {reimbursableSpend} = getMoneyRequestSpendBreakdown(report); const isReimbursed = isSettled(report); - const hasAnyViolations = hasAnyViolationsUtil(report.reportID, violations); + const hasAnyViolations = hasAnyViolationsUtil(report.reportID, violations, currentUserAccountID, currentUserEmail); if (isExpense && isReportPayer && isPaymentsEnabled && isReportFinished && (!hasAnyViolations || !shouldConsiderViolations) && reimbursableSpend !== 0) { return true; @@ -144,13 +154,13 @@ function canPay( const parentReport = getParentReport(report); if (parentReport?.invoiceReceiver?.type === CONST.REPORT.INVOICE_RECEIVER_TYPE.INDIVIDUAL && reimbursableSpend > 0) { - return parentReport?.invoiceReceiver?.accountID === getCurrentUserAccountID(); + return parentReport?.invoiceReceiver?.accountID === currentUserAccountID; } return invoiceReceiverPolicy?.role === CONST.POLICY.ROLE.ADMIN && reimbursableSpend > 0; } -function canExport(report: Report, violations: OnyxCollection, policy?: Policy) { +function canExport(report: Report, violations: OnyxCollection, currentUserAccountID: number, currentUserEmail: string, policy?: Policy) { const isExpense = isExpenseReport(report); const isExporter = policy ? isPreferredExporter(policy) : false; const isReimbursed = isSettled(report); @@ -158,7 +168,7 @@ function canExport(report: Report, violations: OnyxCollection, isReportArchived: boolean, currentUserEmail: string, + currentUserAccountID: number, policy: Policy | undefined, transactions: Transaction[], ) { - const hasAnyViolations = hasMissingSmartscanFields(report.reportID, transactions) || hasAnyViolationsUtil(report.reportID, violations); - const hasVisibleViolations = hasAnyViolations && ViolationsUtils.hasVisibleViolationsForUser(report, violations, currentUserEmail, policy, transactions); + const hasAnyViolations = hasMissingSmartscanFields(report.reportID, transactions) || hasAnyViolationsUtil(report.reportID, violations, currentUserAccountID, currentUserEmail); + const hasVisibleViolations = hasAnyViolations && ViolationsUtils.hasVisibleViolationsForUser(report, violations, currentUserEmail, currentUserAccountID, policy, transactions); const isSubmitter = isCurrentUserSubmitter(report); const isOpen = isOpenExpenseReport(report); const isReimbursed = isSettled(report); @@ -199,16 +210,16 @@ function canReview( !hasVisibleViolations || isReimbursed || (!(isSubmitter && isOpen && policy?.areWorkflowsEnabled) && - !canApprove(report, violations, currentUserEmail, policy, transactions, false) && - !canPay(report, violations, isReportArchived, policy, policy, false)) + !canApprove(report, violations, currentUserEmail, currentUserAccountID, policy, transactions, false) && + !canPay(report, violations, isReportArchived, currentUserAccountID, currentUserEmail, policy, policy, false)) ) { return false; } // We handle RTER violations independently because those are not configured via policy workflows const isAdmin = isPolicyAdmin(policy); - const hasAllPendingRTERViolations = allHavePendingRTERViolation(transactions, violations, currentUserEmail, report, policy); - const shouldShowBrokenConnectionViolation = shouldShowBrokenConnectionViolationForMultipleTransactions(transactions, report, policy, violations, currentUserEmail); + const hasAllPendingRTERViolations = allHavePendingRTERViolation(transactions, violations, currentUserEmail, currentUserAccountID, report, policy); + const shouldShowBrokenConnectionViolation = shouldShowBrokenConnectionViolationForMultipleTransactions(transactions, report, policy, violations, currentUserEmail, currentUserAccountID); if (hasAllPendingRTERViolations || (shouldShowBrokenConnectionViolation && (!isAdmin || isSubmitter) && !isReportApproved({report}) && !isReportManuallyReimbursed(report))) { return true; @@ -226,6 +237,7 @@ function getReportPreviewAction( violations: OnyxCollection, isReportArchived: boolean, currentUserEmail: string, + currentUserAccountID: number, report: Report | undefined, policy: Policy | undefined, transactions: Transaction[], @@ -253,24 +265,31 @@ function getReportPreviewAction( } // When strict policy rules are enabled and there are violations, show REVIEW button instead of SUBMIT - const shouldBlockSubmit = shouldBlockSubmitDueToStrictPolicyRules(report.reportID, violations, areStrictPolicyRulesEnabled ?? false, transactions); - if (shouldBlockSubmit && canReview(report, violations, isReportArchived, currentUserEmail, policy, transactions)) { + const shouldBlockSubmit = shouldBlockSubmitDueToStrictPolicyRules( + report.reportID, + violations, + areStrictPolicyRulesEnabled ?? false, + currentUserAccountID, + currentUserEmail, + transactions, + ); + if (shouldBlockSubmit && canReview(report, violations, isReportArchived, currentUserEmail, currentUserAccountID, policy, transactions)) { return CONST.REPORT.REPORT_PREVIEW_ACTIONS.REVIEW; } - if (canSubmit(report, violations, isReportArchived, policy, transactions)) { + if (canSubmit(report, violations, isReportArchived, currentUserEmail, currentUserAccountID, policy, transactions)) { return CONST.REPORT.REPORT_PREVIEW_ACTIONS.SUBMIT; } - if (canApprove(report, violations, currentUserEmail, policy, transactions)) { + if (canApprove(report, violations, currentUserEmail, currentUserAccountID, policy, transactions)) { return CONST.REPORT.REPORT_PREVIEW_ACTIONS.APPROVE; } - if (canPay(report, violations, isReportArchived, policy, invoiceReceiverPolicy)) { + if (canPay(report, violations, isReportArchived, currentUserAccountID, currentUserEmail, policy, invoiceReceiverPolicy)) { return CONST.REPORT.REPORT_PREVIEW_ACTIONS.PAY; } - if (canExport(report, violations, policy)) { + if (canExport(report, violations, currentUserAccountID, currentUserEmail, policy)) { return CONST.REPORT.REPORT_PREVIEW_ACTIONS.EXPORT_TO_ACCOUNTING; } - if (canReview(report, violations, isReportArchived, currentUserEmail, policy, transactions)) { + if (canReview(report, violations, isReportArchived, currentUserEmail, currentUserAccountID, policy, transactions)) { return CONST.REPORT.REPORT_PREVIEW_ACTIONS.REVIEW; } diff --git a/src/libs/ReportPrimaryActionUtils.ts b/src/libs/ReportPrimaryActionUtils.ts index 9bcbc47c2139..d1b2a706613a 100644 --- a/src/libs/ReportPrimaryActionUtils.ts +++ b/src/libs/ReportPrimaryActionUtils.ts @@ -50,6 +50,7 @@ import { type GetReportPrimaryActionParams = { currentUserEmail: string; + currentUserAccountID: number; report: Report | undefined; chatReport: OnyxEntry; reportTransactions: Transaction[]; @@ -248,8 +249,8 @@ function isRemoveHoldAction(report: Report, chatReport: OnyxEntry, repor return isHolder; } -function isReviewDuplicatesAction(report: Report, reportTransactions: Transaction[], currentUserEmail: string, policy: Policy | undefined) { - const hasDuplicates = reportTransactions.some((transaction) => isDuplicate(transaction, currentUserEmail, report, policy)); +function isReviewDuplicatesAction(report: Report, reportTransactions: Transaction[], currentUserEmail: string, currentUserAccountID: number, policy: Policy | undefined) { + const hasDuplicates = reportTransactions.some((transaction) => isDuplicate(transaction, currentUserEmail, currentUserAccountID, report, policy)); if (!hasDuplicates) { return false; @@ -270,14 +271,21 @@ function isReviewDuplicatesAction(report: Report, reportTransactions: Transactio return false; } -function isMarkAsCashAction(currentUserEmail: string, report: Report, reportTransactions: Transaction[], violations: OnyxCollection, policy?: Policy) { +function isMarkAsCashAction( + currentUserEmail: string, + currentUserAccountID: number, + report: Report, + reportTransactions: Transaction[], + violations: OnyxCollection, + policy?: Policy, +) { const isOneExpenseReport = isExpenseReportUtils(report) && reportTransactions.length === 1; if (!isOneExpenseReport) { return false; } - const hasAllPendingRTERViolations = allHavePendingRTERViolation(reportTransactions, violations, currentUserEmail, report, policy); + const hasAllPendingRTERViolations = allHavePendingRTERViolation(reportTransactions, violations, currentUserEmail, currentUserAccountID, report, policy); if (hasAllPendingRTERViolations) { return true; @@ -287,7 +295,14 @@ function isMarkAsCashAction(currentUserEmail: string, report: Report, reportTran const isReportApprover = isApproverUtils(policy, currentUserEmail); const isAdmin = policy?.role === CONST.POLICY.ROLE.ADMIN; - const shouldShowBrokenConnectionViolation = shouldShowBrokenConnectionViolationForMultipleTransactions(reportTransactions, report, policy, violations, currentUserEmail); + const shouldShowBrokenConnectionViolation = shouldShowBrokenConnectionViolationForMultipleTransactions( + reportTransactions, + report, + policy, + violations, + currentUserEmail, + currentUserAccountID, + ); const userControlsReport = isReportSubmitter || isReportApprover || isAdmin; return userControlsReport && shouldShowBrokenConnectionViolation; } @@ -306,12 +321,19 @@ function isMarkAsResolvedAction(report?: Report, violations?: TransactionViolati return violations?.some((violation) => violation.name === CONST.VIOLATIONS.AUTO_REPORTED_REJECTED_EXPENSE); } -function isPrimaryMarkAsResolvedAction(currentUserEmail: string, report?: Report, reportTransactions?: Transaction[], violations?: OnyxCollection, policy?: Policy) { +function isPrimaryMarkAsResolvedAction( + currentUserEmail: string, + currentUserAccountID: number, + report?: Report, + reportTransactions?: Transaction[], + violations?: OnyxCollection, + policy?: Policy, +) { if (!reportTransactions || reportTransactions.length !== 1) { return false; } - const transactionViolations = getTransactionViolations(reportTransactions.at(0), violations, currentUserEmail, report, policy); + const transactionViolations = getTransactionViolations(reportTransactions.at(0), violations, currentUserEmail, currentUserAccountID, report, policy); return isExpenseReportUtils(report) && isMarkAsResolvedAction(report, transactionViolations, policy); } @@ -335,6 +357,7 @@ function getAllExpensesToHoldIfApplicable(report: Report | undefined, reportActi function getReportPrimaryAction(params: GetReportPrimaryActionParams): ValueOf | '' { const { currentUserEmail, + currentUserAccountID, report, reportTransactions, violations, @@ -363,11 +386,11 @@ function getReportPrimaryAction(params: GetReportPrimaryActionParams): ValueOf isDuplicate(transaction, currentUserLogin, report, policy)); + const reportHasDuplicatedTransactions = reportTransactions.some((transaction) => isDuplicate(transaction, currentUserLogin, currentUserAccountID, report, policy)); if (isExpenseReport && isProcessingReport && reportHasDuplicatedTransactions) { return true; @@ -235,7 +235,7 @@ function isApproveAction(currentUserLogin: string, report: Report, reportTransac return false; } - const hasAllPendingRTERViolations = allHavePendingRTERViolation(reportTransactions, violations, currentUserLogin, report, policy); + const hasAllPendingRTERViolations = allHavePendingRTERViolation(reportTransactions, violations, currentUserLogin, currentUserAccountID, report, policy); if (hasAllPendingRTERViolations) { return true; @@ -243,7 +243,14 @@ function isApproveAction(currentUserLogin: string, report: Report, reportTransac const isAdmin = policy?.role === CONST.POLICY.ROLE.ADMIN; - const shouldShowBrokenConnectionViolation = shouldShowBrokenConnectionViolationForMultipleTransactions(reportTransactions, report, policy, violations, currentUserLogin); + const shouldShowBrokenConnectionViolation = shouldShowBrokenConnectionViolationForMultipleTransactions( + reportTransactions, + report, + policy, + violations, + currentUserLogin, + currentUserAccountID, + ); const isReportApprover = isApproverUtils(policy, currentUserLogin); const userControlsReport = isReportApprover || isAdmin; return userControlsReport && shouldShowBrokenConnectionViolation; @@ -614,6 +621,7 @@ function isReportLayoutAction(report: Report, reportTransactions: Transaction[]) function getSecondaryReportActions({ currentUserEmail, + currentUserAccountID, report, chatReport, reportTransactions, @@ -626,6 +634,7 @@ function getSecondaryReportActions({ isChatReportArchived = false, }: { currentUserEmail: string; + currentUserAccountID: number; report: Report; chatReport: OnyxEntry; reportTransactions: Transaction[]; @@ -650,6 +659,7 @@ function getSecondaryReportActions({ const primaryAction = getReportPrimaryAction({ currentUserEmail, + currentUserAccountID, report, chatReport, reportTransactions, diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index fa97e3ad07f6..49421f528cec 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -8985,10 +8985,44 @@ function shouldDisplayViolationsRBRInLHN(report: OnyxEntry, transactionV return ( !isInvoiceReport(potentialReport) && - ViolationsUtils.hasVisibleViolationsForUser(potentialReport, transactionViolations, currentUserEmail ?? '', policy, transactions) && - (hasViolations(potentialReport.reportID, transactionViolations, true, transactions, currentUserEmail, potentialReport, policy) || - hasWarningTypeViolations(potentialReport.reportID, transactionViolations, true, transactions, currentUserEmail, potentialReport, policy) || - hasNoticeTypeViolations(potentialReport.reportID, transactionViolations, true, transactions, currentUserEmail, potentialReport, policy)) + ViolationsUtils.hasVisibleViolationsForUser( + potentialReport, + transactionViolations, + currentUserEmail ?? '', + currentUserAccountID ?? CONST.DEFAULT_NUMBER_ID, + policy, + transactions, + ) && + (hasViolations( + potentialReport.reportID, + transactionViolations, + currentUserAccountID ?? CONST.DEFAULT_NUMBER_ID, + currentUserEmail ?? '', + true, + transactions, + potentialReport, + policy, + ) || + hasWarningTypeViolations( + potentialReport.reportID, + transactionViolations, + currentUserAccountID ?? CONST.DEFAULT_NUMBER_ID, + currentUserEmail ?? '', + true, + transactions, + potentialReport, + policy, + ) || + hasNoticeTypeViolations( + potentialReport.reportID, + transactionViolations, + currentUserAccountID ?? CONST.DEFAULT_NUMBER_ID, + currentUserEmail ?? '', + true, + transactions, + potentialReport, + policy, + )) ); }); } @@ -8999,14 +9033,15 @@ function shouldDisplayViolationsRBRInLHN(report: OnyxEntry, transactionV function hasViolations( reportID: string | undefined, transactionViolations: OnyxCollection, + currentUserAccountIDParam: number, + currentUserEmailParam: string, shouldShowInReview?: boolean, reportTransactions?: Transaction[], - currentUserEmailParam?: string, report?: OnyxEntry, policy?: OnyxEntry, ): boolean { const transactions = reportTransactions ?? getReportTransactions(reportID); - return transactions.some((transaction) => hasViolation(transaction, transactionViolations, currentUserEmailParam ?? '', report, policy, shouldShowInReview)); + return transactions.some((transaction) => hasViolation(transaction, transactionViolations, currentUserEmailParam ?? '', currentUserAccountIDParam, report, policy, shouldShowInReview)); } /** @@ -9015,14 +9050,17 @@ function hasViolations( function hasWarningTypeViolations( reportID: string | undefined, transactionViolations: OnyxCollection, + currentUserAccountIDParam: number, + currentUserEmailParam: string, shouldShowInReview?: boolean, reportTransactions?: Transaction[], - currentUserEmailParam?: string, report?: OnyxEntry, policy?: OnyxEntry, ): boolean { const transactions = reportTransactions ?? getReportTransactions(reportID); - return transactions.some((transaction) => hasWarningTypeViolation(transaction, transactionViolations, currentUserEmailParam ?? '', report, policy, shouldShowInReview)); + return transactions.some((transaction) => + hasWarningTypeViolation(transaction, transactionViolations, currentUserEmailParam ?? '', currentUserAccountIDParam, report, policy, shouldShowInReview), + ); } /** @@ -9051,14 +9089,17 @@ function hasReceiptErrors(reportID: string | undefined): boolean { function hasNoticeTypeViolations( reportID: string | undefined, transactionViolations: OnyxCollection, + currentUserAccountIDParam: number, + currentUserEmailParam: string, shouldShowInReview?: boolean, reportTransactions?: Transaction[], - currentUserEmailParam?: string, report?: OnyxEntry, policy?: OnyxEntry, ): boolean { const transactions = reportTransactions ?? getReportTransactions(reportID); - return transactions.some((transaction) => hasNoticeTypeViolation(transaction, transactionViolations, currentUserEmailParam ?? '', report, policy, shouldShowInReview)); + return transactions.some((transaction) => + hasNoticeTypeViolation(transaction, transactionViolations, currentUserEmailParam ?? '', currentUserAccountIDParam, report, policy, shouldShowInReview), + ); } /** @@ -9067,15 +9108,16 @@ function hasNoticeTypeViolations( function hasAnyViolations( reportID: string | undefined, transactionViolations: OnyxCollection, + currentUserAccountIDParam: number, + currentUserEmailParam: string, reportTransactions?: Transaction[], - currentUserEmailParam?: string, report?: OnyxEntry, policy?: OnyxEntry, ) { return ( - hasViolations(reportID, transactionViolations, undefined, reportTransactions, currentUserEmailParam, report, policy) || - hasNoticeTypeViolations(reportID, transactionViolations, true, reportTransactions, currentUserEmailParam, report, policy) || - hasWarningTypeViolations(reportID, transactionViolations, true, reportTransactions, currentUserEmailParam, report, policy) + hasViolations(reportID, transactionViolations, currentUserAccountIDParam, currentUserEmailParam, undefined, reportTransactions, report, policy) || + hasNoticeTypeViolations(reportID, transactionViolations, currentUserAccountIDParam, currentUserEmailParam, true, reportTransactions, report, policy) || + hasWarningTypeViolations(reportID, transactionViolations, currentUserAccountIDParam, currentUserEmailParam ?? '', true, reportTransactions, report, policy) ); } @@ -9095,12 +9137,14 @@ function shouldBlockSubmitDueToStrictPolicyRules( reportID: string | undefined, transactionViolations: OnyxCollection, areStrictPolicyRulesEnabled: boolean, + currentUserAccountIDParam: number, + currentUserEmailParam: string, reportTransactions?: Transaction[], ) { if (!areStrictPolicyRulesEnabled) { return false; } - return hasAnyViolations(reportID, transactionViolations, reportTransactions); + return hasAnyViolations(reportID, transactionViolations, currentUserAccountIDParam, currentUserEmailParam, reportTransactions); } type ReportErrorsAndReportActionThatRequiresAttention = { diff --git a/src/libs/SearchUIUtils.ts b/src/libs/SearchUIUtils.ts index 565ccc37916a..145eccc07eda 100644 --- a/src/libs/SearchUIUtils.ts +++ b/src/libs/SearchUIUtils.ts @@ -935,6 +935,7 @@ function getTransactionViolations( // eslint-disable-next-line @typescript-eslint/no-deprecated transaction: SearchTransaction, currentUserEmail: string, + currentUserAccountID: number, report: OnyxEntry, policy: OnyxEntry, ): OnyxTypes.TransactionViolation[] { @@ -942,7 +943,7 @@ function getTransactionViolations( if (!transactionViolations) { return []; } - return transactionViolations.filter((violation) => !isViolationDismissed(transaction, violation, currentUserEmail, report, policy)); + return transactionViolations.filter((violation) => !isViolationDismissed(transaction, violation, currentUserEmail, currentUserAccountID, report, policy)); } /** @@ -1091,7 +1092,7 @@ function getTransactionsSections( const reportAction = moneyRequestReportActionsByTransactionID.get(transactionItem.transactionID); const policy = data[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]; const shouldShowBlankTo = !report || isOpenExpenseReport(report); - const transactionViolations = getTransactionViolations(allViolations, transactionItem, currentUserEmail, report, policy); + const transactionViolations = getTransactionViolations(allViolations, transactionItem, currentUserEmail, currentAccountID ?? CONST.DEFAULT_NUMBER_ID, report, policy); // Use Map.get() for faster lookups with default values const from = reportAction?.actorAccountID ? (personalDetailsMap.get(reportAction.actorAccountID.toString()) ?? emptyPersonalDetails) : emptyPersonalDetails; const to = getToFieldValueForTransaction(transactionItem, report, data.personalDetailsList, reportAction); @@ -1278,12 +1279,19 @@ function getActions( const chatReportRNVP = data[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.chatReportID}`] ?? undefined; const isChatReportArchived = isArchivedReport(chatReportRNVP); - const hasAnyViolationsForReport = hasAnyViolations(report.reportID, allViolations, allReportTransactions, currentUserEmail, report, policy); - const hasVisibleViolationsForReport = hasAnyViolationsForReport && ViolationsUtils.hasVisibleViolationsForUser(report, allViolations, currentUserEmail, policy, allReportTransactions); + const hasAnyViolationsForReport = hasAnyViolations(report.reportID, allViolations, currentAccountID ?? CONST.DEFAULT_NUMBER_ID, currentUserEmail, allReportTransactions, report, policy); + const hasVisibleViolationsForReport = + hasAnyViolationsForReport && + ViolationsUtils.hasVisibleViolationsForUser(report, allViolations, currentUserEmail, currentAccountID ?? CONST.DEFAULT_NUMBER_ID, policy, allReportTransactions); // Only check for violations if we need to (when user has permission to review) if ((isSubmitter || isApprover || isAdmin) && hasVisibleViolationsForReport) { - if (isSubmitter && !isApprover && !isAdmin && !canReview(report, allViolations, isIOUReportArchived || isChatReportArchived, currentUserEmail, policy, allReportTransactions)) { + if ( + isSubmitter && + !isApprover && + !isAdmin && + !canReview(report, allViolations, isIOUReportArchived || isChatReportArchived, currentUserEmail, currentAccountID ?? CONST.DEFAULT_NUMBER_ID, policy, allReportTransactions) + ) { allActions.push(CONST.SEARCH.ACTION_TYPES.VIEW); } else { allActions.push(CONST.SEARCH.ACTION_TYPES.REVIEW); @@ -1597,7 +1605,7 @@ function getReportSections( const report = data[`${ONYXKEYS.COLLECTION.REPORT}${transactionItem.reportID}`] as SearchReport | undefined; const policy = data[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]; const shouldShowBlankTo = !report || isOpenExpenseReport(report); - const transactionViolations = getTransactionViolations(allViolations, transactionItem, currentUserEmail, report, policy); + const transactionViolations = getTransactionViolations(allViolations, transactionItem, currentUserEmail, currentAccountID ?? CONST.DEFAULT_NUMBER_ID, report, policy); const actions = Object.values(reportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionItem.reportID}`] ?? {}); const from = reportAction?.actorAccountID ? (data.personalDetailsList?.[reportAction.actorAccountID] ?? emptyPersonalDetails) : emptyPersonalDetails; const to = getToFieldValueForTransaction(transactionItem, report, data.personalDetailsList, reportAction); diff --git a/src/libs/TransactionPreviewUtils.ts b/src/libs/TransactionPreviewUtils.ts index d94ba971c188..dbb716b4e285 100644 --- a/src/libs/TransactionPreviewUtils.ts +++ b/src/libs/TransactionPreviewUtils.ts @@ -188,6 +188,7 @@ function getTransactionPreviewTextAndTranslationPaths({ violationMessage, reportActions, currentUserEmail, + currentUserAccountID, originalTransaction, }: { iouReport: OnyxEntry; @@ -200,6 +201,7 @@ function getTransactionPreviewTextAndTranslationPaths({ violationMessage?: string; reportActions?: OnyxTypes.ReportActions; currentUserEmail: string; + currentUserAccountID: number; originalTransaction?: OnyxEntry; }) { const isFetchingWaypoints = isFetchingWaypointsFromServer(transaction); @@ -219,7 +221,7 @@ function getTransactionPreviewTextAndTranslationPaths({ // This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850 // eslint-disable-next-line @typescript-eslint/no-deprecated const policy = getPolicy(iouReport?.policyID); - const hasViolationsOfTypeNotice = hasNoticeTypeViolation(transaction, violations, currentUserEmail ?? '', iouReport, policy, true) && isPaidGroupPolicy; + const hasViolationsOfTypeNotice = hasNoticeTypeViolation(transaction, violations, currentUserEmail ?? '', currentUserAccountID, iouReport, policy, true) && isPaidGroupPolicy; const hasActionWithErrors = hasActionWithErrorsForTransaction(iouReport?.reportID, transaction); const {amount: requestAmount, currency: requestCurrency} = transactionDetails; @@ -348,6 +350,7 @@ function createTransactionPreviewConditionals({ isReportAPolicyExpenseChat, areThereDuplicates, currentUserEmail, + currentUserAccountID, }: { iouReport: OnyxInputValue | undefined; transaction: OnyxEntry | undefined; @@ -358,6 +361,7 @@ function createTransactionPreviewConditionals({ isReportAPolicyExpenseChat: boolean; areThereDuplicates: boolean; currentUserEmail: string; + currentUserAccountID: number; }) { const {amount: requestAmount, comment: requestComment, merchant, tag, category} = transactionDetails; @@ -372,7 +376,7 @@ function createTransactionPreviewConditionals({ // eslint-disable-next-line @typescript-eslint/no-deprecated const policy = getPolicy(iouReport?.policyID); const hasViolationsOfTypeNotice = - hasNoticeTypeViolation(transaction, violations, currentUserEmail ?? '', iouReport ?? undefined, policy, true) && iouReport && isPaidGroupPolicyUtil(iouReport); + hasNoticeTypeViolation(transaction, violations, currentUserEmail ?? '', currentUserAccountID, iouReport ?? undefined, policy, true) && iouReport && isPaidGroupPolicyUtil(iouReport); const hasFieldErrors = hasMissingSmartscanFields(transaction); const isFetchingWaypoints = isFetchingWaypointsFromServer(transaction); @@ -392,8 +396,8 @@ function createTransactionPreviewConditionals({ isUnreportedAndHasInvalidDistanceRateTransaction(transaction) || // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing hasViolationsOfTypeNotice || - hasWarningTypeViolation(transaction, violations, currentUserEmail ?? '', iouReport ?? undefined, policy) || - hasViolation(transaction, violations, currentUserEmail ?? '', iouReport ?? undefined, policy, true) || + hasWarningTypeViolation(transaction, violations, currentUserEmail ?? '', currentUserAccountID, iouReport ?? undefined, policy) || + hasViolation(transaction, violations, currentUserEmail ?? '', currentUserAccountID, iouReport ?? undefined, policy, true) || (isDistanceRequest(transaction) && violations?.some( (violation) => violation.name === CONST.VIOLATIONS.MODIFIED_AMOUNT && (violation.type === CONST.VIOLATION_TYPES.VIOLATION || violation.type === CONST.VIOLATION_TYPES.NOTICE), diff --git a/src/libs/TransactionUtils/index.ts b/src/libs/TransactionUtils/index.ts index 7f0abbe57f64..3ba790edd0a2 100644 --- a/src/libs/TransactionUtils/index.ts +++ b/src/libs/TransactionUtils/index.ts @@ -136,14 +136,6 @@ Onyx.connect({ callback: (value) => (allTransactionViolations = value), }); -let deprecatedCurrentUserAccountID = -1; -Onyx.connect({ - key: ONYXKEYS.SESSION, - callback: (val) => { - deprecatedCurrentUserAccountID = val?.accountID ?? CONST.DEFAULT_NUMBER_ID; - }, -}); - function hasDistanceCustomUnit(transaction: OnyxEntry): boolean { const type = transaction?.comment?.type; const customUnitName = transaction?.comment?.customUnit?.name; @@ -1098,6 +1090,7 @@ function getTransactionViolations( transaction: OnyxEntry, transactionViolations: OnyxCollection, currentUserEmail: string, + currentUserAccountID: number, iouReport: OnyxEntry, policy: OnyxEntry, ): TransactionViolations | undefined { @@ -1106,7 +1099,7 @@ function getTransactionViolations( } return transactionViolations?.[ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS + transaction.transactionID]?.filter( - (violation) => !isViolationDismissed(transaction, violation, currentUserEmail, iouReport, policy), + (violation) => !isViolationDismissed(transaction, violation, currentUserEmail, currentUserAccountID, iouReport, policy), ); } @@ -1135,10 +1128,11 @@ function hasBrokenConnectionViolation( transaction: Transaction | SearchTransaction, transactionViolations: OnyxCollection | undefined, currentUserEmail: string, + currentUserAccountID: number, report: OnyxEntry, policy: OnyxEntry, ): boolean { - const violations = getTransactionViolations(transaction, transactionViolations, currentUserEmail, report, policy); + const violations = getTransactionViolations(transaction, transactionViolations, currentUserEmail, currentUserAccountID, report, policy); return !!violations?.find((violation) => isBrokenConnectionViolation(violation)); } @@ -1186,6 +1180,7 @@ function shouldShowBrokenConnectionViolationForMultipleTransactions( policy: OnyxEntry, transactionViolations: OnyxCollection, currentUserEmail: string, + currentUserAccountID: number, ): boolean { const brokenConnectionViolations = transactions.flatMap((transaction) => { const violations = transactionViolations?.[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transaction.transactionID}`] ?? []; @@ -1199,7 +1194,7 @@ function shouldShowBrokenConnectionViolationForMultipleTransactions( return false; } - if (isViolationDismissed(transaction, violation, currentUserEmail, report, policy)) { + if (isViolationDismissed(transaction, violation, currentUserEmail, currentUserAccountID, report, policy)) { return false; } @@ -1274,6 +1269,7 @@ function allHavePendingRTERViolation( transactions: OnyxEntry, transactionViolations: OnyxCollection | undefined, currentUserEmail: string, + currentUserAccountID: number, report: OnyxEntry, policy: OnyxEntry, ): boolean { @@ -1283,7 +1279,7 @@ function allHavePendingRTERViolation( const transactionsWithRTERViolations = transactions.map((transaction) => { // Get violations not dismissed by current user - const filteredTransactionViolations = getTransactionViolations(transaction, transactionViolations, currentUserEmail, report, policy)?.filter((violation) => + const filteredTransactionViolations = getTransactionViolations(transaction, transactionViolations, currentUserEmail, currentUserAccountID, report, policy)?.filter((violation) => // Further filter to only violations visible to the current user shouldShowViolation(report, policy, violation.name, currentUserEmail), ); @@ -1308,13 +1304,14 @@ function hasAnyTransactionWithoutRTERViolation( transactions: Transaction[] | SearchTransaction[], transactionViolations: OnyxCollection | undefined, currentUserEmail: string, + currentUserAccountID: number, report: OnyxEntry, policy: OnyxEntry, ): boolean { return ( transactions.length > 0 && transactions.some((transaction) => { - return !hasBrokenConnectionViolation(transaction, transactionViolations, currentUserEmail, report, policy); + return !hasBrokenConnectionViolation(transaction, transactionViolations, currentUserEmail, currentUserAccountID, report, policy); }) ); } @@ -1404,7 +1401,7 @@ function getRecentTransactions(transactions: Record, size = 2): * Check if transaction has duplicatedTransaction violation. * @param transactionID - the transaction to check */ -function isDuplicate(transaction: OnyxEntry, currentUserEmail: string, iouReport: OnyxEntry, policy: OnyxEntry): boolean { +function isDuplicate(transaction: OnyxEntry, currentUserEmail: string, currentUserAccountID: number, iouReport: OnyxEntry, policy: OnyxEntry): boolean { if (!transaction) { return false; } @@ -1412,7 +1409,7 @@ function isDuplicate(transaction: OnyxEntry, currentUserEmail: stri (violation: TransactionViolation) => violation.name === CONST.VIOLATIONS.DUPLICATED_TRANSACTION, ); const hasDuplicatedTransactionViolation = !!duplicatedTransactionViolation; - const isDuplicatedTransactionViolationDismissed = isViolationDismissed(transaction, duplicatedTransactionViolation, currentUserEmail, iouReport, policy); + const isDuplicatedTransactionViolationDismissed = isViolationDismissed(transaction, duplicatedTransactionViolation, currentUserEmail, currentUserAccountID, iouReport, policy); return hasDuplicatedTransactionViolation && !isDuplicatedTransactionViolationDismissed; } @@ -1435,6 +1432,7 @@ function isViolationDismissed( transaction: OnyxEntry, violation: TransactionViolation | undefined, currentUserEmail: string, + currentUserAccountID: number, iouReport: OnyxEntry, policy: OnyxEntry, ): boolean { @@ -1464,7 +1462,6 @@ function isViolationDismissed( return false; } - const currentUserAccountID = deprecatedCurrentUserAccountID; const isSubmitter = iouReport.ownerAccountID === currentUserAccountID; const shouldViewAsSubmitter = !isSubmitter && isOpenExpenseReport(iouReport); @@ -1495,6 +1492,7 @@ function hasViolation( transaction: Transaction | undefined, transactionViolations: TransactionViolation[] | OnyxCollection, currentUserEmail: string, + currentUserAccountID: number, iouReport: OnyxEntry, policy: OnyxEntry, showInReview?: boolean, @@ -1508,12 +1506,13 @@ function hasViolation( (violation) => violation.type === CONST.VIOLATION_TYPES.VIOLATION && (showInReview === undefined || showInReview === (violation.showInReview ?? false)) && - !isViolationDismissed(transaction, violation, currentUserEmail, iouReport, policy), + !isViolationDismissed(transaction, violation, currentUserEmail, currentUserAccountID, iouReport, policy), ); } function hasDuplicateTransactions( currentUserEmail: string, + currentUserAccountID: number, iouReport: OnyxEntry, policy: OnyxEntry, // eslint-disable-next-line @typescript-eslint/no-deprecated @@ -1522,7 +1521,7 @@ function hasDuplicateTransactions( const transactionsByIouReportID = getReportTransactions(iouReport?.reportID); const reportTransactions = allReportTransactions ?? transactionsByIouReportID; - return reportTransactions.length > 0 && reportTransactions.some((transaction) => isDuplicate(transaction, currentUserEmail, iouReport, policy)); + return reportTransactions.length > 0 && reportTransactions.some((transaction) => isDuplicate(transaction, currentUserEmail, currentUserAccountID, iouReport, policy)); } /** @@ -1532,6 +1531,7 @@ function hasNoticeTypeViolation( transaction: OnyxEntry, transactionViolations: TransactionViolation[] | OnyxCollection, currentUserEmail: string, + currentUserAccountID: number, iouReport: OnyxEntry, policy: OnyxEntry, showInReview?: boolean, @@ -1545,7 +1545,7 @@ function hasNoticeTypeViolation( (violation: TransactionViolation) => violation.type === CONST.VIOLATION_TYPES.NOTICE && (showInReview === undefined || showInReview === (violation.showInReview ?? false)) && - !isViolationDismissed(transaction, violation, currentUserEmail, iouReport, policy), + !isViolationDismissed(transaction, violation, currentUserEmail, currentUserAccountID, iouReport, policy), ); } @@ -1556,6 +1556,7 @@ function hasWarningTypeViolation( transaction: OnyxEntry, transactionViolations: TransactionViolation[] | OnyxCollection, currentUserEmail: string, + currentUserAccountID: number, iouReport: OnyxEntry, policy: OnyxEntry, showInReview?: boolean, @@ -1570,7 +1571,7 @@ function hasWarningTypeViolation( (violation: TransactionViolation) => violation.type === CONST.VIOLATION_TYPES.WARNING && (showInReview === undefined || showInReview === (violation.showInReview ?? false)) && - !isViolationDismissed(transaction, violation, currentUserEmail, iouReport, policy), + !isViolationDismissed(transaction, violation, currentUserEmail, currentUserAccountID, iouReport, policy), ) ?? []; return warningTypeViolations.length > 0; diff --git a/src/libs/Violations/ViolationsUtils.ts b/src/libs/Violations/ViolationsUtils.ts index 39be44a88a60..85060e157196 100644 --- a/src/libs/Violations/ViolationsUtils.ts +++ b/src/libs/Violations/ViolationsUtils.ts @@ -640,6 +640,7 @@ const ViolationsUtils = { report: OnyxEntry, violations: OnyxCollection, currentUserEmail: string, + currentUserAccountID: number, policy: OnyxEntry, transactions: Transaction[], ): boolean { @@ -656,7 +657,10 @@ const ViolationsUtils = { // Check if any violation is not dismissed and should be shown based on user role and violation type return transactionViolations.some((violation: TransactionViolation) => { - return !isViolationDismissed(transaction, violation, currentUserEmail, report, policy) && shouldShowViolation(report, policy, violation.name, currentUserEmail); + return ( + !isViolationDismissed(transaction, violation, currentUserEmail, currentUserAccountID, report, policy) && + shouldShowViolation(report, policy, violation.name, currentUserEmail) + ); }); }); }, diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 37ec827a031b..8e5f20ea9545 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -3679,7 +3679,7 @@ function getMoneyRequestInformation(moneyRequestInformation: MoneyRequestInforma : {}; const predictedNextStatus = policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_NO ? CONST.REPORT.STATUS_NUM.CLOSED : CONST.REPORT.STATUS_NUM.OPEN; - const hasViolations = hasViolationsReportUtils(iouReport.reportID, transactionViolations); + const hasViolations = hasViolationsReportUtils(iouReport.reportID, transactionViolations, currentUserAccountIDParam, currentUserEmailParam); // eslint-disable-next-line @typescript-eslint/no-deprecated const optimisticNextStep = buildNextStepNew({ report: iouReport, @@ -4799,7 +4799,7 @@ function getUpdateMoneyRequestParams(params: GetUpdateMoneyRequestParamsType): U const currentNextStep = allNextSteps[`${ONYXKEYS.COLLECTION.NEXT_STEP}${iouReport?.reportID}`] ?? {}; const shouldFixViolations = Array.isArray(violationsOnyxData.value) && violationsOnyxData.value.length > 0; const moneyRequestReport = updatedMoneyRequestReport ?? iouReport ?? undefined; - const hasViolations = hasViolationsReportUtils(moneyRequestReport?.reportID, allTransactionViolations); + const hasViolations = hasViolationsReportUtils(moneyRequestReport?.reportID, allTransactionViolations, currentUserAccountIDParam, currentUserEmailParam); optimisticData.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.NEXT_STEP}${iouReport?.reportID}`, @@ -7321,7 +7321,7 @@ function createSplitsAndOnyxData({ transactionTags: tag, }) : {}; - const hasViolations = hasViolationsReportUtils(oneOnOneIOUReport.reportID, transactionViolations); + const hasViolations = hasViolationsReportUtils(oneOnOneIOUReport.reportID, transactionViolations, currentUserAccountID, currentUserEmailForIOUSplit); // STEP 5: Build Onyx Data const [oneOnOneOptimisticData, oneOnOneSuccessData, oneOnOneFailureData] = buildOnyxDataForMoneyRequest({ @@ -8142,7 +8142,7 @@ function completeSplitBill( } else { oneOnOneReportPreviewAction = buildOptimisticReportPreview(oneOnOneChatReport, oneOnOneIOUReport, '', oneOnOneTransaction); } - const hasViolations = hasViolationsReportUtils(oneOnOneIOUReport.reportID, transactionViolations); + const hasViolations = hasViolationsReportUtils(oneOnOneIOUReport.reportID, transactionViolations, sessionAccountID, sessionEmail ?? ''); const [oneOnOneOptimisticData, oneOnOneSuccessData, oneOnOneFailureData] = buildOnyxDataForMoneyRequest({ isNewChatReport: isNewOneOnOneChatReport, @@ -10498,8 +10498,8 @@ function canSubmitReport( const currentUserAccountID = getCurrentUserAccountID(); const isOpenExpenseReport = isOpenExpenseReportReportUtils(report); const isAdmin = policy?.role === CONST.POLICY.ROLE.ADMIN; - const hasAllPendingRTERViolations = allHavePendingRTERViolation(transactions, allViolations, currentUserEmailParam, report, policy); - const hasTransactionWithoutRTERViolation = hasAnyTransactionWithoutRTERViolation(transactions, allViolations, currentUserEmailParam, report, policy); + const hasAllPendingRTERViolations = allHavePendingRTERViolation(transactions, allViolations, currentUserEmailParam, currentUserAccountID, report, policy); + const hasTransactionWithoutRTERViolation = hasAnyTransactionWithoutRTERViolation(transactions, allViolations, currentUserEmailParam, currentUserAccountID, report, policy); const hasOnlyPendingCardOrScanFailTransactions = transactions.length > 0 && transactions.every((t) => isPendingCardOrScanningTransaction(t)); return ( @@ -10550,7 +10550,7 @@ function approveMoneyRequest( const currentNextStepDeprecated = allNextSteps[`${ONYXKEYS.COLLECTION.NEXT_STEP}${expenseReport.reportID}`] ?? null; let total = expenseReport.total ?? 0; const hasHeldExpenses = hasHeldExpensesReportUtils(expenseReport.reportID); - const hasDuplicates = hasDuplicateTransactions(currentUserEmailParam, expenseReport, policy); + const hasDuplicates = hasDuplicateTransactions(currentUserEmailParam, currentUserAccountIDParam, expenseReport, policy); if (hasHeldExpenses && !full && !!expenseReport.unheldTotal) { total = expenseReport.unheldTotal; } @@ -10724,7 +10724,9 @@ function approveMoneyRequest( // Remove duplicates violations if we approve the report if (hasDuplicates) { - const transactions = getReportTransactions(expenseReport.reportID).filter((transaction) => isDuplicate(transaction, currentUserEmailParam, expenseReport, policy)); + const transactions = getReportTransactions(expenseReport.reportID).filter((transaction) => + isDuplicate(transaction, currentUserEmailParam, currentUserAccountIDParam, expenseReport, policy), + ); if (!full) { transactions.filter((transaction) => !isOnHold(transaction)); } diff --git a/src/libs/actions/Transaction.ts b/src/libs/actions/Transaction.ts index 7469c6d515f7..d3e1195d8559 100644 --- a/src/libs/actions/Transaction.ts +++ b/src/libs/actions/Transaction.ts @@ -1307,7 +1307,7 @@ function changeTransactionsReport( reportID: destinationReport?.reportID ?? destinationReportID ?? reportID, total: destinationTotal, }; - const hasViolations = hasViolationsReportUtils(nextStepReport?.reportID, allTransactionViolation); + const hasViolations = hasViolationsReportUtils(nextStepReport?.reportID, allTransactionViolation, accountID, email ?? ''); // buildOptimisticNextStep is used in parallel // eslint-disable-next-line @typescript-eslint/no-deprecated diff --git a/src/pages/EditReportFieldPage.tsx b/src/pages/EditReportFieldPage.tsx index 12528ef9021c..3f674634c150 100644 --- a/src/pages/EditReportFieldPage.tsx +++ b/src/pages/EditReportFieldPage.tsx @@ -48,7 +48,7 @@ function EditReportFieldPage({route}: EditReportFieldPageProps) { const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT); const session = useSession(); const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true}); - const hasViolations = hasViolationsReportUtils(report?.reportID, transactionViolations); + const hasViolations = hasViolationsReportUtils(report?.reportID, transactionViolations, session?.accountID ?? CONST.DEFAULT_NUMBER_ID, session?.email ?? ''); const [isDeleteModalVisible, setIsDeleteModalVisible] = useState(false); const {translate} = useLocalize(); diff --git a/src/pages/NewReportWorkspaceSelectionPage.tsx b/src/pages/NewReportWorkspaceSelectionPage.tsx index dc5ddcdeb011..00e430650f06 100644 --- a/src/pages/NewReportWorkspaceSelectionPage.tsx +++ b/src/pages/NewReportWorkspaceSelectionPage.tsx @@ -1,4 +1,4 @@ -import {accountIDSelector} from '@selectors/Session'; +import {accountIDSelector, emailSelector} from '@selectors/Session'; import React, {useCallback, useEffect, useMemo, useState} from 'react'; import type {OnyxCollection} from 'react-native-onyx'; import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator'; @@ -61,7 +61,9 @@ function NewReportWorkspaceSelectionPage({route}: NewReportWorkspaceSelectionPag const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true}); const {isBetaEnabled} = usePermissions(); const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT); - const hasViolations = hasViolationsReportUtils(undefined, transactionViolations); + const [accountID] = useOnyx(ONYXKEYS.SESSION, {selector: accountIDSelector, canBeMissing: true}); + const [email] = useOnyx(ONYXKEYS.SESSION, {selector: emailSelector, canBeMissing: true}); + const hasViolations = hasViolationsReportUtils(undefined, transactionViolations, accountID ?? CONST.DEFAULT_NUMBER_ID, email ?? ''); const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID, {canBeMissing: true}); const [policies, fetchStatus] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: true}); @@ -71,7 +73,6 @@ function NewReportWorkspaceSelectionPage({route}: NewReportWorkspaceSelectionPag const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP, {canBeMissing: true}); const shouldShowLoadingIndicator = isLoadingApp && !isOffline; const [pendingPolicySelection, setPendingPolicySelection] = useState<{policy: WorkspaceListItem; shouldShowEmptyReportConfirmation: boolean} | null>(null); - const [accountID] = useOnyx(ONYXKEYS.SESSION, {selector: accountIDSelector, canBeMissing: true}); const policiesWithEmptyReportsSelector = useCallback( (reports: OnyxCollection) => { diff --git a/src/pages/ReportAddApproverPage.tsx b/src/pages/ReportAddApproverPage.tsx index c7de3ba3d4ca..b7906797fbe9 100644 --- a/src/pages/ReportAddApproverPage.tsx +++ b/src/pages/ReportAddApproverPage.tsx @@ -39,9 +39,8 @@ function ReportAddApproverPage({report, isLoadingReportData, policy}: ReportAddA const {isBetaEnabled} = usePermissions(); const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true}); const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT); - const hasViolations = hasViolationsReportUtils(report?.reportID, transactionViolations); - const currentUserDetails = useCurrentUserPersonalDetails(); + const hasViolations = hasViolationsReportUtils(report?.reportID, transactionViolations, currentUserDetails.accountID, currentUserDetails.login ?? ''); const employeeList = policy?.employeeList; const allApprovers = useMemo(() => { diff --git a/src/pages/ReportChangeApproverPage.tsx b/src/pages/ReportChangeApproverPage.tsx index dc80a1982e19..c6f45f6328d4 100644 --- a/src/pages/ReportChangeApproverPage.tsx +++ b/src/pages/ReportChangeApproverPage.tsx @@ -50,7 +50,7 @@ function ReportChangeApproverPage({report, policy, isLoadingReportData}: ReportC const {isBetaEnabled} = usePermissions(); const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true}); const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT); - const hasViolations = hasViolationsReportUtils(report?.reportID, transactionViolations); + const hasViolations = hasViolationsReportUtils(report?.reportID, transactionViolations, currentUserDetails.accountID, currentUserDetails.login ?? ''); const changeApprover = useCallback(() => { if (!selectedApproverType) { diff --git a/src/pages/ReportChangeWorkspacePage.tsx b/src/pages/ReportChangeWorkspacePage.tsx index ccbb8675add6..0320124d86b7 100644 --- a/src/pages/ReportChangeWorkspacePage.tsx +++ b/src/pages/ReportChangeWorkspacePage.tsx @@ -64,7 +64,7 @@ function ReportChangeWorkspacePage({report, route}: ReportChangeWorkspacePagePro const {isBetaEnabled} = usePermissions(); const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT); const session = useSession(); - const hasViolations = hasViolationsReportUtils(report?.reportID, transactionViolations); + const hasViolations = hasViolationsReportUtils(report?.reportID, transactionViolations, session?.accountID ?? CONST.DEFAULT_NUMBER_ID, session?.email ?? ''); const selectPolicy = useCallback( (policyID?: string) => { diff --git a/src/pages/Search/EmptySearchView.tsx b/src/pages/Search/EmptySearchView.tsx index 787224860397..f13ef605272c 100644 --- a/src/pages/Search/EmptySearchView.tsx +++ b/src/pages/Search/EmptySearchView.tsx @@ -170,7 +170,8 @@ function EmptySearchViewContent({ const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true}); const {isBetaEnabled} = usePermissions(); const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT); - const hasViolations = hasViolationsReportUtils(undefined, transactionViolations); + const [accountID] = useOnyx(ONYXKEYS.SESSION, {selector: accountIDSelector, canBeMissing: true}); + const hasViolations = hasViolationsReportUtils(undefined, transactionViolations, accountID ?? CONST.DEFAULT_NUMBER_ID, ''); const [hasTransactions] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, { canBeMissing: true, @@ -194,7 +195,6 @@ function EmptySearchViewContent({ const defaultChatEnabledPolicyID = defaultChatEnabledPolicy?.id; - const [accountID] = useOnyx(ONYXKEYS.SESSION, {selector: accountIDSelector, canBeMissing: true}); const [reportSummaries = getEmptyArray()] = useOnyx(ONYXKEYS.COLLECTION.REPORT, { canBeMissing: true, selector: reportSummariesOnyxSelector, diff --git a/src/pages/Search/SearchTransactionsChangeReport.tsx b/src/pages/Search/SearchTransactionsChangeReport.tsx index 6e48fa2879bd..b9c0d0211fb9 100644 --- a/src/pages/Search/SearchTransactionsChangeReport.tsx +++ b/src/pages/Search/SearchTransactionsChangeReport.tsx @@ -33,10 +33,10 @@ function SearchTransactionsChangeReport() { const [allPolicyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}`, {canBeMissing: true}); const {policyForMovingExpensesID, shouldSelectPolicy} = usePolicyForMovingExpenses(); const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true}); - const hasViolations = hasViolationsReportUtils(undefined, transactionViolations); const {isBetaEnabled} = usePermissions(); const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT); const session = useSession(); + const hasViolations = hasViolationsReportUtils(undefined, transactionViolations, session?.accountID ?? CONST.DEFAULT_NUMBER_ID, session?.email ?? ''); const currentUserPersonalDetails = useCurrentUserPersonalDetails(); const policyForMovingExpenses = policyForMovingExpensesID ? allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyForMovingExpensesID}`] : undefined; diff --git a/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx b/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx index 4aa4e32f13b8..3e4f24512a15 100644 --- a/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx +++ b/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx @@ -154,8 +154,8 @@ function AttachmentPickerWithMenuItems({ const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true}); const {isBetaEnabled} = usePermissions(); const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT); - const hasViolations = hasViolationsReportUtils(undefined, transactionViolations); const [accountID] = useOnyx(ONYXKEYS.SESSION, {selector: accountIDSelector, canBeMissing: true}); + const hasViolations = hasViolationsReportUtils(undefined, transactionViolations, accountID ?? CONST.DEFAULT_NUMBER_ID, ''); const [reportSummaries = getEmptyArray[number]>()] = useOnyx(ONYXKEYS.COLLECTION.REPORT, { canBeMissing: true, selector: reportSummariesOnyxSelector, diff --git a/src/pages/home/sidebar/FloatingActionButtonAndPopover.tsx b/src/pages/home/sidebar/FloatingActionButtonAndPopover.tsx index 87c836bd1811..11255c6d1fca 100644 --- a/src/pages/home/sidebar/FloatingActionButtonAndPopover.tsx +++ b/src/pages/home/sidebar/FloatingActionButtonAndPopover.tsx @@ -165,7 +165,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu, ref const primaryContactMethod = primaryLogin ?? session?.email ?? ''; const [travelSettings] = useOnyx(ONYXKEYS.NVP_TRAVEL_SETTINGS, {canBeMissing: true}); const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT); - const hasViolations = hasViolationsReportUtils(undefined, transactionViolations); + const hasViolations = hasViolationsReportUtils(undefined, transactionViolations, session?.accountID ?? CONST.DEFAULT_NUMBER_ID, session?.email ?? ''); const canSendInvoice = useMemo(() => canSendInvoicePolicyUtils(allPolicies as OnyxCollection, session?.email), [allPolicies, session?.email]); const isValidReport = !(isEmptyObject(quickActionReport) || isReportArchived); diff --git a/src/pages/iou/request/step/IOURequestEditReport.tsx b/src/pages/iou/request/step/IOURequestEditReport.tsx index 3ef9e681e4e4..0cf3d3c13ecf 100644 --- a/src/pages/iou/request/step/IOURequestEditReport.tsx +++ b/src/pages/iou/request/step/IOURequestEditReport.tsx @@ -56,7 +56,7 @@ function IOURequestEditReport({route}: IOURequestEditReportProps) { const {policyForMovingExpensesID, shouldSelectPolicy} = usePolicyForMovingExpenses(hasPerDiemTransactions); const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true}); - const hasViolations = hasViolationsReportUtils(undefined, transactionViolations); + const hasViolations = hasViolationsReportUtils(undefined, transactionViolations, session?.accountID ?? CONST.DEFAULT_NUMBER_ID, session?.email ?? ''); const policyForMovingExpenses = policyForMovingExpensesID ? allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyForMovingExpensesID}`] : undefined; const selectReport = (item: TransactionGroupListItem, report?: OnyxEntry) => { diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index e9b6e26842c3..c50e835152ef 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -196,7 +196,7 @@ function IOURequestStepConfirmation({ const [reportAttributesDerived] = useOnyx(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES, {canBeMissing: true, selector: reportsSelector}); const [recentlyUsedDestinations] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_DESTINATIONS}${realPolicyID}`, {canBeMissing: true}); const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true}); - const hasViolations = hasViolationsReportUtils(report?.reportID, transactionViolations); + const hasViolations = hasViolationsReportUtils(report?.reportID, transactionViolations, currentUserPersonalDetails.accountID, currentUserPersonalDetails.login ?? ''); const policyCategories = useMemo(() => { if (isDraftPolicy && draftPolicyID) { diff --git a/src/pages/iou/request/step/IOURequestStepReport.tsx b/src/pages/iou/request/step/IOURequestStepReport.tsx index 02cb2f9d9d95..4fa2897ec967 100644 --- a/src/pages/iou/request/step/IOURequestStepReport.tsx +++ b/src/pages/iou/request/step/IOURequestStepReport.tsx @@ -58,7 +58,7 @@ function IOURequestStepReport({route, transaction}: IOURequestStepReportProps) { const currentUserPersonalDetails = useCurrentUserPersonalDetails(); const {policyForMovingExpensesID, shouldSelectPolicy} = usePolicyForMovingExpenses(isPerDiemRequest(transaction)); const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true}); - const hasViolations = hasViolationsReportUtils(undefined, transactionViolations); + const hasViolations = hasViolationsReportUtils(undefined, transactionViolations, session?.accountID ?? CONST.DEFAULT_NUMBER_ID, session?.email ?? ''); const policyForMovingExpenses = policyForMovingExpensesID ? allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyForMovingExpensesID}`] : undefined; useRestartOnReceiptFailure(transaction, reportIDFromRoute, iouType, action); diff --git a/tests/actions/ReportPreviewActionUtilsTest.ts b/tests/actions/ReportPreviewActionUtilsTest.ts index 215fd56c2887..881586ac8093 100644 --- a/tests/actions/ReportPreviewActionUtilsTest.ts +++ b/tests/actions/ReportPreviewActionUtilsTest.ts @@ -74,7 +74,7 @@ describe('getReportPreviewAction', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report); const policy = createRandomPolicy(0, CONST.POLICY.TYPE.PERSONAL); - expect(getReportPreviewAction(VIOLATIONS, false, CURRENT_USER_EMAIL, report, policy, [])).toBe(CONST.REPORT.REPORT_PREVIEW_ACTIONS.ADD_EXPENSE); + expect(getReportPreviewAction(VIOLATIONS, false, CURRENT_USER_EMAIL, CURRENT_USER_ACCOUNT_ID, report, policy, [])).toBe(CONST.REPORT.REPORT_PREVIEW_ACTIONS.ADD_EXPENSE); }); it('canSubmit should return true for expense preview report with manual submit', async () => { @@ -103,7 +103,9 @@ describe('getReportPreviewAction', () => { await waitForBatchedUpdatesWithAct(); - expect(getReportPreviewAction(VIOLATIONS, isReportArchived.current, CURRENT_USER_EMAIL, report, policy, [transaction])).toBe(CONST.REPORT.REPORT_PREVIEW_ACTIONS.SUBMIT); + expect(getReportPreviewAction(VIOLATIONS, isReportArchived.current, CURRENT_USER_EMAIL, CURRENT_USER_ACCOUNT_ID, report, policy, [transaction])).toBe( + CONST.REPORT.REPORT_PREVIEW_ACTIONS.SUBMIT, + ); }); it('canSubmit should return true for open report in instant submit policy with no approvers', async () => { @@ -133,7 +135,9 @@ describe('getReportPreviewAction', () => { // Simulate how components use a hook to pass the isReportArchived parameter const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.parentReportID)); - expect(getReportPreviewAction(VIOLATIONS, isReportArchived.current, CURRENT_USER_EMAIL, report, policy, [transaction])).toBe(CONST.REPORT.REPORT_PREVIEW_ACTIONS.SUBMIT); + expect(getReportPreviewAction(VIOLATIONS, isReportArchived.current, CURRENT_USER_EMAIL, CURRENT_USER_ACCOUNT_ID, report, policy, [transaction])).toBe( + CONST.REPORT.REPORT_PREVIEW_ACTIONS.SUBMIT, + ); }); it('canSubmit should return false for expense preview report with only pending transactions', async () => { @@ -166,7 +170,9 @@ describe('getReportPreviewAction', () => { await waitForBatchedUpdatesWithAct(); - expect(getReportPreviewAction(VIOLATIONS, isReportArchived.current, CURRENT_USER_EMAIL, report, policy, [transaction])).toBe(CONST.REPORT.REPORT_PREVIEW_ACTIONS.VIEW); + expect(getReportPreviewAction(VIOLATIONS, isReportArchived.current, CURRENT_USER_EMAIL, CURRENT_USER_ACCOUNT_ID, report, policy, [transaction])).toBe( + CONST.REPORT.REPORT_PREVIEW_ACTIONS.VIEW, + ); }); describe('canApprove', () => { @@ -194,7 +200,9 @@ describe('getReportPreviewAction', () => { const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.parentReportID)); await waitForBatchedUpdatesWithAct(); - expect(getReportPreviewAction(VIOLATIONS, isReportArchived.current, CURRENT_USER_EMAIL, report, policy, [transaction])).toBe(CONST.REPORT.REPORT_PREVIEW_ACTIONS.APPROVE); + expect(getReportPreviewAction(VIOLATIONS, isReportArchived.current, CURRENT_USER_EMAIL, CURRENT_USER_ACCOUNT_ID, report, policy, [transaction])).toBe( + CONST.REPORT.REPORT_PREVIEW_ACTIONS.APPROVE, + ); }); it('should return false for report with scanning expenses', async () => { @@ -222,7 +230,7 @@ describe('getReportPreviewAction', () => { }, } as unknown as Transaction; - expect(getReportPreviewAction(VIOLATIONS, false, CURRENT_USER_EMAIL, report, policy, [transaction])).toBe(CONST.REPORT.REPORT_PREVIEW_ACTIONS.VIEW); + expect(getReportPreviewAction(VIOLATIONS, false, CURRENT_USER_EMAIL, CURRENT_USER_ACCOUNT_ID, report, policy, [transaction])).toBe(CONST.REPORT.REPORT_PREVIEW_ACTIONS.VIEW); }); it('should return false for report with pending expenses', async () => { @@ -251,7 +259,7 @@ describe('getReportPreviewAction', () => { date: '2025-01-01', } as unknown as Transaction; - expect(getReportPreviewAction(VIOLATIONS, false, CURRENT_USER_EMAIL, report, policy, [transaction])).toBe(CONST.REPORT.REPORT_PREVIEW_ACTIONS.VIEW); + expect(getReportPreviewAction(VIOLATIONS, false, CURRENT_USER_EMAIL, CURRENT_USER_ACCOUNT_ID, report, policy, [transaction])).toBe(CONST.REPORT.REPORT_PREVIEW_ACTIONS.VIEW); }); }); @@ -279,7 +287,9 @@ describe('getReportPreviewAction', () => { const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.parentReportID)); await waitForBatchedUpdatesWithAct(); - expect(getReportPreviewAction(VIOLATIONS, isReportArchived.current, CURRENT_USER_EMAIL, report, policy, [transaction])).toBe(CONST.REPORT.REPORT_PREVIEW_ACTIONS.APPROVE); + expect(getReportPreviewAction(VIOLATIONS, isReportArchived.current, CURRENT_USER_EMAIL, CURRENT_USER_ACCOUNT_ID, report, policy, [transaction])).toBe( + CONST.REPORT.REPORT_PREVIEW_ACTIONS.APPROVE, + ); }); it('canPay should return true for expense report with payments enabled', async () => { @@ -304,7 +314,9 @@ describe('getReportPreviewAction', () => { const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.parentReportID)); await waitForBatchedUpdatesWithAct(); - expect(getReportPreviewAction(VIOLATIONS, isReportArchived.current, CURRENT_USER_EMAIL, report, policy, [transaction])).toBe(CONST.REPORT.REPORT_PREVIEW_ACTIONS.PAY); + expect(getReportPreviewAction(VIOLATIONS, isReportArchived.current, CURRENT_USER_EMAIL, CURRENT_USER_ACCOUNT_ID, report, policy, [transaction])).toBe( + CONST.REPORT.REPORT_PREVIEW_ACTIONS.PAY, + ); }); it('canPay should return false for Expense report with zero total amount', async () => { @@ -330,7 +342,7 @@ describe('getReportPreviewAction', () => { await waitForBatchedUpdatesWithAct(); // Should not show PAY button for zero amount Expenses - expect(getReportPreviewAction(VIOLATIONS, false, CURRENT_USER_EMAIL, report, policy, [transaction])).toBe(CONST.REPORT.REPORT_PREVIEW_ACTIONS.VIEW); + expect(getReportPreviewAction(VIOLATIONS, false, CURRENT_USER_EMAIL, CURRENT_USER_ACCOUNT_ID, report, policy, [transaction])).toBe(CONST.REPORT.REPORT_PREVIEW_ACTIONS.VIEW); }); it('canPay should return true for submitted invoice', async () => { @@ -359,7 +371,7 @@ describe('getReportPreviewAction', () => { const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.parentReportID)); await waitForBatchedUpdatesWithAct(); - expect(getReportPreviewAction(VIOLATIONS, isReportArchived.current, CURRENT_USER_EMAIL, report, policy, [transaction], invoiceReceiverPolicy)).toBe( + expect(getReportPreviewAction(VIOLATIONS, isReportArchived.current, CURRENT_USER_EMAIL, CURRENT_USER_ACCOUNT_ID, report, policy, [transaction], invoiceReceiverPolicy)).toBe( CONST.REPORT.REPORT_PREVIEW_ACTIONS.PAY, ); }); @@ -406,7 +418,7 @@ describe('getReportPreviewAction', () => { const {result: isReportArchived} = renderHook(() => useReportIsArchived(report.parentReportID)); await waitForBatchedUpdatesWithAct(); - expect(getReportPreviewAction(VIOLATIONS, isReportArchived.current, CURRENT_USER_EMAIL, report, policy, [transaction], invoiceReceiverPolicy)).toBe( + expect(getReportPreviewAction(VIOLATIONS, isReportArchived.current, CURRENT_USER_EMAIL, CURRENT_USER_ACCOUNT_ID, report, policy, [transaction], invoiceReceiverPolicy)).toBe( CONST.REPORT.REPORT_PREVIEW_ACTIONS.VIEW, ); }); @@ -441,7 +453,7 @@ describe('getReportPreviewAction', () => { } as unknown as Transaction; const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.parentReportID)); await waitForBatchedUpdatesWithAct(); - expect(getReportPreviewAction(VIOLATIONS, isReportArchived.current, CURRENT_USER_EMAIL, report, policy, [transaction], invoiceReceiverPolicy)).toBe( + expect(getReportPreviewAction(VIOLATIONS, isReportArchived.current, CURRENT_USER_EMAIL, CURRENT_USER_ACCOUNT_ID, report, policy, [transaction], invoiceReceiverPolicy)).toBe( CONST.REPORT.REPORT_PREVIEW_ACTIONS.PAY, ); }); @@ -471,7 +483,9 @@ describe('getReportPreviewAction', () => { const {result: isChatReportArchived} = renderHook(() => useReportIsArchived(report?.chatReportID)); await waitForBatchedUpdatesWithAct(); // Then the getReportPreviewAction should return the View action - expect(getReportPreviewAction(VIOLATIONS, isChatReportArchived.current, CURRENT_USER_EMAIL, report, policy, [transaction], undefined)).toBe(CONST.REPORT.REPORT_PREVIEW_ACTIONS.VIEW); + expect(getReportPreviewAction(VIOLATIONS, isChatReportArchived.current, CURRENT_USER_EMAIL, CURRENT_USER_ACCOUNT_ID, report, policy, [transaction], undefined)).toBe( + CONST.REPORT.REPORT_PREVIEW_ACTIONS.VIEW, + ); }); it('canExport should return true for finished reports', async () => { @@ -494,7 +508,7 @@ describe('getReportPreviewAction', () => { const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.parentReportID)); await waitForBatchedUpdatesWithAct(); - expect(getReportPreviewAction(VIOLATIONS, isReportArchived.current, CURRENT_USER_EMAIL, report, policy, [transaction])).toBe( + expect(getReportPreviewAction(VIOLATIONS, isReportArchived.current, CURRENT_USER_EMAIL, CURRENT_USER_ACCOUNT_ID, report, policy, [transaction])).toBe( CONST.REPORT.REPORT_PREVIEW_ACTIONS.EXPORT_TO_ACCOUNTING, ); }); @@ -541,7 +555,9 @@ describe('getReportPreviewAction', () => { const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.parentReportID)); await waitForBatchedUpdatesWithAct(); - expect(getReportPreviewAction(violations, isReportArchived.current, CURRENT_USER_EMAIL, report, policy, [transaction])).toBe(CONST.REPORT.REPORT_PREVIEW_ACTIONS.REVIEW); + expect(getReportPreviewAction(violations, isReportArchived.current, CURRENT_USER_EMAIL, CURRENT_USER_ACCOUNT_ID, report, policy, [transaction])).toBe( + CONST.REPORT.REPORT_PREVIEW_ACTIONS.REVIEW, + ); }); it('canReview should return true for reports with RTER violations regardless of workspace workflow configuration', async () => { @@ -583,7 +599,7 @@ describe('getReportPreviewAction', () => { reportID: `${REPORT_ID}`, } as unknown as Transaction; - expect(getReportPreviewAction(violations, false, CURRENT_USER_EMAIL, report, policy, [transaction])).toBe(CONST.REPORT.REPORT_PREVIEW_ACTIONS.REVIEW); + expect(getReportPreviewAction(violations, false, CURRENT_USER_EMAIL, CURRENT_USER_ACCOUNT_ID, report, policy, [transaction])).toBe(CONST.REPORT.REPORT_PREVIEW_ACTIONS.REVIEW); }); it('canReview should return true when strict policy rules are enabled and report has violations', async () => { @@ -623,9 +639,9 @@ describe('getReportPreviewAction', () => { await waitForBatchedUpdatesWithAct(); // When strict policy rules are enabled, REVIEW should be shown instead of SUBMIT - expect(getReportPreviewAction(violations, isReportArchived.current, CURRENT_USER_EMAIL, report, policy, [transaction], undefined, false, false, false, true)).toBe( - CONST.REPORT.REPORT_PREVIEW_ACTIONS.REVIEW, - ); + expect( + getReportPreviewAction(violations, isReportArchived.current, CURRENT_USER_EMAIL, CURRENT_USER_ACCOUNT_ID, report, policy, [transaction], undefined, false, false, false, true), + ).toBe(CONST.REPORT.REPORT_PREVIEW_ACTIONS.REVIEW); }); it('canView should return true for reports in which we are waiting for user to add a bank account', async () => { @@ -648,7 +664,9 @@ describe('getReportPreviewAction', () => { const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.parentReportID)); await waitForBatchedUpdatesWithAct(); - expect(getReportPreviewAction(VIOLATIONS, isReportArchived.current, CURRENT_USER_EMAIL, report, policy, [transaction])).toBe(CONST.REPORT.REPORT_PREVIEW_ACTIONS.VIEW); + expect(getReportPreviewAction(VIOLATIONS, isReportArchived.current, CURRENT_USER_EMAIL, CURRENT_USER_ACCOUNT_ID, report, policy, [transaction])).toBe( + CONST.REPORT.REPORT_PREVIEW_ACTIONS.VIEW, + ); }); it('canReview should return false for submitters when RECEIPT_NOT_SMART_SCANNED violation exists but is hidden from submitter', async () => { @@ -685,7 +703,9 @@ describe('getReportPreviewAction', () => { const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.parentReportID)); // Should return VIEW instead of REVIEW because the violation is hidden from submitter - expect(getReportPreviewAction(violations, isReportArchived.current, CURRENT_USER_EMAIL, report, policy, [transaction])).toBe(CONST.REPORT.REPORT_PREVIEW_ACTIONS.VIEW); + expect(getReportPreviewAction(violations, isReportArchived.current, CURRENT_USER_EMAIL, CURRENT_USER_ACCOUNT_ID, report, policy, [transaction])).toBe( + CONST.REPORT.REPORT_PREVIEW_ACTIONS.VIEW, + ); }); it('canReview should return true when report has mix of visible and hidden violations but at least one is visible', async () => { @@ -726,7 +746,9 @@ describe('getReportPreviewAction', () => { const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.parentReportID)); // Should return REVIEW because at least one violation (MISSING_CATEGORY) is visible - expect(getReportPreviewAction(violations, isReportArchived.current, CURRENT_USER_EMAIL, report, policy, [transaction])).toBe(CONST.REPORT.REPORT_PREVIEW_ACTIONS.REVIEW); + expect(getReportPreviewAction(violations, isReportArchived.current, CURRENT_USER_EMAIL, CURRENT_USER_ACCOUNT_ID, report, policy, [transaction])).toBe( + CONST.REPORT.REPORT_PREVIEW_ACTIONS.REVIEW, + ); }); it('canReview should return false when report has no visible violations for current user role', async () => { @@ -766,6 +788,8 @@ describe('getReportPreviewAction', () => { } as unknown as Transaction; const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.parentReportID)); - expect(getReportPreviewAction(violations, isReportArchived.current, CURRENT_USER_EMAIL, report, policy, [transaction])).toBe(CONST.REPORT.REPORT_PREVIEW_ACTIONS.VIEW); + expect(getReportPreviewAction(violations, isReportArchived.current, CURRENT_USER_EMAIL, CURRENT_USER_ACCOUNT_ID, report, policy, [transaction])).toBe( + CONST.REPORT.REPORT_PREVIEW_ACTIONS.VIEW, + ); }); }); diff --git a/tests/ui/MoneyRequestReportPreview.test.tsx b/tests/ui/MoneyRequestReportPreview.test.tsx index 983bd6af16c0..6903d3873e4d 100644 --- a/tests/ui/MoneyRequestReportPreview.test.tsx +++ b/tests/ui/MoneyRequestReportPreview.test.tsx @@ -54,8 +54,13 @@ const getIOUActionForReportID = (reportID: string | undefined, transactionID: st return {...mockAction, originalMessage: {...mockAction, IOUTransactionID: transactionID}}; }; -const hasViolations = (reportID: string | undefined, transactionViolations: OnyxCollection, shouldShowInReview?: boolean) => - (shouldShowInReview === undefined || shouldShowInReview) && Object.values(transactionViolations ?? {}).length > 0; +const hasViolations = ( + reportID: string | undefined, + transactionViolations: OnyxCollection, + _currentUserAccountID: number, + _currentUserEmailParam: string, + shouldShowInReview?: boolean, +) => (shouldShowInReview === undefined || shouldShowInReview) && Object.values(transactionViolations ?? {}).length > 0; const renderPage = ({isWhisper = false, isHovered = false, contextMenuAnchor = null}: Partial) => { return render( diff --git a/tests/unit/IOUUtilsTest.ts b/tests/unit/IOUUtilsTest.ts index 3cb7a70861a2..1b70dd59d4c8 100644 --- a/tests/unit/IOUUtilsTest.ts +++ b/tests/unit/IOUUtilsTest.ts @@ -248,7 +248,7 @@ describe('hasRTERWithoutViolation', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionIDWithViolation}`, transactionWithViolation); await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionIDWithoutViolation}`, transactionWithoutViolation); - expect(hasAnyTransactionWithoutRTERViolation([transactionWithoutViolation, transactionWithViolation], violations, '', undefined, undefined)).toBe(true); + expect(hasAnyTransactionWithoutRTERViolation([transactionWithoutViolation, transactionWithViolation], violations, '', CONST.DEFAULT_NUMBER_ID, undefined, undefined)).toBe(true); }); test('Return false if there is no rter without violation in all transactionViolations with given transactionIDs.', async () => { @@ -277,7 +277,7 @@ describe('hasRTERWithoutViolation', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionIDWithViolation}`, transactionWithViolation); - expect(hasAnyTransactionWithoutRTERViolation([transactionWithViolation], violations, '', undefined, undefined)).toBe(false); + expect(hasAnyTransactionWithoutRTERViolation([transactionWithViolation], violations, '', CONST.DEFAULT_NUMBER_ID, undefined, undefined)).toBe(false); }); }); diff --git a/tests/unit/ReportPrimaryActionUtilsTest.ts b/tests/unit/ReportPrimaryActionUtilsTest.ts index bfb399f1dcf5..722db2551fee 100644 --- a/tests/unit/ReportPrimaryActionUtilsTest.ts +++ b/tests/unit/ReportPrimaryActionUtilsTest.ts @@ -64,7 +64,16 @@ describe('getPrimaryAction', () => { } as unknown as Report; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report); expect( - getReportPrimaryAction({currentUserEmail: CURRENT_USER_EMAIL, report, chatReport, reportTransactions: [], violations: {}, policy: {} as Policy, isChatReportArchived: false}), + getReportPrimaryAction({ + currentUserEmail: CURRENT_USER_EMAIL, + currentUserAccountID: CURRENT_USER_ACCOUNT_ID, + report, + chatReport, + reportTransactions: [], + violations: {}, + policy: {} as Policy, + isChatReportArchived: false, + }), ).toBe(''); }); @@ -87,6 +96,7 @@ describe('getPrimaryAction', () => { expect( getReportPrimaryAction({ currentUserEmail: CURRENT_USER_EMAIL, + currentUserAccountID: CURRENT_USER_ACCOUNT_ID, report, chatReport, reportTransactions: [transaction], @@ -120,6 +130,7 @@ describe('getPrimaryAction', () => { expect( getReportPrimaryAction({ currentUserEmail: CURRENT_USER_EMAIL, + currentUserAccountID: CURRENT_USER_ACCOUNT_ID, report, chatReport, reportTransactions: [transaction], @@ -153,6 +164,7 @@ describe('getPrimaryAction', () => { expect( getReportPrimaryAction({ currentUserEmail: CURRENT_USER_EMAIL, + currentUserAccountID: CURRENT_USER_ACCOUNT_ID, report, chatReport, reportTransactions: [transaction], @@ -187,6 +199,7 @@ describe('getPrimaryAction', () => { expect( getReportPrimaryAction({ currentUserEmail: CURRENT_USER_EMAIL, + currentUserAccountID: CURRENT_USER_ACCOUNT_ID, report, chatReport, reportTransactions: [transaction], @@ -224,6 +237,7 @@ describe('getPrimaryAction', () => { expect( getReportPrimaryAction({ currentUserEmail: CURRENT_USER_EMAIL, + currentUserAccountID: CURRENT_USER_ACCOUNT_ID, report, chatReport, reportTransactions: [transaction], @@ -259,6 +273,7 @@ describe('getPrimaryAction', () => { expect( getReportPrimaryAction({ currentUserEmail: CURRENT_USER_EMAIL, + currentUserAccountID: CURRENT_USER_ACCOUNT_ID, report, chatReport, reportTransactions: [transaction], @@ -299,6 +314,7 @@ describe('getPrimaryAction', () => { expect( getReportPrimaryAction({ currentUserEmail: CURRENT_USER_EMAIL, + currentUserAccountID: CURRENT_USER_ACCOUNT_ID, report, chatReport, reportTransactions: [transaction], @@ -340,6 +356,7 @@ describe('getPrimaryAction', () => { expect( getReportPrimaryAction({ currentUserEmail: CURRENT_USER_EMAIL, + currentUserAccountID: CURRENT_USER_ACCOUNT_ID, report, chatReport, reportTransactions: [transaction], @@ -370,6 +387,7 @@ describe('getPrimaryAction', () => { expect( getReportPrimaryAction({ currentUserEmail: CURRENT_USER_EMAIL, + currentUserAccountID: CURRENT_USER_ACCOUNT_ID, report, chatReport, reportTransactions: [transaction], @@ -408,6 +426,7 @@ describe('getPrimaryAction', () => { expect( getReportPrimaryAction({ currentUserEmail: CURRENT_USER_EMAIL, + currentUserAccountID: CURRENT_USER_ACCOUNT_ID, report, chatReport, reportTransactions: [transaction], @@ -444,6 +463,7 @@ describe('getPrimaryAction', () => { expect( getReportPrimaryAction({ currentUserEmail: CURRENT_USER_EMAIL, + currentUserAccountID: CURRENT_USER_ACCOUNT_ID, report, chatReport, reportTransactions: [transaction], @@ -480,6 +500,7 @@ describe('getPrimaryAction', () => { expect( getReportPrimaryAction({ currentUserEmail: CURRENT_USER_EMAIL, + currentUserAccountID: CURRENT_USER_ACCOUNT_ID, report, chatReport, reportTransactions: [], @@ -542,7 +563,16 @@ describe('getPrimaryAction', () => { await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${CHILD_REPORT_ID}`, {[HOLD_ACTION_ID]: holdAction}); expect( - getReportPrimaryAction({currentUserEmail: CURRENT_USER_EMAIL, report, chatReport, reportTransactions: [transaction], violations: {}, policy, isChatReportArchived: false}), + getReportPrimaryAction({ + currentUserEmail: CURRENT_USER_EMAIL, + currentUserAccountID: CURRENT_USER_ACCOUNT_ID, + report, + chatReport, + reportTransactions: [transaction], + violations: {}, + policy, + isChatReportArchived: false, + }), ).toBe(CONST.REPORT.PRIMARY_ACTIONS.REMOVE_HOLD); }); @@ -593,6 +623,7 @@ describe('getPrimaryAction', () => { expect( getReportPrimaryAction({ currentUserEmail: CURRENT_USER_EMAIL, + currentUserAccountID: CURRENT_USER_ACCOUNT_ID, report, chatReport, reportTransactions: [transaction], @@ -632,6 +663,7 @@ describe('getPrimaryAction', () => { expect( getReportPrimaryAction({ currentUserEmail: CURRENT_USER_EMAIL, + currentUserAccountID: CURRENT_USER_ACCOUNT_ID, report, chatReport, reportTransactions: [transaction], @@ -668,6 +700,7 @@ describe('getPrimaryAction', () => { expect( getReportPrimaryAction({ currentUserEmail: CURRENT_USER_EMAIL, + currentUserAccountID: CURRENT_USER_ACCOUNT_ID, report, chatReport, reportTransactions: [transaction], @@ -705,6 +738,7 @@ describe('getPrimaryAction', () => { expect( getReportPrimaryAction({ currentUserEmail: CURRENT_USER_EMAIL, + currentUserAccountID: CURRENT_USER_ACCOUNT_ID, report, chatReport: invoiceChatReport, reportTransactions: [transaction], @@ -753,7 +787,7 @@ describe('isReviewDuplicatesAction', () => { } as TransactionViolation, ]); - expect(isReviewDuplicatesAction(report, [transaction], CURRENT_USER_EMAIL, undefined)).toBe(true); + expect(isReviewDuplicatesAction(report, [transaction], CURRENT_USER_EMAIL, CURRENT_USER_ACCOUNT_ID, undefined)).toBe(true); }); it('should return false when report approver has no duplicated transactions', async () => { @@ -773,7 +807,7 @@ describe('isReviewDuplicatesAction', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${TRANSACTION_ID}`, transaction); - expect(isReviewDuplicatesAction(report, [transaction], CURRENT_USER_EMAIL, undefined)).toBe(false); + expect(isReviewDuplicatesAction(report, [transaction], CURRENT_USER_EMAIL, CURRENT_USER_ACCOUNT_ID, undefined)).toBe(false); }); it('should return false when current user is neither the report submitter nor approver', async () => { @@ -798,7 +832,7 @@ describe('isReviewDuplicatesAction', () => { } as TransactionViolation, ]); - expect(isReviewDuplicatesAction(report, [transaction], CURRENT_USER_EMAIL, undefined)).toBe(false); + expect(isReviewDuplicatesAction(report, [transaction], CURRENT_USER_EMAIL, CURRENT_USER_ACCOUNT_ID, undefined)).toBe(false); }); }); @@ -841,7 +875,7 @@ describe('getTransactionThreadPrimaryAction', () => { await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${CHILD_REPORT_ID}`, {[HOLD_ACTION_ID]: holdAction}); - expect(getTransactionThreadPrimaryAction(CURRENT_USER_EMAIL, report, {} as Report, transaction, [], policy as Policy, false)).toBe( + expect(getTransactionThreadPrimaryAction(CURRENT_USER_EMAIL, CURRENT_USER_ACCOUNT_ID, report, {} as Report, transaction, [], policy as Policy, false)).toBe( CONST.REPORT.TRANSACTION_PRIMARY_ACTIONS.REMOVE_HOLD, ); }); @@ -871,7 +905,7 @@ describe('getTransactionThreadPrimaryAction', () => { } as TransactionViolation, ]); - expect(getTransactionThreadPrimaryAction(CURRENT_USER_EMAIL, {} as Report, report, transaction, [], policy as Policy, false)).toBe( + expect(getTransactionThreadPrimaryAction(CURRENT_USER_EMAIL, CURRENT_USER_ACCOUNT_ID, {} as Report, report, transaction, [], policy as Policy, false)).toBe( CONST.REPORT.TRANSACTION_PRIMARY_ACTIONS.REVIEW_DUPLICATES, ); }); @@ -900,7 +934,7 @@ describe('getTransactionThreadPrimaryAction', () => { }, } as unknown as TransactionViolation; - expect(getTransactionThreadPrimaryAction(CURRENT_USER_EMAIL, {} as Report, report, transaction, [violation], policy as Policy, false)).toBe( + expect(getTransactionThreadPrimaryAction(CURRENT_USER_EMAIL, CURRENT_USER_ACCOUNT_ID, {} as Report, report, transaction, [violation], policy as Policy, false)).toBe( CONST.REPORT.TRANSACTION_PRIMARY_ACTIONS.MARK_AS_CASH, ); }); @@ -928,7 +962,7 @@ describe('getTransactionThreadPrimaryAction', () => { }, } as unknown as TransactionViolation; - expect(getTransactionThreadPrimaryAction(CURRENT_USER_EMAIL, {} as Report, report, transaction, [violation], policy as Policy, false)).toBe( + expect(getTransactionThreadPrimaryAction(CURRENT_USER_EMAIL, CURRENT_USER_ACCOUNT_ID, {} as Report, report, transaction, [violation], policy as Policy, false)).toBe( CONST.REPORT.TRANSACTION_PRIMARY_ACTIONS.MARK_AS_CASH, ); }); @@ -960,6 +994,7 @@ describe('getTransactionThreadPrimaryAction', () => { expect( getReportPrimaryAction({ currentUserEmail: CURRENT_USER_EMAIL, + currentUserAccountID: CURRENT_USER_ACCOUNT_ID, report, chatReport, reportTransactions: [transaction], @@ -998,6 +1033,7 @@ describe('getTransactionThreadPrimaryAction', () => { expect( getReportPrimaryAction({ currentUserEmail: CURRENT_USER_EMAIL, + currentUserAccountID: CURRENT_USER_ACCOUNT_ID, report, chatReport, reportTransactions: [transaction], @@ -1037,6 +1073,7 @@ describe('getTransactionThreadPrimaryAction', () => { expect( getReportPrimaryAction({ currentUserEmail: CURRENT_USER_EMAIL, + currentUserAccountID: CURRENT_USER_ACCOUNT_ID, report, chatReport, reportTransactions: [transaction], @@ -1191,7 +1228,7 @@ describe('getTransactionThreadPrimaryAction', () => { } as unknown as Transaction, ]; - const result = isPrimaryMarkAsResolvedAction(CURRENT_USER_EMAIL, report, reportTransactions, violations, policy); + const result = isPrimaryMarkAsResolvedAction(CURRENT_USER_EMAIL, CURRENT_USER_ACCOUNT_ID, report, reportTransactions, violations, policy); expect(result).toBe(true); }); @@ -1224,7 +1261,7 @@ describe('getTransactionThreadPrimaryAction', () => { } as unknown as Transaction, ]; - const result = isPrimaryMarkAsResolvedAction(CURRENT_USER_EMAIL, report, reportTransactions, violations, policy); + const result = isPrimaryMarkAsResolvedAction(CURRENT_USER_EMAIL, CURRENT_USER_ACCOUNT_ID, report, reportTransactions, violations, policy); expect(result).toBe(false); }); @@ -1254,7 +1291,7 @@ describe('getTransactionThreadPrimaryAction', () => { } as unknown as Transaction, ]; - const result = isPrimaryMarkAsResolvedAction(CURRENT_USER_EMAIL, report, reportTransactions, violations, policy); + const result = isPrimaryMarkAsResolvedAction(CURRENT_USER_EMAIL, CURRENT_USER_ACCOUNT_ID, report, reportTransactions, violations, policy); expect(result).toBe(false); }); @@ -1284,7 +1321,7 @@ describe('getTransactionThreadPrimaryAction', () => { } as unknown as Transaction, ]; - const result = isPrimaryMarkAsResolvedAction(CURRENT_USER_EMAIL, report, reportTransactions, violations, policy); + const result = isPrimaryMarkAsResolvedAction(CURRENT_USER_EMAIL, CURRENT_USER_ACCOUNT_ID, report, reportTransactions, violations, policy); expect(result).toBe(false); }); }); diff --git a/tests/unit/ReportSecondaryActionUtilsTest.ts b/tests/unit/ReportSecondaryActionUtilsTest.ts index 6dc49324eb76..ecf1d5b92b25 100644 --- a/tests/unit/ReportSecondaryActionUtilsTest.ts +++ b/tests/unit/ReportSecondaryActionUtilsTest.ts @@ -61,7 +61,16 @@ describe('getSecondaryAction', () => { const result = [CONST.REPORT.SECONDARY_ACTIONS.EXPORT, CONST.REPORT.SECONDARY_ACTIONS.DOWNLOAD_PDF, CONST.REPORT.SECONDARY_ACTIONS.VIEW_DETAILS]; expect( - getSecondaryReportActions({currentUserEmail: EMPLOYEE_EMAIL, report, chatReport, reportTransactions: [], originalTransaction: {} as Transaction, violations: {}, policy}), + getSecondaryReportActions({ + currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + report, + chatReport, + reportTransactions: [], + originalTransaction: {} as Transaction, + violations: {}, + policy, + }), ).toEqual(result); }); @@ -87,6 +96,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, reportTransactions: [transaction], @@ -116,6 +126,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, reportTransactions: [], @@ -145,6 +156,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, reportTransactions: [], @@ -188,6 +200,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, reportTransactions: [transaction1, transaction2], @@ -217,6 +230,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, reportTransactions: [], @@ -262,6 +276,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, reportTransactions: [transaction], @@ -293,6 +308,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, reportTransactions: [], @@ -330,6 +346,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, reportTransactions: [transaction], @@ -369,6 +386,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, reportTransactions: [transaction], @@ -405,6 +423,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, reportTransactions: [transaction], @@ -443,6 +462,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, reportTransactions: [transaction], @@ -481,6 +501,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, reportTransactions: [transaction], @@ -516,6 +537,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, reportTransactions: [transaction], @@ -551,6 +573,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, reportTransactions: [transaction], @@ -583,6 +606,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, reportTransactions: [transaction], @@ -606,6 +630,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, reportTransactions: [], @@ -632,6 +657,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, reportTransactions: [], @@ -657,6 +683,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, reportTransactions: [], @@ -682,6 +709,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, reportTransactions: [], @@ -708,6 +736,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, reportTransactions: [], @@ -734,6 +763,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, reportTransactions: [], @@ -761,6 +791,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, reportTransactions: [], @@ -785,6 +816,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, reportTransactions: [], @@ -821,6 +853,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, reportTransactions: [ @@ -854,6 +887,7 @@ describe('getSecondaryAction', () => { jest.spyOn(ReportActionsUtils, 'getOneTransactionThreadReportID').mockReturnValueOnce(originalMessageR14932.IOUTransactionID); const result = getSecondaryReportActions({ currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, reportTransactions: [transaction], @@ -896,6 +930,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, reportTransactions: [], @@ -939,6 +974,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, reportTransactions: [], @@ -997,6 +1033,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, reportTransactions: [], @@ -1055,6 +1092,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, reportTransactions: [], @@ -1113,6 +1151,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, reportTransactions: [], @@ -1137,6 +1176,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, reportTransactions: [{} as Transaction], @@ -1199,6 +1239,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, reportTransactions: [transaction], @@ -1242,6 +1283,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, reportTransactions: [transaction], @@ -1300,6 +1342,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, reportTransactions: [transaction1, transaction2], @@ -1332,6 +1375,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, reportTransactions: [transaction], @@ -1369,6 +1413,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, reportTransactions: [transaction1, transaction2], @@ -1404,6 +1449,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, reportTransactions: [transaction], @@ -1454,6 +1500,7 @@ describe('getSecondaryAction', () => { // Then it should return false since the unreported card expense is imported with deleting disabled const result = getSecondaryReportActions({ currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, reportTransactions: [transaction], @@ -1494,6 +1541,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, reportTransactions: [transaction], @@ -1533,6 +1581,7 @@ describe('getSecondaryAction', () => { const result = getSecondaryReportActions({ currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, reportTransactions: [transaction], @@ -1559,7 +1608,16 @@ describe('getSecondaryAction', () => { jest.spyOn(ReportActionsUtils, 'getOneTransactionThreadReportID').mockReturnValue(originalMessageR14932.IOUTransactionID); jest.spyOn(ReportUtils, 'isHoldCreator').mockReturnValue(false); - const result = getSecondaryReportActions({currentUserEmail: EMPLOYEE_EMAIL, report, chatReport, reportTransactions, originalTransaction: {} as Transaction, violations: {}, policy}); + const result = getSecondaryReportActions({ + currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + report, + chatReport, + reportTransactions, + originalTransaction: {} as Transaction, + violations: {}, + policy, + }); expect(result).toContain(CONST.REPORT.SECONDARY_ACTIONS.REMOVE_HOLD); }); }); @@ -1814,7 +1872,16 @@ describe('getSecondaryExportReportActions', () => { jest.spyOn(ReportActionsUtils, 'getOneTransactionThreadReportID').mockReturnValue(originalMessageR14932.IOUTransactionID); jest.spyOn(ReportUtils, 'isHoldCreator').mockReturnValue(false); - const result = getSecondaryReportActions({currentUserEmail: EMPLOYEE_EMAIL, report, chatReport, reportTransactions, originalTransaction: {} as Transaction, violations: {}, policy}); + const result = getSecondaryReportActions({ + currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, + report, + chatReport, + reportTransactions, + originalTransaction: {} as Transaction, + violations: {}, + policy, + }); expect(result).toContain(CONST.REPORT.SECONDARY_ACTIONS.REMOVE_HOLD); }); }); @@ -1937,6 +2004,7 @@ describe('getSecondaryTransactionThreadActions', () => { const result = getSecondaryReportActions({ currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport, reportTransactions: [], @@ -2104,6 +2172,7 @@ describe('getSecondaryTransactionThreadActions', () => { const result = getSecondaryReportActions({ currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport: undefined, reportTransactions: [transaction], @@ -2155,6 +2224,7 @@ describe('getSecondaryTransactionThreadActions', () => { const result = getSecondaryReportActions({ currentUserEmail: EMPLOYEE_EMAIL, + currentUserAccountID: EMPLOYEE_ACCOUNT_ID, report, chatReport: undefined, reportTransactions: [transaction], diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index e7a46d98d81b..7ea6399d82d2 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -8576,7 +8576,7 @@ describe('ReportUtils', () => { ], }; - const result = shouldBlockSubmitDueToStrictPolicyRules(reportID, transactionViolations, false); + const result = shouldBlockSubmitDueToStrictPolicyRules(reportID, transactionViolations, false, CONST.DEFAULT_NUMBER_ID, ''); expect(result).toBe(false); }); @@ -8584,7 +8584,7 @@ describe('ReportUtils', () => { it('should return false when areStrictPolicyRulesEnabled is true but no violations exist', () => { const transactionViolations = {}; - const result = shouldBlockSubmitDueToStrictPolicyRules(reportID, transactionViolations, true); + const result = shouldBlockSubmitDueToStrictPolicyRules(reportID, transactionViolations, true, 0, ''); expect(result).toBe(false); }); @@ -8600,7 +8600,7 @@ describe('ReportUtils', () => { ], }; - const result = shouldBlockSubmitDueToStrictPolicyRules(undefined, transactionViolations, true); + const result = shouldBlockSubmitDueToStrictPolicyRules(undefined, transactionViolations, true, 0, ''); expect(result).toBe(false); }); @@ -8629,7 +8629,7 @@ describe('ReportUtils', () => { ], }; - const result = shouldBlockSubmitDueToStrictPolicyRules(reportID, transactionViolations, false, transactions); + const result = shouldBlockSubmitDueToStrictPolicyRules(reportID, transactionViolations, false, 0, '', transactions); expect(result).toBe(false); }); @@ -8658,7 +8658,7 @@ describe('ReportUtils', () => { ], }; - const result = shouldBlockSubmitDueToStrictPolicyRules(reportID, transactionViolations, true, transactions); + const result = shouldBlockSubmitDueToStrictPolicyRules(reportID, transactionViolations, true, 0, '', transactions); expect(result).toBe(true); }); diff --git a/tests/unit/TransactionPreviewUtils.test.ts b/tests/unit/TransactionPreviewUtils.test.ts index 2f8e82652d26..b70010199b66 100644 --- a/tests/unit/TransactionPreviewUtils.test.ts +++ b/tests/unit/TransactionPreviewUtils.test.ts @@ -44,6 +44,7 @@ const basicProps = { isReportAPolicyExpenseChat: false, areThereDuplicates: false, currentUserEmail: '', + currentUserAccountID: CONST.DEFAULT_NUMBER_ID, }; describe('TransactionPreviewUtils', () => { diff --git a/tests/unit/TransactionUtilsTest.ts b/tests/unit/TransactionUtilsTest.ts index 4956ae43212a..95e817e18dac 100644 --- a/tests/unit/TransactionUtilsTest.ts +++ b/tests/unit/TransactionUtilsTest.ts @@ -519,6 +519,7 @@ describe('TransactionUtils', () => { policy, transactionViolations, CURRENT_USER_EMAIL, + CURRENT_USER_ID, ); expect(showBrokenConnectionViolation).toBe(true); @@ -810,7 +811,7 @@ describe('TransactionUtils', () => { const violation = {type: CONST.VIOLATION_TYPES.VIOLATION, name: CONST.VIOLATIONS.DUPLICATED_TRANSACTION}; // When checking if violation is dismissed - const result = TransactionUtils.isViolationDismissed(transaction, violation, CURRENT_USER_EMAIL, undefined, undefined); + const result = TransactionUtils.isViolationDismissed(transaction, violation, CURRENT_USER_EMAIL, CURRENT_USER_ID, undefined, undefined); // Then it should return true expect(result).toBe(true); @@ -824,7 +825,7 @@ describe('TransactionUtils', () => { const violation = {type: CONST.VIOLATION_TYPES.VIOLATION, name: CONST.VIOLATIONS.DUPLICATED_TRANSACTION}; // When checking if violation is dismissed - const result = TransactionUtils.isViolationDismissed(transaction, violation, CURRENT_USER_EMAIL, undefined, undefined); + const result = TransactionUtils.isViolationDismissed(transaction, violation, CURRENT_USER_EMAIL, CURRENT_USER_ID, undefined, undefined); // Then it should return false expect(result).toBe(false); @@ -844,7 +845,7 @@ describe('TransactionUtils', () => { const violation = {type: CONST.VIOLATION_TYPES.VIOLATION, name: CONST.VIOLATIONS.DUPLICATED_TRANSACTION}; // When checking if violation is dismissed for current user - const result = TransactionUtils.isViolationDismissed(transaction, violation, CURRENT_USER_EMAIL, undefined, undefined); + const result = TransactionUtils.isViolationDismissed(transaction, violation, CURRENT_USER_EMAIL, CURRENT_USER_ID, undefined, undefined); // Then it should return false since current user hasn't dismissed it expect(result).toBe(false); @@ -873,7 +874,7 @@ describe('TransactionUtils', () => { const violation = {type: CONST.VIOLATION_TYPES.VIOLATION, name: CONST.VIOLATIONS.DUPLICATED_TRANSACTION}; // When current user (admin, not the owner) checks if violation is dismissed - const result = TransactionUtils.isViolationDismissed(transaction, violation, CURRENT_USER_EMAIL, iouReport, undefined); + const result = TransactionUtils.isViolationDismissed(transaction, violation, CURRENT_USER_EMAIL, CURRENT_USER_ID, iouReport, undefined); // Then it should return true because admin sees owner's perspective on open reports expect(result).toBe(true); @@ -900,7 +901,7 @@ describe('TransactionUtils', () => { const violation = {type: CONST.VIOLATION_TYPES.VIOLATION, name: CONST.VIOLATIONS.DUPLICATED_TRANSACTION}; // When current user (admin, not the owner) checks if violation is dismissed - const result = TransactionUtils.isViolationDismissed(transaction, violation, CURRENT_USER_EMAIL, iouReport, undefined); + const result = TransactionUtils.isViolationDismissed(transaction, violation, CURRENT_USER_EMAIL, CURRENT_USER_ID, iouReport, undefined); // Then it should return false because on processing reports, admin must dismiss separately expect(result).toBe(false); @@ -927,7 +928,7 @@ describe('TransactionUtils', () => { const violation = {type: CONST.VIOLATION_TYPES.VIOLATION, name: CONST.VIOLATIONS.DUPLICATED_TRANSACTION}; // When current user (the submitter) checks if violation is dismissed - const result = TransactionUtils.isViolationDismissed(transaction, violation, CURRENT_USER_EMAIL, iouReport, undefined); + const result = TransactionUtils.isViolationDismissed(transaction, violation, CURRENT_USER_EMAIL, CURRENT_USER_ID, iouReport, undefined); // Then it should return false (condition 2 doesn't apply to submitters) expect(result).toBe(false); @@ -956,7 +957,7 @@ describe('TransactionUtils', () => { const violation = {type: CONST.VIOLATION_TYPES.WARNING, name: CONST.VIOLATIONS.RTER}; // When current user checks if violation is dismissed - const result = TransactionUtils.isViolationDismissed(transaction, violation, CURRENT_USER_EMAIL, undefined, policy); + const result = TransactionUtils.isViolationDismissed(transaction, violation, CURRENT_USER_EMAIL, CURRENT_USER_ID, undefined, policy); // Then it should return true because on instant submit, anyone's dismissal counts expect(result).toBe(true); @@ -983,7 +984,7 @@ describe('TransactionUtils', () => { const violation = {type: CONST.VIOLATION_TYPES.WARNING, name: CONST.VIOLATIONS.RTER}; // When current user checks if violation is dismissed - const result = TransactionUtils.isViolationDismissed(transaction, violation, CURRENT_USER_EMAIL, undefined, policy); + const result = TransactionUtils.isViolationDismissed(transaction, violation, CURRENT_USER_EMAIL, CURRENT_USER_ID, undefined, policy); // Then it should return false because on non-instant submit, each person must dismiss separately expect(result).toBe(false); @@ -1010,7 +1011,7 @@ describe('TransactionUtils', () => { const violation = {type: CONST.VIOLATION_TYPES.WARNING, name: CONST.VIOLATIONS.DUPLICATED_TRANSACTION}; // When current user checks if violation is dismissed - const result = TransactionUtils.isViolationDismissed(transaction, violation, CURRENT_USER_EMAIL, undefined, policy); + const result = TransactionUtils.isViolationDismissed(transaction, violation, CURRENT_USER_EMAIL, CURRENT_USER_ID, undefined, policy); // Then it should return false because condition 3 only applies to RTER violations expect(result).toBe(false); @@ -1038,7 +1039,7 @@ describe('TransactionUtils', () => { const violation = {type: CONST.VIOLATION_TYPES.WARNING, name: CONST.VIOLATIONS.RTER}; // When current user checks if violation is dismissed - const result = TransactionUtils.isViolationDismissed(transaction, violation, CURRENT_USER_EMAIL, undefined, policy); + const result = TransactionUtils.isViolationDismissed(transaction, violation, CURRENT_USER_EMAIL, CURRENT_USER_ID, undefined, policy); // Then it should return true expect(result).toBe(true); @@ -1048,13 +1049,13 @@ describe('TransactionUtils', () => { describe('Edge cases and data validation', () => { it('should return false when transaction is null', () => { const violation = {type: CONST.VIOLATION_TYPES.VIOLATION, name: CONST.VIOLATIONS.DUPLICATED_TRANSACTION}; - const result = TransactionUtils.isViolationDismissed(undefined, violation, CURRENT_USER_EMAIL, undefined, undefined); + const result = TransactionUtils.isViolationDismissed(undefined, violation, CURRENT_USER_EMAIL, CURRENT_USER_ID, undefined, undefined); expect(result).toBe(false); }); it('should return false when violation is null', () => { const transaction = generateTransaction({}); - const result = TransactionUtils.isViolationDismissed(transaction, undefined, CURRENT_USER_EMAIL, undefined, undefined); + const result = TransactionUtils.isViolationDismissed(transaction, undefined, CURRENT_USER_EMAIL, CURRENT_USER_ID, undefined, undefined); expect(result).toBe(false); }); @@ -1069,7 +1070,7 @@ describe('TransactionUtils', () => { }, }); const violation = {type: CONST.VIOLATION_TYPES.VIOLATION, name: CONST.VIOLATIONS.DUPLICATED_TRANSACTION}; - const result = TransactionUtils.isViolationDismissed(transaction, violation, CURRENT_USER_EMAIL, undefined, undefined); + const result = TransactionUtils.isViolationDismissed(transaction, violation, CURRENT_USER_EMAIL, CURRENT_USER_ID, undefined, undefined); expect(result).toBe(false); }); }); diff --git a/tests/unit/ViolationUtilsTest.ts b/tests/unit/ViolationUtilsTest.ts index 9bf311d71c63..3ae011a20d00 100644 --- a/tests/unit/ViolationUtilsTest.ts +++ b/tests/unit/ViolationUtilsTest.ts @@ -602,8 +602,8 @@ describe('getViolations', () => { await Onyx.multiSet({...transactionCollectionDataSet}); - const isSmartScanDismissed = isViolationDismissed(transaction, smartScanFailedViolation, CARLOS_EMAIL, undefined, undefined); - const isDuplicateViolationDismissed = isViolationDismissed(transaction, duplicatedTransactionViolation, CARLOS_EMAIL, undefined, undefined); + const isSmartScanDismissed = isViolationDismissed(transaction, smartScanFailedViolation, CARLOS_EMAIL, CARLOS_ACCOUNT_ID, undefined, undefined); + const isDuplicateViolationDismissed = isViolationDismissed(transaction, duplicatedTransactionViolation, CARLOS_EMAIL, CARLOS_ACCOUNT_ID, undefined, undefined); expect(isSmartScanDismissed).toBeTruthy(); expect(isDuplicateViolationDismissed).toBeFalsy(); @@ -641,8 +641,8 @@ describe('getViolations', () => { await Onyx.multiSet({...transactionCollectionDataSet}); - const isSmartScanDismissed = isViolationDismissed(transaction, smartScanFailedViolation, CARLOS_EMAIL, report, policy); - const isDuplicateViolationDismissed = isViolationDismissed(transaction, duplicatedTransactionViolation, CARLOS_EMAIL, report, policy); + const isSmartScanDismissed = isViolationDismissed(transaction, smartScanFailedViolation, CARLOS_EMAIL, CARLOS_ACCOUNT_ID, report, policy); + const isDuplicateViolationDismissed = isViolationDismissed(transaction, duplicatedTransactionViolation, CARLOS_EMAIL, CARLOS_ACCOUNT_ID, report, policy); expect(isSmartScanDismissed).toBeTruthy(); expect(isDuplicateViolationDismissed).toBeFalsy(); @@ -664,7 +664,7 @@ describe('getViolations', () => { await Onyx.multiSet({...transactionCollectionDataSet}); // Should filter out the smartScanFailedViolation - const filteredViolations = getTransactionViolations(transaction, transactionViolationsCollection, CARLOS_EMAIL, undefined, undefined); + const filteredViolations = getTransactionViolations(transaction, transactionViolationsCollection, CARLOS_EMAIL, CARLOS_ACCOUNT_ID, undefined, undefined); expect(filteredViolations).toEqual([duplicatedTransactionViolation, tagOutOfPolicyViolation]); }); @@ -705,7 +705,7 @@ describe('getViolations', () => { await Onyx.multiSet({...transactionCollectionDataSet}); // Should filter out the smartScanFailedViolation - const filteredViolations = getTransactionViolations(transaction, transactionViolationsCollection, CARLOS_EMAIL, report, policy); + const filteredViolations = getTransactionViolations(transaction, transactionViolationsCollection, CARLOS_EMAIL, CARLOS_ACCOUNT_ID, report, policy); expect(filteredViolations).toEqual([duplicatedTransactionViolation, tagOutOfPolicyViolation]); }); @@ -723,7 +723,7 @@ describe('getViolations', () => { }; await Onyx.multiSet({...transactionCollectionDataSet}); - const hasWarningTypeViolationRes = hasWarningTypeViolation(transaction, transactionViolationsCollection, '', undefined, undefined); + const hasWarningTypeViolationRes = hasWarningTypeViolation(transaction, transactionViolationsCollection, '', CONST.DEFAULT_NUMBER_ID, undefined, undefined); expect(hasWarningTypeViolationRes).toBeTruthy(); }); @@ -763,7 +763,7 @@ describe('getViolations', () => { }; await Onyx.multiSet({...transactionCollectionDataSet}); - const hasWarningTypeViolationRes = hasWarningTypeViolation(transaction, transactionViolationsCollection, CARLOS_EMAIL, report, policy); + const hasWarningTypeViolationRes = hasWarningTypeViolation(transaction, transactionViolationsCollection, CARLOS_EMAIL, CARLOS_ACCOUNT_ID, report, policy); expect(hasWarningTypeViolationRes).toBeTruthy(); }); }); @@ -887,12 +887,12 @@ describe('hasVisibleViolationsForUser', () => { [`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${testTransactionID}`]: [missingCategoryViolation], }; - const result = ViolationsUtils.hasVisibleViolationsForUser(undefined, violations, '', mockPolicy, [mockTransaction]); + const result = ViolationsUtils.hasVisibleViolationsForUser(undefined, violations, '', CONST.DEFAULT_NUMBER_ID, mockPolicy, [mockTransaction]); expect(result).toBe(false); }); it('should return false when violations is null', () => { - const result = ViolationsUtils.hasVisibleViolationsForUser(mockReport, undefined, '', mockPolicy, [mockTransaction]); + const result = ViolationsUtils.hasVisibleViolationsForUser(mockReport, undefined, '', CONST.DEFAULT_NUMBER_ID, mockPolicy, [mockTransaction]); expect(result).toBe(false); }); @@ -901,14 +901,14 @@ describe('hasVisibleViolationsForUser', () => { [`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${testTransactionID}`]: [missingCategoryViolation], }; - const result = ViolationsUtils.hasVisibleViolationsForUser(mockReport, violations, '', mockPolicy, []); + const result = ViolationsUtils.hasVisibleViolationsForUser(mockReport, violations, '', CONST.DEFAULT_NUMBER_ID, mockPolicy, []); expect(result).toBe(false); }); it('should return false when no violations exist for transactions', () => { const violations = {}; - const result = ViolationsUtils.hasVisibleViolationsForUser(mockReport, violations, '', mockPolicy, [mockTransaction]); + const result = ViolationsUtils.hasVisibleViolationsForUser(mockReport, violations, '', CONST.DEFAULT_NUMBER_ID, mockPolicy, [mockTransaction]); expect(result).toBe(false); }); @@ -920,7 +920,7 @@ describe('hasVisibleViolationsForUser', () => { // Mock shouldShowViolation to return true for missing category jest.spyOn(require('@src/libs/TransactionUtils'), 'shouldShowViolation').mockReturnValue(true); - const result = ViolationsUtils.hasVisibleViolationsForUser(mockReport, violations, '', mockPolicy, [mockTransaction]); + const result = ViolationsUtils.hasVisibleViolationsForUser(mockReport, violations, '', CONST.DEFAULT_NUMBER_ID, mockPolicy, [mockTransaction]); expect(result).toBe(true); }); @@ -942,7 +942,7 @@ describe('hasVisibleViolationsForUser', () => { return true; }); - const result = ViolationsUtils.hasVisibleViolationsForUser(mockReport, violations, '', mockPolicy, [mockTransaction]); + const result = ViolationsUtils.hasVisibleViolationsForUser(mockReport, violations, '', CONST.DEFAULT_NUMBER_ID, mockPolicy, [mockTransaction]); expect(result).toBe(false); }); @@ -967,7 +967,7 @@ describe('hasVisibleViolationsForUser', () => { return true; }); - const result = ViolationsUtils.hasVisibleViolationsForUser(mockReport, violations, '', mockPolicy, [mockTransaction]); + const result = ViolationsUtils.hasVisibleViolationsForUser(mockReport, violations, '', CONST.DEFAULT_NUMBER_ID, mockPolicy, [mockTransaction]); expect(result).toBe(true); }); @@ -1003,7 +1003,7 @@ describe('hasVisibleViolationsForUser', () => { return true; }); - const result = ViolationsUtils.hasVisibleViolationsForUser(mockReport, violations, '', mockPolicy, [mockTransaction, secondTransaction]); + const result = ViolationsUtils.hasVisibleViolationsForUser(mockReport, violations, '', CONST.DEFAULT_NUMBER_ID, mockPolicy, [mockTransaction, secondTransaction]); expect(result).toBe(true); }); });