diff --git a/src/libs/actions/IOU/TrackExpense.ts b/src/libs/actions/IOU/TrackExpense.ts index bb33b98ee55d..2502540e3f90 100644 --- a/src/libs/actions/IOU/TrackExpense.ts +++ b/src/libs/actions/IOU/TrackExpense.ts @@ -182,6 +182,8 @@ type GetTrackExpenseInformationParams = { quickAction: OnyxEntry; betas: OnyxEntry; isSelfTourViewed: boolean; + // TODO: Make it required once we complete refactoring the getTrackExpenseInformation function to use hasCompletedGuidedSetupFlow. Refactor issue: https://github.com/Expensify/App/issues/66424 + hasCompletedGuidedSetupFlow?: boolean; defaultWorkspaceName?: string; optimisticChatReportID?: string; currentUserLocalCurrency: string | undefined; @@ -831,6 +833,7 @@ function getTrackExpenseInformation(params: GetTrackExpenseInformationParams): T defaultWorkspaceName, optimisticChatReportID, delegateAccountID, + hasCompletedGuidedSetupFlow, currentUserLocalCurrency, } = params; const {payeeAccountID = currentUserAccountIDParam, payeeEmail = currentUserEmailParam, participant} = participantParams; @@ -979,6 +982,7 @@ function getTrackExpenseInformation(params: GetTrackExpenseInformationParams): T hasActiveAdminPolicies: undefined, betas, isSelfTourViewed, + hasCompletedGuidedSetupFlow, }); createdWorkspaceParams = workspaceData.params; onyxData.optimisticData?.push(...(workspaceData.optimisticData ?? [])); @@ -2322,6 +2326,7 @@ function trackExpense(params: CreateTrackExpenseParams) { recentWaypoints = [], betas, isSelfTourViewed, + hasCompletedGuidedSetupFlow, defaultWorkspaceName, previousOdometerDraft, delegateAccountID, @@ -2483,6 +2488,7 @@ function trackExpense(params: CreateTrackExpenseParams) { quickAction, betas, isSelfTourViewed, + hasCompletedGuidedSetupFlow, defaultWorkspaceName, optimisticChatReportID, delegateAccountID, diff --git a/src/libs/actions/IOU/types/CreateTrackExpenseParams.ts b/src/libs/actions/IOU/types/CreateTrackExpenseParams.ts index 7bd2b21ad2c7..08afd22a33b7 100644 --- a/src/libs/actions/IOU/types/CreateTrackExpenseParams.ts +++ b/src/libs/actions/IOU/types/CreateTrackExpenseParams.ts @@ -34,6 +34,8 @@ type CreateTrackExpenseParams = { recentWaypoints: OnyxEntry; betas: OnyxEntry; isSelfTourViewed: boolean; + // TODO: Make it required once we complete refactoring the trackExpense function to use hasCompletedGuidedSetupFlow. Refactor issue: https://github.com/Expensify/App/issues/66424 + hasCompletedGuidedSetupFlow?: boolean; defaultWorkspaceName?: string; currentUserLocalCurrency: string | undefined; previousOdometerDraft?: OnyxEntry; diff --git a/src/libs/actions/Policy/Policy.ts b/src/libs/actions/Policy/Policy.ts index ad7bfe87022b..d934e7cb4acb 100644 --- a/src/libs/actions/Policy/Policy.ts +++ b/src/libs/actions/Policy/Policy.ts @@ -232,6 +232,8 @@ type BuildPolicyDataOptions = { type?: typeof CONST.POLICY.TYPE.TEAM | typeof CONST.POLICY.TYPE.CORPORATE | typeof CONST.POLICY.TYPE.SUBMIT; // TODO: Make it required once we complete refactoring the buildPolicyData function to use isSelfTourViewed. Refactor issue: https://github.com/Expensify/App/issues/66424 isSelfTourViewed?: boolean; + // TODO: Make it required once we complete refactoring the buildPolicyData function to use hasCompletedGuidedSetupFlow. Refactor issue: https://github.com/Expensify/App/issues/66424 + hasCompletedGuidedSetupFlow?: boolean; hasActiveAdminPolicies: boolean | undefined; betas?: OnyxEntry; personalTrackGoal?: string; @@ -2563,6 +2565,7 @@ function buildPolicyData(options: BuildPolicyDataOptions): OnyxData { expect(resultWithoutTourViewed.chatReport).toBeDefined(); expect(resultWithoutTourViewed.transaction).toBeDefined(); }); + + it('should pass hasCompletedGuidedSetupFlow: true to trackExpense and create transaction successfully', async () => { + // Given a selfDM report + const selfDMReport: Report = { + ...createRandomReport(1, CONST.REPORT.CHAT_TYPE.SELF_DM), + reportID: 'selfDM-guided-setup-1', + }; + + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${selfDMReport.reportID}`, selfDMReport); + + // When trackExpense is called with hasCompletedGuidedSetupFlow: true + trackExpense({ + ...getDefaultTrackExpenseParams(selfDMReport, {amount: 11000, merchant: 'Guided Setup Complete Merchant'}), + hasCompletedGuidedSetupFlow: true, + }); + await waitForBatchedUpdates(); + + // Then the transaction should be created with correct values + let transactions: OnyxCollection; + await getOnyxData({ + key: ONYXKEYS.COLLECTION.TRANSACTION, + waitForCollectionCallback: true, + callback: (val) => { + transactions = val; + }, + }); + + const createdTransaction = Object.values(transactions ?? {}).at(0); + expect(createdTransaction).toBeTruthy(); + expect(Math.abs(createdTransaction?.amount ?? 0)).toBe(11000); + expect(createdTransaction?.merchant).toBe('Guided Setup Complete Merchant'); + }); + + it('should pass hasCompletedGuidedSetupFlow: false to trackExpense and create transaction successfully', async () => { + // Given a selfDM report + const selfDMReport: Report = { + ...createRandomReport(1, CONST.REPORT.CHAT_TYPE.SELF_DM), + reportID: 'selfDM-guided-setup-2', + }; + + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${selfDMReport.reportID}`, selfDMReport); + + // When trackExpense is called with hasCompletedGuidedSetupFlow: false + trackExpense({ + ...getDefaultTrackExpenseParams(selfDMReport, {amount: 8000, merchant: 'Guided Setup Incomplete Merchant'}), + hasCompletedGuidedSetupFlow: false, + }); + await waitForBatchedUpdates(); + + // Then the transaction should be created with correct values + let transactions: OnyxCollection; + await getOnyxData({ + key: ONYXKEYS.COLLECTION.TRANSACTION, + waitForCollectionCallback: true, + callback: (val) => { + transactions = val; + }, + }); + + const createdTransaction = Object.values(transactions ?? {}).at(0); + expect(createdTransaction).toBeTruthy(); + expect(Math.abs(createdTransaction?.amount ?? 0)).toBe(8000); + expect(createdTransaction?.merchant).toBe('Guided Setup Incomplete Merchant'); + }); + + it('should pass hasCompletedGuidedSetupFlow: undefined to trackExpense and create transaction successfully', async () => { + // Given a selfDM report + const selfDMReport: Report = { + ...createRandomReport(1, CONST.REPORT.CHAT_TYPE.SELF_DM), + reportID: 'selfDM-guided-setup-3', + }; + + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${selfDMReport.reportID}`, selfDMReport); + + // When trackExpense is called without hasCompletedGuidedSetupFlow (undefined) + trackExpense({ + ...getDefaultTrackExpenseParams(selfDMReport, {amount: 6000, merchant: 'Guided Setup Undefined Merchant'}), + hasCompletedGuidedSetupFlow: undefined, + }); + await waitForBatchedUpdates(); + + // Then the transaction should be created with correct values + let transactions: OnyxCollection; + await getOnyxData({ + key: ONYXKEYS.COLLECTION.TRANSACTION, + waitForCollectionCallback: true, + callback: (val) => { + transactions = val; + }, + }); + + const createdTransaction = Object.values(transactions ?? {}).at(0); + expect(createdTransaction).toBeTruthy(); + expect(Math.abs(createdTransaction?.amount ?? 0)).toBe(6000); + expect(createdTransaction?.merchant).toBe('Guided Setup Undefined Merchant'); + }); }); describe('requestMoney', () => {