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
4 changes: 4 additions & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@
Onyx.connect({
key: ONYXKEYS.CONCIERGE_REPORT_ID,
callback: (value) => {
conciergeReportID = value;

Check warning on line 887 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
},
});

Expand All @@ -892,7 +892,7 @@
Onyx.connect({
key: ONYXKEYS.SESSION,
callback: (value) => {
// When signed out, val is undefined

Check warning on line 895 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
if (!value) {
return;
}
Expand All @@ -910,7 +910,7 @@
Onyx.connect({
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
if (currentUserAccountID) {

Check warning on line 913 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
currentUserPersonalDetails = value?.[currentUserAccountID] ?? undefined;
}
allPersonalDetails = value ?? {};
Expand All @@ -922,14 +922,14 @@
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT_DRAFT,
waitForCollectionCallback: true,
callback: (value) => (allReportsDraft = value),

Check warning on line 925 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
});

let allPolicies: OnyxCollection<Policy>;
Onyx.connect({
key: ONYXKEYS.COLLECTION.POLICY,
waitForCollectionCallback: true,
callback: (value) => (allPolicies = value),

Check warning on line 932 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
});

let allReports: OnyxCollection<Report>;
Expand All @@ -937,7 +937,7 @@
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {

Check warning on line 940 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
allReports = value;
UnreadIndicatorUpdaterHelper().then((module) => {
module.triggerUnreadUpdate();
Expand Down Expand Up @@ -974,14 +974,14 @@
Onyx.connect({
key: ONYXKEYS.BETAS,
callback: (value) => (allBetas = value),
});

Check warning on line 977 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

let allTransactions: OnyxCollection<Transaction> = {};
let reportsTransactions: Record<string, Transaction[]> = {};
Onyx.connect({
key: ONYXKEYS.COLLECTION.TRANSACTION,
waitForCollectionCallback: true,
callback: (value) => {

Check warning on line 984 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
if (!value) {
return;
}
Expand All @@ -1007,7 +1007,7 @@
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
waitForCollectionCallback: true,
callback: (actions) => {

Check warning on line 1010 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
if (!actions) {
return;
}
Expand All @@ -1020,7 +1020,7 @@
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT_METADATA,
waitForCollectionCallback: true,
callback: (value) => {

Check warning on line 1023 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
if (!value) {
return;
}
Expand Down Expand Up @@ -10824,6 +10824,10 @@
return false;
}

if (!newPolicy?.isPolicyExpenseChatEnabled) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAB: We can merge this return false condition with the one above, and also add a comment here for clarity.

if (doesReportContainRequestsFromMultipleUsers(report) || !newPolicy?.isPolicyExpenseChatEnabled) {
    return false;
}

return false;
}

// We can only move the iou report to the workspace if the manager is the payer of the new policy
if (isIOUReport(report)) {
return isPaidGroupPolicyPolicyUtils(newPolicy) && isWorkspacePayer(managerLogin ?? '', newPolicy);
Expand Down
29 changes: 29 additions & 0 deletions tests/unit/PolicyUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,7 @@ describe('PolicyUtils', () => {

const newPolicy = {
...createRandomPolicy(1, CONST.POLICY.TYPE.PERSONAL),
isPolicyExpenseChatEnabled: true,
employeeList: {
[currentUserLogin]: {email: currentUserLogin, role: CONST.POLICY.ROLE.USER},
},
Expand All @@ -675,6 +676,7 @@ describe('PolicyUtils', () => {
const newPolicy = {
...createRandomPolicy(1, CONST.POLICY.TYPE.TEAM),
reimbursementChoice: CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_MANUAL,
isPolicyExpenseChatEnabled: true,
employeeList: {
[currentUserLogin]: {email: currentUserLogin, role: CONST.POLICY.ROLE.ADMIN},
},
Expand All @@ -696,6 +698,7 @@ describe('PolicyUtils', () => {
it('returns false if the manager is not the payer of the new policy', async () => {
const newPolicy = {
...createRandomPolicy(1, CONST.POLICY.TYPE.TEAM),
isPolicyExpenseChatEnabled: true,
role: CONST.POLICY.ROLE.ADMIN,
employeeList: {
[approverEmail]: {email: approverEmail, role: CONST.POLICY.ROLE.USER},
Expand All @@ -714,6 +717,32 @@ describe('PolicyUtils', () => {
const result = isWorkspaceEligibleForReportChange(newPolicy, report, policies);
expect(result).toBe(false);
});

it('returns false if policies are not policyExpenseChatEnabled', async () => {
const currentUserLogin = employeeEmail;
const currentUserAccountID = employeeAccountID;

const newPolicy = {
...createRandomPolicy(1, CONST.POLICY.TYPE.TEAM),
reimbursementChoice: CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_MANUAL,
isPolicyExpenseChatEnabled: false,
employeeList: {
[currentUserLogin]: {email: currentUserLogin, role: CONST.POLICY.ROLE.ADMIN},
},
};
const policies = {[`${ONYXKEYS.COLLECTION.POLICY}${newPolicy.id}`]: newPolicy};
await Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${newPolicy.id}`, newPolicy);
const report = {
...createRandomReport(0),
type: CONST.REPORT.TYPE.IOU,
stateNum: CONST.REPORT.STATE_NUM.SUBMITTED,
ownerAccountID: approverAccountID,
managerID: currentUserAccountID,
};

const result = isWorkspaceEligibleForReportChange(newPolicy, report, policies);
expect(result).toBe(false);
});
});

describe('isUserInvitedToWorkspace', () => {
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/ReportSecondaryActionUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ describe('getSecondaryAction', () => {
id: POLICY_ID,
type: CONST.POLICY.TYPE.TEAM,
reimbursementChoice: CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_MANUAL,
isPolicyExpenseChatEnabled: true,
employeeList: {
[EMPLOYEE_EMAIL]: {email: EMPLOYEE_EMAIL, role: CONST.POLICY.ROLE.ADMIN},
[MANAGER_EMAIL]: {email: MANAGER_EMAIL, role: CONST.POLICY.ROLE.USER},
Expand Down Expand Up @@ -513,6 +514,7 @@ describe('getSecondaryAction', () => {
id: POLICY_ID,
type: CONST.POLICY.TYPE.TEAM,
role: CONST.POLICY.ROLE.ADMIN,
isPolicyExpenseChatEnabled: true,
employeeList: {
[ADMIN_EMAIL]: {email: ADMIN_EMAIL, role: CONST.POLICY.ROLE.ADMIN},
[EMPLOYEE_EMAIL]: {email: EMPLOYEE_EMAIL, role: CONST.POLICY.ROLE.USER},
Expand Down Expand Up @@ -542,6 +544,7 @@ describe('getSecondaryAction', () => {
const newPolicy = {
id: POLICY_ID,
type: CONST.POLICY.TYPE.TEAM,
isPolicyExpenseChatEnabled: true,
employeeList: {
[MANAGER_EMAIL]: {email: MANAGER_EMAIL, role: CONST.POLICY.ROLE.USER},
[EMPLOYEE_EMAIL]: {email: EMPLOYEE_EMAIL, role: CONST.POLICY.ROLE.USER},
Expand Down Expand Up @@ -611,6 +614,7 @@ describe('getSecondaryAction', () => {
id: POLICY_ID,
type: CONST.POLICY.TYPE.TEAM,
approver: APPROVER_EMAIL,
isPolicyExpenseChatEnabled: true,
employeeList: {
[APPROVER_EMAIL]: {email: APPROVER_EMAIL, role: CONST.POLICY.ROLE.USER},
[EMPLOYEE_EMAIL]: {email: EMPLOYEE_EMAIL, role: CONST.POLICY.ROLE.USER},
Expand Down Expand Up @@ -652,6 +656,7 @@ describe('getSecondaryAction', () => {
id: POLICY_ID,
type: CONST.POLICY.TYPE.TEAM,
role: CONST.POLICY.ROLE.ADMIN,
isPolicyExpenseChatEnabled: true,
employeeList: {
[ADMIN_EMAIL]: {email: ADMIN_EMAIL, role: CONST.POLICY.ROLE.ADMIN},
[EMPLOYEE_EMAIL]: {login: EMPLOYEE_EMAIL, role: CONST.POLICY.ROLE.USER},
Expand Down
Loading