Skip to content
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
18 changes: 9 additions & 9 deletions src/libs/ReportNameUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@

let allPersonalDetails: OnyxEntry<PersonalDetailsList>;

Onyx.connect({

Check warning on line 143 in src/libs/ReportNameUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
allPersonalDetails = value;
Expand Down Expand Up @@ -393,15 +393,15 @@
) {
const harvesting = !isMarkAsClosedAction(parentReportAction) ? (getOriginalMessage(parentReportAction)?.harvesting ?? false) : false;
if (harvesting) {
return translate('iou.automaticallySubmitted');
return Parser.htmlToText(translate('iou.automaticallySubmitted'));
}
return translate('iou.submitted', getOriginalMessage(parentReportAction)?.message);
}

if (isActionOfType(parentReportAction, CONST.REPORT.ACTIONS.TYPE.FORWARDED)) {
const {automaticAction} = getOriginalMessage(parentReportAction) ?? {};
if (automaticAction) {
return translate('iou.automaticallyForwarded');
return Parser.htmlToText(translate('iou.automaticallyForwarded'));
}
return translate('iou.forwarded');
}
Expand Down Expand Up @@ -566,7 +566,7 @@
}

if (isMovedAction(parentReportAction)) {
return getMovedActionMessage(translate, parentReportAction, parentReport);
return Parser.htmlToText(getMovedActionMessage(translate, parentReportAction, parentReport));
}

if (
Expand All @@ -591,13 +591,13 @@
}
if (originalMessage.paymentType === CONST.IOU.PAYMENT_TYPE.VBBA) {
if (originalMessage.automaticAction) {
return translate('iou.automaticallyPaidWithBusinessBankAccount', undefined, last4Digits);
return Parser.htmlToText(translate('iou.automaticallyPaidWithBusinessBankAccount', undefined, last4Digits));
}
return translate('iou.businessBankAccount', undefined, last4Digits);
}
if (originalMessage.paymentType === CONST.IOU.PAYMENT_TYPE.EXPENSIFY) {
if (originalMessage.automaticAction) {
return translate('iou.automaticallyPaidWithExpensify');
return Parser.htmlToText(translate('iou.automaticallyPaidWithExpensify'));
}
return translate('iou.paidWithExpensify');
}
Expand All @@ -607,7 +607,7 @@
if (isActionOfType(parentReportAction, CONST.REPORT.ACTIONS.TYPE.APPROVED)) {
const {automaticAction} = getOriginalMessage(parentReportAction) ?? {};
if (automaticAction) {
return translate('iou.automaticallyApproved');
return Parser.htmlToText(translate('iou.automaticallyApproved'));
}
return translate('iou.approvedMessage');
}
Expand All @@ -629,11 +629,11 @@
}

if (isActionOfType(parentReportAction, CONST.REPORT.ACTIONS.TYPE.COMPANY_CARD_CONNECTION_BROKEN)) {
return getCompanyCardConnectionBrokenMessage(translate, parentReportAction);
return Parser.htmlToText(getCompanyCardConnectionBrokenMessage(translate, parentReportAction));
}

if (isActionOfType(parentReportAction, CONST.REPORT.ACTIONS.TYPE.PLAID_BALANCE_FAILURE)) {
return getPlaidBalanceFailureMessage(translate, parentReportAction);
return Parser.htmlToText(getPlaidBalanceFailureMessage(translate, parentReportAction));
}

if (isActionOfType(parentReportAction, CONST.REPORT.ACTIONS.TYPE.TRAVEL_UPDATE)) {
Expand All @@ -651,7 +651,7 @@
}

if (isActionOfType(parentReportAction, CONST.REPORT.ACTIONS.TYPE.SETTLEMENT_ACCOUNT_LOCKED)) {
return getSettlementAccountLockedMessage(translate, parentReportAction);
return Parser.htmlToText(getSettlementAccountLockedMessage(translate, parentReportAction));
}

