diff --git a/src/components/AddExistingExpenseFooter.tsx b/src/components/AddExistingExpenseFooter.tsx index e2c700109d02..99792f5ea29e 100644 --- a/src/components/AddExistingExpenseFooter.tsx +++ b/src/components/AddExistingExpenseFooter.tsx @@ -1,3 +1,4 @@ +import useDelegateAccountID from '@hooks/useDelegateAccountID'; import useLocalize from '@hooks/useLocalize'; import useOnyx from '@hooks/useOnyx'; import usePermissions from '@hooks/usePermissions'; @@ -50,6 +51,7 @@ function AddExistingExpenseFooter({selectedIds, report, reportToConfirm, reportN const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT); const session = useSession(); const personalDetails = usePersonalDetails(); + const delegateAccountID = useDelegateAccountID(); const personalPolicy = usePersonalPolicy(); const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS); const [allReports] = useOnyx(ONYXKEYS.COLLECTION.REPORT); @@ -84,6 +86,7 @@ function AddExistingExpenseFooter({selectedIds, report, reportToConfirm, reportN personalDetails, betas, policyTagList: report?.policyID ? policyTagList : chatReportPolicyTagList, + delegateAccountID, }); } else { changeTransactionsReport({ diff --git a/src/components/MoneyRequestHeaderSecondaryActions.tsx b/src/components/MoneyRequestHeaderSecondaryActions.tsx index 6ecb5b56afd0..8df5746e8b6d 100644 --- a/src/components/MoneyRequestHeaderSecondaryActions.tsx +++ b/src/components/MoneyRequestHeaderSecondaryActions.tsx @@ -2,6 +2,7 @@ import useConfirmModal from '@hooks/useConfirmModal'; import {useCurrencyListActions} from '@hooks/useCurrencyList'; import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; import useDefaultExpensePolicy from '@hooks/useDefaultExpensePolicy'; +import useDelegateAccountID from '@hooks/useDelegateAccountID'; import useDeleteTransactions from '@hooks/useDeleteTransactions'; import useDuplicateTransactionsAndViolations from '@hooks/useDuplicateTransactionsAndViolations'; import useEnvironment from '@hooks/useEnvironment'; @@ -110,6 +111,7 @@ function MoneyRequestHeaderSecondaryActions({reportID, onBackButtonPress}: Money const theme = useTheme(); const {translate, localeCompare} = useLocalize(); const {login: currentUserLogin, accountID, localCurrencyCode} = useCurrentUserPersonalDetails(); + const delegateAccountID = useDelegateAccountID(); const personalDetails = usePersonalDetails(); const expensifyIcons = useMemoizedLazyExpensifyIcons([ @@ -261,6 +263,7 @@ function MoneyRequestHeaderSecondaryActions({reportID, onBackButtonPress}: Money targetPolicyTags, currentUser: {accountID, email: currentUserLogin ?? ''}, currentUserLocalCurrency: localCurrencyCode ?? CONST.CURRENCY.USD, + delegateAccountID, policyTagList, }); } diff --git a/src/hooks/useBulkDuplicateAction.ts b/src/hooks/useBulkDuplicateAction.ts index f22d84de6a2b..bb8ead6f082c 100644 --- a/src/hooks/useBulkDuplicateAction.ts +++ b/src/hooks/useBulkDuplicateAction.ts @@ -14,6 +14,7 @@ import {validTransactionDraftsSelector} from '@selectors/TransactionDraft'; import useCurrentUserPersonalDetails from './useCurrentUserPersonalDetails'; import useDefaultExpensePolicy from './useDefaultExpensePolicy'; +import useDelegateAccountID from './useDelegateAccountID'; import useMoneyRequestPolicyTagsForReport from './useMoneyRequestPolicyTagsForReport'; import useOnyx from './useOnyx'; import usePermissions from './usePermissions'; @@ -33,6 +34,7 @@ type UseBulkDuplicateActionParams = { */ function useBulkDuplicateAction({selectedTransactionsKeys, allTransactions, allReports, searchData, onAfterDuplicate}: UseBulkDuplicateActionParams) { const {accountID, login: currentUserLogin, localCurrencyCode} = useCurrentUserPersonalDetails(); + const delegateAccountID = useDelegateAccountID(); const {clearSelectedTransactions} = useSearchSelectionActions(); const defaultExpensePolicy = useDefaultExpensePolicy(); const {isBetaEnabled} = usePermissions(); @@ -83,6 +85,7 @@ function useBulkDuplicateAction({selectedTransactionsKeys, allTransactions, allR recentWaypoints, currentUser: {accountID, email: currentUserLogin ?? ''}, currentUserLocalCurrency: localCurrencyCode ?? CONST.CURRENCY.USD, + delegateAccountID, policyTagList, }); diff --git a/src/hooks/useBulkDuplicateReportAction.ts b/src/hooks/useBulkDuplicateReportAction.ts index a401388727e2..5d5e5a6fc4e9 100644 --- a/src/hooks/useBulkDuplicateReportAction.ts +++ b/src/hooks/useBulkDuplicateReportAction.ts @@ -14,6 +14,7 @@ import {hasSeenTourSelector} from '@selectors/Onboarding'; import useCurrentUserPersonalDetails from './useCurrentUserPersonalDetails'; import useDefaultExpensePolicy from './useDefaultExpensePolicy'; +import useDelegateAccountID from './useDelegateAccountID'; import useLocalize from './useLocalize'; import useOnyx from './useOnyx'; import usePermissions from './usePermissions'; @@ -26,6 +27,7 @@ type UseBulkDuplicateReportActionParams = { function useBulkDuplicateReportAction({selectedReports, allReports, searchData}: UseBulkDuplicateReportActionParams) { const currentUserPersonalDetails = useCurrentUserPersonalDetails(); + const delegateAccountID = useDelegateAccountID(); const {clearSelectedTransactions} = useSearchSelectionActions(); const defaultExpensePolicy = useDefaultExpensePolicy(); const {isBetaEnabled} = usePermissions(); @@ -67,6 +69,7 @@ function useBulkDuplicateReportAction({selectedReports, allReports, searchData}: recentWaypoints, currentUserLogin: currentUserPersonalDetails.login ?? '', currentUserAccountID: currentUserPersonalDetails?.accountID, + delegateAccountID, }); clearSelectedTransactions(undefined, true); diff --git a/src/hooks/useExpenseActions.ts b/src/hooks/useExpenseActions.ts index 9939732a6d8c..42633ad3782e 100644 --- a/src/hooks/useExpenseActions.ts +++ b/src/hooks/useExpenseActions.ts @@ -60,6 +60,7 @@ import useConfirmModal from './useConfirmModal'; import {useCurrencyListActions} from './useCurrencyList'; import useCurrentUserPersonalDetails from './useCurrentUserPersonalDetails'; import useDefaultExpensePolicy from './useDefaultExpensePolicy'; +import useDelegateAccountID from './useDelegateAccountID'; import useDeleteTransactions from './useDeleteTransactions'; import useDuplicateTransactionsAndViolations from './useDuplicateTransactionsAndViolations'; import useEnvironment from './useEnvironment'; @@ -102,6 +103,7 @@ function useExpenseActions({reportID, isReportInSearch = false, backTo, onDuplic const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT); const {getCurrencyDecimals} = useCurrencyListActions(); const currentUserPersonalDetails = useCurrentUserPersonalDetails(); + const delegateAccountID = useDelegateAccountID(); const {login: currentUserLogin, accountID, email} = currentUserPersonalDetails; const {currentSearchHash} = useSearchQueryContext(); const {removeTransaction} = useSearchSelectionActions(); @@ -270,6 +272,7 @@ function useExpenseActions({reportID, isReportInSearch = false, backTo, onDuplic targetPolicyTags, currentUser: {accountID: currentUserPersonalDetails?.accountID, email: currentUserPersonalDetails?.email ?? ''}, currentUserLocalCurrency: currentUserPersonalDetails?.localCurrencyCode ?? CONST.CURRENCY.USD, + delegateAccountID, policyTagList, }); } @@ -429,6 +432,7 @@ function useExpenseActions({reportID, isReportInSearch = false, backTo, onDuplic recentWaypoints: recentWaypoints ?? [], currentUserAccountID: currentUserPersonalDetails?.accountID, currentUserLogin: currentUserPersonalDetails?.email ?? '', + delegateAccountID, }); }, }, diff --git a/src/libs/IOUAmountSubmission.ts b/src/libs/IOUAmountSubmission.ts index 740f0d997c19..2b65b90a4815 100644 --- a/src/libs/IOUAmountSubmission.ts +++ b/src/libs/IOUAmountSubmission.ts @@ -336,6 +336,7 @@ function submitAmount({ isSelfTourViewed, optimisticChatReportID, optimisticTransactionID, + delegateAccountID, reportActionsList: undefined, }); } else { @@ -372,6 +373,7 @@ function submitAmount({ personalDetails: allPersonalDetails, optimisticChatReportID, optimisticTransactionID, + delegateAccountID, }); } cleanupAfterSkipConfirmSubmit(overrides.shouldHandleNavigation, { diff --git a/src/libs/actions/IOU/Duplicate.ts b/src/libs/actions/IOU/Duplicate.ts index e879e2d453ac..571463cac952 100644 --- a/src/libs/actions/IOU/Duplicate.ts +++ b/src/libs/actions/IOU/Duplicate.ts @@ -752,6 +752,7 @@ type DuplicateExpenseTransactionParams = { optimisticReportPreviewActionID?: string; currentUser: CurrentUser; currentUserLocalCurrency: string | undefined; + delegateAccountID: number | undefined; policyTagList: OnyxTypes.PolicyTagLists; }; @@ -779,6 +780,7 @@ function duplicateExpenseTransaction({ optimisticReportPreviewActionID: externalReportPreviewActionID, currentUser, currentUserLocalCurrency, + delegateAccountID, policyTagList, }: DuplicateExpenseTransactionParams) { if (!transaction) { @@ -827,6 +829,7 @@ function duplicateExpenseTransaction({ betas, personalDetails, shouldDeferAutoSubmit, + delegateAccountID, }; // If no workspace is provided the expense should be unreported @@ -866,6 +869,7 @@ function duplicateExpenseTransaction({ betas, isSelfTourViewed, currentUserLocalCurrency, + delegateAccountID, reportActionsList: undefined, }; return trackExpense(trackExpenseParams); @@ -914,6 +918,7 @@ type DuplicateReportParams = { currentUserLogin: string; currentUserAccountID: number; shouldPlaySound?: boolean; + delegateAccountID: number | undefined; }; function duplicateReport({ @@ -937,6 +942,7 @@ function duplicateReport({ currentUserAccountID, currentUserLogin, shouldPlaySound = true, + delegateAccountID, }: DuplicateReportParams) { if (!targetPolicy || !parentChatReport) { return; @@ -1027,6 +1033,7 @@ function duplicateReport({ betas, personalDetails, shouldDeferAutoSubmit: !isLastExpense, + delegateAccountID, }; const isMoneyRequestReport = isMoneyRequestReportReportUtils(params.report); @@ -1085,6 +1092,7 @@ type BulkDuplicateExpensesParams = { recentWaypoints: OnyxEntry; currentUser: CurrentUser; currentUserLocalCurrency: string | undefined; + delegateAccountID: number | undefined; policyTagList: OnyxTypes.PolicyTagLists; }; @@ -1107,6 +1115,7 @@ function bulkDuplicateExpenses({ recentWaypoints, currentUser, currentUserLocalCurrency, + delegateAccountID, policyTagList, }: BulkDuplicateExpensesParams) { const transactionsToDuplicate = transactionIDs.map((id) => allTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${id}`]).filter((t): t is OnyxTypes.Transaction => !!t); @@ -1203,6 +1212,7 @@ function bulkDuplicateExpenses({ optimisticReportPreviewActionID: currentReportPreviewActionID, currentUser, currentUserLocalCurrency, + delegateAccountID, policyTagList, }); @@ -1239,6 +1249,7 @@ type BulkDuplicateReportsParams = { recentWaypoints: OnyxEntry; currentUserLogin: string; currentUserAccountID: number; + delegateAccountID: number | undefined; }; function bulkDuplicateReports({ @@ -1262,6 +1273,7 @@ function bulkDuplicateReports({ recentWaypoints, currentUserLogin, currentUserAccountID, + delegateAccountID, }: BulkDuplicateReportsParams) { const allTransactionsMap = getAllTransactions(); const transactionsByReportID = new Map(); @@ -1336,6 +1348,7 @@ function bulkDuplicateReports({ shouldPlaySound: false, currentUserAccountID, currentUserLogin, + delegateAccountID, }); } diff --git a/src/libs/actions/IOU/MoneyRequest.ts b/src/libs/actions/IOU/MoneyRequest.ts index 71e93f0f2ab5..57ea73495150 100644 --- a/src/libs/actions/IOU/MoneyRequest.ts +++ b/src/libs/actions/IOU/MoneyRequest.ts @@ -95,6 +95,7 @@ type CreateTransactionParams = { optimisticTransactionIDs: string[]; optimisticChatReportID: string | undefined; currentUserLocalCurrency: string | undefined; + delegateAccountID: number | undefined; }; function createTransaction({ @@ -123,6 +124,7 @@ function createTransaction({ optimisticTransactionIDs, optimisticChatReportID, currentUserLocalCurrency, + delegateAccountID, }: CreateTransactionParams) { const draftTransactionIDs = Object.keys(allTransactionDrafts ?? {}); const isMoneyRequestReport = isMoneyRequestReportReportUtils(report); @@ -182,6 +184,7 @@ function createTransaction({ optimisticChatReportID, optimisticTransactionID, currentUserLocalCurrency, + delegateAccountID, reportActionsList: undefined, }); } else { @@ -225,6 +228,7 @@ function createTransaction({ personalDetails, optimisticChatReportID, optimisticTransactionID, + delegateAccountID, }); } } diff --git a/src/libs/actions/IOU/MoneyRequestBuilder.ts b/src/libs/actions/IOU/MoneyRequestBuilder.ts index ffe1aa61a683..2cd5a8b197d2 100644 --- a/src/libs/actions/IOU/MoneyRequestBuilder.ts +++ b/src/libs/actions/IOU/MoneyRequestBuilder.ts @@ -186,8 +186,7 @@ type RequestMoneyInformation = { betas: OnyxEntry; personalDetails: OnyxEntry; shouldDeferAutoSubmit?: boolean; - // TODO: delegateAccountID will be made required in PR 10 when all callers pass the value (https://github.com/Expensify/App/issues/66425) - delegateAccountID?: number | undefined; + delegateAccountID: number | undefined; }; type MoneyRequestInformationParams = { @@ -221,8 +220,7 @@ type MoneyRequestInformationParams = { quickAction: OnyxEntry; policyRecentlyUsedCurrencies: string[]; personalDetails: OnyxEntry; - // TODO: delegateAccountID will be made required in PR 10 when all callers pass the value (https://github.com/Expensify/App/issues/66425) - delegateAccountID?: number | undefined; + delegateAccountID: number | undefined; }; type MoneyRequestOptimisticParams = { @@ -270,8 +268,7 @@ type BuildOnyxDataForMoneyRequestParams = { transactionViolations?: OnyxCollection; hasViolations: boolean; quickAction: OnyxEntry; - // TODO: delegateAccountID will be made required in PR 10 when all callers pass the value (https://github.com/Expensify/App/issues/66425) - delegateAccountID?: number | undefined; + delegateAccountID: number | undefined; personalDetails?: OnyxEntry; /** Whether this is a selfDM split transaction */ isSelfDMSplit?: boolean; diff --git a/src/libs/actions/IOU/Split.ts b/src/libs/actions/IOU/Split.ts index 69120c3a4447..09941faf3f25 100644 --- a/src/libs/actions/IOU/Split.ts +++ b/src/libs/actions/IOU/Split.ts @@ -141,8 +141,7 @@ type CreateDistanceRequestInformation = { optimisticReportPreviewActionID?: string; shouldDeferAutoSubmit?: boolean; previousOdometerDraft?: OnyxEntry; - // TODO: delegateAccountID will be made required in PR 10 when all callers pass the value (https://github.com/Expensify/App/issues/66425) - delegateAccountID?: number | undefined; + delegateAccountID: number | undefined; }; type CreateSplitsTransactionParams = Omit & { diff --git a/src/libs/actions/IOU/SplitTransactionUpdate.ts b/src/libs/actions/IOU/SplitTransactionUpdate.ts index 7b6da20796d6..5bea7d64c1da 100644 --- a/src/libs/actions/IOU/SplitTransactionUpdate.ts +++ b/src/libs/actions/IOU/SplitTransactionUpdate.ts @@ -590,6 +590,8 @@ function updateSplitTransactions({ policyRecentlyUsedCurrencies, betas, personalDetails, + // TODO: delegateAccountID will be threaded in PR 11 (https://github.com/Expensify/App/issues/66425) + delegateAccountID: undefined, } as MoneyRequestInformationParams; if (isReverseSplitOperation) { @@ -702,6 +704,8 @@ function updateSplitTransactions({ policyRecentlyUsedCurrencies, betas, personalDetails, + // TODO: delegateAccountID will be threaded in PR 11 (https://github.com/Expensify/App/issues/66425) + delegateAccountID: undefined, }); let updateMoneyRequestParamsOnyxData: OnyxData = {}; diff --git a/src/libs/actions/IOU/TrackExpense.ts b/src/libs/actions/IOU/TrackExpense.ts index 4aa71b47d550..89be1887d1ab 100644 --- a/src/libs/actions/IOU/TrackExpense.ts +++ b/src/libs/actions/IOU/TrackExpense.ts @@ -197,8 +197,7 @@ type GetTrackExpenseInformationParams = { defaultWorkspaceName?: string; optimisticChatReportID?: string; currentUserLocalCurrency: string | undefined; - // TODO: delegateAccountID will be made required in PR 10 when all callers pass the value (https://github.com/Expensify/App/issues/66425) - delegateAccountID?: number | undefined; + delegateAccountID: number | undefined; // TODO: Remove optional (?) once all callers are updated in follow-up PRs of https://github.com/Expensify/App/issues/66414 isDraftChatReport?: boolean; }; @@ -1946,6 +1945,7 @@ function convertBulkTrackedExpensesToIOU({ personalDetails, betas, policyTagList, + delegateAccountID, }: { transactions: OnyxTypes.Transaction[]; iouReport: OnyxEntry; @@ -1959,6 +1959,7 @@ function convertBulkTrackedExpensesToIOU({ personalDetails: OnyxEntry; betas: OnyxEntry; policyTagList: OnyxEntry; + delegateAccountID: number | undefined; }) { const iouReportID = iouReport?.reportID; @@ -2079,6 +2080,7 @@ function convertBulkTrackedExpensesToIOU({ policyParams: { policyTagList, }, + delegateAccountID, }); const isDistanceRequest = isDistanceRequestTransactionUtils(transaction); diff --git a/src/libs/actions/IOU/types/CreateTrackExpenseParams.ts b/src/libs/actions/IOU/types/CreateTrackExpenseParams.ts index 5107b7f1df25..aa8674e278d0 100644 --- a/src/libs/actions/IOU/types/CreateTrackExpenseParams.ts +++ b/src/libs/actions/IOU/types/CreateTrackExpenseParams.ts @@ -40,8 +40,7 @@ type CreateTrackExpenseParams = { defaultWorkspaceName?: string; currentUserLocalCurrency: string | undefined; previousOdometerDraft?: OnyxEntry; - // TODO: delegateAccountID will be made required in PR 10 when all callers pass the value (https://github.com/Expensify/App/issues/66425) - delegateAccountID?: number | undefined; + delegateAccountID: number | undefined; reportActionsList: OnyxCollection | undefined; // TODO: Remove optional (?) once all callers are updated in follow-up PRs of https://github.com/Expensify/App/issues/66414 isDraftChatReport?: boolean; diff --git a/src/pages/Share/SubmitDetailsPage.tsx b/src/pages/Share/SubmitDetailsPage.tsx index 60b20b337981..4d6dedc73249 100644 --- a/src/pages/Share/SubmitDetailsPage.tsx +++ b/src/pages/Share/SubmitDetailsPage.tsx @@ -5,6 +5,7 @@ import MoneyRequestConfirmationList from '@components/MoneyRequestConfirmationLi import ScreenWrapper from '@components/ScreenWrapper'; import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; +import useDelegateAccountID from '@hooks/useDelegateAccountID'; import useLocalize from '@hooks/useLocalize'; import useMoneyRequestPolicyTags from '@hooks/useMoneyRequestPolicyTags'; import useNetwork from '@hooks/useNetwork'; @@ -74,6 +75,7 @@ function SubmitDetailsPage({ }: ShareDetailsPageProps) { const styles = useThemeStyles(); const {translate} = useLocalize(); + const delegateAccountID = useDelegateAccountID(); const [unknownUserDetails] = useOnyx(ONYXKEYS.SHARE_UNKNOWN_USER_DETAILS); const [personalDetails] = useOnyx(`${ONYXKEYS.PERSONAL_DETAILS_LIST}`); const report: OnyxEntry = useReportOrReportDraft(reportOrAccountID); @@ -296,6 +298,7 @@ function SubmitDetailsPage({ isSelfTourViewed, optimisticTransactionID, currentUserLocalCurrency: currentUserPersonalDetails.localCurrencyCode ?? CONST.CURRENCY.USD, + delegateAccountID, reportActionsList: undefined, }); } else { @@ -341,6 +344,7 @@ function SubmitDetailsPage({ betas, personalDetails, optimisticTransactionID, + delegateAccountID, }); } cleanupAndNavigateAfterExpenseCreate({ diff --git a/src/pages/iou/request/step/IOURequestStepDistance/handleMoneyRequestStepDistanceNavigation.ts b/src/pages/iou/request/step/IOURequestStepDistance/handleMoneyRequestStepDistanceNavigation.ts index 322a711a60ce..56a8243c2278 100644 --- a/src/pages/iou/request/step/IOURequestStepDistance/handleMoneyRequestStepDistanceNavigation.ts +++ b/src/pages/iou/request/step/IOURequestStepDistance/handleMoneyRequestStepDistanceNavigation.ts @@ -101,6 +101,7 @@ type MoneyRequestStepDistanceNavigationParams = { optimisticChatReportID: string | undefined; reportDraft: OnyxEntry | undefined; action: IOUAction; + delegateAccountID: number | undefined; policyTagList: PolicyTagLists; }; @@ -196,6 +197,7 @@ function handleMoneyRequestStepDistanceNavigation({ optimisticChatReportID, reportDraft, action, + delegateAccountID, policyTagList, }: MoneyRequestStepDistanceNavigationParams): void { const isManualDistance = manualDistance !== undefined; @@ -324,6 +326,7 @@ function handleMoneyRequestStepDistanceNavigation({ optimisticTransactionID, optimisticChatReportID, currentUserLocalCurrency, + delegateAccountID, reportActionsList: undefined, }); cleanupAfterSkipConfirmSubmit(overrides.shouldHandleNavigation, { @@ -397,6 +400,7 @@ function handleMoneyRequestStepDistanceNavigation({ policyParams: { policyTagList, }, + delegateAccountID, }); cleanupAfterSkipConfirmSubmit(overrides.shouldHandleNavigation, { report, diff --git a/src/pages/iou/request/step/IOURequestStepDistance/hooks/useDistanceNavigation.ts b/src/pages/iou/request/step/IOURequestStepDistance/hooks/useDistanceNavigation.ts index fe51d935a11a..7dbee8f3bd6f 100644 --- a/src/pages/iou/request/step/IOURequestStepDistance/hooks/useDistanceNavigation.ts +++ b/src/pages/iou/request/step/IOURequestStepDistance/hooks/useDistanceNavigation.ts @@ -1,5 +1,6 @@ import type {LocaleContextProps} from '@components/LocaleContextProvider'; +import useDelegateAccountID from '@hooks/useDelegateAccountID'; import useMoneyRequestPolicyTagsForReport from '@hooks/useMoneyRequestPolicyTagsForReport'; import useOnyx from '@hooks/useOnyx'; @@ -145,6 +146,7 @@ function useDistanceNavigation({ const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS); const reportIDToCheck = isMoneyRequestReportReportUtils(report) ? report?.chatReportID : report?.reportID; const [reportDraft] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_DRAFT}${reportIDToCheck}`); + const delegateAccountID = useDelegateAccountID(); const policyTagList = useMoneyRequestPolicyTagsForReport({report, currentUserAccountID}); return () => { const optimisticTransactionID = rand64(); @@ -191,6 +193,7 @@ function useDistanceNavigation({ optimisticTransactionID, optimisticChatReportID, reportDraft, + delegateAccountID, policyTagList, }); }; diff --git a/src/pages/iou/request/step/IOURequestStepDistance/hooks/useOdometerNavigation.ts b/src/pages/iou/request/step/IOURequestStepDistance/hooks/useOdometerNavigation.ts index f0e6e87e8222..93199d134cf0 100644 --- a/src/pages/iou/request/step/IOURequestStepDistance/hooks/useOdometerNavigation.ts +++ b/src/pages/iou/request/step/IOURequestStepDistance/hooks/useOdometerNavigation.ts @@ -1,5 +1,6 @@ import type {LocaleContextProps} from '@components/LocaleContextProvider'; +import useDelegateAccountID from '@hooks/useDelegateAccountID'; import useMoneyRequestPolicyTagsForReport from '@hooks/useMoneyRequestPolicyTagsForReport'; import useOnyx from '@hooks/useOnyx'; @@ -150,6 +151,8 @@ function useOdometerNavigation({ const [reportDraft] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_DRAFT}${reportIDToCheck}`); const policyTagList = useMoneyRequestPolicyTagsForReport({report, currentUserAccountID}); + const delegateAccountID = useDelegateAccountID(); + return ({odometerStart, odometerEnd, odometerDistance, unit, previousOdometerDraft}: NavigateOptions) => { const optimisticTransactionID = rand64(); const optimisticChatReportID = selfDMReport?.reportID ?? generateReportID(); @@ -198,6 +201,7 @@ function useOdometerNavigation({ optimisticTransactionID, optimisticChatReportID, reportDraft, + delegateAccountID, policyTagList, }); }; diff --git a/src/pages/iou/request/step/IOURequestStepDistanceGPS/index.native.tsx b/src/pages/iou/request/step/IOURequestStepDistanceGPS/index.native.tsx index c0078cf8d110..e9d37c649484 100644 --- a/src/pages/iou/request/step/IOURequestStepDistanceGPS/index.native.tsx +++ b/src/pages/iou/request/step/IOURequestStepDistanceGPS/index.native.tsx @@ -4,6 +4,7 @@ import type {Coordinate} from '@components/MapView/MapViewTypes'; import withCurrentUserPersonalDetails from '@components/withCurrentUserPersonalDetails'; import useDefaultExpensePolicy from '@hooks/useDefaultExpensePolicy'; +import useDelegateAccountID from '@hooks/useDelegateAccountID'; import useIsInLandscapeMode from '@hooks/useIsInLandscapeMode'; import useLocalize from '@hooks/useLocalize'; import useMoneyRequestPolicyTagsForReport from '@hooks/useMoneyRequestPolicyTagsForReport'; @@ -56,6 +57,7 @@ function IOURequestStepDistanceGPS({ currentUserPersonalDetails, }: IOURequestStepDistanceGPSProps) { const styles = useThemeStyles(); + const delegateAccountID = useDelegateAccountID(); const {translate} = useLocalize(); const {isBetaEnabled} = usePermissions(); @@ -167,6 +169,7 @@ function IOURequestStepDistanceGPS({ optimisticTransactionID, optimisticChatReportID, reportDraft, + delegateAccountID, policyTagList, }); }; diff --git a/src/pages/iou/request/step/IOURequestStepDistanceManual.tsx b/src/pages/iou/request/step/IOURequestStepDistanceManual.tsx index b9cdf5641112..d52baea3100a 100644 --- a/src/pages/iou/request/step/IOURequestStepDistanceManual.tsx +++ b/src/pages/iou/request/step/IOURequestStepDistanceManual.tsx @@ -289,6 +289,7 @@ function IOURequestStepDistanceManual({ optimisticTransactionID, optimisticChatReportID, reportDraft, + delegateAccountID, policyTagList, }); }; diff --git a/src/pages/iou/request/step/IOURequestStepScan/components/ScanSkipConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepScan/components/ScanSkipConfirmation.tsx index f6789b4c8f99..20bfa75ad28d 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/components/ScanSkipConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/components/ScanSkipConfirmation.tsx @@ -2,6 +2,7 @@ import {useFullScreenLoaderActions} from '@components/FullScreenLoaderContext'; import withCurrentUserPersonalDetails from '@components/withCurrentUserPersonalDetails'; import type {WithCurrentUserPersonalDetailsProps} from '@components/withCurrentUserPersonalDetails'; +import useDelegateAccountID from '@hooks/useDelegateAccountID'; import useFilesValidation from '@hooks/useFilesValidation'; import useLocalize from '@hooks/useLocalize'; import useOnyx from '@hooks/useOnyx'; @@ -77,6 +78,7 @@ function ScanSkipConfirmation({report, action, iouType, reportID, transactionID, const reportAttributesDerived = useReportAttributes(); const {isBetaEnabled} = usePermissions(); const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT); + const delegateAccountID = useDelegateAccountID(); const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST); const [quickAction] = useOnyx(ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE); @@ -279,6 +281,7 @@ function ScanSkipConfirmation({report, action, iouType, reportID, transactionID, optimisticTransactionIDs, optimisticChatReportID, currentUserLocalCurrency: currentUserPersonalDetails.localCurrencyCode ?? CONST.CURRENCY.USD, + delegateAccountID, }; const scanDestinationReportID = iouType === CONST.IOU.TYPE.TRACK ? (report?.reportID ?? selfDMReport?.reportID) : report?.reportID; diff --git a/src/pages/iou/request/step/confirmation/useExpenseSubmission.ts b/src/pages/iou/request/step/confirmation/useExpenseSubmission.ts index 495ef735e307..3a7a2107de51 100644 --- a/src/pages/iou/request/step/confirmation/useExpenseSubmission.ts +++ b/src/pages/iou/request/step/confirmation/useExpenseSubmission.ts @@ -1,4 +1,5 @@ import useActivePolicy from '@hooks/useActivePolicy'; +import useDelegateAccountID from '@hooks/useDelegateAccountID'; import useLastWorkspaceNumber from '@hooks/useLastWorkspaceNumber'; import useLocalize from '@hooks/useLocalize'; import useMoneyRequestPolicyTags from '@hooks/useMoneyRequestPolicyTags'; @@ -276,6 +277,7 @@ function useExpenseSubmission(params: UseExpenseSubmissionParams) { const [gpsDraftDetails] = useOnyx(ONYXKEYS.GPS_DRAFT_DETAILS); const [recentWaypoints] = useOnyx(ONYXKEYS.NVP_RECENT_WAYPOINTS); const [odometerDraft] = useOnyx(ONYXKEYS.ODOMETER_DRAFT); + const delegateAccountID = useDelegateAccountID(); const [delegateEmail] = useOnyx(ONYXKEYS.ACCOUNT, {selector: delegateEmailSelector}); // Onboarding task data const { @@ -494,6 +496,7 @@ function useExpenseSubmission(params: UseExpenseSubmissionParams) { isSelfTourViewed, betas, personalDetails, + delegateAccountID, }); existingIOUReport = iouReport; if (!iouReport) { @@ -707,6 +710,7 @@ function useExpenseSubmission(params: UseExpenseSubmissionParams) { reportActionsList: policyExpenseChatReportActions, personalDetailsList: personalDetails, currentUserLocalCurrency: currentUserPersonalDetails.localCurrencyCode ?? CONST.CURRENCY.USD, + delegateAccountID, }); } performPostBatchCleanup({ @@ -775,6 +779,7 @@ function useExpenseSubmission(params: UseExpenseSubmissionParams) { recentWaypoints, betas, previousOdometerDraft: odometerDraft, + delegateAccountID, }); const isExpenseReport = isMoneyRequestReportReportUtils(report); diff --git a/tests/actions/IOU/BuildOnyxDataForMoneyRequestTest.ts b/tests/actions/IOU/BuildOnyxDataForMoneyRequestTest.ts index ced81546f57e..fc51ef1f20e1 100644 --- a/tests/actions/IOU/BuildOnyxDataForMoneyRequestTest.ts +++ b/tests/actions/IOU/BuildOnyxDataForMoneyRequestTest.ts @@ -188,6 +188,7 @@ describe('buildOnyxDataForMoneyRequest', () => { isSelfDMSplit: true, selfDMReportID: selfDMReport.reportID, optimisticParams: buildBaseOptimisticParams(IOU_REPORT_ID), + delegateAccountID: undefined, }; } @@ -328,6 +329,7 @@ describe('buildOnyxDataForMoneyRequest', () => { quickAction: undefined, isSelfDMSplit: false, optimisticParams: buildBaseOptimisticParams(IOU_REPORT_ID), + delegateAccountID: undefined, }; } @@ -367,6 +369,7 @@ describe('buildOnyxDataForMoneyRequest', () => { isSelfDMSplit: true, selfDMReportID: undefined, optimisticParams: buildBaseOptimisticParams(IOU_REPORT_ID), + delegateAccountID: undefined, }; } @@ -412,6 +415,7 @@ describe('buildOnyxDataForMoneyRequest', () => { } as Report, }, }, + delegateAccountID: undefined, }; } diff --git a/tests/actions/IOU/GetMoneyRequestInformationTest.ts b/tests/actions/IOU/GetMoneyRequestInformationTest.ts index 3d6b247e6278..431a95fb3f8e 100644 --- a/tests/actions/IOU/GetMoneyRequestInformationTest.ts +++ b/tests/actions/IOU/GetMoneyRequestInformationTest.ts @@ -68,6 +68,7 @@ const baseParams = { quickAction: undefined, policyRecentlyUsedCurrencies: [] as string[], personalDetails: {}, + delegateAccountID: undefined, } as const; describe('getMoneyRequestInformation', () => { diff --git a/tests/actions/IOU/MoneyRequestTest.ts b/tests/actions/IOU/MoneyRequestTest.ts index d7665e275792..1a6d91215d74 100644 --- a/tests/actions/IOU/MoneyRequestTest.ts +++ b/tests/actions/IOU/MoneyRequestTest.ts @@ -141,6 +141,7 @@ describe('MoneyRequest', () => { optimisticTransactionIDs: ['mock-txn-id'], optimisticChatReportID: undefined, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, }; beforeEach(async () => { @@ -156,6 +157,7 @@ describe('MoneyRequest', () => { ...baseParams, iouType: CONST.IOU.TYPE.TRACK, allTransactionDrafts: {}, + delegateAccountID: undefined, }); expect(TrackExpense.trackExpense).toHaveBeenCalledTimes(1); @@ -197,6 +199,7 @@ describe('MoneyRequest', () => { ...baseParams, iouType: CONST.IOU.TYPE.SEND, allTransactionDrafts: {}, + delegateAccountID: undefined, }); expect(TrackExpense.requestMoney).toHaveBeenCalledTimes(1); @@ -245,6 +248,7 @@ describe('MoneyRequest', () => { iouType: CONST.IOU.TYPE.TRACK, files, allTransactionDrafts: {}, + delegateAccountID: undefined, }); expect(TrackExpense.trackExpense).toHaveBeenCalledTimes(files.length); @@ -259,6 +263,7 @@ describe('MoneyRequest', () => { ...baseParams, files, allTransactionDrafts: {}, + delegateAccountID: undefined, }); expect(TrackExpense.requestMoney).toHaveBeenCalledWith( @@ -278,6 +283,7 @@ describe('MoneyRequest', () => { ...baseParams, currentUserEmail: undefined, allTransactionDrafts: {}, + delegateAccountID: undefined, }); expect(TrackExpense.requestMoney).toHaveBeenCalledWith( @@ -310,6 +316,7 @@ describe('MoneyRequest', () => { allTransactionDrafts: { [draftTransaction.transactionID]: draftTransaction, }, + delegateAccountID: undefined, }); expect(TrackExpense.requestMoney).toHaveBeenCalledWith( @@ -324,6 +331,7 @@ describe('MoneyRequest', () => { createTransaction({ ...baseParams, allTransactionDrafts: undefined, + delegateAccountID: undefined, }); expect(TrackExpense.requestMoney).toHaveBeenCalledWith( @@ -339,6 +347,7 @@ describe('MoneyRequest', () => { iouType: CONST.IOU.TYPE.TRACK, billable: true, reimbursable: false, + delegateAccountID: undefined, }); expect(TrackExpense.trackExpense).toHaveBeenCalledWith( @@ -355,6 +364,7 @@ describe('MoneyRequest', () => { createTransaction({ ...baseParams, allTransactionDrafts: {}, + delegateAccountID: undefined, }); expect(TrackExpense.requestMoney).toHaveBeenCalledWith( @@ -388,6 +398,7 @@ describe('MoneyRequest', () => { [draft1.transactionID]: draft1, [draft2.transactionID]: draft2, }, + delegateAccountID: undefined, }); expect(TrackExpense.requestMoney).toHaveBeenCalledWith( @@ -403,6 +414,7 @@ describe('MoneyRequest', () => { ...baseParams, iouType: CONST.IOU.TYPE.TRACK, gpsPoint, + delegateAccountID: undefined, }); expect(TrackExpense.trackExpense).toHaveBeenCalledWith( @@ -438,6 +450,7 @@ describe('MoneyRequest', () => { iouType: CONST.IOU.TYPE.TRACK, transactions: [transactionWithoutTax], policyParams: {policy: policyWithTax}, + delegateAccountID: undefined, }); expect(TrackExpense.trackExpense).toHaveBeenCalledWith( @@ -474,6 +487,7 @@ describe('MoneyRequest', () => { iouType: CONST.IOU.TYPE.REQUEST, transactions: [transactionWithoutTax], policyParams: {policy: policyWithTax}, + delegateAccountID: undefined, }); expect(TrackExpense.requestMoney).toHaveBeenCalledWith( @@ -510,6 +524,7 @@ describe('MoneyRequest', () => { iouType: CONST.IOU.TYPE.TRACK, transactions: [transactionWithTax], policyParams: {policy: policyWithTax}, + delegateAccountID: undefined, }); expect(TrackExpense.trackExpense).toHaveBeenCalledWith( @@ -534,6 +549,7 @@ describe('MoneyRequest', () => { iouType: CONST.IOU.TYPE.REQUEST, transactions: [transactionWithoutTax], policyParams: undefined, + delegateAccountID: undefined, }); expect(TrackExpense.requestMoney).toHaveBeenCalledWith( @@ -552,6 +568,7 @@ describe('MoneyRequest', () => { iouType: CONST.IOU.TYPE.REQUEST, optimisticTransactionIDs: ['ui-id-1'], allTransactionDrafts: {}, + delegateAccountID: undefined, }); const requestMoneyArg = jest.mocked(TrackExpense.requestMoney).mock.calls.at(0)?.at(0); expect(requestMoneyArg?.optimisticTransactionID).toBe('ui-id-1'); @@ -565,6 +582,7 @@ describe('MoneyRequest', () => { participant: {accountID: 222, login: 'test@test.com'}, optimisticChatReportID: 'ui-resolved-chat', allTransactionDrafts: {}, + delegateAccountID: undefined, }); const requestMoneyArg = jest.mocked(TrackExpense.requestMoney).mock.calls.at(0)?.at(0); expect(requestMoneyArg?.optimisticChatReportID).toBe('ui-resolved-chat'); @@ -656,6 +674,7 @@ describe('MoneyRequest', () => { ...baseParams, backTo, draftTransactionIDs: [baseParams.transactionID], + delegateAccountID: undefined, }); expect(Navigation.goBack).toHaveBeenCalledWith(backTo); @@ -666,6 +685,7 @@ describe('MoneyRequest', () => { ...baseParams, backTo, draftTransactionIDs: undefined, + delegateAccountID: undefined, }); expect(Navigation.goBack).toHaveBeenCalledWith(backTo); @@ -684,6 +704,7 @@ describe('MoneyRequest', () => { shouldSkipConfirmation: true, iouType: CONST.IOU.TYPE.TRACK, draftTransactionIDs: [baseParams.transactionID], + delegateAccountID: undefined, }); expect(Split.resetSplitShares).toHaveBeenCalledWith(splitTransaction, undefined, undefined, 1); @@ -696,6 +717,7 @@ describe('MoneyRequest', () => { shouldSkipConfirmation: true, iouType: CONST.IOU.TYPE.TRACK, draftTransactionIDs: [baseParams.transactionID], + delegateAccountID: undefined, }); expect(Split.resetSplitShares).not.toHaveBeenCalled(); @@ -749,6 +771,7 @@ describe('MoneyRequest', () => { iouType: CONST.IOU.TYPE.TRACK, optimisticTransactionID: 'optimistic-should-be-ignored', draftTransactionIDs: [baseParams.transactionID], + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -770,6 +793,7 @@ describe('MoneyRequest', () => { iouType: CONST.IOU.TYPE.SUBMIT, optimisticTransactionID: 'optimistic-should-be-ignored', draftTransactionIDs: [baseParams.transactionID], + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -814,6 +838,7 @@ describe('MoneyRequest', () => { shouldSkipConfirmation: true, iouType: CONST.IOU.TYPE.TRACK, draftTransactionIDs: [baseParams.transactionID], + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -879,6 +904,7 @@ describe('MoneyRequest', () => { manualDistance: 20, iouType: CONST.IOU.TYPE.SUBMIT, draftTransactionIDs: [baseParams.transactionID], + delegateAccountID: undefined, }); expect(Split.createDistanceRequest).toHaveBeenCalledWith( @@ -921,6 +947,7 @@ describe('MoneyRequest', () => { manualDistance: undefined, iouType: CONST.IOU.TYPE.SUBMIT, draftTransactionIDs: [baseParams.transactionID], + delegateAccountID: undefined, }); expect(Split.createDistanceRequest).toHaveBeenCalledWith( @@ -962,6 +989,7 @@ describe('MoneyRequest', () => { shouldSkipConfirmation: false, iouType: CONST.IOU.TYPE.SUBMIT, draftTransactionIDs: [baseParams.transactionID], + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -998,6 +1026,7 @@ describe('MoneyRequest', () => { isAutoReporting: true, iouType: CONST.IOU.TYPE.CREATE, draftTransactionIDs: [baseParams.transactionID], + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -1039,6 +1068,7 @@ describe('MoneyRequest', () => { defaultExpensePolicy, iouType: CONST.IOU.TYPE.CREATE, draftTransactionIDs: [baseParams.transactionID], + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -1051,6 +1081,7 @@ describe('MoneyRequest', () => { ...baseParams, iouType: CONST.IOU.TYPE.CREATE, draftTransactionIDs: [baseParams.transactionID], + delegateAccountID: undefined, }); expect(Navigation.navigate).toHaveBeenCalledWith(ROUTES.MONEY_REQUEST_STEP_PARTICIPANTS.getRoute(CONST.IOU.TYPE.CREATE, baseParams.transactionID, baseParams.reportID)); @@ -1063,6 +1094,7 @@ describe('MoneyRequest', () => { defaultExpensePolicy: undefined, iouType: CONST.IOU.TYPE.CREATE, amountOwed: 8010, + delegateAccountID: undefined, }); expect(Navigation.navigate).toHaveBeenCalledWith(ROUTES.MONEY_REQUEST_STEP_PARTICIPANTS.getRoute(CONST.IOU.TYPE.CREATE, baseParams.transactionID, baseParams.reportID)); @@ -1077,6 +1109,7 @@ describe('MoneyRequest', () => { iouType: CONST.IOU.TYPE.CREATE, amountOwed: 100, ownerBillingGracePeriodEnd: pastDate, + delegateAccountID: undefined, }); expect(Navigation.navigate).toHaveBeenCalledWith(ROUTES.MONEY_REQUEST_STEP_PARTICIPANTS.getRoute(CONST.IOU.TYPE.CREATE, baseParams.transactionID, baseParams.reportID)); @@ -1088,6 +1121,7 @@ describe('MoneyRequest', () => { report: undefined, defaultExpensePolicy: fakePolicy, iouType: CONST.IOU.TYPE.CREATE, + delegateAccountID: undefined, }); const lastCallArgs = jest.mocked(shouldUseDefaultExpensePolicy).mock.calls.at(-1) ?? []; @@ -1103,6 +1137,7 @@ describe('MoneyRequest', () => { isArchivedExpenseReport: false, draftTransactionIDs: [baseParams.transactionID], conciergeReportID, + delegateAccountID: undefined, }); // When report exists and iouType is not CREATE, the function calls getMoneyRequestParticipantOptions @@ -1119,6 +1154,7 @@ describe('MoneyRequest', () => { isArchivedExpenseReport: false, draftTransactionIDs: [baseParams.transactionID], conciergeReportID: undefined, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -1137,6 +1173,7 @@ describe('MoneyRequest', () => { setDistanceRequestData: (participants) => { capturedParticipants = participants; }, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -1156,6 +1193,7 @@ describe('MoneyRequest', () => { setDistanceRequestData: (participants) => { capturedParticipants = participants; }, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); diff --git a/tests/actions/IOU/RequestMoneyTest.ts b/tests/actions/IOU/RequestMoneyTest.ts index 2713734b633d..1ec27561a1bd 100644 --- a/tests/actions/IOU/RequestMoneyTest.ts +++ b/tests/actions/IOU/RequestMoneyTest.ts @@ -216,6 +216,7 @@ describe('actions/IOU', () => { quickAction: undefined, betas: [CONST.BETAS.ALL], personalDetails: {}, + delegateAccountID: undefined, }); return waitForBatchedUpdates() .then( @@ -481,6 +482,7 @@ describe('actions/IOU', () => { quickAction: undefined, betas: [CONST.BETAS.ALL], personalDetails: {}, + delegateAccountID: undefined, }); return waitForBatchedUpdates(); }) @@ -714,6 +716,7 @@ describe('actions/IOU', () => { quickAction: undefined, betas: [CONST.BETAS.ALL], personalDetails: {}, + delegateAccountID: undefined, }); } return waitForBatchedUpdates(); @@ -883,6 +886,7 @@ describe('actions/IOU', () => { quickAction: undefined, betas: [CONST.BETAS.ALL], personalDetails: {}, + delegateAccountID: undefined, }); return ( waitForBatchedUpdates() @@ -1289,6 +1293,7 @@ describe('actions/IOU', () => { draftTransactionIDs: [], isSelfTourViewed: false, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, reportActionsList: undefined, }); @@ -1358,6 +1363,7 @@ describe('actions/IOU', () => { draftTransactionIDs: [], isSelfTourViewed: false, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, reportActionsList: undefined, }); await waitForBatchedUpdates(); @@ -1407,6 +1413,7 @@ describe('actions/IOU', () => { quickAction: undefined, betas: [CONST.BETAS.ALL], personalDetails: {}, + delegateAccountID: undefined, }); expect(notifyNewAction).toHaveBeenCalledTimes(0); }); @@ -1439,6 +1446,7 @@ describe('actions/IOU', () => { quickAction: undefined, betas: [CONST.BETAS.ALL], personalDetails: {}, + delegateAccountID: undefined, }); expect(Navigation.setNavigationActionToMicrotaskQueue).toHaveBeenCalledTimes(1); }); @@ -1471,6 +1479,7 @@ describe('actions/IOU', () => { quickAction: undefined, betas: [CONST.BETAS.ALL], personalDetails: {}, + delegateAccountID: undefined, }); // Verify that the iouReport is created successfully when isSelfTourViewed is true expect(iouReport).toBeDefined(); @@ -1522,6 +1531,7 @@ describe('actions/IOU', () => { quickAction: undefined, betas: [CONST.BETAS.ALL], personalDetails: {}, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -1566,6 +1576,7 @@ describe('actions/IOU', () => { quickAction: undefined, betas: [CONST.BETAS.ALL], personalDetails: {}, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -1637,6 +1648,7 @@ describe('actions/IOU', () => { quickAction: undefined, betas: [CONST.BETAS.ALL], personalDetails: {}, + delegateAccountID: undefined, }); waitForBatchedUpdates(); @@ -1705,6 +1717,7 @@ describe('actions/IOU', () => { draftTransactionIDs: [], personalDetails: testPersonalDetails, betas: [CONST.BETAS.ALL], + delegateAccountID: undefined, }); expect(iouReport).toBeDefined(); @@ -1778,6 +1791,7 @@ describe('actions/IOU', () => { draftTransactionIDs: [], personalDetails: testPersonalDetails, betas: [CONST.BETAS.ALL], + delegateAccountID: undefined, }); expect(iouReport).toBeDefined(); @@ -1822,6 +1836,7 @@ describe('actions/IOU', () => { draftTransactionIDs: [], personalDetails: {}, betas: [CONST.BETAS.ALL], + delegateAccountID: undefined, }); // Should still create the expense even with empty personalDetails @@ -1884,6 +1899,7 @@ describe('actions/IOU', () => { draftTransactionIDs: [], isSelfTourViewed: false, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, reportActionsList: undefined, }); await waitForBatchedUpdates(); @@ -1982,6 +1998,7 @@ describe('actions/IOU', () => { draftTransactionIDs: [], personalDetails: {}, betas: [CONST.BETAS.ALL], + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -2057,6 +2074,7 @@ describe('actions/IOU', () => { existingTransactionDraft: undefined, draftTransactionIDs: [], personalDetails: {}, + delegateAccountID: undefined, }); return waitForBatchedUpdates(); }) @@ -2144,6 +2162,7 @@ describe('actions/IOU', () => { existingTransactionDraft: undefined, draftTransactionIDs: [], personalDetails: {}, + delegateAccountID: undefined, }); return waitForBatchedUpdates(); }) @@ -2222,6 +2241,7 @@ describe('actions/IOU', () => { existingTransactionDraft: undefined, draftTransactionIDs: [], personalDetails: {}, + delegateAccountID: undefined, }); return waitForBatchedUpdates(); }) @@ -2295,6 +2315,7 @@ describe('actions/IOU', () => { existingTransactionDraft: undefined, draftTransactionIDs: [], personalDetails: {}, + delegateAccountID: undefined, }); return waitForBatchedUpdates(); }) @@ -2369,6 +2390,7 @@ describe('actions/IOU', () => { existingTransactionDraft: undefined, draftTransactionIDs: [], personalDetails: {}, + delegateAccountID: undefined, }); return waitForBatchedUpdates(); }) @@ -2407,6 +2429,66 @@ describe('actions/IOU', () => { ) .then(mockFetch?.resume); }); + + describe('delegateAccountID forwarding', () => { + it('sets delegateAccountID on the IOU action when delegateAccountID is provided', async () => { + const DELEGATE_ACCOUNT_ID = 999; + mockFetch?.pause?.(); + + requestMoney({ + report: {reportID: ''}, + participantParams: { + payeeEmail: RORY_EMAIL, + payeeAccountID: RORY_ACCOUNT_ID, + participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, + }, + transactionParams: { + amount: 10000, + attendees: [], + currency: CONST.CURRENCY.USD, + created: format(new Date(), CONST.DATE.FNS_FORMAT_STRING), + merchant: 'Test', + comment: 'delegate test', + }, + shouldGenerateTransactionThreadReport: true, + isASAPSubmitBetaEnabled: false, + transactionViolations: {}, + currentUserAccountIDParam: RORY_ACCOUNT_ID, + currentUserEmailParam: RORY_EMAIL, + policyRecentlyUsedCurrencies: [], + existingTransactionDraft: undefined, + draftTransactionIDs: [], + isSelfTourViewed: false, + quickAction: undefined, + betas: [CONST.BETAS.ALL], + personalDetails: {}, + delegateAccountID: DELEGATE_ACCOUNT_ID, + }); + await waitForBatchedUpdates(); + + let iouReport: Report | undefined; + await getOnyxData({ + key: ONYXKEYS.COLLECTION.REPORT, + waitForCollectionCallback: true, + callback: (allReports) => { + iouReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.IOU); + }, + }); + const iouReportID = iouReport?.reportID; + expect(iouReportID).toBeTruthy(); + if (!iouReportID) { + throw new Error('Expected IOU report to be created'); + } + + const reportActions = await getOnyxValue(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReportID}`); + const iouAction = Object.values(reportActions ?? {}).find((reportAction): reportAction is ReportAction => + isMoneyRequestAction(reportAction), + ); + expect(iouAction?.delegateAccountID).toBe(DELEGATE_ACCOUNT_ID); + + await mockFetch?.resume?.(); + }); + }); }); describe('should have valid parameters', () => { @@ -2461,6 +2543,7 @@ describe('actions/IOU', () => { quickAction: undefined, betas: [CONST.BETAS.ALL], personalDetails: {}, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -2534,6 +2617,7 @@ describe('actions/IOU', () => { existingTransactionDraft: undefined, draftTransactionIDs: [], personalDetails: {}, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -2608,6 +2692,7 @@ describe('actions/IOU', () => { draftTransactionIDs: [], isSelfTourViewed: false, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, reportActionsList: undefined, }); diff --git a/tests/actions/IOUTest/DeleteMoneyRequestTest.ts b/tests/actions/IOUTest/DeleteMoneyRequestTest.ts index b85525c524d3..8dd9dd68addf 100644 --- a/tests/actions/IOUTest/DeleteMoneyRequestTest.ts +++ b/tests/actions/IOUTest/DeleteMoneyRequestTest.ts @@ -191,6 +191,7 @@ describe('actions/IOU/DeleteMoneyRequest', () => { quickAction: undefined, betas: [CONST.BETAS.ALL], personalDetails: {}, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -446,6 +447,7 @@ describe('actions/IOU/DeleteMoneyRequest', () => { quickAction: undefined, betas: [CONST.BETAS.ALL], personalDetails: {}, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -1142,6 +1144,7 @@ describe('actions/IOU/DeleteMoneyRequest', () => { quickAction: undefined, betas: [CONST.BETAS.ALL], personalDetails: {}, + delegateAccountID: undefined, }); } @@ -1223,6 +1226,7 @@ describe('actions/IOU/DeleteMoneyRequest', () => { quickAction: undefined, betas: [CONST.BETAS.ALL], personalDetails: {}, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -1394,6 +1398,7 @@ describe('actions/IOU/DeleteMoneyRequest', () => { existingTransactionDraft: undefined, betas: [CONST.BETAS.ALL], personalDetails: {}, + delegateAccountID: undefined, }); } diff --git a/tests/actions/IOUTest/DuplicateTest.ts b/tests/actions/IOUTest/DuplicateTest.ts index d58b1a59bf7d..31c4d2557fc8 100644 --- a/tests/actions/IOUTest/DuplicateTest.ts +++ b/tests/actions/IOUTest/DuplicateTest.ts @@ -1342,6 +1342,7 @@ describe('actions/Duplicate', () => { policyTagList: targetPolicyTags ?? {}, currentUser: {accountID: RORY_ACCOUNT_ID, email: RORY_EMAIL}, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -1407,6 +1408,7 @@ describe('actions/Duplicate', () => { policyTagList: targetPolicyTags ?? {}, currentUser: {accountID: RORY_ACCOUNT_ID, email: RORY_EMAIL}, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -1464,6 +1466,7 @@ describe('actions/Duplicate', () => { policyTagList: targetPolicyTags ?? {}, currentUser: {accountID: RORY_ACCOUNT_ID, email: RORY_EMAIL}, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -1514,6 +1517,7 @@ describe('actions/Duplicate', () => { policyTagList: targetPolicyTags ?? {}, currentUser: {accountID: RORY_ACCOUNT_ID, email: RORY_EMAIL}, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -1564,6 +1568,7 @@ describe('actions/Duplicate', () => { policyTagList: targetPolicyTags ?? {}, currentUser: {accountID: RORY_ACCOUNT_ID, email: RORY_EMAIL}, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -1617,6 +1622,7 @@ describe('actions/Duplicate', () => { policyTagList: targetPolicyTags ?? {}, currentUser: {accountID: RORY_ACCOUNT_ID, email: RORY_EMAIL}, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -1680,6 +1686,7 @@ describe('actions/Duplicate', () => { policyTagList: targetPolicyTags ?? {}, currentUser: {accountID: RORY_ACCOUNT_ID, email: RORY_EMAIL}, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -1728,6 +1735,7 @@ describe('actions/Duplicate', () => { policyTagList: targetPolicyTags ?? {}, currentUser: {accountID: RORY_ACCOUNT_ID, email: RORY_EMAIL}, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -1769,6 +1777,7 @@ describe('actions/Duplicate', () => { policyTagList: targetPolicyTags ?? {}, currentUser: {accountID: RORY_ACCOUNT_ID, email: RORY_EMAIL}, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -1813,6 +1822,7 @@ describe('actions/Duplicate', () => { policyTagList: targetPolicyTags ?? {}, currentUser: {accountID: RORY_ACCOUNT_ID, email: RORY_EMAIL}, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -1863,6 +1873,7 @@ describe('actions/Duplicate', () => { policyTagList: targetPolicyTags ?? {}, currentUser: {accountID: RORY_ACCOUNT_ID, email: RORY_EMAIL}, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -1929,6 +1940,7 @@ describe('actions/Duplicate', () => { policyTagList: targetPolicyTags ?? {}, currentUser: {accountID: RORY_ACCOUNT_ID, email: RORY_EMAIL}, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -1995,6 +2007,7 @@ describe('actions/Duplicate', () => { policyTagList: targetPolicyTags ?? {}, currentUser: {accountID: RORY_ACCOUNT_ID, email: RORY_EMAIL}, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -2045,6 +2058,7 @@ describe('actions/Duplicate', () => { policyTagList: targetPolicyTags ?? {}, currentUser: {accountID: RORY_ACCOUNT_ID, email: RORY_EMAIL}, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -2106,6 +2120,7 @@ describe('actions/Duplicate', () => { policyTagList: targetPolicyTags ?? {}, currentUser: {accountID: RORY_ACCOUNT_ID, email: RORY_EMAIL}, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -2277,6 +2292,7 @@ describe('actions/Duplicate', () => { currentUserAccountID: RORY_ACCOUNT_ID, currentUserLogin: RORY_EMAIL, recentWaypoints: [], + delegateAccountID: undefined, ...overrides, }); @@ -2847,6 +2863,7 @@ describe('actions/Duplicate', () => { recentWaypoints: [], currentUser: {accountID: RORY_ACCOUNT_ID, email: RORY_EMAIL}, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -2962,6 +2979,7 @@ describe('actions/Duplicate', () => { transactionViolations: {}, translate: mockTranslate, recentWaypoints: [], + delegateAccountID: undefined, ...overrides, }); diff --git a/tests/actions/IOUTest/PayMoneyRequestTest.ts b/tests/actions/IOUTest/PayMoneyRequestTest.ts index 4db333dd6bc2..9442e5c0738a 100644 --- a/tests/actions/IOUTest/PayMoneyRequestTest.ts +++ b/tests/actions/IOUTest/PayMoneyRequestTest.ts @@ -164,6 +164,7 @@ describe('actions/IOU/PayMoneyRequest', () => { quickAction: undefined, betas: [CONST.BETAS.ALL], personalDetails: {}, + delegateAccountID: undefined, }); return waitForBatchedUpdates() .then( @@ -435,6 +436,7 @@ describe('actions/IOU/PayMoneyRequest', () => { quickAction: undefined, betas: [CONST.BETAS.ALL], personalDetails: {}, + delegateAccountID: undefined, }); } return waitForBatchedUpdates(); @@ -601,6 +603,7 @@ describe('actions/IOU/PayMoneyRequest', () => { quickAction: undefined, betas: [CONST.BETAS.ALL], personalDetails: {}, + delegateAccountID: undefined, }); } return waitForBatchedUpdates(); @@ -1419,6 +1422,7 @@ describe('actions/IOU/PayMoneyRequest', () => { quickAction: undefined, betas: [CONST.BETAS.ALL], personalDetails: {}, + delegateAccountID: undefined, }); } return waitForBatchedUpdates(); @@ -1545,6 +1549,7 @@ describe('actions/IOU/PayMoneyRequest', () => { quickAction: undefined, betas: [CONST.BETAS.ALL], personalDetails: {}, + delegateAccountID: undefined, }); } await waitForBatchedUpdates(); @@ -1795,6 +1800,7 @@ describe('actions/IOU/PayMoneyRequest', () => { quickAction: undefined, betas: [CONST.BETAS.ALL], personalDetails: {}, + delegateAccountID: undefined, }); } await waitForBatchedUpdates(); diff --git a/tests/actions/IOUTest/ReportWorkflowTest.ts b/tests/actions/IOUTest/ReportWorkflowTest.ts index fbca72f8bfe1..68b3c2f060ba 100644 --- a/tests/actions/IOUTest/ReportWorkflowTest.ts +++ b/tests/actions/IOUTest/ReportWorkflowTest.ts @@ -209,6 +209,7 @@ describe('actions/IOU/ReportWorkflow', () => { quickAction: undefined, betas: [CONST.BETAS.ALL], personalDetails: {}, + delegateAccountID: undefined, }); } return waitForBatchedUpdates(); @@ -359,6 +360,7 @@ describe('actions/IOU/ReportWorkflow', () => { quickAction: undefined, betas: [CONST.BETAS.ALL], personalDetails: {}, + delegateAccountID: undefined, }); } return waitForBatchedUpdates(); @@ -439,6 +441,7 @@ describe('actions/IOU/ReportWorkflow', () => { existingTransactionDraft: undefined, betas: [], personalDetails: {}, + delegateAccountID: undefined, }); } return waitForBatchedUpdates(); @@ -486,6 +489,7 @@ describe('actions/IOU/ReportWorkflow', () => { existingTransactionDraft: undefined, betas: [], personalDetails: {}, + delegateAccountID: undefined, }); } return waitForBatchedUpdates(); @@ -714,6 +718,7 @@ describe('actions/IOU/ReportWorkflow', () => { existingTransactionDraft: undefined, betas: [], personalDetails: {}, + delegateAccountID: undefined, }); } return waitForBatchedUpdates(); @@ -761,6 +766,7 @@ describe('actions/IOU/ReportWorkflow', () => { existingTransactionDraft: undefined, betas: [], personalDetails: {}, + delegateAccountID: undefined, }); } return waitForBatchedUpdates(); @@ -958,6 +964,7 @@ describe('actions/IOU/ReportWorkflow', () => { quickAction: undefined, betas: [CONST.BETAS.ALL], personalDetails: {}, + delegateAccountID: undefined, }); } return waitForBatchedUpdates(); @@ -1165,6 +1172,7 @@ describe('actions/IOU/ReportWorkflow', () => { quickAction: undefined, betas: [CONST.BETAS.ALL], personalDetails: {}, + delegateAccountID: undefined, }); } await waitForBatchedUpdates(); diff --git a/tests/actions/IOUTest/SplitTest.ts b/tests/actions/IOUTest/SplitTest.ts index 837bbf693194..98471a7be180 100644 --- a/tests/actions/IOUTest/SplitTest.ts +++ b/tests/actions/IOUTest/SplitTest.ts @@ -2134,6 +2134,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { isSelfTourViewed: false, existingTransactionDraft: undefined, personalDetails: {}, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -2362,6 +2363,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { isSelfTourViewed: false, existingTransactionDraft: undefined, personalDetails: {}, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -2948,6 +2950,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { isSelfTourViewed: false, betas: [CONST.BETAS.ALL], personalDetails: {}, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); await getOnyxData({ @@ -3127,6 +3130,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { isSelfTourViewed: false, betas: [CONST.BETAS.ALL], personalDetails: {}, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); await getOnyxData({ @@ -3311,6 +3315,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { isSelfTourViewed: false, betas: [CONST.BETAS.ALL], personalDetails: {}, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -3505,6 +3510,7 @@ describe('updateSplitTransactionsFromSplitExpensesFlow', () => { isSelfTourViewed: false, betas: [CONST.BETAS.ALL], personalDetails: {}, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -3764,6 +3770,7 @@ describe('updateSplitTransactions', () => { betas: [CONST.BETAS.ALL], personalDetails: {}, existingTransactionDraft: undefined, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -3898,6 +3905,7 @@ describe('updateSplitTransactions', () => { personalDetails: {}, existingTransactionDraft: undefined, draftTransactionIDs: [], + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -4032,6 +4040,7 @@ describe('updateSplitTransactions', () => { betas: [CONST.BETAS.ALL], personalDetails: {}, existingTransactionDraft: undefined, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -4177,6 +4186,7 @@ describe('updateSplitTransactions', () => { isSelfTourViewed: false, betas: [CONST.BETAS.ALL], personalDetails: {}, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -7492,6 +7502,7 @@ describe('createDistanceRequest', () => { recentWaypoints: recentWaypoints ?? [], personalDetails: distanceMockPersonalDetails, betas: [CONST.BETAS.ALL], + delegateAccountID: undefined, }; } @@ -7502,6 +7513,7 @@ describe('createDistanceRequest', () => { createDistanceRequest({ ...getDefaultDistanceRequestParams({reportID: '123', type: CONST.REPORT.TYPE.EXPENSE}, {amount: 1}, recentWaypoints), participants: [], + delegateAccountID: undefined, }); expect(notifyNewAction).toHaveBeenCalledTimes(0); @@ -7514,6 +7526,7 @@ describe('createDistanceRequest', () => { createDistanceRequest({ ...getDefaultDistanceRequestParams({reportID: '123'}, {amount: 1}, recentWaypoints), participants: [], + delegateAccountID: undefined, }); expect(notifyNewAction).toHaveBeenCalledTimes(1); @@ -7583,6 +7596,7 @@ describe('createDistanceRequest', () => { ...getDefaultDistanceRequestParams({reportID: '123', type: CONST.REPORT.TYPE.EXPENSE}, {amount: 1}, recentWaypoints), iouType: CONST.IOU.TYPE.SPLIT, participants: [], + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -7593,6 +7607,7 @@ describe('createDistanceRequest', () => { iouType: CONST.IOU.TYPE.SPLIT, participants: [], quickAction: {action: CONST.QUICK_ACTIONS.SEND_MONEY, chatReportID: '456'}, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -7612,6 +7627,7 @@ describe('createDistanceRequest', () => { iouType: CONST.IOU.TYPE.SPLIT, policyRecentlyUsedCurrencies: initialCurrencies, personalDetails: distanceMockPersonalDetails, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -7687,6 +7703,7 @@ describe('createDistanceRequest', () => { {accountID: CARLOS_ACCOUNT_ID, login: CARLOS_EMAIL}, {accountID: VIT_ACCOUNT_ID, login: VIT_EMAIL}, ], + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -7744,6 +7761,7 @@ describe('createDistanceRequest', () => { createDistanceRequest({ ...getDefaultDistanceRequestParams(policyExpenseChat, {amount: 2500, merchant: 'Work Trip', comment: 'Business travel', category: testCategory}, recentWaypoints), policyParams: {policy: fakePolicy, policyCategories: fakeCategories}, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -7893,6 +7911,7 @@ describe('createDistanceRequest', () => { createDistanceRequest({ ...getDefaultDistanceRequestParams(testReport, {amount: 1500, comment: 'Billable distance', billable: true}, recentWaypoints), policyParams: {policy: fakePolicy}, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -7927,6 +7946,7 @@ describe('createDistanceRequest', () => { createDistanceRequest({ ...getDefaultDistanceRequestParams(testReport, {comment: 'Tax distance', taxCode: testTaxCode, taxAmount: testTaxAmount}, recentWaypoints), policyParams: {policy: fakePolicy}, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); diff --git a/tests/actions/IOUTest/TrackExpenseTest.ts b/tests/actions/IOUTest/TrackExpenseTest.ts index 895d58a75b3c..3223f6b83085 100644 --- a/tests/actions/IOUTest/TrackExpenseTest.ts +++ b/tests/actions/IOUTest/TrackExpenseTest.ts @@ -211,6 +211,7 @@ describe('actions/IOU/TrackExpense', () => { betas: [CONST.BETAS.ALL], isSelfTourViewed: false, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, reportActionsList: undefined, }); await waitForBatchedUpdates(); @@ -335,6 +336,7 @@ describe('actions/IOU/TrackExpense', () => { betas: [CONST.BETAS.ALL], isSelfTourViewed: false, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, reportActionsList: undefined, }); await waitForBatchedUpdates(); @@ -444,6 +446,7 @@ describe('actions/IOU/TrackExpense', () => { betas: [CONST.BETAS.ALL], isSelfTourViewed: false, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, reportActionsList: undefined, }); await waitForBatchedUpdates(); @@ -535,6 +538,7 @@ describe('actions/IOU/TrackExpense', () => { betas: [CONST.BETAS.ALL], isSelfTourViewed: false, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, reportActionsList: undefined, }); await waitForBatchedUpdates(); @@ -590,6 +594,7 @@ describe('actions/IOU/TrackExpense', () => { betas: [CONST.BETAS.ALL], isSelfTourViewed: false, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, reportActionsList: undefined, }); await waitForBatchedUpdates(); @@ -673,6 +678,7 @@ describe('actions/IOU/TrackExpense', () => { betas: [CONST.BETAS.ALL], isSelfTourViewed: false, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, reportActionsList: undefined, }); await waitForBatchedUpdates(); @@ -728,6 +734,7 @@ describe('actions/IOU/TrackExpense', () => { betas: [CONST.BETAS.ALL], isSelfTourViewed: false, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, reportActionsList: undefined, }); await waitForBatchedUpdates(); @@ -815,6 +822,7 @@ describe('actions/IOU/TrackExpense', () => { draftTransactionIDs: [transaction.transactionID], isSelfTourViewed: false, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, reportActionsList: undefined, }); await waitForBatchedUpdates(); @@ -870,6 +878,7 @@ describe('actions/IOU/TrackExpense', () => { draftTransactionIDs: [], isSelfTourViewed: false, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, reportActionsList: undefined, }); await waitForBatchedUpdates(); @@ -955,6 +964,7 @@ describe('actions/IOU/TrackExpense', () => { draftTransactionIDs: [transaction.transactionID], isSelfTourViewed: false, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, reportActionsList: undefined, }); await waitForBatchedUpdates(); @@ -1010,6 +1020,7 @@ describe('actions/IOU/TrackExpense', () => { draftTransactionIDs: [], isSelfTourViewed: false, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, reportActionsList: undefined, }); await waitForBatchedUpdates(); @@ -1114,6 +1125,7 @@ describe('actions/IOU/TrackExpense', () => { draftTransactionIDs: [transaction.transactionID], isSelfTourViewed: false, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, reportActionsList: undefined, }); await waitForBatchedUpdates(); @@ -1170,6 +1182,7 @@ describe('actions/IOU/TrackExpense', () => { draftTransactionIDs: [], isSelfTourViewed: false, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -1233,6 +1246,7 @@ describe('actions/IOU/TrackExpense', () => { betas: [CONST.BETAS.ALL], isSelfTourViewed: false, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, reportActionsList: undefined, }; } @@ -1457,6 +1471,7 @@ describe('actions/IOU/TrackExpense', () => { betas: [CONST.BETAS.ALL], isSelfTourViewed: false, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, reportActionsList: undefined, }); await waitForBatchedUpdates(); @@ -1548,6 +1563,7 @@ describe('actions/IOU/TrackExpense', () => { betas: [CONST.BETAS.ALL], isSelfTourViewed: false, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, reportActionsList: undefined, }); await waitForBatchedUpdates(); @@ -1670,6 +1686,7 @@ describe('actions/IOU/TrackExpense', () => { trackExpense({ ...getDefaultTrackExpenseParams(undefined, {amount: 3000, merchant: 'Optimistic SelfDM ID Test'}), optimisticChatReportID: optimisticSelfDMReportID, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); const reports = await new Promise>((resolve) => { @@ -1692,6 +1709,7 @@ describe('actions/IOU/TrackExpense', () => { trackExpense({ ...getDefaultTrackExpenseParams(undefined, {amount: 3000, merchant: 'Optimistic Txn ID Test'}), optimisticTransactionID, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -1758,6 +1776,7 @@ describe('actions/IOU/TrackExpense', () => { receipt: {source: 'new-receipt.jpg', name: 'new-receipt.jpg', state: CONST.IOU.RECEIPT_STATE.SCAN_READY}, }), existingTransaction, + delegateAccountID: undefined, }); await mockFetch?.resume?.(); await waitForBatchedUpdates(); @@ -1887,6 +1906,7 @@ describe('actions/IOU/TrackExpense', () => { ...getDefaultTrackExpenseParams(selfDMReport, {amount: 12000, merchant: 'Tour Viewed Merchant'}), isSelfTourViewed: true, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, reportActionsList: undefined, }); await waitForBatchedUpdates(); @@ -1921,6 +1941,7 @@ describe('actions/IOU/TrackExpense', () => { ...getDefaultTrackExpenseParams(selfDMReport, {amount: 9000, merchant: 'Tour Not Viewed Merchant'}), isSelfTourViewed: false, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, reportActionsList: undefined, }); await waitForBatchedUpdates(); @@ -1977,6 +1998,7 @@ describe('actions/IOU/TrackExpense', () => { betas: [CONST.BETAS.ALL], isSelfTourViewed: true, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, }); // Then the result should contain valid track expense data @@ -2023,6 +2045,7 @@ describe('actions/IOU/TrackExpense', () => { betas: [CONST.BETAS.ALL], isSelfTourViewed: false, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, }); // Then the result should contain valid track expense data @@ -2071,6 +2094,7 @@ describe('actions/IOU/TrackExpense', () => { betas: [CONST.BETAS.ALL], isSelfTourViewed: true, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, }); // Then result should be valid @@ -2110,6 +2134,7 @@ describe('actions/IOU/TrackExpense', () => { betas: [CONST.BETAS.ALL], isSelfTourViewed: false, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, }); expect(resultWithoutTourViewed).toBeDefined(); @@ -2117,6 +2142,28 @@ describe('actions/IOU/TrackExpense', () => { expect(resultWithoutTourViewed.transaction).toBeDefined(); }); + describe('delegateAccountID forwarding', () => { + it('sets delegateAccountID on the IOU action when delegateAccountID is provided', async () => { + const DELEGATE_ACCOUNT_ID = 999; + const selfDMReport: Report = { + ...createRandomReport(1, CONST.REPORT.CHAT_TYPE.SELF_DM), + reportID: 'selfDM-delegate-forward', + }; + + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${selfDMReport.reportID}`, selfDMReport); + + trackExpense({ + ...getDefaultTrackExpenseParams(selfDMReport), + delegateAccountID: DELEGATE_ACCOUNT_ID, + }); + await waitForBatchedUpdates(); + + const reportActions = await getOnyxValue(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${selfDMReport.reportID}`); + const iouAction = Object.values(reportActions ?? {}).find((action) => isMoneyRequestAction(action)); + expect(iouAction?.delegateAccountID).toBe(DELEGATE_ACCOUNT_ID); + }); + }); + it('getTrackExpenseInformation with isDraftChatReport:true should produce createdWorkspaceParams', () => { // Given a selfDM report that is a draft (not yet committed to the server) const draftSelfDMReport: Report = { @@ -2154,6 +2201,7 @@ describe('actions/IOU/TrackExpense', () => { betas: [CONST.BETAS.ALL], isSelfTourViewed: false, currentUserLocalCurrency: 'USD', + delegateAccountID: undefined, isDraftChatReport: true, }); @@ -2200,6 +2248,7 @@ describe('actions/IOU/TrackExpense', () => { betas: [CONST.BETAS.ALL], isSelfTourViewed: false, currentUserLocalCurrency: 'USD', + delegateAccountID: undefined, isDraftChatReport: false, }); @@ -2263,6 +2312,7 @@ describe('actions/IOU/TrackExpense', () => { quickAction: undefined, betas: [CONST.BETAS.ALL], personalDetails: {}, + delegateAccountID: undefined, }); await mockFetch?.resume?.(); await waitForBatchedUpdates(); @@ -2365,6 +2415,7 @@ describe('actions/IOU/TrackExpense', () => { betas: [CONST.BETAS.ALL], isSelfTourViewed: false, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, reportActionsList: undefined, }); await waitForBatchedUpdates(); @@ -2671,6 +2722,7 @@ describe('actions/IOU/TrackExpense', () => { betas: [CONST.BETAS.ALL], isSelfTourViewed: false, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, reportActionsList: undefined, }); await waitForBatchedUpdates(); @@ -2858,6 +2910,7 @@ describe('actions/IOU/TrackExpense', () => { personalDetails: testPersonalDetails, policyTagList: undefined, betas: [CONST.BETAS.ALL], + delegateAccountID: undefined, }); }).not.toThrow(); }); @@ -2929,6 +2982,7 @@ describe('actions/IOU/TrackExpense', () => { personalDetails: testPersonalDetails, policyTagList: undefined, betas: [CONST.BETAS.ALL], + delegateAccountID: undefined, }); }).not.toThrow(); }); @@ -2970,6 +3024,7 @@ describe('actions/IOU/TrackExpense', () => { personalDetails: undefined, policyTagList: undefined, betas: [CONST.BETAS.ALL], + delegateAccountID: undefined, }); }).not.toThrow(); }); @@ -3011,6 +3066,7 @@ describe('actions/IOU/TrackExpense', () => { personalDetails: undefined, policyTagList: undefined, betas: [CONST.BETAS.ALL], + delegateAccountID: undefined, }); }).not.toThrow(); }); diff --git a/tests/actions/TransactionTest.ts b/tests/actions/TransactionTest.ts index e786764f0022..13ca356cffe7 100644 --- a/tests/actions/TransactionTest.ts +++ b/tests/actions/TransactionTest.ts @@ -237,6 +237,7 @@ describe('actions/Transaction', () => { draftTransactionIDs: [], isSelfTourViewed: false, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, reportActionsList: undefined, }); await getOnyxData({ @@ -496,6 +497,7 @@ describe('actions/Transaction', () => { quickAction: undefined, betas: [CONST.BETAS.ALL], personalDetails: {}, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); await getOnyxData({ @@ -675,6 +677,7 @@ describe('actions/Transaction', () => { quickAction: undefined, betas: [CONST.BETAS.ALL], personalDetails: {}, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); await getOnyxData({ @@ -859,6 +862,7 @@ describe('actions/Transaction', () => { quickAction: undefined, betas: [CONST.BETAS.ALL], personalDetails: {}, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); @@ -1053,6 +1057,7 @@ describe('actions/Transaction', () => { quickAction: undefined, betas: [CONST.BETAS.ALL], personalDetails: {}, + delegateAccountID: undefined, }); await waitForBatchedUpdates(); diff --git a/tests/ui/UnreadIndicatorsTest.tsx b/tests/ui/UnreadIndicatorsTest.tsx index bf30ed352231..e2888b3db697 100644 --- a/tests/ui/UnreadIndicatorsTest.tsx +++ b/tests/ui/UnreadIndicatorsTest.tsx @@ -807,6 +807,7 @@ describe('Unread Indicators', () => { betas: [CONST.BETAS.ALL], isSelfTourViewed: false, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, reportActionsList: undefined, }); await waitForBatchedUpdates(); diff --git a/tests/unit/GoogleTagManagerTest.tsx b/tests/unit/GoogleTagManagerTest.tsx index ed49f9da198a..83024f829282 100644 --- a/tests/unit/GoogleTagManagerTest.tsx +++ b/tests/unit/GoogleTagManagerTest.tsx @@ -290,6 +290,7 @@ describe('GoogleTagManagerTest', () => { betas: [CONST.BETAS.ALL], isSelfTourViewed: false, currentUserLocalCurrency: undefined, + delegateAccountID: undefined, reportActionsList: undefined, });