diff --git a/src/libs/NextStepUtils.ts b/src/libs/NextStepUtils.ts index 64db07491100..2ec5b4bc4806 100644 --- a/src/libs/NextStepUtils.ts +++ b/src/libs/NextStepUtils.ts @@ -11,8 +11,8 @@ import type DeepValueOf from '@src/types/utils/DeepValueOf'; import {getNextApproverAccountID} from './actions/IOU'; import DateUtils from './DateUtils'; import EmailUtils from './EmailUtils'; -import * as PolicyUtils from './PolicyUtils'; -import * as ReportUtils from './ReportUtils'; +import {getCorrectedAutoReportingFrequency, getReimburserAccountID} from './PolicyUtils'; +import {getDisplayNameForParticipant, getPersonalDetailsForAccountID, isExpenseReport, isInvoiceReport, isPayer} from './ReportUtils'; let currentUserAccountID = -1; let currentUserEmail = ''; @@ -23,7 +23,7 @@ Onyx.connect({ return; } - currentUserAccountID = value?.accountID ?? -1; + currentUserAccountID = value?.accountID ?? CONST.DEFAULT_NUMBER_ID; currentUserEmail = value?.email ?? ''; }, }); @@ -69,7 +69,7 @@ function parseMessage(messages: Message[] | undefined) { function getNextApproverDisplayName(report: OnyxEntry) { const approverAccountID = getNextApproverAccountID(report); - return ReportUtils.getDisplayNameForParticipant(approverAccountID) ?? ReportUtils.getPersonalDetailsForAccountID(approverAccountID).login; + return getDisplayNameForParticipant(approverAccountID) ?? getPersonalDetailsForAccountID(approverAccountID).login; } /** @@ -81,18 +81,18 @@ function getNextApproverDisplayName(report: OnyxEntry) { * @returns nextStep */ function buildNextStep(report: OnyxEntry, predictedNextStatus: ValueOf): ReportNextStep | null { - if (!ReportUtils.isExpenseReport(report)) { + if (!isExpenseReport(report)) { return null; } const {policyID = '', ownerAccountID = -1} = report ?? {}; const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`] ?? ({} as Policy); const {harvesting, autoReportingOffset} = policy; - const autoReportingFrequency = PolicyUtils.getCorrectedAutoReportingFrequency(policy); - const ownerDisplayName = ReportUtils.getDisplayNameForParticipant(ownerAccountID); + const autoReportingFrequency = getCorrectedAutoReportingFrequency(policy); + const ownerDisplayName = getDisplayNameForParticipant(ownerAccountID); const nextApproverDisplayName = getNextApproverDisplayName(report); - const reimburserAccountID = PolicyUtils.getReimburserAccountID(policy); + const reimburserAccountID = getReimburserAccountID(policy); const hasValidAccount = !!policy?.achAccount?.accountNumber; const type: ReportNextStep['type'] = 'neutral'; let optimisticNextStep: ReportNextStep | null; @@ -194,6 +194,29 @@ function buildNextStep(report: OnyxEntry, predictedNextStatus: ValueOf, predictedNextStatus: ValueOf, predictedNextStatus: ValueOf { icon: CONST.NEXT_STEP.ICONS.HOURGLASS, message: [], }; - const report = ReportUtils.buildOptimisticExpenseReport('fake-chat-report-id-1', policyID, 1, -500, CONST.CURRENCY.USD) as Report; + const report = buildOptimisticExpenseReport('fake-chat-report-id-1', policyID, 1, -500, CONST.CURRENCY.USD) as Report; beforeAll(() => { const policyCollectionDataSet = toCollectionDataSet(ONYXKEYS.COLLECTION.POLICY, [policy], (item) => item.id); @@ -101,7 +101,7 @@ describe('libs/NextStepUtils', () => { }, ]; - const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.OPEN); + const result = buildNextStep(report, CONST.REPORT.STATUS_NUM.OPEN); expect(result).toMatchObject(optimisticNextStep); }); @@ -142,7 +142,7 @@ describe('libs/NextStepUtils', () => { enabled: true, }, }).then(() => { - const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.OPEN); + const result = buildNextStep(report, CONST.REPORT.STATUS_NUM.OPEN); expect(result).toMatchObject(optimisticNextStep); }); @@ -177,7 +177,7 @@ describe('libs/NextStepUtils', () => { enabled: true, }, }).then(() => { - const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.OPEN); + const result = buildNextStep(report, CONST.REPORT.STATUS_NUM.OPEN); expect(result).toMatchObject(optimisticNextStep); }); @@ -212,7 +212,7 @@ describe('libs/NextStepUtils', () => { enabled: true, }, }).then(() => { - const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.OPEN); + const result = buildNextStep(report, CONST.REPORT.STATUS_NUM.OPEN); expect(result).toMatchObject(optimisticNextStep); }); @@ -248,7 +248,7 @@ describe('libs/NextStepUtils', () => { enabled: true, }, }).then(() => { - const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.OPEN); + const result = buildNextStep(report, CONST.REPORT.STATUS_NUM.OPEN); expect(result).toMatchObject(optimisticNextStep); }); @@ -284,7 +284,7 @@ describe('libs/NextStepUtils', () => { enabled: true, }, }).then(() => { - const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.OPEN); + const result = buildNextStep(report, CONST.REPORT.STATUS_NUM.OPEN); expect(result).toMatchObject(optimisticNextStep); }); @@ -322,7 +322,7 @@ describe('libs/NextStepUtils', () => { enabled: true, }, }).then(() => { - const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.OPEN); + const result = buildNextStep(report, CONST.REPORT.STATUS_NUM.OPEN); expect(result).toMatchObject(optimisticNextStep); }); @@ -357,14 +357,14 @@ describe('libs/NextStepUtils', () => { enabled: true, }, }).then(() => { - const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.OPEN); + const result = buildNextStep(report, CONST.REPORT.STATUS_NUM.OPEN); expect(result).toMatchObject(optimisticNextStep); }); }); test('manual', () => { - // Waiting for userSubmitter to add expense(s). + // Waiting for userSubmitter to submit expense(s). optimisticNextStep.message = [ { text: 'Waiting for ', @@ -377,7 +377,7 @@ describe('libs/NextStepUtils', () => { text: ' to ', }, { - text: 'add', + text: 'submit', }, { text: ' %expenses.', @@ -390,7 +390,7 @@ describe('libs/NextStepUtils', () => { enabled: false, }, }).then(() => { - const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.OPEN); + const result = buildNextStep(report, CONST.REPORT.STATUS_NUM.OPEN); expect(result).toMatchObject(optimisticNextStep); }); @@ -421,7 +421,7 @@ describe('libs/NextStepUtils', () => { }, ]; - const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.APPROVED); + const result = buildNextStep(report, CONST.REPORT.STATUS_NUM.APPROVED); expect(result).toMatchObject(optimisticNextStep); }); @@ -453,7 +453,7 @@ describe('libs/NextStepUtils', () => { accountNumber: '123456789', }, }).then(() => { - const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.APPROVED); + const result = buildNextStep(report, CONST.REPORT.STATUS_NUM.APPROVED); expect(result).toMatchObject(optimisticNextStep); @@ -495,7 +495,7 @@ describe('libs/NextStepUtils', () => { }, }, }).then(() => { - const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.SUBMITTED); + const result = buildNextStep(report, CONST.REPORT.STATUS_NUM.SUBMITTED); expect(result).toMatchObject(optimisticNextStep); }); @@ -532,7 +532,7 @@ describe('libs/NextStepUtils', () => { }, }, }).then(() => { - const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.SUBMITTED); + const result = buildNextStep(report, CONST.REPORT.STATUS_NUM.SUBMITTED); expect(result).toMatchObject(optimisticNextStep); }); @@ -549,7 +549,7 @@ describe('libs/NextStepUtils', () => { return Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, { approvalMode: CONST.POLICY.APPROVAL_MODE.OPTIONAL, }).then(() => { - const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.CLOSED); + const result = buildNextStep(report, CONST.REPORT.STATUS_NUM.CLOSED); expect(result).toMatchObject(optimisticNextStep); }); @@ -566,7 +566,7 @@ describe('libs/NextStepUtils', () => { }, ]; - const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.APPROVED); + const result = buildNextStep(report, CONST.REPORT.STATUS_NUM.APPROVED); expect(result).toMatchObject(optimisticNextStep); }); @@ -597,7 +597,7 @@ describe('libs/NextStepUtils', () => { report.stateNum = CONST.REPORT.STATE_NUM.APPROVED; report.statusNum = CONST.REPORT.STATUS_NUM.APPROVED; - const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.APPROVED); + const result = buildNextStep(report, CONST.REPORT.STATUS_NUM.APPROVED); expect(result).toMatchObject(optimisticNextStep); @@ -633,7 +633,7 @@ describe('libs/NextStepUtils', () => { accountNumber: '123456789', }, }).then(() => { - const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.APPROVED); + const result = buildNextStep(report, CONST.REPORT.STATUS_NUM.APPROVED); expect(result).toMatchObject(optimisticNextStep); }); @@ -648,7 +648,7 @@ describe('libs/NextStepUtils', () => { }, ]; - const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.REIMBURSED); + const result = buildNextStep(report, CONST.REPORT.STATUS_NUM.REIMBURSED); expect(result).toMatchObject(optimisticNextStep); });