diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 82789d2a4eb5..86477f624d88 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -7940,6 +7940,7 @@ function buildOptimisticGroupChatReport( participantAccountIDs: number[], reportName: string, avatarUri: string, + currentUserAccountID: number, optimisticReportID?: string, notificationPreference?: NotificationPreference, ) { @@ -7950,6 +7951,7 @@ function buildOptimisticGroupChatReport( notificationPreference, avatarUrl: avatarUri, optimisticReportID, + currentUserAccountID, }); } diff --git a/src/libs/actions/Report/index.ts b/src/libs/actions/Report/index.ts index a9e5d5f5b452..1c4fdfb8d1bd 100644 --- a/src/libs/actions/Report/index.ts +++ b/src/libs/actions/Report/index.ts @@ -2013,13 +2013,14 @@ function navigateToAndCreateGroupChat( introSelected: OnyxEntry, isSelfTourViewed: boolean | undefined, betas: OnyxEntry, + currentUserAccountID: number, avatarUri?: string, avatarFile?: File | CustomRNImageManipulatorResult | undefined, ) { const participantAccountIDs = PersonalDetailsUtils.getAccountIDsByLogins(userLogins); // If we are creating a group chat then participantAccountIDs is expected to contain currentUserAccountID - const newChat = buildOptimisticGroupChatReport(participantAccountIDs, reportName, avatarUri ?? '', optimisticReportID, CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN); + const newChat = buildOptimisticGroupChatReport(participantAccountIDs, reportName, avatarUri ?? '', currentUserAccountID, optimisticReportID, CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN); createGroupChat(newChat.reportID, userLogins, newChat, currentUserLogin, introSelected, isSelfTourViewed, betas, avatarFile); navigateToReport(newChat.reportID); diff --git a/src/pages/NewChatConfirmPage.tsx b/src/pages/NewChatConfirmPage.tsx index 798295892f13..1ead666dd45b 100644 --- a/src/pages/NewChatConfirmPage.tsx +++ b/src/pages/NewChatConfirmPage.tsx @@ -171,6 +171,7 @@ function NewChatConfirmPage() { introSelected, isSelfTourViewed, betas, + personalData.accountID, newGroupDraft.avatarUri ?? '', avatarFile, ); diff --git a/tests/actions/ReportTest.ts b/tests/actions/ReportTest.ts index a74603ef8da4..53c0209b0e99 100644 --- a/tests/actions/ReportTest.ts +++ b/tests/actions/ReportTest.ts @@ -5867,7 +5867,16 @@ describe('actions/Report', () => { await waitForBatchedUpdates(); // When create group chat is called - Report.navigateToAndCreateGroupChat([TEST_USER_LOGIN, PARTICIPANT_1_LOGIN], GROUP_CHAT_NAME, TEST_USER_LOGIN, GROUP_CHAT_REPORT_ID, TEST_INTRO_SELECTED, false, undefined); + Report.navigateToAndCreateGroupChat( + [TEST_USER_LOGIN, PARTICIPANT_1_LOGIN], + GROUP_CHAT_NAME, + TEST_USER_LOGIN, + GROUP_CHAT_REPORT_ID, + TEST_INTRO_SELECTED, + false, + undefined, + TEST_USER_ACCOUNT_ID, + ); await waitForBatchedUpdates(); // Then it should create a new group chat report in Onyx @@ -5921,6 +5930,7 @@ describe('actions/Report', () => { TEST_INTRO_SELECTED, true, undefined, + TEST_USER_ACCOUNT_ID, AVATAR_URI, ); await waitForBatchedUpdates(); @@ -5955,6 +5965,7 @@ describe('actions/Report', () => { {...TEST_INTRO_SELECTED, isInviteOnboardingComplete: true}, true, undefined, + TEST_USER_ACCOUNT_ID, ); await waitForBatchedUpdates(); @@ -5981,6 +5992,7 @@ describe('actions/Report', () => { {choice: CONST.ONBOARDING_CHOICES.ADMIN}, false, undefined, + TEST_USER_ACCOUNT_ID, undefined, avatarFile, ); @@ -6011,6 +6023,7 @@ describe('actions/Report', () => { {choice: CONST.ONBOARDING_CHOICES.ADMIN}, false, undefined, + TEST_USER_ACCOUNT_ID, ); await waitForBatchedUpdates(); diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 84376c6634f2..1f4f4eedb476 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -42,6 +42,7 @@ import { buildOptimisticCreatedReportForUnapprovedAction, buildOptimisticEmptyReport, buildOptimisticExpenseReport, + buildOptimisticGroupChatReport, buildOptimisticInvoiceReport, buildOptimisticIOUReportAction, buildOptimisticReportPreview, @@ -6737,6 +6738,43 @@ describe('ReportUtils', () => { }); }); + describe('buildOptimisticGroupChatReport', () => { + it('should create a group chat report with correct properties', () => { + const avatarUri = 'https://example.com/avatar.png'; + const reportID = 'custom-report-id-123'; + const result = buildOptimisticGroupChatReport([1, 2, 3], 'My Group Chat', avatarUri, 1, reportID); + + expect(result.chatType).toBe(CONST.REPORT.CHAT_TYPE.GROUP); + expect(result.reportName).toBe('My Group Chat'); + expect(result.avatarUrl).toBe(avatarUri); + expect(result.reportID).toBe(reportID); + }); + + it('should assign ADMIN role to currentUserAccountID and MEMBER to others', () => { + const currentUser = 100; + const participantIDs = [currentUser, 200, 300]; + const result = buildOptimisticGroupChatReport(participantIDs, 'Group', '', currentUser); + + expect(result.participants?.[currentUser]?.role).toBe(CONST.REPORT.ROLE.ADMIN); + expect(result.participants?.[200]?.role).toBe(CONST.REPORT.ROLE.MEMBER); + expect(result.participants?.[300]?.role).toBe(CONST.REPORT.ROLE.MEMBER); + const participantKeys = Object.keys(result.participants ?? {}).map(Number); + expect(participantKeys).toEqual(expect.arrayContaining(participantIDs)); + expect(participantKeys).toHaveLength(participantIDs.length); + }); + + it('should apply the provided notificationPreference', () => { + const result = buildOptimisticGroupChatReport([1, 2], 'Group', '', 1, undefined, CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN); + expect(result.participants?.[1]?.notificationPreference).toBe(CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN); + expect(result.participants?.[2]?.notificationPreference).toBe(CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN); + }); + + it('should default notificationPreference to ALWAYS when not provided', () => { + const result = buildOptimisticGroupChatReport([1, 2], 'Group', '', 1); + expect(result.participants?.[1]?.notificationPreference).toBe(CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS); + }); + }); + describe('getWorkspaceNameUpdatedMessage', () => { it('return the encoded workspace name updated message', () => { const action = {