Skip to content

Commit da3beb5

Browse files
committed
add test for workspace submit manager
1 parent 3bf9b88 commit da3beb5

1 file changed

Lines changed: 82 additions & 0 deletions

File tree

tests/actions/IOUTest/ReportWorkflowTest.ts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,6 +1383,88 @@ describe('actions/IOU/ReportWorkflow', () => {
13831383
const optimisticReportUpdate = onyxData.optimisticData?.find((update) => update.key === `${ONYXKEYS.COLLECTION.REPORT}${expenseReport.reportID}`);
13841384
expect((optimisticReportUpdate?.value as Report | undefined)?.managerID).toBe(adminAccountID);
13851385
});
1386+
it('keeps the workspace chat outstanding when an admin submits after approver changes', async () => {
1387+
// eslint-disable-next-line rulesdir/no-multiple-api-calls -- Inspecting optimistic parent chat data after submit from workspace chat.
1388+
const apiWriteSpy = jest.spyOn(API, 'write').mockImplementation(() => Promise.resolve());
1389+
const policyID = '1';
1390+
const workspaceChatReportID = '2';
1391+
const adminAccountID = 100;
1392+
const submitterAccountID = 101;
1393+
const previousApproverAccountID = 102;
1394+
const adminEmail = 'admin@example.com';
1395+
const submitterEmail = 'submitter@example.com';
1396+
const previousApproverEmail = 'previous-approver@example.com';
1397+
1398+
await Onyx.set(ONYXKEYS.PERSONAL_DETAILS_LIST, {
1399+
[adminAccountID]: {accountID: adminAccountID, login: adminEmail},
1400+
[submitterAccountID]: {accountID: submitterAccountID, login: submitterEmail},
1401+
[previousApproverAccountID]: {accountID: previousApproverAccountID, login: previousApproverEmail},
1402+
});
1403+
1404+
const parentReport: Report = {
1405+
...createRandomReport(Number(workspaceChatReportID), undefined),
1406+
reportID: workspaceChatReportID,
1407+
type: CONST.REPORT.TYPE.CHAT,
1408+
chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT,
1409+
policyID,
1410+
ownerAccountID: submitterAccountID,
1411+
managerID: adminAccountID,
1412+
iouReportID: '1',
1413+
hasOutstandingChildRequest: true,
1414+
};
1415+
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${workspaceChatReportID}`, parentReport);
1416+
await waitForBatchedUpdates();
1417+
1418+
const policy: Policy = {
1419+
...createRandomPolicy(Number(policyID)),
1420+
id: policyID,
1421+
role: CONST.POLICY.ROLE.ADMIN,
1422+
type: CONST.POLICY.TYPE.CORPORATE,
1423+
approvalMode: CONST.POLICY.APPROVAL_MODE.ADVANCED,
1424+
approver: adminEmail,
1425+
owner: adminEmail,
1426+
employeeList: {
1427+
[submitterEmail]: {
1428+
email: submitterEmail,
1429+
submitsTo: adminEmail,
1430+
},
1431+
},
1432+
};
1433+
const expenseReport: Report = {
1434+
...createRandomReport(Number(policyID), undefined),
1435+
reportID: '1',
1436+
policyID,
1437+
parentReportID: workspaceChatReportID,
1438+
type: CONST.REPORT.TYPE.EXPENSE,
1439+
ownerAccountID: submitterAccountID,
1440+
managerID: previousApproverAccountID,
1441+
stateNum: CONST.REPORT.STATE_NUM.OPEN,
1442+
statusNum: CONST.REPORT.STATUS_NUM.OPEN,
1443+
total: 1000,
1444+
currency: CONST.CURRENCY.USD,
1445+
};
1446+
1447+
submitReport({
1448+
expenseReport,
1449+
policy,
1450+
currentUserAccountIDParam: adminAccountID,
1451+
currentUserEmailParam: adminEmail,
1452+
hasViolations: false,
1453+
isASAPSubmitBetaEnabled: false,
1454+
expenseReportCurrentNextStepDeprecated: undefined,
1455+
userBillingGracePeriodEnds: undefined,
1456+
amountOwed: 0,
1457+
ownerBillingGracePeriodEnd: undefined,
1458+
delegateEmail: undefined,
1459+
});
1460+
1461+
const [, parameters, onyxData] = apiWriteSpy.mock.calls.at(-1) as [unknown, {managerAccountID?: number}, OnyxData<typeof ONYXKEYS.COLLECTION.REPORT>];
1462+
expect(parameters.managerAccountID).toBe(adminAccountID);
1463+
1464+
const optimisticParentReportUpdate = onyxData.optimisticData?.find((update) => update.key === `${ONYXKEYS.COLLECTION.REPORT}${workspaceChatReportID}`);
1465+
expect((optimisticParentReportUpdate?.value as Report | undefined)?.hasOutstandingChildRequest).toBe(true);
1466+
expect((optimisticParentReportUpdate?.value as Report | undefined)?.iouReportID).toBeNull();
1467+
});
13861468

13871469
it('recomputes the submit approver for a retracted forwarded report', async () => {
13881470
// eslint-disable-next-line rulesdir/no-multiple-api-calls -- Inspecting API.write calls to verify submit payload and optimistic data.

0 commit comments

Comments
 (0)