From 4a8d3848246cbdbd19a70e3b5aa8e04cc65aae28 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Thu, 31 Jul 2025 22:22:31 +0700 Subject: [PATCH 1/3] fix: expense created offline for new chat shows two avatar --- src/libs/ReportUtils.ts | 2 ++ tests/unit/ReportUtilsTest.ts | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index c68c280a7002..7dcb2f934b44 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -6675,6 +6675,8 @@ function buildOptimisticReportPreview( childLastActorAccountID: currentUserAccountID, childLastMoneyRequestComment: comment, childRecentReceiptTransactionIDs: hasReceipt && !isEmptyObject(transaction) && transaction?.transactionID ? {[transaction.transactionID]: created} : undefined, + childOwnerAccountID: iouReport?.ownerAccountID, + childManagerAccountID: iouReport?.managerID, ...((isTestDriveTransaction || isTestTransaction) && !isScanRequest && {childStateNum: 2, childStatusNum: 4}), }; } diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 6d0085f770b3..54a906ea7ec8 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -4978,4 +4978,28 @@ describe('ReportUtils', () => { expect(getReportStatusTranslation(undefined, CONST.REPORT.STATUS_NUM.OPEN)).toBe(''); }); }); + + describe('buildOptimisticReportPreview', () => { + it('should include childOwnerAccountID and childManagerAccountID that matches with iouReport data', () => { + const chatReport: Report = { + ...createRandomReport(1), + type: CONST.REPORT.TYPE.CHAT, + chatType: undefined, + }; + + const iouReport: Report = { + ...createRandomReport(2), + parentReportID: '1', + type: CONST.REPORT.TYPE.IOU, + chatType: undefined, + ownerAccountID: 1, + managerID: 2, + }; + + const reportPreviewAction = buildOptimisticReportPreview(chatReport, iouReport); + + expect(reportPreviewAction.childOwnerAccountID).toBe(iouReport.ownerAccountID); + expect(reportPreviewAction.childManagerAccountID).toBe(iouReport.managerID); + }); + }); }); From 20daedf1b704a7b0b4b84e8465d88aba72141a61 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Thu, 31 Jul 2025 23:30:30 +0700 Subject: [PATCH 2/3] fix test --- tests/unit/ReportUtilsTest.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 39f4ae516c53..6552e4939f2e 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -4982,13 +4982,13 @@ describe('ReportUtils', () => { describe('buildOptimisticReportPreview', () => { it('should include childOwnerAccountID and childManagerAccountID that matches with iouReport data', () => { const chatReport: Report = { - ...createRandomReport(1), + ...createRandomReport(100), type: CONST.REPORT.TYPE.CHAT, chatType: undefined, }; const iouReport: Report = { - ...createRandomReport(2), + ...createRandomReport(200), parentReportID: '1', type: CONST.REPORT.TYPE.IOU, chatType: undefined, From 27feda2e9de39773ee97d86fe820bbfdd6937935 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Thu, 31 Jul 2025 23:55:13 +0700 Subject: [PATCH 3/3] fix wrong code --- tests/unit/ReportUtilsTest.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 6552e4939f2e..d1d948b090d0 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -1926,7 +1926,7 @@ describe('ReportUtils', () => { expenseCreatedAction.childReportID = transactionThreadReport.reportID; await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, { - currentUserAccountID: { + [currentUserAccountID]: { accountID: currentUserAccountID, displayName: currentUserEmail, login: currentUserEmail,