From 7939e3b266b0c97be93f9089846279039156694f Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Thu, 13 Mar 2025 23:20:17 +0700 Subject: [PATCH 1/3] fix: expense is created in the task report --- src/libs/ReportUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 2e86cc300d55..34423f87a3e7 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -7430,7 +7430,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; }); } From b7e6dbf7f6f9550a9fb38ed035ffc19112285ec2 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Sat, 15 Mar 2025 16:55:42 +0700 Subject: [PATCH 2/3] add test --- tests/unit/ReportUtilsTest.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 72144af19b6b..a76732f7e710 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', () => { From dc2f58792ba9762e63ed3cb1fc6f1de12055f118 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Sat, 15 Mar 2025 16:58:06 +0700 Subject: [PATCH 3/3] run prettier --- tests/unit/ReportUtilsTest.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index a76732f7e710..45e6b29d52d5 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -1928,7 +1928,7 @@ describe('ReportUtils', () => { policyID: '1', chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, type: CONST.REPORT.TYPE.CHAT, - } + }; const taskReport: Report = { ...createRandomReport(10), @@ -1938,14 +1938,14 @@ describe('ReportUtils', () => { 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', () => {