Skip to content

Commit

Permalink
Merge pull request #42018 from dominictb/fix/41614
Browse files Browse the repository at this point in the history
fix: update next step for approver
  • Loading branch information
mountiny authored May 27, 2024
2 parents b720ae6 + 9bbed8f commit 63a20f4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 43 deletions.
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

0 comments on commit 63a20f4

Please sign in to comment.