From 2654d1be2786cc06dc03ee0604994bee5cf8cdc5 Mon Sep 17 00:00:00 2001 From: Daniel Gale-Rosen Date: Wed, 22 Jan 2025 13:34:28 -0500 Subject: [PATCH 1/5] update next steps for manual reports --- src/libs/NextStepUtils.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/libs/NextStepUtils.ts b/src/libs/NextStepUtils.ts index 64db07491100..d22153149314 100644 --- a/src/libs/NextStepUtils.ts +++ b/src/libs/NextStepUtils.ts @@ -194,6 +194,33 @@ function buildNextStep(report: OnyxEntry, predictedNextStatus: ValueOf Date: Wed, 22 Jan 2025 13:34:40 -0500 Subject: [PATCH 2/5] update tests to match --- tests/unit/NextStepUtilsTest.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/unit/NextStepUtilsTest.ts b/tests/unit/NextStepUtilsTest.ts index 776c5f95cce7..447151ad0e51 100644 --- a/tests/unit/NextStepUtilsTest.ts +++ b/tests/unit/NextStepUtilsTest.ts @@ -41,6 +41,7 @@ describe('libs/NextStepUtils', () => { message: [], }; const report = ReportUtils.buildOptimisticExpenseReport('fake-chat-report-id-1', policyID, 1, -500, CONST.CURRENCY.USD) as Report; + const report2 = ReportUtils.buildOptimisticExpenseReport('fake-chat-report-id-2', policyID, 1, 0, CONST.CURRENCY.USD) as Report; beforeAll(() => { const policyCollectionDataSet = toCollectionDataSet(ONYXKEYS.COLLECTION.POLICY, [policy], (item) => item.id); @@ -364,7 +365,7 @@ describe('libs/NextStepUtils', () => { }); test('manual', () => { - // Waiting for userSubmitter to add expense(s). + // Waiting for userSubmitter to submit expense(s). optimisticNextStep.message = [ { text: 'Waiting for ', @@ -377,7 +378,7 @@ describe('libs/NextStepUtils', () => { text: ' to ', }, { - text: 'add', + text: 'submit', }, { text: ' %expenses.', From 6218ac2db7784ed78f1370906fcbae4a416dee0e Mon Sep 17 00:00:00 2001 From: Daniel Gale-Rosen Date: Wed, 22 Jan 2025 13:47:49 -0500 Subject: [PATCH 3/5] typescript - and it will always be MANUAL not IMMEDIATE here --- src/libs/NextStepUtils.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/libs/NextStepUtils.ts b/src/libs/NextStepUtils.ts index d22153149314..7175364e324f 100644 --- a/src/libs/NextStepUtils.ts +++ b/src/libs/NextStepUtils.ts @@ -195,11 +195,7 @@ function buildNextStep(report: OnyxEntry, predictedNextStatus: ValueOf Date: Wed, 22 Jan 2025 13:57:34 -0500 Subject: [PATCH 4/5] lint utils --- src/libs/NextStepUtils.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/libs/NextStepUtils.ts b/src/libs/NextStepUtils.ts index 7175364e324f..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; @@ -263,8 +263,8 @@ function buildNextStep(report: OnyxEntry, predictedNextStatus: ValueOf, predictedNextStatus: ValueOf Date: Wed, 22 Jan 2025 13:57:40 -0500 Subject: [PATCH 5/5] lint tests --- tests/unit/NextStepUtilsTest.ts | 43 ++++++++++++++++----------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/tests/unit/NextStepUtilsTest.ts b/tests/unit/NextStepUtilsTest.ts index 447151ad0e51..6e53a2b74d25 100644 --- a/tests/unit/NextStepUtilsTest.ts +++ b/tests/unit/NextStepUtilsTest.ts @@ -1,8 +1,8 @@ import {format, lastDayOfMonth, setDate} from 'date-fns'; import Onyx from 'react-native-onyx'; import DateUtils from '@libs/DateUtils'; -import * as NextStepUtils from '@libs/NextStepUtils'; -import * as ReportUtils from '@libs/ReportUtils'; +import {buildNextStep} from '@libs/NextStepUtils'; +import {buildOptimisticExpenseReport} from '@libs/ReportUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {Policy, Report, ReportNextStep} from '@src/types/onyx'; @@ -40,8 +40,7 @@ describe('libs/NextStepUtils', () => { 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 report2 = ReportUtils.buildOptimisticExpenseReport('fake-chat-report-id-2', policyID, 1, 0, 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); @@ -102,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); }); @@ -143,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); }); @@ -178,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); }); @@ -213,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); }); @@ -249,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); }); @@ -285,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); }); @@ -323,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); }); @@ -358,7 +357,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); }); @@ -391,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); }); @@ -422,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); }); @@ -454,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); @@ -496,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); }); @@ -533,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); }); @@ -550,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); }); @@ -567,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); }); @@ -598,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); @@ -634,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); }); @@ -649,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); });