Skip to content

Commit 4db0fc1

Browse files
authored
Merge pull request Expensify#63546 from software-mansion-labs/korytko/remove-pay-from-transaction-count
[Better Expense Report Preview] Fix one-expense report view not displaying properly when we have one expense that was paid
2 parents 7388329 + da7cebc commit 4db0fc1

3 files changed

Lines changed: 77 additions & 3 deletions

File tree

src/libs/ReportActionsUtils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,9 @@ function getOneTransactionThreadReportID(
12391239

12401240
const iouRequestActions = [];
12411241
for (const action of reportActionsArray) {
1242-
if (!isIOUActionMatchingTransactionList(action, reportTransactionIDs, true)) {
1242+
// If the original message is a 'pay' IOU, it shouldn't be added to the transaction count.
1243+
// However, it is excluded from the matching function in order to display it properly, so we need to compare the type here.
1244+
if (!isIOUActionMatchingTransactionList(action, reportTransactionIDs, true) || getOriginalMessage(action)?.type === CONST.IOU.REPORT_ACTION_TYPE.PAY) {
12431245
// eslint-disable-next-line no-continue
12441246
continue;
12451247
}

tests/unit/ReportActionsUtilsTest.ts

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import type {KeyValueMapping} from 'react-native-onyx';
22
import Onyx from 'react-native-onyx';
33
import {isExpenseReport} from '@libs/ReportUtils';
44
import {actionR14932 as mockIOUAction, originalMessageR14932 as mockOriginalMessage} from '../../__mocks__/reportData/actions';
5+
import {iouReportR14932 as mockIOUReport} from '../../__mocks__/reportData/reports';
56
import CONST from '../../src/CONST';
67
import * as ReportActionsUtils from '../../src/libs/ReportActionsUtils';
7-
import {isIOUActionMatchingTransactionList} from '../../src/libs/ReportActionsUtils';
8+
import {getOneTransactionThreadReportID, getOriginalMessage, isIOUActionMatchingTransactionList} from '../../src/libs/ReportActionsUtils';
89
import ONYXKEYS from '../../src/ONYXKEYS';
910
import type {Report, ReportAction} from '../../src/types/onyx';
1011
import createRandomReport from '../utils/collections/reports';
@@ -353,6 +354,75 @@ describe('ReportActionsUtils', () => {
353354
});
354355
});
355356

357+
describe('getOneTransactionThreadReportID', () => {
358+
const IOUReportID = 'REPORT_IOU';
359+
const IOUExpenseReportID = 'REPORT_EXPENSE';
360+
const IOUTransactionID = 'TRANSACTION_IOU';
361+
const IOUExpenseTransactionID = 'TRANSACTION_EXPENSE';
362+
363+
const mockedReports: Record<`${typeof ONYXKEYS.COLLECTION.REPORT}${string}`, Report> = {
364+
[`${ONYXKEYS.COLLECTION.REPORT}${IOUReportID}`]: {...mockIOUReport, reportID: IOUReportID},
365+
[`${ONYXKEYS.COLLECTION.REPORT}${IOUExpenseReportID}`]: {...mockIOUReport, type: CONST.REPORT.TYPE.EXPENSE, reportID: IOUExpenseReportID},
366+
};
367+
368+
const linkedCreateAction = {
369+
...mockIOUAction,
370+
originalMessage: {...getOriginalMessage(mockIOUAction), IOUTransactionID},
371+
};
372+
373+
const unlinkedCreateAction = {
374+
...mockIOUAction,
375+
originalMessage: {...getOriginalMessage(mockIOUAction), IOUTransactionID: IOUExpenseTransactionID},
376+
};
377+
378+
const linkedDeleteAction = {
379+
...mockIOUAction,
380+
originalMessage: {
381+
...getOriginalMessage(mockIOUAction),
382+
IOUTransactionID,
383+
type: CONST.IOU.REPORT_ACTION_TYPE.DELETE,
384+
},
385+
};
386+
387+
const linkedPayAction = {
388+
...mockIOUAction,
389+
originalMessage: {
390+
...getOriginalMessage(mockIOUAction),
391+
IOUTransactionID,
392+
type: CONST.IOU.REPORT_ACTION_TYPE.PAY,
393+
},
394+
};
395+
396+
beforeEach(async () => {
397+
await Onyx.mergeCollection(ONYXKEYS.COLLECTION.REPORT, mockedReports);
398+
});
399+
400+
it('should return the childReportID for a valid single IOU action', () => {
401+
const result = getOneTransactionThreadReportID(IOUReportID, [linkedCreateAction], false, [IOUTransactionID]);
402+
expect(result).toEqual(linkedCreateAction.childReportID);
403+
});
404+
405+
it('should return undefined for action with a transaction that is not linked to it', () => {
406+
const result = getOneTransactionThreadReportID(IOUReportID, [unlinkedCreateAction], false, [IOUTransactionID]);
407+
expect(result).toBeUndefined();
408+
});
409+
410+
it('should return undefined if multiple IOU actions are present', () => {
411+
const result = getOneTransactionThreadReportID(IOUReportID, [linkedCreateAction, linkedCreateAction], false, [IOUTransactionID]);
412+
expect(result).toBeUndefined();
413+
});
414+
415+
it('should skip actions where original message type is PAY', () => {
416+
const result = getOneTransactionThreadReportID(IOUReportID, [linkedPayAction, linkedCreateAction], false, [IOUTransactionID]);
417+
expect(result).toEqual(linkedCreateAction.childReportID);
418+
});
419+
420+
it('should return undefined if no valid IOU actions are present', () => {
421+
const result = getOneTransactionThreadReportID(IOUReportID, [unlinkedCreateAction, linkedDeleteAction, linkedPayAction], false, [IOUTransactionID]);
422+
expect(result).toBeUndefined();
423+
});
424+
});
425+
356426
describe('getSortedReportActionsForDisplay', () => {
357427
it('should filter out non-whitelisted actions', () => {
358428
const input: ReportAction[] = [
@@ -786,6 +856,8 @@ describe('ReportActionsUtils', () => {
786856
});
787857
});
788858

859+
describe('getOneTransactionThreadReportID', () => {});
860+
789861
describe('shouldShowAddMissingDetails', () => {
790862
it('should return true if personal detail is not completed', async () => {
791863
const card = {

tests/unit/ReportPrimaryActionUtilsTest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ describe('getPrimaryAction', () => {
236236
},
237237
],
238238
originalMessage: {
239-
type: CONST.IOU.REPORT_ACTION_TYPE.PAY,
239+
type: CONST.IOU.REPORT_ACTION_TYPE.CREATE,
240240
IOUTransactionID: TRANSACTION_ID,
241241
},
242242
} as unknown as ReportAction;

0 commit comments

Comments
 (0)