return undefined;
Expand Down
169 changes: 150 additions & 19 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1307,9 +1307,9 @@ describe('ReportUtils', () => {

const policies = {[`${ONYXKEYS.COLLECTION.POLICY}${policy.id}`]: policy};
const reportActions = {[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.parentReportID}`]: {[submittedParentReportAction.reportActionID]: submittedParentReportAction}};
expect(computeReportName(expenseReport, undefined, policies, undefined, undefined, undefined, reportActions)).toBe(
'approved via <a href="https://help.expensify.com/articles/new-expensify/workspaces/Set-up-rules#configure-expense-report-rules">workspace rules</a>',
);

// Note: computeReportName returns the text version, not HTML
expect(computeReportName(expenseReport, undefined, policies, undefined, undefined, undefined, reportActions)).toBe('approved via workspace rules');
});

test('shown when the report is approved', () => {
Expand All @@ -1334,9 +1334,9 @@ describe('ReportUtils', () => {

const policies = {[`${ONYXKEYS.COLLECTION.POLICY}${policy.id}`]: policy};
const reportActions = {[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.parentReportID}`]: {[submittedParentReportAction.reportActionID]: submittedParentReportAction}};
expect(computeReportName(expenseReport, undefined, policies, undefined, undefined, undefined, reportActions)).toBe(
'approved via <a href="https://help.expensify.com/articles/new-expensify/workspaces/Set-up-rules#configure-expense-report-rules">workspace rules</a>',
);

// Note: computeReportName returns the text version, not HTML
expect(computeReportName(expenseReport, undefined, policies, undefined, undefined, undefined, reportActions)).toBe('approved via workspace rules');
});
});

Expand All @@ -1363,9 +1363,9 @@ describe('ReportUtils', () => {

const policies = {[`${ONYXKEYS.COLLECTION.POLICY}${policy.id}`]: policy};
const reportActions = {[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.parentReportID}`]: {[submittedParentReportAction.reportActionID]: submittedParentReportAction}};
expect(computeReportName(expenseReport, undefined, policies, undefined, undefined, undefined, reportActions)).toBe(
'submitted via <a href="https://help.expensify.com/articles/new-expensify/workspaces/Set-up-workflows#select-workflows">delay submissions</a>',
);

// Note: computeReportName returns the text version, not HTML
expect(computeReportName(expenseReport, undefined, policies, undefined, undefined, undefined, reportActions)).toBe('submitted via delay submissions');
});

test('shown when report is submitted and status is closed', () => {
Expand All @@ -1390,9 +1390,9 @@ describe('ReportUtils', () => {

const policies = {[`${ONYXKEYS.COLLECTION.POLICY}${policy.id}`]: policy};
const reportActions = {[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.parentReportID}`]: {[submittedParentReportAction.reportActionID]: submittedParentReportAction}};
expect(computeReportName(expenseReport, undefined, policies, undefined, undefined, undefined, reportActions)).toBe(
'submitted via <a href="https://help.expensify.com/articles/new-expensify/workspaces/Set-up-workflows#select-workflows">delay submissions</a>',
);

// Note: computeReportName returns the text version, not HTML
expect(computeReportName(expenseReport, undefined, policies, undefined, undefined, undefined, reportActions)).toBe('submitted via delay submissions');
});
});

Expand Down Expand Up @@ -2227,9 +2227,9 @@ describe('ReportUtils', () => {
[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${threadReport.parentReportID}`]: {[vbbaPayAction.reportActionID]: vbbaPayAction},
};
const reportName = computeReportName(threadReport, undefined, policies, undefined, undefined, participantsPersonalDetails, reportActions);
expect(reportName).toBe(
'paid with bank account 7890 via <a href="https://help.expensify.com/articles/new-expensify/workspaces/Set-up-rules#configure-expense-report-rules">workspace rules</a>',
);

// Note: computeReportName returns the text version, not HTML
expect(reportName).toBe('paid with bank account 7890 via workspace rules');
});

test('should return forwarded action name', () => {
Expand Down Expand Up @@ -2275,9 +2275,8 @@ describe('ReportUtils', () => {
};
const reportName = computeReportName(threadReport, undefined, undefined, undefined, undefined, participantsPersonalDetails, reportActions);

expect(reportName).toBe(
'approved via <a href="https://help.expensify.com/articles/new-expensify/workspaces/Set-up-rules#configure-expense-report-rules">workspace rules</a>',
);
// Note: computeReportName returns the text version, not HTML
expect(reportName).toBe('approved via workspace rules');
});

test('should return submitted action name', () => {
Expand Down Expand Up @@ -2401,10 +2400,142 @@ describe('ReportUtils', () => {
};
const reportName = computeReportName(threadReport, undefined, undefined, undefined, undefined, participantsPersonalDetails, reportActions);

// Note: computeReportName returns the text version, not HTML
expect(reportName).toBe('The Regions Bank cards connection is broken. To restore card imports, log into your bank.');
});

test('should handle automatically paid with Expensify action', () => {
const expensifyPayAction: ReportAction = {
...baseParentReportAction,
actionName: CONST.REPORT.ACTIONS.TYPE.IOU,
originalMessage: {
type: CONST.IOU.REPORT_ACTION_TYPE.PAY,
paymentType: CONST.IOU.PAYMENT_TYPE.EXPENSIFY,
automaticAction: true,
},
};

const threadReport: Report = {
...baseExpenseReport,
parentReportID: baseChatReport.reportID,
parentReportActionID: expensifyPayAction.reportActionID,
};

const reportActions = {
[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${threadReport.parentReportID}`]: {[expensifyPayAction.reportActionID]: expensifyPayAction},
};
const reportName = computeReportName(threadReport, undefined, undefined, undefined, undefined, participantsPersonalDetails, reportActions);

// Note: computeReportName returns the text version, not HTML
expect(reportName).toBe('paid with Expensify via workspace rules');
});

