Skip to content

Commit

Permalink
Merge pull request #49424 from Expensify/dangrous-nextstepreimburser
Browse files Browse the repository at this point in the history
Update Report Next Steps to fallback to "an admin" instead of policy owner if no reimburser set
  • Loading branch information
roryabraham authored Sep 30, 2024
2 parents bab776b + 4d2ac40 commit 889ba4b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
13 changes: 8 additions & 5 deletions src/libs/NextStepUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ function buildNextStep(report: OnyxEntry<Report>, predictedNextStatus: ValueOf<t
const nextApproverDisplayName = getNextApproverDisplayName(report);

const reimburserAccountID = PolicyUtils.getReimburserAccountID(policy);
const reimburserDisplayName = ReportUtils.getDisplayNameForParticipant(reimburserAccountID);
const type: ReportNextStep['type'] = 'neutral';
let optimisticNextStep: ReportNextStep | null;

Expand Down Expand Up @@ -261,10 +260,14 @@ function buildNextStep(report: OnyxEntry<Report>, predictedNextStatus: ValueOf<t
{
text: 'Waiting for ',
},
{
text: reimburserDisplayName,
type: 'strong',
},
reimburserAccountID === -1
? {
text: 'an admin',
}
: {
text: ReportUtils.getDisplayNameForParticipant(reimburserAccountID),
type: 'strong',
},
{
text: ' to ',
},
Expand Down
6 changes: 3 additions & 3 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,11 +550,11 @@ function getForwardsToAccount(policy: OnyxEntry<Policy>, employeeEmail: string,
}

/**
* Returns the accountID of the policy reimburser, if not available — falls back to the policy owner.
* Returns the accountID of the policy reimburser, if not available returns -1.
*/
function getReimburserAccountID(policy: OnyxEntry<Policy>): number {
const reimburserEmail = policy?.achAccount?.reimburser ?? policy?.owner ?? '';
return getAccountIDsByLogins([reimburserEmail])[0];
const reimburserEmail = policy?.achAccount?.reimburser ?? '';
return reimburserEmail ? getAccountIDsByLogins([reimburserEmail])[0] : -1;
}

function getPersonalPolicy() {
Expand Down
19 changes: 12 additions & 7 deletions tests/unit/NextStepUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ describe('libs/NextStepUtils', () => {
const currentUserAccountID = 37;
const strangeEmail = 'stranger@expensify.com';
const strangeAccountID = 50;
const ownerEmail = 'owner@expensify.com';
const ownerAccountID = 99;
const policyID = '1';
const policy: Policy = {
// Important props
id: policyID,
owner: currentUserEmail,
owner: ownerEmail,
harvesting: {
enabled: false,
},
Expand Down Expand Up @@ -56,6 +58,11 @@ describe('libs/NextStepUtils', () => {
login: currentUserEmail,
avatar: '',
},
[ownerAccountID]: {
accountID: ownerAccountID,
login: ownerEmail,
avatar: '',
},
},
...policyCollectionDataSet,
}).then(waitForBatchedUpdates);
Expand Down Expand Up @@ -395,14 +402,13 @@ describe('libs/NextStepUtils', () => {
test('self review', () => {
optimisticNextStep.icon = CONST.NEXT_STEP.ICONS.HOURGLASS;

// Waiting for userAdmin to pay expense(s)
// Waiting for an admin to pay expense(s)
optimisticNextStep.message = [
{
text: 'Waiting for ',
},
{
text: `${currentUserEmail}`,
type: 'strong',
text: `an admin`,
},
{
text: ' to ',
Expand Down Expand Up @@ -530,14 +536,13 @@ describe('libs/NextStepUtils', () => {
test('payer', () => {
optimisticNextStep.icon = CONST.NEXT_STEP.ICONS.HOURGLASS;

// Waiting for userAdmin to pay expense(s).
// Waiting for an admin to pay expense(s).
optimisticNextStep.message = [
{
text: 'Waiting for ',
},
{
text: currentUserEmail,
type: 'strong',
text: 'an admin',
},
{
text: ' to ',
Expand Down

0 comments on commit 889ba4b

Please sign in to comment.