diff --git a/src/components/MoneyReportHeader.tsx b/src/components/MoneyReportHeader.tsx index 282aa5c2c369..39c30326938f 100644 --- a/src/components/MoneyReportHeader.tsx +++ b/src/components/MoneyReportHeader.tsx @@ -5,6 +5,7 @@ import React, {useCallback, useContext, useEffect, useMemo, useState} from 'reac import {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'; @@ -181,9 +182,8 @@ function MoneyReportHeader({ | PlatformStackRouteProp | PlatformStackRouteProp >(); - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + const {login: currentUserLogin} = 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: isUserValidatedSelector, canBeMissing: true}); const [transactionThreadReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`, {canBeMissing: true}); @@ -537,6 +537,7 @@ function MoneyReportHeader({ const primaryAction = useMemo(() => { return getReportPrimaryAction({ + currentUserEmail: currentUserLogin ?? '', report: moneyRequestReport, chatReport, reportTransactions: transactions, @@ -561,6 +562,7 @@ function MoneyReportHeader({ reportActions, isChatReportArchived, invoiceReceiverPolicy, + currentUserLogin, ]); const confirmExport = useCallback(() => { @@ -833,6 +835,7 @@ function MoneyReportHeader({ return []; } return getSecondaryReportActions({ + currentUserEmail: currentUserLogin ?? '', report: moneyRequestReport, chatReport, reportTransactions: transactions, @@ -843,7 +846,7 @@ function MoneyReportHeader({ policies, isChatReportArchived, }); - }, [moneyRequestReport, transactions, violations, policy, reportNameValuePairs, reportActions, policies, chatReport, isChatReportArchived]); + }, [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 247d10dc413b..edb397e99d36 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'; @@ -100,6 +101,7 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre const styles = useThemeStyles(); const theme = useTheme(); const {translate} = useLocalize(); + const {login: currentUserLogin} = useCurrentUserPersonalDetails(); const isOnHold = isOnHoldTransactionUtils(transaction); const isDuplicate = isDuplicateTransactionUtils(transaction); const reportID = report?.reportID; @@ -180,8 +182,8 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre if (!report || !parentReport || !transaction) { return ''; } - return getTransactionThreadPrimaryAction(report, parentReport, transaction, transactionViolations, policy, isFromReviewDuplicates); - }, [parentReport, policy, report, transaction, transactionViolations, isFromReviewDuplicates]); + 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]: ( @@ -250,8 +252,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(currentUserLogin ?? '', parentReport, transaction, Object.values(reportActions), policy, report); + }, [report, parentReport, policy, transaction, currentUserLogin]); const dismissModalAndUpdateUseReject = () => { setIsRejectEducationalModalVisible(false); diff --git a/src/libs/ReportPrimaryActionUtils.ts b/src/libs/ReportPrimaryActionUtils.ts index b59c38143476..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, @@ -52,6 +51,7 @@ import { } from './TransactionUtils'; type GetReportPrimaryActionParams = { + currentUserEmail: string; report: Report | undefined; chatReport: OnyxEntry; reportTransactions: Transaction[]; @@ -275,7 +275,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) { @@ -290,7 +290,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); @@ -298,35 +298,6 @@ function isMarkAsCashAction(report: Report, reportTransactions: Transaction[], v 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; @@ -351,6 +322,7 @@ function getAllExpensesToHoldIfApplicable(report?: Report, reportActions?: Repor function getReportPrimaryAction(params: GetReportPrimaryActionParams): ValueOf | '' { const { + currentUserEmail, report, reportTransactions, violations, @@ -376,7 +348,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) { @@ -236,14 +236,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; @@ -558,6 +558,7 @@ function isRemoveHoldActionForTransaction(report: Report, reportTransaction: Tra } function getSecondaryReportActions({ + currentUserEmail, report, chatReport, reportTransactions, @@ -568,6 +569,7 @@ function getSecondaryReportActions({ policies, isChatReportArchived = false, }: { + currentUserEmail: string; report: Report; chatReport: OnyxEntry; reportTransactions: Transaction[]; @@ -590,6 +592,7 @@ function getSecondaryReportActions({ } const primaryAction = getReportPrimaryAction({ + currentUserEmail, report, chatReport, reportTransactions, @@ -604,11 +607,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); } @@ -632,7 +635,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); } @@ -686,6 +689,7 @@ function getSecondaryExportReportActions(report: Report, policy?: Policy, export } function getSecondaryTransactionThreadActions( + currentUserEmail: string, parentReport: Report, reportTransaction: Transaction, reportActions: ReportAction[], @@ -702,7 +706,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 01da59b65608..9d1ee882ae7b 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -11563,12 +11563,12 @@ function getReportPersonalDetailsParticipants(report: Report, personalDetailsPar }; } -function canRejectReportAction(report: Report, policy?: Policy): boolean { +function canRejectReportAction(currentUserLogin: string, report: Report, policy?: Policy): boolean { if (!Permissions.isBetaEnabled(CONST.BETAS.NEWDOT_REJECT, allBetas)) { return false; } - const isReportApprover = isApproverUtils(policy, currentUserAccountID ?? CONST.DEFAULT_NUMBER_ID); + const isReportApprover = isApproverUtils(policy, currentUserLogin); const isReportBeingProcessed = isProcessingReport(report); const isReportPayer = isPayer(getSession(), report, false, policy); const isIOU = isIOUReport(report); 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 c38177b981c0..17838d3620c6 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 e73dcb25aceb..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({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 () => { @@ -72,9 +74,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 return SUBMIT for open report in instant submit policy with no approvers', async () => { @@ -99,6 +109,7 @@ describe('getPrimaryAction', () => { expect( getReportPrimaryAction({ + currentUserEmail: CURRENT_USER_EMAIL, report, chatReport, reportTransactions: [transaction], @@ -129,7 +140,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 () => { @@ -153,9 +174,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 () => { @@ -182,7 +211,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 () => { @@ -207,7 +246,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 () => { @@ -237,9 +286,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 () => { @@ -269,7 +327,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 () => { @@ -288,9 +357,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 () => { @@ -316,9 +393,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 () => { @@ -344,9 +429,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 () => { @@ -374,6 +467,7 @@ describe('getPrimaryAction', () => { expect( getReportPrimaryAction({ + currentUserEmail: CURRENT_USER_EMAIL, report, chatReport, reportTransactions: [], @@ -435,9 +529,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 () => { @@ -484,9 +578,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 () => { @@ -517,6 +619,7 @@ describe('getPrimaryAction', () => { expect( getReportPrimaryAction({ + currentUserEmail: CURRENT_USER_EMAIL, report, chatReport, reportTransactions: [transaction], @@ -552,6 +655,7 @@ describe('getPrimaryAction', () => { expect( getReportPrimaryAction({ + currentUserEmail: CURRENT_USER_EMAIL, report, chatReport, reportTransactions: [transaction], @@ -588,6 +692,7 @@ describe('getPrimaryAction', () => { // Then the getReportPrimaryAction should return the empty string expect( getReportPrimaryAction({ + currentUserEmail: CURRENT_USER_EMAIL, report, chatReport: invoiceChatReport, reportTransactions: [transaction], @@ -724,7 +829,9 @@ 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, 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 () => { @@ -752,7 +859,9 @@ describe('getTransactionThreadPrimaryAction', () => { } as TransactionViolation, ]); - expect(getTransactionThreadPrimaryAction({} 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 () => { @@ -779,7 +888,9 @@ describe('getTransactionThreadPrimaryAction', () => { }, } as unknown as TransactionViolation; - expect(getTransactionThreadPrimaryAction({} 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 () => { @@ -805,7 +916,9 @@ describe('getTransactionThreadPrimaryAction', () => { }, } as unknown as TransactionViolation; - expect(getTransactionThreadPrimaryAction({} 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 () => { @@ -834,6 +947,7 @@ describe('getTransactionThreadPrimaryAction', () => { expect( getReportPrimaryAction({ + currentUserEmail: CURRENT_USER_EMAIL, report, chatReport, reportTransactions: [transaction], @@ -871,6 +985,7 @@ describe('getTransactionThreadPrimaryAction', () => { } as unknown as Transaction; expect( getReportPrimaryAction({ + currentUserEmail: CURRENT_USER_EMAIL, report, chatReport, reportTransactions: [transaction], @@ -909,6 +1024,7 @@ describe('getTransactionThreadPrimaryAction', () => { } as unknown as Transaction; expect( getReportPrimaryAction({ + currentUserEmail: CURRENT_USER_EMAIL, report, chatReport, reportTransactions: [transaction], @@ -1026,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); - }); - }); }); diff --git a/tests/unit/ReportSecondaryActionUtilsTest.ts b/tests/unit/ReportSecondaryActionUtilsTest.ts index b4ddf5714abf..4387e10439e8 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(false); }); @@ -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); }); @@ -700,6 +713,7 @@ describe('getSecondaryAction', () => { await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, personalDetails); const result = getSecondaryReportActions({ + currentUserEmail: EMPLOYEE_EMAIL, report, chatReport, reportTransactions: [], @@ -755,7 +769,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); }); @@ -804,7 +818,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); }); @@ -819,7 +833,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); }); @@ -839,7 +853,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); }); @@ -872,7 +886,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); }); @@ -906,7 +920,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); }); @@ -955,7 +969,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); }); @@ -978,7 +1000,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); }); @@ -1007,7 +1029,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); }); @@ -1034,7 +1056,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); }); @@ -1065,7 +1087,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 () => { @@ -1096,7 +1118,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); }); }); @@ -1350,7 +1372,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); }); }); @@ -1374,7 +1396,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', () => { @@ -1393,7 +1415,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); }); @@ -1410,12 +1432,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); }); @@ -1432,7 +1454,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); }); @@ -1471,7 +1493,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); }); @@ -1508,7 +1530,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); }); @@ -1544,7 +1566,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); }); @@ -1581,7 +1603,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); }); });