diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 5ae882182330..b287167f7e53 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -7477,7 +7477,7 @@ function getPolicyExpenseChat(ownerAccountID: number | undefined, policyID: stri return false; } - return report.policyID === policyID && isPolicyExpenseChat(report) && report.ownerAccountID === ownerAccountID; + return report.policyID === policyID && isPolicyExpenseChat(report) && !isThread(report) && report.ownerAccountID === ownerAccountID; }); } diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 72144af19b6b..45e6b29d52d5 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -22,6 +22,7 @@ import { getIconsForParticipants, getInvoiceChatByParticipants, getMostRecentlyVisitedReport, + getPolicyExpenseChat, getQuickActionDetails, getReportIDFromLink, getReportName, @@ -1919,6 +1920,33 @@ describe('ReportUtils', () => { }); }); + describe('getPolicyExpenseChat', () => { + it('should return the correct policy expense chat when we have a task report is the child of this report', async () => { + const policyExpenseChat: Report = { + ...createRandomReport(11), + ownerAccountID: 1, + policyID: '1', + chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, + type: CONST.REPORT.TYPE.CHAT, + }; + + const taskReport: Report = { + ...createRandomReport(10), + ownerAccountID: 1, + policyID: '1', + chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, + type: CONST.REPORT.TYPE.TASK, + parentReportID: policyExpenseChat.reportID, + parentReportActionID: '1', + }; + + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${taskReport.reportID}`, taskReport); + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${policyExpenseChat.reportID}`, policyExpenseChat); + + expect(getPolicyExpenseChat(1, '1')?.reportID).toBe(policyExpenseChat.reportID); + }); + }); + describe('getApprovalChain', () => { describe('submit and close policy', () => { it('should return empty array', () => {