Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update next step for approver #42018

Merged
merged 7 commits into from
May 27, 2024
Merged
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
47 changes: 23 additions & 24 deletions src/libs/NextStepUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import * as PolicyUtils from './PolicyUtils';
import * as ReportUtils from './ReportUtils';

let currentUserAccountID = -1;
let currentUserEmail = '';
Onyx.connect({
key: ONYXKEYS.SESSION,
callback: (value) => {
Expand All @@ -24,6 +25,7 @@ Onyx.connect({
}

currentUserAccountID = value?.accountID ?? -1;
currentUserEmail = value?.email ?? '';
},
});

Expand Down Expand Up @@ -273,6 +275,27 @@ function buildNextStep(

// Generates an optimistic nextStep once a report has been approved
case CONST.REPORT.STATUS_NUM.APPROVED:
if (
ReportUtils.isInvoiceReport(report) ||
!ReportUtils.isPayer(
{
accountID: currentUserAccountID,
email: currentUserEmail,
},
report as Report,
)
) {
optimisticNextStep = {
type,
title: 'Finished!',
message: [
{
text: 'No further action required!',
},
],
};
break;
}
// Self review
optimisticNextStep = {
type,
Expand All @@ -297,30 +320,6 @@ function buildNextStep(
},
],
};

// Another owner
if (!isOwner) {
optimisticNextStep.message = [
{
text: 'Waiting for ',
},
{
text: managerDisplayName,
type: 'strong',
},
{
text: ' to ',
},
{
text: 'pay',
type: 'strong',
},
{
text: ' %expenses.',
},
];
}

break;

// Generates an optimistic nextStep once a report has been paid
Expand Down
33 changes: 14 additions & 19 deletions tests/unit/NextStepUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe('libs/NextStepUtils', () => {
type: 'team',
outputCurrency: CONST.CURRENCY.USD,
isPolicyExpenseChatEnabled: true,
reimbursementChoice: CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_MANUAL,
};
const optimisticNextStep: ReportNextStep = {
type: 'neutral',
Expand Down Expand Up @@ -483,25 +484,12 @@ describe('libs/NextStepUtils', () => {
});

describe('it generates an optimistic nextStep once a report has been approved', () => {
test('self review', () => {
optimisticNextStep.title = 'Next Steps:';
test('non-payer', () => {
report.managerID = strangeAccountID;
optimisticNextStep.title = 'Finished!';
optimisticNextStep.message = [
{
text: 'Waiting for ',
},
{
text: 'you',
type: 'strong',
},
{
text: ' to ',
},
{
text: 'pay',
type: 'strong',
},
{
text: ' %expenses.',
text: 'No further action required!',
},
];

Expand All @@ -510,8 +498,7 @@ describe('libs/NextStepUtils', () => {
expect(result).toMatchObject(optimisticNextStep);
});

test('another owner', () => {
report.ownerAccountID = strangeAccountID;
test('payer', () => {
optimisticNextStep.title = 'Next Steps:';
optimisticNextStep.message = [
{
Expand All @@ -532,10 +519,18 @@ describe('libs/NextStepUtils', () => {
text: ' %expenses.',
},
];
// mock the report as approved
const originalState = {stateNum: report.stateNum, statusNum: report.statusNum};
report.stateNum = CONST.REPORT.STATE_NUM.APPROVED;
report.statusNum = CONST.REPORT.STATUS_NUM.APPROVED;

const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.APPROVED);

expect(result).toMatchObject(optimisticNextStep);

// restore
report.stateNum = originalState.stateNum;
report.statusNum = originalState.statusNum;
});
});

Expand Down
Loading