Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/libs/actions/IOU/Duplicate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -875,8 +875,9 @@ function duplicateExpenseTransaction({
getCurrencyDecimals,
};

// If no workspace is provided the expense should be unreported
if (!targetPolicy) {
// A duplicate mirrors the source, so an unreported source stays unreported even when a workspace is available
const isSourceUnreported = !transaction.reportID || transaction.reportID === CONST.REPORT.UNREPORTED_REPORT_ID;
if (!targetPolicy || isSourceUnreported) {
const trackExpenseParams: CreateTrackExpenseParams = {
...params,
participantParams: {
Expand Down
48 changes: 48 additions & 0 deletions tests/actions/IOUTest/DuplicateTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2083,6 +2083,54 @@ describe('actions/Duplicate', () => {
expect(writeSpy).toHaveBeenCalledWith(WRITE_COMMANDS.TRACK_EXPENSE, expect.objectContaining({}), expect.objectContaining({}));
});

it('should call trackExpense when the source expense is unreported even though a targetPolicy is provided', async () => {
const {waypoints, ...restOfComment} = mockTransaction.comment ?? {};
const mockUnreportedTransaction = {
...mockTransaction,
reportID: CONST.REPORT.UNREPORTED_REPORT_ID,
amount: mockTransaction.amount * -1,
comment: {
...restOfComment,
},
};

await Onyx.clear();

duplicateExpenseTransaction({
dateFnsLocale: undefined,
transaction: mockUnreportedTransaction,
optimisticChatReportID: mockOptimisticChatReportID,
optimisticIOUReportID: mockOptimisticIOUReportID,
isASAPSubmitBetaEnabled: mockIsASAPSubmitBetaEnabled,
introSelected: undefined,
quickAction: undefined,
policyRecentlyUsedCurrencies: [],
isSelfTourViewed: false,
customUnitPolicyID: '',
targetPolicy: mockPolicy,
targetPolicyCategories: fakePolicyCategories,
targetReport: policyExpenseChat,
existingTransactionDraft: undefined,
betas: [CONST.BETAS.ALL],
personalDetails: mockPersonalDetails,
recentWaypoints,
targetPolicyTags,
policyTagList: targetPolicyTags ?? {},
currentUser: {accountID: RORY_ACCOUNT_ID, email: RORY_EMAIL},
currentUserLocalCurrency: undefined,
delegateAccountID: undefined,
isTrackIntentUser: false,
formatPhoneNumber,
getCurrencyDecimals: getCurrencyDecimalsLocal,
participantsPolicyTags: {},
});

await waitForBatchedUpdates();

expect(writeSpy).toHaveBeenCalledWith(WRITE_COMMANDS.TRACK_EXPENSE, expect.objectContaining({}), expect.objectContaining({}));
expect(writeSpy).not.toHaveBeenCalledWith(WRITE_COMMANDS.REQUEST_MONEY, expect.objectContaining({}), expect.objectContaining({}));
});

it('should call createDistanceRequest for distance transactions', async () => {
const mockDistanceTransaction = {
...mockTransaction,
Expand Down
Loading