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
10 changes: 9 additions & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@
| 'participants'
| 'managerID'
| 'type'
| 'chatType'
| 'parentReportID'
| 'policyID'
| 'stateNum'
Expand Down Expand Up @@ -1059,7 +1060,7 @@
};

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

Check warning on line 1063 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 @@ -1067,7 +1068,7 @@
});

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

Check warning on line 1071 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 @@ -1085,7 +1086,7 @@
let allPersonalDetails: OnyxEntry<PersonalDetailsList>;
let allPersonalDetailLogins: string[];
let currentUserPersonalDetails: OnyxEntry<PersonalDetails>;
Onyx.connect({

Check warning on line 1089 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 @@ -1097,7 +1098,7 @@
});

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

Check warning on line 1101 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 @@ -1105,7 +1106,7 @@

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

Check warning on line 1109 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 @@ -1115,7 +1116,7 @@
});

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

Check warning on line 1119 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 @@ -1123,7 +1124,7 @@

let allReports: OnyxCollection<Report>;
let reportsByPolicyID: ReportByPolicyMap;
Onyx.connect({

Check warning on line 1127 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 @@ -1159,14 +1160,14 @@
});

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

Check warning on line 1163 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 1170 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 @@ -1192,7 +1193,7 @@
});

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

Check warning on line 1196 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 @@ -8741,6 +8742,7 @@
* @param title - Task title.
* @param description - Task description.
* @param policyID - PolicyID of the parent report
* @param parentChatType - Chat type of the parent report.
*/

