Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,7 @@
};

let conciergeReportIDOnyxConnect: OnyxEntry<string>;
Onyx.connect({

Check warning on line 1048 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.CONCIERGE_REPORT_ID,
callback: (value) => {
conciergeReportIDOnyxConnect = value;
Expand All @@ -1053,7 +1053,7 @@
});

const defaultAvatarBuildingIconTestID = 'SvgDefaultAvatarBuilding Icon';
Onyx.connect({

Check warning on line 1056 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
// When signed out, val is undefined
Expand All @@ -1071,7 +1071,7 @@
let allPersonalDetails: OnyxEntry<PersonalDetailsList>;
let allPersonalDetailLogins: string[];
let currentUserPersonalDetails: OnyxEntry<PersonalDetails>;
Onyx.connect({

Check warning on line 1074 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
if (deprecatedCurrentUserAccountID) {
Expand All @@ -1083,7 +1083,7 @@
});

let allReportsDraft: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 1086 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_DRAFT,
waitForCollectionCallback: true,
callback: (value) => (allReportsDraft = value),
Expand All @@ -1091,7 +1091,7 @@

let allPolicies: OnyxCollection<Policy>;
let policiesArray: Policy[] = [];
Onyx.connect({

Check warning on line 1094 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -1101,7 +1101,7 @@
});

let allPolicyDrafts: OnyxCollection<Policy>;
Onyx.connect({

Check warning on line 1104 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY_DRAFTS,
waitForCollectionCallback: true,
callback: (value) => (allPolicyDrafts = value),
Expand All @@ -1109,7 +1109,7 @@

let deprecatedAllReports: OnyxCollection<Report>;
let deprecatedReportsByPolicyID: ReportByPolicyMap;
Onyx.connect({

Check warning on line 1112 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand Down Expand Up @@ -1145,14 +1145,14 @@
});

let betaConfiguration: OnyxEntry<BetaConfiguration> = {};
Onyx.connect({

Check warning on line 1148 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.BETA_CONFIGURATION,
callback: (value) => (betaConfiguration = value ?? {}),
});

let deprecatedAllTransactions: OnyxCollection<Transaction> = {};
let deprecatedReportsTransactions: Record<string, Transaction[]> = {};
Onyx.connect({

Check warning on line 1155 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -1178,7 +1178,7 @@
});

let allReportActions: OnyxCollection<ReportActions>;
Onyx.connect({

Check warning on line 1181 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
waitForCollectionCallback: true,
callback: (actions) => {
Expand Down Expand Up @@ -7940,6 +7940,7 @@
participantAccountIDs: number[],
reportName: string,
avatarUri: string,
currentUserAccountID: number,
optimisticReportID?: string,
notificationPreference?: NotificationPreference,
) {
Expand All @@ -7950,6 +7951,7 @@
notificationPreference,
avatarUrl: avatarUri,
optimisticReportID,
currentUserAccountID,
});
}

Expand Down
3 changes: 2 additions & 1 deletion src/libs/actions/Report/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2013,13 +2013,14 @@ function navigateToAndCreateGroupChat(
introSelected: OnyxEntry<IntroSelected>,
isSelfTourViewed: boolean | undefined,
betas: OnyxEntry<Beta[]>,
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);
Expand Down
1 change: 1 addition & 0 deletions src/pages/NewChatConfirmPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ function NewChatConfirmPage() {
introSelected,
isSelfTourViewed,
betas,
personalData.accountID,
newGroupDraft.avatarUri ?? '',
avatarFile,
);
Expand Down
15 changes: 14 additions & 1 deletion tests/actions/ReportTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -5921,6 +5930,7 @@ describe('actions/Report', () => {
TEST_INTRO_SELECTED,
true,
undefined,
TEST_USER_ACCOUNT_ID,
AVATAR_URI,
);
await waitForBatchedUpdates();
Expand Down Expand Up @@ -5955,6 +5965,7 @@ describe('actions/Report', () => {
{...TEST_INTRO_SELECTED, isInviteOnboardingComplete: true},
true,
undefined,
TEST_USER_ACCOUNT_ID,
);
await waitForBatchedUpdates();

Expand All @@ -5981,6 +5992,7 @@ describe('actions/Report', () => {
{choice: CONST.ONBOARDING_CHOICES.ADMIN},
false,
undefined,
TEST_USER_ACCOUNT_ID,
undefined,
avatarFile,
);
Expand Down Expand Up @@ -6011,6 +6023,7 @@ describe('actions/Report', () => {
{choice: CONST.ONBOARDING_CHOICES.ADMIN},
false,
undefined,
TEST_USER_ACCOUNT_ID,
);
await waitForBatchedUpdates();

Expand Down
38 changes: 38 additions & 0 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
buildOptimisticCreatedReportForUnapprovedAction,
buildOptimisticEmptyReport,
buildOptimisticExpenseReport,
buildOptimisticGroupChatReport,
buildOptimisticInvoiceReport,
buildOptimisticIOUReportAction,
buildOptimisticReportPreview,
Expand Down Expand Up @@ -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 = {
Expand Down
Loading