From 0b80a3a8a16809836fedf3cc2d99691df2976fc1 Mon Sep 17 00:00:00 2001 From: Shubham Agrawal Date: Sun, 14 Sep 2025 18:30:56 +0530 Subject: [PATCH 1/5] Refactored isApprover function usage --- src/components/MoneyReportHeader.tsx | 9 +- src/components/MoneyRequestHeader.tsx | 10 +- src/libs/ReportPrimaryActionUtils.ts | 15 +- src/libs/ReportSecondaryActionUtils.ts | 20 +- src/libs/ReportUtils.ts | 4 +- src/libs/actions/Policy/Member.ts | 10 +- src/pages/workspace/WorkspaceMembersPage.tsx | 6 +- .../members/WorkspaceMemberDetailsPage.tsx | 8 +- tests/unit/ReportPrimaryActionUtilsTest.ts | 181 ++++++++++++++---- tests/unit/ReportSecondaryActionUtilsTest.ts | 106 ++++++---- 10 files changed, 260 insertions(+), 109 deletions(-) diff --git a/src/components/MoneyReportHeader.tsx b/src/components/MoneyReportHeader.tsx index 8a87641d45dc..051db7bcdc35 100644 --- a/src/components/MoneyReportHeader.tsx +++ b/src/components/MoneyReportHeader.tsx @@ -3,6 +3,7 @@ import React, {useCallback, useContext, useEffect, useMemo, useState} from 'reac import {ActivityIndicator, InteractionManager, View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; +import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; import useDuplicateTransactionsAndViolations from '@hooks/useDuplicateTransactionsAndViolations'; import useLoadingBarVisibility from '@hooks/useLoadingBarVisibility'; import useLocalize from '@hooks/useLocalize'; @@ -178,9 +179,8 @@ function MoneyReportHeader({ | PlatformStackRouteProp | PlatformStackRouteProp >(); - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + const {login} = useCurrentUserPersonalDetails(); const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${moneyRequestReport?.chatReportID}`, {canBeMissing: true}); - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing const [nextStep] = useOnyx(`${ONYXKEYS.COLLECTION.NEXT_STEP}${moneyRequestReport?.reportID}`, {canBeMissing: true}); const [isUserValidated] = useOnyx(ONYXKEYS.ACCOUNT, {selector: (account) => account?.validated, canBeMissing: true}); const [transactionThreadReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`, {canBeMissing: true}); @@ -558,6 +558,7 @@ function MoneyReportHeader({ const primaryAction = useMemo(() => { return getReportPrimaryAction({ + currentUserEmail: login ?? '', report: moneyRequestReport, chatReport, reportTransactions: transactions, @@ -582,6 +583,7 @@ function MoneyReportHeader({ reportActions, isChatReportArchived, invoiceReceiverPolicy, + login, ]); const confirmExport = useCallback(() => { @@ -903,6 +905,7 @@ function MoneyReportHeader({ return []; } return getSecondaryReportActions({ + currentUserEmail: login ?? '', report: moneyRequestReport, chatReport, reportTransactions: transactions, @@ -913,7 +916,7 @@ function MoneyReportHeader({ policies, isChatReportArchived, }); - }, [moneyRequestReport, transactions, violations, policy, reportNameValuePairs, reportActions, policies, chatReport, isChatReportArchived]); + }, [moneyRequestReport, transactions, violations, policy, reportNameValuePairs, reportActions, policies, chatReport, isChatReportArchived, login]); const secondaryExportActions = useMemo(() => { if (!moneyRequestReport) { diff --git a/src/components/MoneyRequestHeader.tsx b/src/components/MoneyRequestHeader.tsx index 960a6d79e011..f3e67433d6d3 100644 --- a/src/components/MoneyRequestHeader.tsx +++ b/src/components/MoneyRequestHeader.tsx @@ -4,6 +4,7 @@ import React, {useCallback, useContext, useEffect, useMemo, useState} from 'reac import {View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; +import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; import useDuplicateTransactionsAndViolations from '@hooks/useDuplicateTransactionsAndViolations'; import useLoadingBarVisibility from '@hooks/useLoadingBarVisibility'; import useLocalize from '@hooks/useLocalize'; @@ -95,6 +96,7 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre const styles = useThemeStyles(); const theme = useTheme(); const {translate} = useLocalize(); + const {login} = useCurrentUserPersonalDetails(); const isOnHold = isOnHoldTransactionUtils(transaction); const isDuplicate = isDuplicateTransactionUtils(transaction); const reportID = report?.reportID; @@ -173,8 +175,8 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre if (!report || !parentReport || !transaction) { return ''; } - return getTransactionThreadPrimaryAction(report, parentReport, transaction, transactionViolations, policy); - }, [parentReport, policy, report, transaction, transactionViolations]); + return getTransactionThreadPrimaryAction(login ?? '', report, parentReport, transaction, transactionViolations, policy); + }, [parentReport, policy, report, transaction, transactionViolations, login]); const primaryActionImplementation = { [CONST.REPORT.TRANSACTION_PRIMARY_ACTIONS.REMOVE_HOLD]: ( @@ -224,8 +226,8 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre if (!transaction || !reportActions) { return []; } - return getSecondaryTransactionThreadActions(parentReport, transaction, Object.values(reportActions), policy, report); - }, [report, parentReport, policy, transaction]); + return getSecondaryTransactionThreadActions(login ?? '', parentReport, transaction, Object.values(reportActions), policy, report); + }, [report, parentReport, policy, transaction, login]); const dismissModalAndUpdateUseReject = () => { setIsRejectEducationalModalVisible(false); diff --git a/src/libs/ReportPrimaryActionUtils.ts b/src/libs/ReportPrimaryActionUtils.ts index 8180eaaac9d7..e3c415826c8c 100644 --- a/src/libs/ReportPrimaryActionUtils.ts +++ b/src/libs/ReportPrimaryActionUtils.ts @@ -52,6 +52,7 @@ import { } from './TransactionUtils'; type GetReportPrimaryActionParams = { + currentUserEmail: string; report: Report | undefined; chatReport: OnyxEntry; reportTransactions: Transaction[]; @@ -276,7 +277,7 @@ function isReviewDuplicatesAction(report: Report, reportTransactions: Transactio return false; } -function isMarkAsCashAction(report: Report, reportTransactions: Transaction[], violations: OnyxCollection, policy?: Policy) { +function isMarkAsCashAction(currentUserEmail: string, report: Report, reportTransactions: Transaction[], violations: OnyxCollection, policy?: Policy) { const isOneExpenseReport = isExpenseReportUtils(report) && reportTransactions.length === 1; if (!isOneExpenseReport) { @@ -291,7 +292,7 @@ function isMarkAsCashAction(report: Report, reportTransactions: Transaction[], v } const isReportSubmitter = isCurrentUserSubmitter(report); - const isReportApprover = isApproverUtils(policy, getCurrentUserAccountID()); + const isReportApprover = isApproverUtils(policy, currentUserEmail); const isAdmin = policy?.role === CONST.POLICY.ROLE.ADMIN; const shouldShowBrokenConnectionViolation = shouldShowBrokenConnectionViolationForMultipleTransactions(transactionIDs, report, policy, violations); @@ -352,6 +353,7 @@ function getAllExpensesToHoldIfApplicable(report?: Report, reportActions?: Repor function getReportPrimaryAction(params: GetReportPrimaryActionParams): ValueOf | '' { const { + currentUserEmail, report, reportTransactions, violations, @@ -385,7 +387,7 @@ function getReportPrimaryAction(params: GetReportPrimaryActionParams): ValueOf, policy?: Policy): boolean { +function isApproveAction(currentUserLogin: string, report: Report, reportTransactions: Transaction[], violations: OnyxCollection, policy?: Policy): boolean { const isAnyReceiptBeingScanned = reportTransactions?.some((transaction) => isReceiptBeingScanned(transaction)); if (isAnyReceiptBeingScanned) { @@ -234,14 +234,14 @@ function isApproveAction(report: Report, reportTransactions: Transaction[], viol const isAdmin = policy?.role === CONST.POLICY.ROLE.ADMIN; const shouldShowBrokenConnectionViolation = shouldShowBrokenConnectionViolationForMultipleTransactions(transactionIDs, report, policy, violations); - const isReportApprover = isApproverUtils(policy, currentUserAccountID); + const isReportApprover = isApproverUtils(policy, currentUserLogin); const userControlsReport = isReportApprover || isAdmin; return userControlsReport && shouldShowBrokenConnectionViolation; } -function isUnapproveAction(report: Report, policy?: Policy): boolean { +function isUnapproveAction(currentUserLogin: string, report: Report, policy?: Policy): boolean { const isExpenseReport = isExpenseReportUtils(report); - const isReportApprover = isApproverUtils(policy, getCurrentUserAccountID()); + const isReportApprover = isApproverUtils(policy, currentUserLogin); const isReportApproved = isReportApprovedUtils({report}); const isReportSettled = isSettled(report); const isPaymentProcessing = report.isWaitingOnBankAccount && report.statusNum === CONST.REPORT.STATUS_NUM.APPROVED; @@ -593,6 +593,7 @@ function isRemoveHoldActionForTransaction(report: Report, reportTransaction: Tra } function getSecondaryReportActions({ + currentUserEmail, report, chatReport, reportTransactions, @@ -603,6 +604,7 @@ function getSecondaryReportActions({ policies, isChatReportArchived = false, }: { + currentUserEmail: string; report: Report; chatReport: OnyxEntry; reportTransactions: Transaction[]; @@ -625,6 +627,7 @@ function getSecondaryReportActions({ } const primaryAction = getReportPrimaryAction({ + currentUserEmail, report, chatReport, reportTransactions, @@ -639,11 +642,11 @@ function getSecondaryReportActions({ options.push(CONST.REPORT.SECONDARY_ACTIONS.SUBMIT); } - if (isApproveAction(report, reportTransactions, violations, policy)) { + if (isApproveAction(currentUserEmail, report, reportTransactions, violations, policy)) { options.push(CONST.REPORT.SECONDARY_ACTIONS.APPROVE); } - if (isUnapproveAction(report, policy)) { + if (isUnapproveAction(currentUserEmail, report, policy)) { options.push(CONST.REPORT.SECONDARY_ACTIONS.UNAPPROVE); } @@ -667,7 +670,7 @@ function getSecondaryReportActions({ options.push(CONST.REPORT.SECONDARY_ACTIONS.REMOVE_HOLD); } - if (canRejectReportAction(report, policy)) { + if (canRejectReportAction(currentUserEmail, report, policy)) { options.push(CONST.REPORT.SECONDARY_ACTIONS.REJECT); } @@ -736,6 +739,7 @@ function getSecondaryExportReportActions( } function getSecondaryTransactionThreadActions( + currentUserEmail: string, parentReport: Report, reportTransaction: Transaction, reportActions: ReportAction[], @@ -752,7 +756,7 @@ function getSecondaryTransactionThreadActions( options.push(CONST.REPORT.TRANSACTION_SECONDARY_ACTIONS.REMOVE_HOLD); } - if (canRejectReportAction(parentReport, policy)) { + if (canRejectReportAction(currentUserEmail, parentReport, policy)) { options.push(CONST.REPORT.TRANSACTION_SECONDARY_ACTIONS.REJECT); } diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index c0a0c0c26c78..c8cff85067f8 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -11403,8 +11403,8 @@ function findReportIDForAction(action?: ReportAction): string | undefined { }) ?.replace(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}`, ''); } -function canRejectReportAction(report: Report, policy?: Policy): boolean { - const isReportApprover = isApproverUtils(policy, currentUserAccountID ?? CONST.DEFAULT_NUMBER_ID); +function canRejectReportAction(currentUserLogin: string, report: Report, policy?: Policy): boolean { + const isReportApprover = isApproverUtils(policy, currentUserLogin); const isReportBeingProcessed = isProcessingReport(report); const isApproved = isReportApproved({report}); const isReportPayer = isPayer(getSession(), report, false, policy); diff --git a/src/libs/actions/Policy/Member.ts b/src/libs/actions/Policy/Member.ts index 2f43a45024fb..438095113b75 100644 --- a/src/libs/actions/Policy/Member.ts +++ b/src/libs/actions/Policy/Member.ts @@ -124,8 +124,7 @@ Onyx.connect({ }); /** Check if the passed employee is an approver in the policy's employeeList */ -function isApprover(policy: OnyxEntry, employeeAccountID: number) { - const employeeLogin = allPersonalDetails?.[employeeAccountID]?.login; +function isApprover(policy: OnyxEntry, employeeLogin: string) { if (policy?.approver === employeeLogin) { return true; } @@ -134,6 +133,12 @@ function isApprover(policy: OnyxEntry, employeeAccountID: number) { ); } +/** Temporary function alias for isApprover with employeeAccountID */ +function isApproverTemp(policy: OnyxEntry, employeeAccountID: number) { + const employeeLogin = allPersonalDetails?.[employeeAccountID]?.login; + return isApprover(policy, employeeLogin ?? ''); +} + /** * Returns the policy of the report * @deprecated Get the data straight from Onyx - This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850 @@ -1385,4 +1390,5 @@ export { clearWorkspaceInviteRoleDraft, setImportedSpreadsheetMemberData, clearImportedSpreadsheetMemberData, + isApproverTemp, }; diff --git a/src/pages/workspace/WorkspaceMembersPage.tsx b/src/pages/workspace/WorkspaceMembersPage.tsx index 5f2361cac286..13a61fb8d82e 100644 --- a/src/pages/workspace/WorkspaceMembersPage.tsx +++ b/src/pages/workspace/WorkspaceMembersPage.tsx @@ -38,7 +38,7 @@ import { clearInviteDraft, clearWorkspaceOwnerChangeFlow, downloadMembersCSV, - isApprover, + isApproverTemp, openWorkspaceMembersPage, removeMembers, updateWorkspaceMembersRole, @@ -158,7 +158,7 @@ function WorkspaceMembersPage({personalDetails, route, policy}: WorkspaceMembers const canSelectMultiple = isPolicyAdmin && (shouldUseNarrowLayout ? isMobileSelectionModeEnabled : true); const confirmModalPrompt = useMemo(() => { - const approverAccountID = selectedEmployees.find((selectedEmployee) => isApprover(policy, selectedEmployee)); + const approverAccountID = selectedEmployees.find((selectedEmployee) => isApproverTemp(policy, selectedEmployee)); if (!approverAccountID) { return translate('workspace.people.removeMembersPrompt', { count: selectedEmployees.length, @@ -267,7 +267,7 @@ function WorkspaceMembersPage({personalDetails, route, policy}: WorkspaceMembers const accountIDsToRemove = session?.accountID ? selectedEmployees.filter((id) => id !== session.accountID) : selectedEmployees; // Check if any of the account IDs are approvers - const hasApprovers = accountIDsToRemove.some((accountID) => isApprover(policy, accountID)); + const hasApprovers = accountIDsToRemove.some((accountID) => isApproverTemp(policy, accountID)); if (hasApprovers) { const ownerEmail = ownerDetails.login; diff --git a/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx b/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx index ca4bfa8e6bb9..c1f01c9e3218 100644 --- a/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx +++ b/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx @@ -127,7 +127,7 @@ function WorkspaceMemberDetailsPage({personalDetails, policy, route}: WorkspaceM }, [accountID, workspaceCards]); const confirmModalPrompt = useMemo(() => { - const isApprover = isApproverUserAction(policy, accountID); + const isApprover = isApproverUserAction(policy, memberLogin); if (!isApprover) { return translate('workspace.people.removeMemberPrompt', {memberName: displayName}); } @@ -135,7 +135,7 @@ function WorkspaceMemberDetailsPage({personalDetails, policy, route}: WorkspaceM memberName: displayName, ownerName: policyOwnerDisplayName, }); - }, [accountID, policy, displayName, policyOwnerDisplayName, translate]); + }, [memberLogin, policy, displayName, policyOwnerDisplayName, translate]); const roleItems: ListItemType[] = useMemo( () => [ @@ -192,7 +192,7 @@ function WorkspaceMemberDetailsPage({personalDetails, policy, route}: WorkspaceM const removedApprover = personalDetails?.[accountID]; // If the user is not an approver, proceed with member removal - if (!isApproverUserAction(policy, accountID) || !removedApprover?.login || !ownerEmail) { + if (!isApproverUserAction(policy, memberLogin) || !removedApprover?.login || !ownerEmail) { removeMemberAndCloseModal(); return; } @@ -216,7 +216,7 @@ function WorkspaceMemberDetailsPage({personalDetails, policy, route}: WorkspaceM // Remove the member and close the modal removeMemberAndCloseModal(); - }, [accountID, approvalWorkflows, ownerDetails, personalDetails, policy, policyID, removeMemberAndCloseModal]); + }, [accountID, approvalWorkflows, ownerDetails, personalDetails, policy, policyID, removeMemberAndCloseModal, memberLogin]); const navigateToProfile = useCallback(() => { Navigation.navigate(ROUTES.PROFILE.getRoute(accountID, Navigation.getActiveRoute())); diff --git a/tests/unit/ReportPrimaryActionUtilsTest.ts b/tests/unit/ReportPrimaryActionUtilsTest.ts index 24f4f2dfb9a6..bccc8815377b 100644 --- a/tests/unit/ReportPrimaryActionUtilsTest.ts +++ b/tests/unit/ReportPrimaryActionUtilsTest.ts @@ -54,9 +54,9 @@ describe('getPrimaryAction', () => { } as unknown as Report; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report); - expect(getReportPrimaryAction({report, chatReport, reportTransactions: [], violations: {}, policy: {} as Policy, isChatReportArchived: false})).toBe( - CONST.REPORT.PRIMARY_ACTIONS.ADD_EXPENSE, - ); + expect( + getReportPrimaryAction({currentUserEmail: CURRENT_USER_EMAIL, report, chatReport, reportTransactions: [], violations: {}, policy: {} as Policy, isChatReportArchived: false}), + ).toBe(CONST.REPORT.PRIMARY_ACTIONS.ADD_EXPENSE); }); it('should return SUBMIT for expense report with manual submit', async () => { @@ -75,9 +75,17 @@ describe('getPrimaryAction', () => { reportID: `${REPORT_ID}`, } as unknown as Transaction; - expect(getReportPrimaryAction({report, chatReport, reportTransactions: [transaction], violations: {}, policy: policy as Policy, isChatReportArchived: false})).toBe( - CONST.REPORT.PRIMARY_ACTIONS.SUBMIT, - ); + expect( + getReportPrimaryAction({ + currentUserEmail: CURRENT_USER_EMAIL, + report, + chatReport, + reportTransactions: [transaction], + violations: {}, + policy: policy as Policy, + isChatReportArchived: false, + }), + ).toBe(CONST.REPORT.PRIMARY_ACTIONS.SUBMIT); }); it('should not return SUBMIT option for admin with only pending transactions', async () => { @@ -101,7 +109,17 @@ describe('getPrimaryAction', () => { date: '2025-01-01', } as unknown as Transaction; - expect(getReportPrimaryAction({report, chatReport, reportTransactions: [transaction], violations: {}, policy: policy as Policy, isChatReportArchived: false})).toBe(''); + expect( + getReportPrimaryAction({ + currentUserEmail: CURRENT_USER_EMAIL, + report, + chatReport, + reportTransactions: [transaction], + violations: {}, + policy: policy as Policy, + isChatReportArchived: false, + }), + ).toBe(''); }); it('should return Approve for report being processed', async () => { @@ -125,9 +143,17 @@ describe('getPrimaryAction', () => { }, } as unknown as Transaction; - expect(getReportPrimaryAction({report, chatReport, reportTransactions: [transaction], violations: {}, policy: policy as Policy, isChatReportArchived: false})).toBe( - CONST.REPORT.PRIMARY_ACTIONS.APPROVE, - ); + expect( + getReportPrimaryAction({ + currentUserEmail: CURRENT_USER_EMAIL, + report, + chatReport, + reportTransactions: [transaction], + violations: {}, + policy: policy as Policy, + isChatReportArchived: false, + }), + ).toBe(CONST.REPORT.PRIMARY_ACTIONS.APPROVE); }); it('should return empty for report being processed but transactions are scanning', async () => { @@ -154,7 +180,17 @@ describe('getPrimaryAction', () => { }, } as unknown as Transaction; - expect(getReportPrimaryAction({report, chatReport, reportTransactions: [transaction], violations: {}, policy: policy as Policy, isChatReportArchived: false})).toBe(''); + expect( + getReportPrimaryAction({ + currentUserEmail: CURRENT_USER_EMAIL, + report, + chatReport, + reportTransactions: [transaction], + violations: {}, + policy: policy as Policy, + isChatReportArchived: false, + }), + ).toBe(''); }); it('should return empty for report being processed but transactions are pending', async () => { @@ -179,7 +215,17 @@ describe('getPrimaryAction', () => { date: '2025-01-01', } as unknown as Transaction; - expect(getReportPrimaryAction({report, chatReport, reportTransactions: [transaction], violations: {}, policy: policy as Policy, isChatReportArchived: false})).toBe(''); + expect( + getReportPrimaryAction({ + currentUserEmail: CURRENT_USER_EMAIL, + report, + chatReport, + reportTransactions: [transaction], + violations: {}, + policy: policy as Policy, + isChatReportArchived: false, + }), + ).toBe(''); }); it('should return PAY for submitted invoice report if paid as personal', async () => { @@ -209,9 +255,18 @@ describe('getPrimaryAction', () => { reportID: `${REPORT_ID}`, } as unknown as Transaction; - expect(getReportPrimaryAction({report, chatReport, reportTransactions: [transaction], violations: {}, policy, invoiceReceiverPolicy, isChatReportArchived: false})).toBe( - CONST.REPORT.PRIMARY_ACTIONS.PAY, - ); + expect( + getReportPrimaryAction({ + currentUserEmail: CURRENT_USER_EMAIL, + report, + chatReport, + reportTransactions: [transaction], + violations: {}, + policy, + invoiceReceiverPolicy, + isChatReportArchived: false, + }), + ).toBe(CONST.REPORT.PRIMARY_ACTIONS.PAY); }); it('should not return PAY for zero value invoice report if paid as personal', async () => { @@ -241,7 +296,18 @@ describe('getPrimaryAction', () => { reportID: `${REPORT_ID}`, } as unknown as Transaction; - expect(getReportPrimaryAction({report, chatReport, reportTransactions: [transaction], violations: {}, policy, invoiceReceiverPolicy, isChatReportArchived: false})).toBe(''); + expect( + getReportPrimaryAction({ + currentUserEmail: CURRENT_USER_EMAIL, + report, + chatReport, + reportTransactions: [transaction], + violations: {}, + policy, + invoiceReceiverPolicy, + isChatReportArchived: false, + }), + ).toBe(''); }); it('should return PAY for expense report with payments enabled', async () => { @@ -260,9 +326,17 @@ describe('getPrimaryAction', () => { reportID: `${REPORT_ID}`, } as unknown as Transaction; - expect(getReportPrimaryAction({report, chatReport, reportTransactions: [transaction], violations: {}, policy: policy as Policy, isChatReportArchived: false})).toBe( - CONST.REPORT.PRIMARY_ACTIONS.PAY, - ); + expect( + getReportPrimaryAction({ + currentUserEmail: CURRENT_USER_EMAIL, + report, + chatReport, + reportTransactions: [transaction], + violations: {}, + policy: policy as Policy, + isChatReportArchived: false, + }), + ).toBe(CONST.REPORT.PRIMARY_ACTIONS.PAY); }); it('should return EXPORT TO ACCOUNTING for finished reports', async () => { @@ -288,9 +362,17 @@ describe('getPrimaryAction', () => { reportID: `${REPORT_ID}`, } as unknown as Transaction; - expect(getReportPrimaryAction({report, chatReport, reportTransactions: [transaction], violations: {}, policy: policy as Policy, isChatReportArchived: false})).toBe( - CONST.REPORT.PRIMARY_ACTIONS.EXPORT_TO_ACCOUNTING, - ); + expect( + getReportPrimaryAction({ + currentUserEmail: CURRENT_USER_EMAIL, + report, + chatReport, + reportTransactions: [transaction], + violations: {}, + policy: policy as Policy, + isChatReportArchived: false, + }), + ).toBe(CONST.REPORT.PRIMARY_ACTIONS.EXPORT_TO_ACCOUNTING); }); it('should not return EXPORT TO ACCOUNTING for invoice reports', async () => { @@ -316,9 +398,17 @@ describe('getPrimaryAction', () => { reportID: `${REPORT_ID}`, } as unknown as Transaction; - expect(getReportPrimaryAction({report, chatReport, reportTransactions: [transaction], violations: {}, policy: policy as Policy, isChatReportArchived: false})).not.toBe( - CONST.REPORT.PRIMARY_ACTIONS.EXPORT_TO_ACCOUNTING, - ); + expect( + getReportPrimaryAction({ + currentUserEmail: CURRENT_USER_EMAIL, + report, + chatReport, + reportTransactions: [transaction], + violations: {}, + policy: policy as Policy, + isChatReportArchived: false, + }), + ).not.toBe(CONST.REPORT.PRIMARY_ACTIONS.EXPORT_TO_ACCOUNTING); }); it('should not return EXPORT TO ACCOUNTING for reports marked manually as exported', async () => { @@ -346,6 +436,7 @@ describe('getPrimaryAction', () => { expect( getReportPrimaryAction({ + currentUserEmail: CURRENT_USER_EMAIL, report, chatReport, reportTransactions: [], @@ -407,9 +498,9 @@ describe('getPrimaryAction', () => { await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${REPORT_ID}`, {[REPORT_ACTION_ID]: reportAction}); await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${CHILD_REPORT_ID}`, {[HOLD_ACTION_ID]: holdAction}); - expect(getReportPrimaryAction({report, chatReport, reportTransactions: [transaction], violations: {}, policy, isChatReportArchived: false})).toBe( - CONST.REPORT.PRIMARY_ACTIONS.REMOVE_HOLD, - ); + expect( + getReportPrimaryAction({currentUserEmail: CURRENT_USER_EMAIL, report, chatReport, reportTransactions: [transaction], violations: {}, policy, isChatReportArchived: false}), + ).toBe(CONST.REPORT.PRIMARY_ACTIONS.REMOVE_HOLD); }); it('should return REMOVE HOLD for reports with transactions on hold', async () => { @@ -456,9 +547,17 @@ describe('getPrimaryAction', () => { await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${REPORT_ID}`, {[REPORT_ACTION_ID]: reportAction}); await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${CHILD_REPORT_ID}`, {[HOLD_ACTION_ID]: holdAction}); - expect(getReportPrimaryAction({report, chatReport, reportTransactions: [transaction], violations: {}, policy: policy as Policy, isChatReportArchived: false})).toBe( - CONST.REPORT.PRIMARY_ACTIONS.REMOVE_HOLD, - ); + expect( + getReportPrimaryAction({ + currentUserEmail: CURRENT_USER_EMAIL, + report, + chatReport, + reportTransactions: [transaction], + violations: {}, + policy: policy as Policy, + isChatReportArchived: false, + }), + ).toBe(CONST.REPORT.PRIMARY_ACTIONS.REMOVE_HOLD); }); it('should return MARK AS CASH if has all RTER violations', async () => { @@ -489,6 +588,7 @@ describe('getPrimaryAction', () => { expect( getReportPrimaryAction({ + currentUserEmail: CURRENT_USER_EMAIL, report, chatReport, reportTransactions: [transaction], @@ -524,6 +624,7 @@ describe('getPrimaryAction', () => { expect( getReportPrimaryAction({ + currentUserEmail: CURRENT_USER_EMAIL, report, chatReport, reportTransactions: [transaction], @@ -560,6 +661,7 @@ describe('getPrimaryAction', () => { // Then the getReportPrimaryAction should return the empty string expect( getReportPrimaryAction({ + currentUserEmail: CURRENT_USER_EMAIL, report, chatReport: invoiceChatReport, reportTransactions: [transaction], @@ -696,7 +798,7 @@ describe('getTransactionThreadPrimaryAction', () => { await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${CHILD_REPORT_ID}`, {[HOLD_ACTION_ID]: holdAction}); - expect(getTransactionThreadPrimaryAction(report, {} as Report, transaction, [], policy as Policy)).toBe(CONST.REPORT.TRANSACTION_PRIMARY_ACTIONS.REMOVE_HOLD); + expect(getTransactionThreadPrimaryAction(CURRENT_USER_EMAIL, report, {} as Report, transaction, [], policy as Policy)).toBe(CONST.REPORT.TRANSACTION_PRIMARY_ACTIONS.REMOVE_HOLD); }); it('should return REVIEW DUPLICATES when there are duplicated transactions', async () => { @@ -724,7 +826,9 @@ describe('getTransactionThreadPrimaryAction', () => { } as TransactionViolation, ]); - expect(getTransactionThreadPrimaryAction({} as Report, report, transaction, [], policy as Policy)).toBe(CONST.REPORT.TRANSACTION_PRIMARY_ACTIONS.REVIEW_DUPLICATES); + expect(getTransactionThreadPrimaryAction(CURRENT_USER_EMAIL, {} as Report, report, transaction, [], policy as Policy)).toBe( + CONST.REPORT.TRANSACTION_PRIMARY_ACTIONS.REVIEW_DUPLICATES, + ); }); it('should return MARK AS CASH if has all RTER violations', async () => { @@ -751,7 +855,9 @@ describe('getTransactionThreadPrimaryAction', () => { }, } as unknown as TransactionViolation; - expect(getTransactionThreadPrimaryAction({} as Report, report, transaction, [violation], policy as Policy)).toBe(CONST.REPORT.TRANSACTION_PRIMARY_ACTIONS.MARK_AS_CASH); + expect(getTransactionThreadPrimaryAction(CURRENT_USER_EMAIL, {} as Report, report, transaction, [violation], policy as Policy)).toBe( + CONST.REPORT.TRANSACTION_PRIMARY_ACTIONS.MARK_AS_CASH, + ); }); it('should return MARK AS CASH for broken connection', async () => { @@ -777,7 +883,9 @@ describe('getTransactionThreadPrimaryAction', () => { }, } as unknown as TransactionViolation; - expect(getTransactionThreadPrimaryAction({} as Report, report, transaction, [violation], policy as Policy)).toBe(CONST.REPORT.TRANSACTION_PRIMARY_ACTIONS.MARK_AS_CASH); + expect(getTransactionThreadPrimaryAction(CURRENT_USER_EMAIL, {} as Report, report, transaction, [violation], policy as Policy)).toBe( + CONST.REPORT.TRANSACTION_PRIMARY_ACTIONS.MARK_AS_CASH, + ); }); it('Should return empty string when we are waiting for user to add a bank account', async () => { @@ -806,6 +914,7 @@ describe('getTransactionThreadPrimaryAction', () => { expect( getReportPrimaryAction({ + currentUserEmail: CURRENT_USER_EMAIL, report, chatReport, reportTransactions: [transaction], @@ -843,6 +952,7 @@ describe('getTransactionThreadPrimaryAction', () => { } as unknown as Transaction; expect( getReportPrimaryAction({ + currentUserEmail: CURRENT_USER_EMAIL, report, chatReport, reportTransactions: [transaction], @@ -881,6 +991,7 @@ describe('getTransactionThreadPrimaryAction', () => { } as unknown as Transaction; expect( getReportPrimaryAction({ + currentUserEmail: CURRENT_USER_EMAIL, report, chatReport, reportTransactions: [transaction], diff --git a/tests/unit/ReportSecondaryActionUtilsTest.ts b/tests/unit/ReportSecondaryActionUtilsTest.ts index fd9cdd0c5730..eaef96ec99a4 100644 --- a/tests/unit/ReportSecondaryActionUtilsTest.ts +++ b/tests/unit/ReportSecondaryActionUtilsTest.ts @@ -49,7 +49,7 @@ describe('getSecondaryAction', () => { const policy = {} as unknown as Policy; const result = [CONST.REPORT.SECONDARY_ACTIONS.EXPORT, CONST.REPORT.SECONDARY_ACTIONS.DOWNLOAD_PDF, CONST.REPORT.SECONDARY_ACTIONS.VIEW_DETAILS]; - expect(getSecondaryReportActions({report, chatReport, reportTransactions: [], violations: {}, policy})).toEqual(result); + expect(getSecondaryReportActions({currentUserEmail: EMPLOYEE_EMAIL, report, chatReport, reportTransactions: [], violations: {}, policy})).toEqual(result); }); it('includes ADD_EXPENSE option for empty report', async () => { @@ -72,7 +72,7 @@ describe('getSecondaryAction', () => { transactionID: TRANSACTION_ID, } as unknown as Transaction; - const result = getSecondaryReportActions({report, chatReport, reportTransactions: [transaction], violations: {}, policy}); + const result = getSecondaryReportActions({currentUserEmail: EMPLOYEE_EMAIL, report, chatReport, reportTransactions: [transaction], violations: {}, policy}); expect(result.includes(CONST.REPORT.SECONDARY_ACTIONS.ADD_EXPENSE)).toBe(true); }); @@ -93,7 +93,7 @@ describe('getSecondaryAction', () => { } as unknown as Policy; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report); - const result = getSecondaryReportActions({report, chatReport, reportTransactions: [], violations: {}, policy}); + const result = getSecondaryReportActions({currentUserEmail: EMPLOYEE_EMAIL, report, chatReport, reportTransactions: [], violations: {}, policy}); expect(result.includes(CONST.REPORT.SECONDARY_ACTIONS.SUBMIT)).toBe(true); }); @@ -114,7 +114,7 @@ describe('getSecondaryAction', () => { } as unknown as Policy; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report); - const result = getSecondaryReportActions({report, chatReport, reportTransactions: [], violations: {}, policy}); + const result = getSecondaryReportActions({currentUserEmail: EMPLOYEE_EMAIL, report, chatReport, reportTransactions: [], violations: {}, policy}); expect(result.includes(CONST.REPORT.SECONDARY_ACTIONS.SUBMIT)).toBe(true); }); @@ -137,7 +137,7 @@ describe('getSecondaryAction', () => { } as unknown as Policy; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report); - const result = getSecondaryReportActions({report, chatReport, reportTransactions: [], violations: {}, policy}); + const result = getSecondaryReportActions({currentUserEmail: EMPLOYEE_EMAIL, report, chatReport, reportTransactions: [], violations: {}, policy}); expect(result.includes(CONST.REPORT.SECONDARY_ACTIONS.SUBMIT)).toBe(false); }); @@ -166,7 +166,7 @@ describe('getSecondaryAction', () => { date: '2025-01-01', } as unknown as Transaction; - const result = getSecondaryReportActions({report, chatReport, reportTransactions: [transaction], violations: {}, policy}); + const result = getSecondaryReportActions({currentUserEmail: EMPLOYEE_EMAIL, report, chatReport, reportTransactions: [transaction], violations: {}, policy}); expect(result.includes(CONST.REPORT.SECONDARY_ACTIONS.SUBMIT)).toBe(false); }); @@ -197,7 +197,7 @@ describe('getSecondaryAction', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report); - const result = getSecondaryReportActions({report, chatReport, reportTransactions: [transaction], violations: {}, policy}); + const result = getSecondaryReportActions({currentUserEmail: EMPLOYEE_EMAIL, report, chatReport, reportTransactions: [transaction], violations: {}, policy}); expect(result.includes(CONST.REPORT.SECONDARY_ACTIONS.APPROVE)).toBe(true); }); @@ -225,7 +225,7 @@ describe('getSecondaryAction', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${TRANSACTION_ID}`, transaction); await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report); - const result = getSecondaryReportActions({report, chatReport, reportTransactions: [transaction], violations: {}, policy}); + const result = getSecondaryReportActions({currentUserEmail: EMPLOYEE_EMAIL, report, chatReport, reportTransactions: [transaction], violations: {}, policy}); expect(result.includes(CONST.REPORT.SECONDARY_ACTIONS.APPROVE)).toBe(false); }); @@ -256,6 +256,7 @@ describe('getSecondaryAction', () => { } as unknown as TransactionViolation; const result = getSecondaryReportActions({ + currentUserEmail: EMPLOYEE_EMAIL, report, chatReport, reportTransactions: [transaction], @@ -292,6 +293,7 @@ describe('getSecondaryAction', () => { } as unknown as TransactionViolation; const result = getSecondaryReportActions({ + currentUserEmail: EMPLOYEE_EMAIL, report, chatReport, reportTransactions: [transaction], @@ -325,6 +327,7 @@ describe('getSecondaryAction', () => { } as unknown as TransactionViolation; const result = getSecondaryReportActions({ + currentUserEmail: EMPLOYEE_EMAIL, report, chatReport, reportTransactions: [transaction], @@ -358,6 +361,7 @@ describe('getSecondaryAction', () => { } as unknown as TransactionViolation; const result = getSecondaryReportActions({ + currentUserEmail: EMPLOYEE_EMAIL, report, chatReport, reportTransactions: [transaction], @@ -387,7 +391,7 @@ describe('getSecondaryAction', () => { }, } as unknown as Transaction; - const result = getSecondaryReportActions({report, chatReport, reportTransactions: [transaction], violations: {}, policy}); + const result = getSecondaryReportActions({currentUserEmail: EMPLOYEE_EMAIL, report, chatReport, reportTransactions: [transaction], violations: {}, policy}); expect(result.includes(CONST.REPORT.SECONDARY_ACTIONS.APPROVE)).toBe(false); }); @@ -402,7 +406,7 @@ describe('getSecondaryAction', () => { } as unknown as Report; const policy = {approver: EMPLOYEE_EMAIL} as unknown as Policy; - const result = getSecondaryReportActions({report, chatReport, reportTransactions: [], violations: {}, policy}); + const result = getSecondaryReportActions({currentUserEmail: EMPLOYEE_EMAIL, report, chatReport, reportTransactions: [], violations: {}, policy}); expect(result.includes(CONST.REPORT.SECONDARY_ACTIONS.UNAPPROVE)).toBe(true); }); @@ -420,7 +424,7 @@ describe('getSecondaryAction', () => { role: CONST.POLICY.ROLE.ADMIN, } as unknown as Policy; - const result = getSecondaryReportActions({report, chatReport, reportTransactions: [], violations: {}, policy}); + const result = getSecondaryReportActions({currentUserEmail: EMPLOYEE_EMAIL, report, chatReport, reportTransactions: [], violations: {}, policy}); expect(result.includes(CONST.REPORT.SECONDARY_ACTIONS.UNAPPROVE)).toBe(true); }); @@ -437,7 +441,7 @@ describe('getSecondaryAction', () => { approver: APPROVER_EMAIL, } as unknown as Policy; - const result = getSecondaryReportActions({report, chatReport, reportTransactions: [], violations: {}, policy}); + const result = getSecondaryReportActions({currentUserEmail: EMPLOYEE_EMAIL, report, chatReport, reportTransactions: [], violations: {}, policy}); expect(result.includes(CONST.REPORT.SECONDARY_ACTIONS.UNAPPROVE)).toBe(true); }); @@ -454,7 +458,7 @@ describe('getSecondaryAction', () => { approver: APPROVER_EMAIL, } as unknown as Policy; - const result = getSecondaryReportActions({report, chatReport, reportTransactions: [], violations: {}, policy}); + const result = getSecondaryReportActions({currentUserEmail: EMPLOYEE_EMAIL, report, chatReport, reportTransactions: [], violations: {}, policy}); expect(result.includes(CONST.REPORT.SECONDARY_ACTIONS.UNAPPROVE)).toBe(false); }); @@ -472,7 +476,7 @@ describe('getSecondaryAction', () => { role: CONST.POLICY.ROLE.ADMIN, } as unknown as Policy; - const result = getSecondaryReportActions({report, chatReport, reportTransactions: [], violations: {}, policy}); + const result = getSecondaryReportActions({currentUserEmail: EMPLOYEE_EMAIL, report, chatReport, reportTransactions: [], violations: {}, policy}); expect(result.includes(CONST.REPORT.SECONDARY_ACTIONS.UNAPPROVE)).toBe(false); }); @@ -490,7 +494,7 @@ describe('getSecondaryAction', () => { role: CONST.POLICY.ROLE.ADMIN, } as unknown as Policy; - const result = getSecondaryReportActions({report, chatReport, reportTransactions: [], violations: {}, policy}); + const result = getSecondaryReportActions({currentUserEmail: EMPLOYEE_EMAIL, report, chatReport, reportTransactions: [], violations: {}, policy}); expect(result.includes(CONST.REPORT.SECONDARY_ACTIONS.UNAPPROVE)).toBe(false); }); @@ -509,7 +513,7 @@ describe('getSecondaryAction', () => { role: CONST.POLICY.ROLE.ADMIN, } as unknown as Policy; - const result = getSecondaryReportActions({report, chatReport, reportTransactions: [], violations: {}, policy}); + const result = getSecondaryReportActions({currentUserEmail: EMPLOYEE_EMAIL, report, chatReport, reportTransactions: [], violations: {}, policy}); expect(result.includes(CONST.REPORT.SECONDARY_ACTIONS.UNAPPROVE)).toBe(false); }); @@ -525,7 +529,7 @@ describe('getSecondaryAction', () => { role: CONST.POLICY.ROLE.ADMIN, } as unknown as Policy; - const result = getSecondaryReportActions({report, chatReport, reportTransactions: [], violations: {}, policy}); + const result = getSecondaryReportActions({currentUserEmail: EMPLOYEE_EMAIL, report, chatReport, reportTransactions: [], violations: {}, policy}); expect(result.includes(CONST.REPORT.SECONDARY_ACTIONS.CANCEL_PAYMENT)).toBe(true); }); @@ -554,6 +558,7 @@ describe('getSecondaryAction', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${REPORT_ID}`, {[ACTION_ID]: reportAction}); const result = getSecondaryReportActions({ + currentUserEmail: EMPLOYEE_EMAIL, report, chatReport, reportTransactions: [ @@ -583,7 +588,15 @@ describe('getSecondaryAction', () => { jest.spyOn(ReportUtils, 'canHoldUnholdReportAction').mockReturnValueOnce({canHoldRequest: true, canUnholdRequest: true}); jest.spyOn(ReportActionsUtils, 'getOneTransactionThreadReportID').mockReturnValueOnce(originalMessageR14932.IOUTransactionID); - const result = getSecondaryReportActions({report, chatReport, reportTransactions: [transaction], violations: {}, policy, reportActions: [actionR14932]}); + const result = getSecondaryReportActions({ + currentUserEmail: EMPLOYEE_EMAIL, + report, + chatReport, + reportTransactions: [transaction], + violations: {}, + policy, + reportActions: [actionR14932], + }); expect(result.includes(CONST.REPORT.SECONDARY_ACTIONS.HOLD)).toBe(true); }); @@ -616,7 +629,7 @@ describe('getSecondaryAction', () => { await Onyx.merge(ONYXKEYS.SESSION, {email: EMPLOYEE_EMAIL, accountID: EMPLOYEE_ACCOUNT_ID}); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, personalDetails); - const result = getSecondaryReportActions({report, chatReport, reportTransactions: [], violations: {}, policy, policies}); + const result = getSecondaryReportActions({currentUserEmail: EMPLOYEE_EMAIL, report, chatReport, reportTransactions: [], violations: {}, policy, policies}); expect(result.includes(CONST.REPORT.SECONDARY_ACTIONS.CHANGE_WORKSPACE)).toBe(true); }); @@ -650,7 +663,7 @@ describe('getSecondaryAction', () => { await Onyx.merge(ONYXKEYS.SESSION, {email: EMPLOYEE_EMAIL, accountID: EMPLOYEE_ACCOUNT_ID}); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, personalDetails); - const result = getSecondaryReportActions({report, chatReport, reportTransactions: [], violations: {}, policy, policies}); + const result = getSecondaryReportActions({currentUserEmail: EMPLOYEE_EMAIL, report, chatReport, reportTransactions: [], violations: {}, policy, policies}); expect(result.includes(CONST.REPORT.SECONDARY_ACTIONS.CHANGE_WORKSPACE)).toBe(true); }); @@ -698,6 +711,7 @@ describe('getSecondaryAction', () => { await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, personalDetails); const result = getSecondaryReportActions({ + currentUserEmail: EMPLOYEE_EMAIL, report, chatReport, reportTransactions: [], @@ -751,7 +765,7 @@ describe('getSecondaryAction', () => { await Onyx.merge(ONYXKEYS.SESSION, {email: APPROVER_EMAIL, accountID: APPROVER_ACCOUNT_ID}); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, personalDetails); - const result = getSecondaryReportActions({report, chatReport, reportTransactions: [], violations: {}, policy, policies}); + const result = getSecondaryReportActions({currentUserEmail: EMPLOYEE_EMAIL, report, chatReport, reportTransactions: [], violations: {}, policy, policies}); expect(result.includes(CONST.REPORT.SECONDARY_ACTIONS.CHANGE_WORKSPACE)).toBe(true); }); @@ -800,7 +814,7 @@ describe('getSecondaryAction', () => { await Onyx.merge(ONYXKEYS.SESSION, {email: ADMIN_EMAIL, accountID: ADMIN_ACCOUNT_ID}); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, personalDetails); - const result = getSecondaryReportActions({report, chatReport, reportTransactions: [], violations: {}, policy, policies}); + const result = getSecondaryReportActions({currentUserEmail: EMPLOYEE_EMAIL, report, chatReport, reportTransactions: [], violations: {}, policy, policies}); expect(result.includes(CONST.REPORT.SECONDARY_ACTIONS.CHANGE_WORKSPACE)).toBe(true); }); @@ -815,7 +829,7 @@ describe('getSecondaryAction', () => { const policy = {} as unknown as Policy; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report); - const result = getSecondaryReportActions({report, chatReport, reportTransactions: [{} as Transaction], violations: {}, policy}); + const result = getSecondaryReportActions({currentUserEmail: EMPLOYEE_EMAIL, report, chatReport, reportTransactions: [{} as Transaction], violations: {}, policy}); expect(result.includes(CONST.REPORT.SECONDARY_ACTIONS.DELETE)).toBe(true); }); @@ -835,7 +849,7 @@ describe('getSecondaryAction', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report); - const result = getSecondaryTransactionThreadActions(report, {} as Transaction, [], policy); + const result = getSecondaryTransactionThreadActions(EMPLOYEE_EMAIL, report, {} as Transaction, [], policy); expect(result.includes(CONST.REPORT.SECONDARY_ACTIONS.DELETE)).toBe(true); }); @@ -868,7 +882,7 @@ describe('getSecondaryAction', () => { const policy = {} as unknown as Policy; - const result = getSecondaryReportActions({report, chatReport, reportTransactions: [transaction], violations: {}, policy, reportActions}); + const result = getSecondaryReportActions({currentUserEmail: EMPLOYEE_EMAIL, report, chatReport, reportTransactions: [transaction], violations: {}, policy, reportActions}); expect(result.includes(CONST.REPORT.SECONDARY_ACTIONS.DELETE)).toBe(true); }); @@ -902,7 +916,7 @@ describe('getSecondaryAction', () => { const policy = {} as unknown as Policy; - const result = getSecondaryReportActions({report, chatReport, reportTransactions: [transaction], violations: {}, policy, reportActions}); + const result = getSecondaryReportActions({currentUserEmail: EMPLOYEE_EMAIL, report, chatReport, reportTransactions: [transaction], violations: {}, policy, reportActions}); expect(result.includes(CONST.REPORT.SECONDARY_ACTIONS.DELETE)).toBe(true); }); @@ -951,7 +965,15 @@ describe('getSecondaryAction', () => { const policy = {} as unknown as Policy; - const result = getSecondaryReportActions({report, chatReport, reportTransactions: [transaction1, transaction2], violations: {}, policy, reportActions}); + const result = getSecondaryReportActions({ + currentUserEmail: EMPLOYEE_EMAIL, + report, + chatReport, + reportTransactions: [transaction1, transaction2], + violations: {}, + policy, + reportActions, + }); expect(result.includes(CONST.REPORT.SECONDARY_ACTIONS.DELETE)).toBe(false); }); @@ -974,7 +996,7 @@ describe('getSecondaryAction', () => { const policy = {} as unknown as Policy; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report); - const result = getSecondaryReportActions({report, chatReport, reportTransactions: [transaction], violations: {}, policy}); + const result = getSecondaryReportActions({currentUserEmail: EMPLOYEE_EMAIL, report, chatReport, reportTransactions: [transaction], violations: {}, policy}); expect(result.includes(CONST.REPORT.SECONDARY_ACTIONS.DELETE)).toBe(true); }); @@ -1003,7 +1025,7 @@ describe('getSecondaryAction', () => { const policy = {} as unknown as Policy; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report); - const result = getSecondaryReportActions({report, chatReport, reportTransactions: [transaction1, transaction2], violations: {}, policy}); + const result = getSecondaryReportActions({currentUserEmail: EMPLOYEE_EMAIL, report, chatReport, reportTransactions: [transaction1, transaction2], violations: {}, policy}); expect(result.includes(CONST.REPORT.SECONDARY_ACTIONS.DELETE)).toBe(true); }); @@ -1030,7 +1052,7 @@ describe('getSecondaryAction', () => { const policy = {} as unknown as Policy; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report); - const result = getSecondaryReportActions({report, chatReport, reportTransactions: [transaction], violations: {}, policy}); + const result = getSecondaryReportActions({currentUserEmail: EMPLOYEE_EMAIL, report, chatReport, reportTransactions: [transaction], violations: {}, policy}); expect(result.includes(CONST.REPORT.SECONDARY_ACTIONS.DELETE)).toBe(false); }); @@ -1061,7 +1083,7 @@ describe('getSecondaryAction', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report); await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${POLICY_ID}`, policy); - const result = getSecondaryReportActions({report, chatReport, reportTransactions: [transaction], violations: {}, policy}); + const result = getSecondaryReportActions({currentUserEmail: EMPLOYEE_EMAIL, report, chatReport, reportTransactions: [transaction], violations: {}, policy}); expect(result.includes(CONST.REPORT.SECONDARY_ACTIONS.DELETE)).toBe(false); }); it('include DELETE option for demo transaction', async () => { @@ -1092,7 +1114,7 @@ describe('getSecondaryAction', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report); await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${POLICY_ID}`, policy); - const result = getSecondaryReportActions({report, chatReport, reportTransactions: [transaction], violations: {}, policy}); + const result = getSecondaryReportActions({currentUserEmail: EMPLOYEE_EMAIL, report, chatReport, reportTransactions: [transaction], violations: {}, policy}); expect(result.includes(CONST.REPORT.SECONDARY_ACTIONS.DELETE)).toBe(true); }); }); @@ -1286,7 +1308,7 @@ describe('getSecondaryExportReportActions', () => { jest.spyOn(ReportActionsUtils, 'getOneTransactionThreadReportID').mockReturnValue(originalMessageR14932.IOUTransactionID); jest.spyOn(ReportUtils, 'isHoldCreator').mockReturnValue(false); - const result = getSecondaryReportActions({report, chatReport, reportTransactions, violations: {}, policy}); + const result = getSecondaryReportActions({currentUserEmail: EMPLOYEE_EMAIL, report, chatReport, reportTransactions, violations: {}, policy}); expect(result).toContain(CONST.REPORT.SECONDARY_ACTIONS.REMOVE_HOLD); }); }); @@ -1310,7 +1332,7 @@ describe('getSecondaryTransactionThreadActions', () => { const policy = {} as unknown as Policy; const result = [CONST.REPORT.TRANSACTION_SECONDARY_ACTIONS.VIEW_DETAILS]; - expect(getSecondaryTransactionThreadActions(report, {} as Transaction, [], policy)).toEqual(result); + expect(getSecondaryTransactionThreadActions(EMPLOYEE_EMAIL, report, {} as Transaction, [], policy)).toEqual(result); }); it('includes HOLD option', () => { @@ -1329,7 +1351,7 @@ describe('getSecondaryTransactionThreadActions', () => { const policy = {} as unknown as Policy; jest.spyOn(ReportUtils, 'canHoldUnholdReportAction').mockReturnValueOnce({canHoldRequest: true, canUnholdRequest: true}); - const result = getSecondaryTransactionThreadActions(report, transaction, [actionR14932], policy); + const result = getSecondaryTransactionThreadActions(EMPLOYEE_EMAIL, report, transaction, [actionR14932], policy); expect(result.includes(CONST.REPORT.SECONDARY_ACTIONS.HOLD)).toBe(true); }); @@ -1346,12 +1368,12 @@ describe('getSecondaryTransactionThreadActions', () => { } as unknown as Transaction; jest.spyOn(ReportUtils, 'isHoldCreator').mockReturnValue(false); - const result = getSecondaryTransactionThreadActions(report, transaction, [], policy, transactionThreadReport); + const result = getSecondaryTransactionThreadActions(EMPLOYEE_EMAIL, report, transaction, [], policy, transactionThreadReport); expect(result).toContain(CONST.REPORT.SECONDARY_ACTIONS.REMOVE_HOLD); // Do not show if admin is the holder jest.spyOn(ReportUtils, 'isHoldCreator').mockReturnValue(true); - const result2 = getSecondaryTransactionThreadActions(report, transaction, [], policy, transactionThreadReport); + const result2 = getSecondaryTransactionThreadActions(EMPLOYEE_EMAIL, report, transaction, [], policy, transactionThreadReport); expect(result2).not.toContain(CONST.REPORT.SECONDARY_ACTIONS.REMOVE_HOLD); }); @@ -1368,7 +1390,7 @@ describe('getSecondaryTransactionThreadActions', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report); - const result = getSecondaryTransactionThreadActions(report, {} as Transaction, [], policy); + const result = getSecondaryTransactionThreadActions(EMPLOYEE_EMAIL, report, {} as Transaction, [], policy); expect(result.includes(CONST.REPORT.SECONDARY_ACTIONS.DELETE)).toBe(true); }); @@ -1407,7 +1429,7 @@ describe('getSecondaryTransactionThreadActions', () => { await Onyx.merge(ONYXKEYS.SESSION, {email: EMPLOYEE_EMAIL, accountID: EMPLOYEE_ACCOUNT_ID}); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, personalDetails); - const result = getSecondaryReportActions({report, chatReport, reportTransactions: [], violations: {}, policy, policies, reportActions}); + const result = getSecondaryReportActions({currentUserEmail: EMPLOYEE_EMAIL, report, chatReport, reportTransactions: [], violations: {}, policy, policies, reportActions}); expect(result.includes(CONST.REPORT.SECONDARY_ACTIONS.CHANGE_WORKSPACE)).toBe(false); }); @@ -1444,7 +1466,7 @@ describe('getSecondaryTransactionThreadActions', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${POLICY_ID}`, policy); await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report); - const result = getSecondaryTransactionThreadActions(report, transaction, [actionR14932], policy); + const result = getSecondaryTransactionThreadActions(EMPLOYEE_EMAIL, report, transaction, [actionR14932], policy); expect(result.includes(CONST.REPORT.SECONDARY_ACTIONS.SPLIT)).toBe(true); }); @@ -1480,7 +1502,7 @@ describe('getSecondaryTransactionThreadActions', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${POLICY_ID}`, policy); await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report); - const result = getSecondaryTransactionThreadActions(report, transaction, [actionR14932], policy); + const result = getSecondaryTransactionThreadActions(EMPLOYEE_EMAIL, report, transaction, [actionR14932], policy); expect(result.includes(CONST.REPORT.SECONDARY_ACTIONS.SPLIT)).toBe(false); }); @@ -1517,7 +1539,7 @@ describe('getSecondaryTransactionThreadActions', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${POLICY_ID}`, policy); await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report); - const result = getSecondaryTransactionThreadActions(report, transaction, [actionR14932], policy); + const result = getSecondaryTransactionThreadActions(EMPLOYEE_EMAIL, report, transaction, [actionR14932], policy); expect(result.includes(CONST.REPORT.SECONDARY_ACTIONS.SPLIT)).toBe(false); }); }); From 90ee41d326db2055399c5a999d5fd758eac4c56b Mon Sep 17 00:00:00 2001 From: Shubham Agrawal Date: Thu, 25 Sep 2025 22:07:44 +0530 Subject: [PATCH 2/5] Fixed prettier --- tests/unit/ReportPrimaryActionUtilsTest.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tests/unit/ReportPrimaryActionUtilsTest.ts b/tests/unit/ReportPrimaryActionUtilsTest.ts index 864d68c674ce..165643655ae3 100644 --- a/tests/unit/ReportPrimaryActionUtilsTest.ts +++ b/tests/unit/ReportPrimaryActionUtilsTest.ts @@ -110,6 +110,7 @@ describe('getPrimaryAction', () => { expect( getReportPrimaryAction({ + currentUserEmail: CURRENT_USER_EMAIL, report, chatReport, reportTransactions: [transaction], @@ -829,7 +830,9 @@ 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(CONST.REPORT.TRANSACTION_PRIMARY_ACTIONS.REMOVE_HOLD); + expect(getTransactionThreadPrimaryAction(CURRENT_USER_EMAIL, report, {} as Report, transaction, [], policy as Policy, false)).toBe( + CONST.REPORT.TRANSACTION_PRIMARY_ACTIONS.REMOVE_HOLD, + ); }); it('should return REVIEW DUPLICATES when there are duplicated transactions', async () => { @@ -857,7 +860,9 @@ describe('getTransactionThreadPrimaryAction', () => { } as TransactionViolation, ]); - expect(getTransactionThreadPrimaryAction(CURRENT_USER_EMAIL, {} as Report, report, transaction, [], policy as Policy, false)).toBe(CONST.REPORT.TRANSACTION_PRIMARY_ACTIONS.REVIEW_DUPLICATES); + expect(getTransactionThreadPrimaryAction(CURRENT_USER_EMAIL, {} as Report, report, transaction, [], policy as Policy, false)).toBe( + CONST.REPORT.TRANSACTION_PRIMARY_ACTIONS.REVIEW_DUPLICATES, + ); }); it('should return MARK AS CASH if has all RTER violations', async () => { @@ -884,7 +889,9 @@ describe('getTransactionThreadPrimaryAction', () => { }, } as unknown as TransactionViolation; - expect(getTransactionThreadPrimaryAction(CURRENT_USER_EMAIL, {} as Report, report, transaction, [violation], policy as Policy, false)).toBe(CONST.REPORT.TRANSACTION_PRIMARY_ACTIONS.MARK_AS_CASH); + expect(getTransactionThreadPrimaryAction(CURRENT_USER_EMAIL, {} as Report, report, transaction, [violation], policy as Policy, false)).toBe( + CONST.REPORT.TRANSACTION_PRIMARY_ACTIONS.MARK_AS_CASH, + ); }); it('should return MARK AS CASH for broken connection', async () => { @@ -910,7 +917,9 @@ describe('getTransactionThreadPrimaryAction', () => { }, } as unknown as TransactionViolation; - expect(getTransactionThreadPrimaryAction(CURRENT_USER_EMAIL, {} as Report, report, transaction, [violation], policy as Policy, false)).toBe(CONST.REPORT.TRANSACTION_PRIMARY_ACTIONS.MARK_AS_CASH); + expect(getTransactionThreadPrimaryAction(CURRENT_USER_EMAIL, {} as Report, report, transaction, [violation], policy as Policy, false)).toBe( + CONST.REPORT.TRANSACTION_PRIMARY_ACTIONS.MARK_AS_CASH, + ); }); it('Should return empty string when we are waiting for user to add a bank account', async () => { From 9a24e32e2afe44cac2556b20d2b4b63766227e04 Mon Sep 17 00:00:00 2001 From: Shubham Agrawal Date: Wed, 1 Oct 2025 18:29:59 +0530 Subject: [PATCH 3/5] Fixed lint after merge --- src/libs/ReportPrimaryActionUtils.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libs/ReportPrimaryActionUtils.ts b/src/libs/ReportPrimaryActionUtils.ts index 1c6ca42c4015..1d83840a2afc 100644 --- a/src/libs/ReportPrimaryActionUtils.ts +++ b/src/libs/ReportPrimaryActionUtils.ts @@ -378,8 +378,7 @@ function getReportPrimaryAction(params: GetReportPrimaryActionParams): ValueOf Date: Wed, 1 Oct 2025 18:33:14 +0530 Subject: [PATCH 4/5] Removed unused function --- src/libs/ReportPrimaryActionUtils.ts | 31 ---- tests/unit/ReportPrimaryActionUtilsTest.ts | 205 +-------------------- 2 files changed, 4 insertions(+), 232 deletions(-) diff --git a/src/libs/ReportPrimaryActionUtils.ts b/src/libs/ReportPrimaryActionUtils.ts index 1d83840a2afc..d9ce94303dc3 100644 --- a/src/libs/ReportPrimaryActionUtils.ts +++ b/src/libs/ReportPrimaryActionUtils.ts @@ -41,7 +41,6 @@ import { import {getSession} from './SessionUtils'; import { allHavePendingRTERViolation, - getTransactionViolations, hasPendingRTERViolation as hasPendingRTERViolationTransactionUtils, isDuplicate, isOnHold as isOnHoldTransactionUtils, @@ -299,35 +298,6 @@ function isMarkAsCashAction(currentUserEmail: string, report: Report, reportTran return userControlsReport && shouldShowBrokenConnectionViolation; } -function isMarkAsResolvedReportAction( - report: Report, - chatReport: OnyxEntry, - reportTransactions?: Transaction[], - violations?: OnyxCollection, - policy?: Policy, - reportActions?: ReportAction[], -) { - if (!report || !reportTransactions || !violations) { - return false; - } - - const transactionThreadReportID = getOneTransactionThreadReportID(report, chatReport, reportActions); - const isOneExpenseReport = reportTransactions.length === 1; - const transaction = reportTransactions.at(0); - - if ((!!reportActions && !transactionThreadReportID) || !isOneExpenseReport || !transaction) { - return false; - } - - const isReportSubmitter = isCurrentUserSubmitter(report); - const isAdmin = isPolicyAdminPolicyUtils(policy); - if (!isReportSubmitter && !isAdmin) { - return false; - } - - return getTransactionViolations(transaction, violations)?.some((violation) => violation.name === CONST.VIOLATIONS.AUTO_REPORTED_REJECTED_EXPENSE); -} - function isMarkAsResolvedAction(report?: Report, violations?: TransactionViolation[], policy?: Policy) { if (!report || !violations) { return false; @@ -468,7 +438,6 @@ export { isPrimaryPayAction, isExportAction, isMarkAsResolvedAction, - isMarkAsResolvedReportAction, getAllExpensesToHoldIfApplicable, isReviewDuplicatesAction, }; diff --git a/tests/unit/ReportPrimaryActionUtilsTest.ts b/tests/unit/ReportPrimaryActionUtilsTest.ts index 812598a12fcc..1a97f5d785ce 100644 --- a/tests/unit/ReportPrimaryActionUtilsTest.ts +++ b/tests/unit/ReportPrimaryActionUtilsTest.ts @@ -1,7 +1,7 @@ import {renderHook} from '@testing-library/react-native'; import Onyx from 'react-native-onyx'; import useReportIsArchived from '@hooks/useReportIsArchived'; -import {getReportPrimaryAction, getTransactionThreadPrimaryAction, isMarkAsResolvedAction, isMarkAsResolvedReportAction, isReviewDuplicatesAction} from '@libs/ReportPrimaryActionUtils'; +import {getReportPrimaryAction, getTransactionThreadPrimaryAction, isMarkAsResolvedAction, isReviewDuplicatesAction} from '@libs/ReportPrimaryActionUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {Policy, Report, ReportAction, Transaction, TransactionViolation} from '@src/types/onyx'; @@ -53,7 +53,9 @@ describe('getPrimaryAction', () => { statusNum: CONST.REPORT.STATUS_NUM.OPEN, } 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})).toBe(''); + expect( + getReportPrimaryAction({currentUserEmail: CURRENT_USER_EMAIL, report, chatReport, reportTransactions: [], violations: {}, policy: {} as Policy, isChatReportArchived: false}), + ).toBe(''); }); it('should return SUBMIT for expense report with manual submit', async () => { @@ -1140,203 +1142,4 @@ describe('getTransactionThreadPrimaryAction', () => { expect(result2).toBe(false); }); }); - - describe('isMarkAsResolvedReportAction', () => { - const submitterAccountID = 1; - const otherUserAccountID = 3; - - beforeEach(async () => { - jest.clearAllMocks(); - Onyx.clear(); - await Onyx.merge(ONYXKEYS.SESSION, {accountID: submitterAccountID}); - }); - - it('should return true for submitter with pending auto rejected expense violation in transactions', () => { - const report = { - reportID: REPORT_ID, - ownerAccountID: submitterAccountID, - type: CONST.REPORT.TYPE.EXPENSE, - } as unknown as Report; - - const transactions = [ - { - transactionID: '1', - reportID: REPORT_ID.toString(), - amount: 1000, - created: '2023-01-01', - currency: 'USD', - merchant: 'Test Merchant', - } as Transaction, - ]; - - const violations = { - [`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}1`]: [ - { - name: CONST.VIOLATIONS.AUTO_REPORTED_REJECTED_EXPENSE, - type: CONST.VIOLATION_TYPES.WARNING, - }, - ], - }; - - const reportActions = [ - { - reportActionID: '1', - actionName: CONST.REPORT.ACTIONS.TYPE.IOU, - actorAccountID: CURRENT_USER_ACCOUNT_ID, - created: '2023-01-01', - message: [{type: 'COMMENT', text: 'Test message'}], - originalMessage: { - type: CONST.IOU.REPORT_ACTION_TYPE.CREATE, - IOUTransactionID: '1', - }, - childReportID: '1', - } as ReportAction, - ]; - - const result = isMarkAsResolvedReportAction(report, chatReport, transactions, violations, undefined, reportActions); - expect(result).toBe(true); - }); - - it('should return true for admin with pending auto rejected expense violation', () => { - const policy = { - role: CONST.POLICY.ROLE.ADMIN, - } as Policy; - - const report = { - reportID: REPORT_ID, - ownerAccountID: otherUserAccountID, // Different from current user - type: CONST.REPORT.TYPE.EXPENSE, - } as unknown as Report; - - const transactions = [ - { - transactionID: '1', - reportID: REPORT_ID.toString(), - amount: 1000, - created: '2023-01-01', - currency: 'USD', - merchant: 'Test Merchant', - } as Transaction, - ]; - - const violations = { - [`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}1`]: [ - { - name: CONST.VIOLATIONS.AUTO_REPORTED_REJECTED_EXPENSE, - type: CONST.VIOLATION_TYPES.WARNING, - }, - ], - }; - - const reportActions = [ - { - reportActionID: '1', - actionName: CONST.REPORT.ACTIONS.TYPE.IOU, - actorAccountID: CURRENT_USER_ACCOUNT_ID, - created: '2023-01-01', - message: [{type: 'COMMENT', text: 'Test message'}], - originalMessage: { - type: CONST.IOU.REPORT_ACTION_TYPE.CREATE, - IOUTransactionID: '1', - }, - childReportID: '1', - } as ReportAction, - ]; - - const result = isMarkAsResolvedReportAction(report, chatReport, transactions, violations, policy, reportActions); - expect(result).toBe(true); - }); - - it('should return false for non-submitter non-admin user', () => { - const policy = { - role: CONST.POLICY.ROLE.USER, - } as Policy; - - const report = { - reportID: REPORT_ID, - ownerAccountID: otherUserAccountID, // Different from current user - } as unknown as Report; - - const transactions = [ - { - transactionID: '1', - reportID: REPORT_ID.toString(), - amount: 1000, - created: '2023-01-01', - currency: 'USD', - merchant: 'Test Merchant', - } as Transaction, - ]; - - const violations = { - [`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}1`]: [ - { - name: CONST.VIOLATIONS.AUTO_REPORTED_REJECTED_EXPENSE, - type: CONST.VIOLATION_TYPES.WARNING, - }, - ], - }; - - const reportActions = [ - { - reportActionID: '1', - actionName: CONST.REPORT.ACTIONS.TYPE.IOU, - actorAccountID: CURRENT_USER_ACCOUNT_ID, - created: '2023-01-01', - message: [{type: 'COMMENT', text: 'Test message'}], - originalMessage: { - type: CONST.IOU.REPORT_ACTION_TYPE.CREATE, - IOUTransactionID: '1', - }, - } as ReportAction, - ]; - - const result = isMarkAsResolvedReportAction(report, chatReport, transactions, violations, policy, reportActions); - expect(result).toBe(false); - }); - - it('should return false when no auto rejected expense violations are present', () => { - const report = { - reportID: REPORT_ID, - ownerAccountID: submitterAccountID, - } as unknown as Report; - - const transactions = [ - { - transactionID: '1', - reportID: REPORT_ID.toString(), - amount: 1000, - created: '2023-01-01', - currency: 'USD', - merchant: 'Test Merchant', - } as Transaction, - ]; - - const violations = { - transactionViolation1: [ - { - name: CONST.VIOLATIONS.MISSING_CATEGORY, - type: CONST.VIOLATION_TYPES.VIOLATION, - }, - ], - }; - - const reportActions = [ - { - reportActionID: '1', - actionName: CONST.REPORT.ACTIONS.TYPE.IOU, - actorAccountID: CURRENT_USER_ACCOUNT_ID, - created: '2023-01-01', - message: [{type: 'COMMENT', text: 'Test message'}], - originalMessage: { - type: CONST.IOU.REPORT_ACTION_TYPE.CREATE, - IOUTransactionID: '1', - }, - } as ReportAction, - ]; - - const result = isMarkAsResolvedReportAction(report, chatReport, transactions, violations, undefined, reportActions); - expect(result).toBe(false); - }); - }); }); From 192fcd41e825800eceb86f3333843bd22d25fd1c Mon Sep 17 00:00:00 2001 From: Shubham Agrawal Date: Mon, 6 Oct 2025 16:59:25 +0530 Subject: [PATCH 5/5] Rename variables --- src/components/MoneyReportHeader.tsx | 10 +++++----- src/components/MoneyRequestHeader.tsx | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/components/MoneyReportHeader.tsx b/src/components/MoneyReportHeader.tsx index e464e67a7929..39c30326938f 100644 --- a/src/components/MoneyReportHeader.tsx +++ b/src/components/MoneyReportHeader.tsx @@ -182,7 +182,7 @@ function MoneyReportHeader({ | PlatformStackRouteProp | PlatformStackRouteProp >(); - const {login} = useCurrentUserPersonalDetails(); + const {login: currentUserLogin} = useCurrentUserPersonalDetails(); const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${moneyRequestReport?.chatReportID}`, {canBeMissing: true}); const [nextStep] = useOnyx(`${ONYXKEYS.COLLECTION.NEXT_STEP}${moneyRequestReport?.reportID}`, {canBeMissing: true}); const [isUserValidated] = useOnyx(ONYXKEYS.ACCOUNT, {selector: isUserValidatedSelector, canBeMissing: true}); @@ -537,7 +537,7 @@ function MoneyReportHeader({ const primaryAction = useMemo(() => { return getReportPrimaryAction({ - currentUserEmail: login ?? '', + currentUserEmail: currentUserLogin ?? '', report: moneyRequestReport, chatReport, reportTransactions: transactions, @@ -562,7 +562,7 @@ function MoneyReportHeader({ reportActions, isChatReportArchived, invoiceReceiverPolicy, - login, + currentUserLogin, ]); const confirmExport = useCallback(() => { @@ -835,7 +835,7 @@ function MoneyReportHeader({ return []; } return getSecondaryReportActions({ - currentUserEmail: login ?? '', + currentUserEmail: currentUserLogin ?? '', report: moneyRequestReport, chatReport, reportTransactions: transactions, @@ -846,7 +846,7 @@ function MoneyReportHeader({ policies, isChatReportArchived, }); - }, [moneyRequestReport, transactions, violations, policy, reportNameValuePairs, reportActions, policies, chatReport, isChatReportArchived, login]); + }, [moneyRequestReport, transactions, violations, policy, reportNameValuePairs, reportActions, policies, chatReport, isChatReportArchived, currentUserLogin]); const secondaryExportActions = useMemo(() => { if (!moneyRequestReport) { diff --git a/src/components/MoneyRequestHeader.tsx b/src/components/MoneyRequestHeader.tsx index 0115ac5661ab..edb397e99d36 100644 --- a/src/components/MoneyRequestHeader.tsx +++ b/src/components/MoneyRequestHeader.tsx @@ -101,7 +101,7 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre const styles = useThemeStyles(); const theme = useTheme(); const {translate} = useLocalize(); - const {login} = useCurrentUserPersonalDetails(); + const {login: currentUserLogin} = useCurrentUserPersonalDetails(); const isOnHold = isOnHoldTransactionUtils(transaction); const isDuplicate = isDuplicateTransactionUtils(transaction); const reportID = report?.reportID; @@ -182,8 +182,8 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre if (!report || !parentReport || !transaction) { return ''; } - return getTransactionThreadPrimaryAction(login ?? '', report, parentReport, transaction, transactionViolations, policy, isFromReviewDuplicates); - }, [parentReport, policy, report, transaction, transactionViolations, isFromReviewDuplicates, login]); + return getTransactionThreadPrimaryAction(currentUserLogin ?? '', report, parentReport, transaction, transactionViolations, policy, isFromReviewDuplicates); + }, [parentReport, policy, report, transaction, transactionViolations, isFromReviewDuplicates, currentUserLogin]); const primaryActionImplementation = { [CONST.REPORT.TRANSACTION_PRIMARY_ACTIONS.REMOVE_HOLD]: ( @@ -252,8 +252,8 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre if (!transaction || !reportActions) { return []; } - return getSecondaryTransactionThreadActions(login ?? '', parentReport, transaction, Object.values(reportActions), policy, report); - }, [report, parentReport, policy, transaction, login]); + return getSecondaryTransactionThreadActions(currentUserLogin ?? '', parentReport, transaction, Object.values(reportActions), policy, report); + }, [report, parentReport, policy, transaction, currentUserLogin]); const dismissModalAndUpdateUseReject = () => { setIsRejectEducationalModalVisible(false);