Skip to content
Merged
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
76 changes: 49 additions & 27 deletions tests/unit/NextStepUtilsTest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type {LocalizedTranslate} from '@components/LocaleContextProvider';

import DateUtils from '@libs/DateUtils';
import {
buildNextStepMessage,
buildOptimisticNextStepForPreventSelfApprovalsEnabled,
Expand All @@ -19,7 +18,6 @@ import {toCollectionDataSet} from '@src/types/utils/CollectionDataSet';
import type {OnyxCollection} from 'react-native-onyx';

import {execFileSync} from 'child_process';
import {format} from 'date-fns';
import Onyx from 'react-native-onyx';

import createMock from '../utils/createMock';
Expand Down Expand Up @@ -280,38 +278,62 @@ describe('libs/NextStepUtils', () => {
expect(result).toMatchObject(expectedResult);
});

test('monthly on the 2nd', () => {
// Waiting for userSubmitter's expense(s) to automatically submit on the 2nd of each month
const expectedResult: ReportNextStep = {
describe('monthly on the 2nd', () => {
const buildMonthlyOnThe2ndNextStep = () =>
buildOptimisticNextStep({
report,
policy: {
...policy,
autoReportingFrequency: CONST.POLICY.AUTO_REPORTING_FREQUENCIES.MONTHLY,
autoReportingOffset: 2,
harvesting: {
enabled: true,
},
},
currentUserAccountIDParam: currentUserAccountID,
currentUserEmailParam: currentUserEmail,
hasViolations: false,
isASAPSubmitBetaEnabled: false,
predictedNextStatus: CONST.REPORT.STATUS_NUM.OPEN,
shouldFixViolations: false,
isUnapprove: false,
isReopen: false,
isTrackIntentUser: false,
});

const expectedResultWithEtaDate = (dateTime: string): ReportNextStep => ({
messageKey: CONST.NEXT_STEP.MESSAGE_KEY.WAITING_FOR_AUTOMATIC_SUBMIT,
icon: CONST.NEXT_STEP.ICONS.HOURGLASS,
actorAccountID: currentUserAccountID,
eta: {
dateTime: format(DateUtils.getNextNthOfMonth(2), 'yyyy-MM-dd'),
},
};
const result = buildOptimisticNextStep({
report,
policy: {
...policy,
autoReportingFrequency: CONST.POLICY.AUTO_REPORTING_FREQUENCIES.MONTHLY,
autoReportingOffset: 2,
harvesting: {
enabled: true,
},
dateTime,
},
currentUserAccountIDParam: currentUserAccountID,
currentUserEmailParam: currentUserEmail,
hasViolations: false,
isASAPSubmitBetaEnabled: false,
predictedNextStatus: CONST.REPORT.STATUS_NUM.OPEN,
shouldFixViolations: false,
isUnapprove: false,
isReopen: false,
isTrackIntentUser: false,
});

expect(result).toMatchObject(expectedResult);
afterEach(() => {
jest.useRealTimers();
});

test('is the 2nd of this month when the 2nd is still ahead', () => {
jest.useFakeTimers();
jest.setSystemTime(new Date('2026-01-01T12:00:00Z'));

expect(buildMonthlyOnThe2ndNextStep()).toMatchObject(expectedResultWithEtaDate('2026-01-02'));
});

test('is today when today is the 2nd', () => {
jest.useFakeTimers();
jest.setSystemTime(new Date('2026-01-02T12:00:00Z'));

expect(buildMonthlyOnThe2ndNextStep()).toMatchObject(expectedResultWithEtaDate('2026-01-02'));
});

test('is the 2nd of next month once the 2nd has passed', () => {
jest.useFakeTimers();
jest.setSystemTime(new Date('2026-01-15T12:00:00Z'));

expect(buildMonthlyOnThe2ndNextStep()).toMatchObject(expectedResultWithEtaDate('2026-02-02'));
});
});

test('monthly on the last day', () => {
Expand Down
Loading