Skip to content
Merged
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
3 changes: 3 additions & 0 deletions src/libs/actions/MergeTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ function getTransactionsForMerging({
cardList?: CardList;
}) {
const transactionID = targetTransaction.transactionID;
if (!transactionID) {
return;
}

// Collect/Control workspaces:
// - Admins and approvers: The list of eligible expenses will only contain the expenses from the report that the admin/approver triggered the merge from. This is intentionally limited since they’ll only be reviewing one report at a time.
Expand Down
28 changes: 27 additions & 1 deletion tests/actions/MergeTransactionTest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {getReportPreviewAction} from '@libs/actions/IOU/MoneyRequestBuilder';
import {areTransactionsEligibleForMerge, mergeTransactionRequest, setMergeTransactionKey, setupMergeTransactionData} from '@libs/actions/MergeTransaction';
import {areTransactionsEligibleForMerge, getTransactionsForMerging, mergeTransactionRequest, setMergeTransactionKey, setupMergeTransactionData} from '@libs/actions/MergeTransaction';
import {addComment, openReport} from '@libs/actions/Report';
import {WRITE_COMMANDS} from '@libs/API/types';
import {getLoginsByAccountIDs} from '@libs/PersonalDetailsUtils';
Expand Down Expand Up @@ -1428,6 +1428,32 @@ describe('mergeTransactionRequest', () => {
});
});

describe('getTransactionsForMerging', () => {
beforeEach(() => {
return Onyx.clear().then(waitForBatchedUpdates);
});

it('should do nothing when the target transaction has no transactionID', async () => {
// Given a target transaction with an empty transactionID
const targetTransaction = {...createRandomTransaction(0), transactionID: ''} as Transaction;

// When we request merge candidates for it (offline path, which would otherwise write eligible transactions locally)
getTransactionsForMerging({
isOffline: true,
targetTransaction,
transactions: {},
policy: undefined,
report: undefined,
currentUserLogin: undefined,
});
await waitForBatchedUpdates();

// Then no merge transaction entry is written for the empty key
const mergeTransaction = await getOnyxValue(`${ONYXKEYS.COLLECTION.MERGE_TRANSACTION}${targetTransaction.transactionID}`);
expect(mergeTransaction).toBeUndefined();
});
});

describe('setupMergeTransactionData', () => {
beforeEach(() => {
return Onyx.clear().then(waitForBatchedUpdates);
Expand Down
Loading