Skip to content
2 changes: 1 addition & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@
const parsedReportActionMessageCache: Record<string, string> = {};

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

Check warning on line 963 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) => {
conciergeReportID = value;
Expand All @@ -968,7 +968,7 @@
});

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

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

Check warning on line 989 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 (currentUserAccountID) {
Expand All @@ -998,14 +998,14 @@
});

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

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

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

Check warning on line 1008 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) => (allPolicies = value),
Expand All @@ -1020,7 +1020,7 @@

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

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
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand Down Expand Up @@ -1058,14 +1058,14 @@
});

let allBetas: OnyxEntry<Beta[]>;
Onyx.connect({

Check warning on line 1061 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.BETAS,
callback: (value) => (allBetas = value),
});

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

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

let allReportActions: OnyxCollection<ReportActions>;
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.REPORT_ACTIONS,
waitForCollectionCallback: true,
callback: (actions) => {
Expand All @@ -1104,7 +1104,7 @@

let allReportMetadata: OnyxCollection<ReportMetadata>;
const allReportMetadataKeyValue: Record<string, ReportMetadata> = {};
Onyx.connect({

Check warning on line 1107 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_METADATA,
waitForCollectionCallback: true,
callback: (value) => {
Expand Down Expand Up @@ -11110,7 +11110,7 @@
// This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
// eslint-disable-next-line @typescript-eslint/no-deprecated
const policy = getPolicy(iouReport.policyID);
const shouldBeManuallySubmitted = isPaidGroupPolicyPolicyUtils(policy) && !policy?.harvesting?.enabled;
const shouldBeManuallySubmitted = isPaidGroupPolicyPolicyUtils(policy) && !policy?.harvesting?.enabled && isOpenReport(iouReport);
Comment thread
mountiny marked this conversation as resolved.
if (shouldBeManuallySubmitted) {
return {
hasOutstandingChildRequest: true,
Expand Down
89 changes: 89 additions & 0 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import {
getIOUReportActionDisplayMessage,
getMoneyReportPreviewName,
getMostRecentlyVisitedReport,
getOutstandingChildRequest,
getParentNavigationSubtitle,
getParticipantsList,
getPolicyExpenseChat,
Expand Down Expand Up @@ -9535,6 +9536,94 @@ describe('ReportUtils', () => {
await Onyx.clear();
});

describe('getOutstandingChildRequest', () => {
const fakePolicy: Policy = {
...createRandomPolicy(12),
harvesting: {
enabled: false,
},
type: CONST.POLICY.TYPE.TEAM,
};

beforeAll(async () => {
await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${fakePolicy.id}`, fakePolicy);
});

it('should return hasOutstandingChildRequest as true if the expense report is open report', async () => {
Comment thread
nkdengineer marked this conversation as resolved.
const iouReport: Report = {
...createRandomReport(100, undefined),
stateNum: CONST.REPORT.STATE_NUM.OPEN,
statusNum: CONST.REPORT.STATUS_NUM.OPEN,
type: CONST.REPORT.TYPE.EXPENSE,
policyID: fakePolicy.id,
};

expect(getOutstandingChildRequest(iouReport).hasOutstandingChildRequest).toBe(true);
});

it('should return empty object if the expense report is not open report', async () => {
const iouReport: Report = {
...createRandomReport(100, undefined),
stateNum: CONST.REPORT.STATE_NUM.SUBMITTED,
statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED,
type: CONST.REPORT.TYPE.EXPENSE,
policyID: fakePolicy.id,
};

expect(getOutstandingChildRequest(iouReport).hasOutstandingChildRequest).toBeFalsy();
});

it('should return empty object if harvesting is enabled', async () => {
await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${fakePolicy.id}`, {harvesting: {enabled: true}});

const iouReport: Report = {
...createRandomReport(100, undefined),
stateNum: CONST.REPORT.STATE_NUM.OPEN,
statusNum: CONST.REPORT.STATUS_NUM.OPEN,
type: CONST.REPORT.TYPE.EXPENSE,
policyID: fakePolicy.id,
};

expect(getOutstandingChildRequest(iouReport).hasOutstandingChildRequest).toBeFalsy();
});

it('should return true if the current user is the manger of the iou report and the total spend is not zero', async () => {
const iouReport: Report = {
...createRandomReport(100, undefined),
type: CONST.REPORT.TYPE.IOU,
policyID: fakePolicy.id,
managerID: currentUserAccountID,
total: 100,
};

expect(getOutstandingChildRequest(iouReport).hasOutstandingChildRequest).toBe(true);
});

it('should return false if the current user is not the manger of the iou report', async () => {
const iouReport: Report = {
...createRandomReport(100, undefined),
type: CONST.REPORT.TYPE.IOU,
policyID: fakePolicy.id,
ownerAccountID: currentUserAccountID,
total: 100,
};

expect(getOutstandingChildRequest(iouReport).hasOutstandingChildRequest).toBeFalsy();
});

it('should return false if the total spend is zero', async () => {
const iouReport: Report = {
...createRandomReport(100, undefined),
type: CONST.REPORT.TYPE.IOU,
policyID: fakePolicy.id,
managerID: currentUserAccountID,
total: 0,
};

expect(getOutstandingChildRequest(iouReport).hasOutstandingChildRequest).toBeFalsy();
});
});

it('should stop surfacing a GBR for a workspace once it is archived', async () => {
await Onyx.clear();

Expand Down
Loading