Skip to content
Draft
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
5 changes: 5 additions & 0 deletions src/libs/actions/IOU/ReportWorkflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,10 @@ function approveMoneyRequest(params: ApproveMoneyRequestFunctionParams) {
statusNum: predictedNextStatus,
managerID,
nextStep: optimisticNextStep ?? undefined,
// The current user just approved this report, so it no longer awaits their action.
// Clear the expense report's own outstanding-child flag so the LHN green dot disappears
// optimistically instead of lingering until OpenReport re-fetches the server's false value.
hasOutstandingChildRequest: false,
pendingFields: {
partial: full ? null : CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
nextStep: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
Expand Down Expand Up @@ -659,6 +663,7 @@ function approveMoneyRequest(params: ApproveMoneyRequestFunctionParams) {
statusNum: expenseReport.statusNum,
stateNum: expenseReport.stateNum,
nextStep: expenseReport.nextStep ?? null,
hasOutstandingChildRequest: expenseReport.hasOutstandingChildRequest,
pendingFields: {
partial: null,
nextStep: null,
Expand Down
55 changes: 54 additions & 1 deletion tests/actions/IOUTest/ReportWorkflowTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import ROUTES from '@src/ROUTES';
import type {Policy, Report, ReportNameValuePairs, ReportNextStepDeprecated} from '@src/types/onyx';
import type ReportAction from '@src/types/onyx/ReportAction';
import type {ReportActions} from '@src/types/onyx/ReportAction';
import type {OnyxData} from '@src/types/onyx/Request';
import type {AnyOnyxData, OnyxData} from '@src/types/onyx/Request';
import type Transaction from '@src/types/onyx/Transaction';

import type {OnyxEntry, OnyxMultiSetInput} from 'react-native-onyx';
Expand Down Expand Up @@ -2294,6 +2294,59 @@ describe('actions/IOU/ReportWorkflow', () => {
});
});

describe('approveMoneyRequest outstanding child request', () => {
beforeEach(() => {
jest.clearAllMocks();
// eslint-disable-next-line rulesdir/no-multiple-api-calls -- Inspecting API.write calls to verify optimistic/failure data.
jest.spyOn(API, 'write').mockImplementation(() => Promise.resolve());
});

it('clears hasOutstandingChildRequest optimistically and restores it if the approve request fails', () => {
const expenseReport: Report = {
...createRandomReport(1, undefined),
type: CONST.REPORT.TYPE.EXPENSE,
total: 10000,
currency: CONST.CURRENCY.USD,
statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED,
stateNum: CONST.REPORT.STATE_NUM.SUBMITTED,
// The report shows the LHN green dot before approval.
hasOutstandingChildRequest: true,
};
const expenseReportPolicy: Policy = {
...createRandomPolicy(Number(expenseReport.policyID), CONST.POLICY.TYPE.TEAM),
approvalMode: CONST.POLICY.APPROVAL_MODE.BASIC,
};
const reportKey = `${ONYXKEYS.COLLECTION.REPORT}${expenseReport.reportID}` as const;

approveMoneyRequest({
expenseReport,
expenseReportPolicy,
currentUserAccountIDParam: CARLOS_ACCOUNT_ID,
currentUserEmailParam: CARLOS_EMAIL,
hasViolations: false,
isASAPSubmitBetaEnabled: false,
expenseReportCurrentNextStepDeprecated: undefined,
betas: [CONST.BETAS.ALL],
userBillingGracePeriodEnds: undefined,
amountOwed: 0,
ownerBillingGracePeriodEnd: undefined,
delegateEmail: undefined,
ownerLogin: undefined,
});

// eslint-disable-next-line rulesdir/no-multiple-api-calls -- Inspecting mock call args to verify optimistic/failure data structure
const onyxData: AnyOnyxData | undefined = jest.mocked(API.write).mock.calls.at(0)?.[2];

// The green dot clears optimistically because the expense report's own flag is set to false.
const optimisticReport: OnyxEntry<Report> = onyxData?.optimisticData?.find((update) => update.key === reportKey)?.value;
expect(optimisticReport?.hasOutstandingChildRequest).toBe(false);

// If the approve request fails, the flag is restored so the green dot reappears.
const failureReport: OnyxEntry<Report> = onyxData?.failureData?.find((update) => update.key === reportKey)?.value;
expect(failureReport?.hasOutstandingChildRequest).toBe(true);
});
});

describe('canIOUBePaid', () => {
it('For invoices from archived workspaces', async () => {
const {policy, convertedInvoiceChat: chatReport}: InvoiceTestData = InvoiceData;
Expand Down
Loading