test('should handle plaid balance failure action', () => {
const plaidBalanceFailureAction: ReportAction = {
...baseParentReportAction,
actionName: CONST.REPORT.ACTIONS.TYPE.PLAID_BALANCE_FAILURE,
originalMessage: {
maskedAccountNumber: '****1234',
policyID: '1',
},
};

const threadReport: Report = {
...baseExpenseReport,
parentReportID: baseChatReport.reportID,
parentReportActionID: plaidBalanceFailureAction.reportActionID,
};

const reportActions = {
[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${threadReport.parentReportID}`]: {[plaidBalanceFailureAction.reportActionID]: plaidBalanceFailureAction},
};
const reportName = computeReportName(threadReport, undefined, undefined, undefined, undefined, participantsPersonalDetails, reportActions);

// Note: computeReportName returns the text version, not HTML
expect(reportName).toBe(
`The Regions Bank cards connection is broken. To restore card imports, <a href='https://dev.new.expensify.com:8082/workspaces/1/company-cards'>log into your bank</a>.`,
'the Plaid connection to your business bank account is broken. Please reconnect your bank account ****1234 so you can continue to use your Expensify Cards.',
);
});

test('should handle settlement account locked action', () => {
const settlementAccountLockedAction: ReportAction = {
...baseParentReportAction,
actionName: CONST.REPORT.ACTIONS.TYPE.SETTLEMENT_ACCOUNT_LOCKED,
originalMessage: {
maskedBankAccountNumber: '****5678',
policyID: 'policy1',
},
};

const threadReport: Report = {
...baseExpenseReport,
parentReportID: baseChatReport.reportID,
parentReportActionID: settlementAccountLockedAction.reportActionID,
};

const reportActions = {
[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${threadReport.parentReportID}`]: {[settlementAccountLockedAction.reportActionID]: settlementAccountLockedAction},
};
const reportName = computeReportName(threadReport, undefined, undefined, undefined, undefined, participantsPersonalDetails, reportActions);

// Note: computeReportName returns the text version, not HTML
expect(reportName).toBe(
'business bank account ****5678 has been automatically locked due to an issue with either Reimbursement or Expensify Card settlement. Please fix the issue in your workspace settings.',
);
});

test('should handle automatically forwarded action', () => {
const autoForwardedAction: ReportAction = {
...baseParentReportAction,
actionName: CONST.REPORT.ACTIONS.TYPE.FORWARDED,
originalMessage: {
amount: 169,
currency: 'USD',
automaticAction: true,
type: CONST.IOU.REPORT_ACTION_TYPE.CREATE,
},
};

const threadReport: Report = {
...baseExpenseReport,
parentReportID: baseChatReport.reportID,
parentReportActionID: autoForwardedAction.reportActionID,
};

const reportActions = {
[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${threadReport.parentReportID}`]: {[autoForwardedAction.reportActionID]: autoForwardedAction},
};
const reportName = computeReportName(threadReport, undefined, undefined, undefined, undefined, participantsPersonalDetails, reportActions);

// Note: computeReportName returns the text version, not HTML
expect(reportName).toBe('approved via workspace rules');
});

test('should handle automatically submitted via harvesting action', () => {
const autoSubmittedAction: ReportAction = {
...baseParentReportAction,
actionName: CONST.REPORT.ACTIONS.TYPE.SUBMITTED,
originalMessage: {
harvesting: true,
amount: 1000,
currency: 'USD',
},
};

const threadReport: Report = {
...baseExpenseReport,
parentReportID: baseChatReport.reportID,
parentReportActionID: autoSubmittedAction.reportActionID,
};

const reportActions = {
[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${threadReport.parentReportID}`]: {[autoSubmittedAction.reportActionID]: autoSubmittedAction},
};
const reportName = computeReportName(threadReport, undefined, undefined, undefined, undefined, participantsPersonalDetails, reportActions);

// Note: computeReportName returns the text version, not HTML
expect(reportName).toBe('submitted via delay submissions');
});
});

describe('Invoices', () => {
Expand Down
Loading