function buildOptimisticTaskReport(
Expand All @@ -8751,6 +8753,7 @@
description?: string,
policyID: string = CONST.POLICY.OWNER_EMAIL_FAKE,
notificationPreference: NotificationPreference = CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN,
parentChatType?: ValueOf<typeof CONST.REPORT.CHAT_TYPE>,
): OptimisticTaskReport {
const participants: Participants = {
[ownerAccountID]: {
Expand All @@ -8771,6 +8774,9 @@
participants,
managerID: assigneeAccountID,
type: CONST.REPORT.TYPE.TASK,
// Only #admins tasks inherit chatType for Concierge routing.
// Task reports are not expense chats, so we do not inherit policyExpenseChat (or other chat types).
...(parentChatType === CONST.REPORT.CHAT_TYPE.POLICY_ADMINS && {chatType: CONST.REPORT.CHAT_TYPE.POLICY_ADMINS}),
Comment thread
c3024 marked this conversation as resolved.
parentReportID,
policyID,
stateNum: CONST.REPORT.STATE_NUM.OPEN,
Expand Down Expand Up @@ -11831,9 +11837,10 @@
const shouldUseFollowupsInsteadOfTasks = shouldPostTasksInAdminsRoom && Permissions.isBetaEnabled(CONST.BETAS.SUGGESTED_FOLLOWUPS, betas ?? allBetas, betaConfiguration);
const adminsChatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${adminsChatReportID}`];
const targetChatReport = shouldPostTasksInAdminsRoom
? (adminsChatReport ?? {reportID: adminsChatReportID, policyID: onboardingPolicyID})
? (adminsChatReport ?? {reportID: adminsChatReportID, policyID: onboardingPolicyID, chatType: CONST.REPORT.CHAT_TYPE.POLICY_ADMINS})
: getChatByParticipants([CONST.ACCOUNT_ID.CONCIERGE, deprecatedCurrentUserAccountID ?? CONST.DEFAULT_NUMBER_ID], allReports, false);
const {reportID: targetChatReportID = '', policyID: targetChatPolicyID = ''} = targetChatReport ?? {};
const targetChatType = targetChatReport?.chatType;

if (!targetChatReportID) {
Log.warn('Missing reportID for onboarding optimistic data');
Expand Down Expand Up @@ -11976,6 +11983,7 @@
taskDescription,
targetChatPolicyID,
CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN,
targetChatType,
);
const emailCreatingAction =
engagementChoice === CONST.ONBOARDING_CHOICES.MANAGE_TEAM ? (allPersonalDetails?.[actorAccountID]?.login ?? CONST.EMAIL.CONCIERGE) : CONST.EMAIL.CONCIERGE;
Expand Down
11 changes: 10 additions & 1 deletion src/libs/actions/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,16 @@ function createTaskAndNavigate(params: CreateTaskAndNavigateParams) {
return;
}

const optimisticTaskReport = ReportUtils.buildOptimisticTaskReport(currentUserAccountID, parentReportID, assigneeAccountID, title, description, policyID);
const optimisticTaskReport = ReportUtils.buildOptimisticTaskReport(
currentUserAccountID,
parentReportID,
assigneeAccountID,
title,
description,
policyID,
CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN,
parentReport?.chatType,
Comment thread
c3024 marked this conversation as resolved.
);

const assigneeChatReportID = assigneeChatReport?.reportID;
const taskReportID = optimisticTaskReport.reportID;
Expand Down
73 changes: 66 additions & 7 deletions tests/actions/TaskTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,18 @@ describe('actions/Task', () => {
global.fetch = getGlobalFetchMock();

// Setup ReportUtils mocks
mockBuildOptimisticTaskReport.mockReturnValue({
reportID: 'task_report_123',
reportName: mockTitle,
description: mockDescription,
managerID: mockAssigneeAccountID,
type: CONST.REPORT.TYPE.TASK,
parentReportID: mockParentReportID,
mockBuildOptimisticTaskReport.mockImplementation((...args: unknown[]) => {
const parentChatType = args.at(7);

return {
reportID: 'task_report_123',
reportName: mockTitle,
description: mockDescription,
managerID: mockAssigneeAccountID,
type: CONST.REPORT.TYPE.TASK,
parentReportID: mockParentReportID,
...(parentChatType === CONST.REPORT.CHAT_TYPE.POLICY_ADMINS && {chatType: CONST.REPORT.CHAT_TYPE.POLICY_ADMINS}),
};
});

mockBuildOptimisticCreatedReportAction.mockReturnValue({
Expand Down Expand Up @@ -425,6 +430,60 @@ describe('actions/Task', () => {
);
});

it('should set optimistic task chatType to policyAdmins for tasks created in admins rooms', async () => {
// Given a task created in a parent report with policyAdmins chatType
createTaskAndNavigate({
parentReport: {
reportID: mockParentReportID,
chatType: CONST.REPORT.CHAT_TYPE.POLICY_ADMINS,
},
title: mockTitle,
description: mockDescription,
assigneeEmail: mockAssigneeEmail,
currentUserAccountID: mockCurrentUserAccountID,
currentUserEmail: mockCurrentUserEmail,
assigneeAccountID: mockAssigneeAccountID,
policyID: mockPolicyID,
isCreatedUsingMarkdown: false,
quickAction: {},
});

await waitForBatchedUpdatesWithAct();

// Then the optimistic task report should include policyAdmins chatType
// eslint-disable-next-line rulesdir/no-multiple-api-calls
const [, , onyx] = (API.write as jest.Mock).mock.calls.at(0) as [unknown, unknown, OnyxData<typeof ONYXKEYS.COLLECTION.REPORT>];
const optimisticTaskReportUpdate = onyx.optimisticData?.find((update) => update.key === `${ONYXKEYS.COLLECTION.REPORT}task_report_123`);
expect((optimisticTaskReportUpdate?.value as Report | undefined)?.chatType).toBe(CONST.REPORT.CHAT_TYPE.POLICY_ADMINS);
});

it('should not set optimistic task chatType for tasks created in policy expense chats', async () => {
// Given a task created in a parent report with policyExpenseChat chatType
createTaskAndNavigate({
parentReport: {
reportID: mockParentReportID,
chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT,
},
title: mockTitle,
description: mockDescription,
assigneeEmail: mockAssigneeEmail,
currentUserAccountID: mockCurrentUserAccountID,
currentUserEmail: mockCurrentUserEmail,
assigneeAccountID: mockAssigneeAccountID,
policyID: mockPolicyID,
isCreatedUsingMarkdown: false,
quickAction: {},
});

await waitForBatchedUpdatesWithAct();

// Then the optimistic task report should keep chatType unset
// eslint-disable-next-line rulesdir/no-multiple-api-calls
const [, , onyx] = (API.write as jest.Mock).mock.calls.at(0) as [unknown, unknown, OnyxData<typeof ONYXKEYS.COLLECTION.REPORT>];
const optimisticTaskReportUpdate = onyx.optimisticData?.find((update) => update.key === `${ONYXKEYS.COLLECTION.REPORT}task_report_123`);
expect((optimisticTaskReportUpdate?.value as Report | undefined)?.chatType).toBeUndefined();
});

it('should handle task creation without assignee chat report', async () => {
// Given: Task creation without assignee chat report
const mockQuickAction = {
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,18 @@ describe('ReportUtils', () => {
});
// Without the beta, tasks SHOULD be generated (old behavior)
expect(result?.guidedSetupData).toHaveLength(3);
const taskReportIDs =
result?.guidedSetupData.reduce<string[]>((acc, item) => {
if (item.type === 'task' && typeof item.taskReportID === 'string') {
acc.push(item.taskReportID);
}
return acc;
}, []) ?? [];
expect(taskReportIDs.length).toBeGreaterThan(0);
for (const taskReportID of taskReportIDs) {
const taskReportUpdate = result?.optimisticData.find((update) => update.key === `${ONYXKEYS.COLLECTION.REPORT}${taskReportID}`);
expect((taskReportUpdate?.value as Report | undefined)?.chatType).toBe(CONST.REPORT.CHAT_TYPE.POLICY_ADMINS);
}
});

it('should add guidedSetupData when email has a +', async () => {
Expand Down
Loading