Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/libs/ReportNameUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ function computeReportNameBasedOnReportAction(

if (isMoneyRequestAction(parentReportAction)) {
const originalMessage = getOriginalMessage(parentReportAction);
const last4Digits = reportPolicy?.achAccount?.accountNumber?.slice(-4) ?? '';
const last4Digits = originalMessage?.accountNumber?.slice(-4) ?? reportPolicy?.achAccount?.accountNumber?.slice(-4) ?? '';

if (originalMessage?.type === CONST.IOU.REPORT_ACTION_TYPE.PAY) {
if (originalMessage.paymentType === CONST.IOU.PAYMENT_TYPE.ELSEWHERE) {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/inbox/report/actionContents/PaymentContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function PaymentContent({action, policyID}: PaymentContentProps) {
}

if (paymentType === CONST.IOU.PAYMENT_TYPE.VBBA) {
const last4Digits = getBankAccountLastFourDigits(originalMessage.bankAccountID, bankAccountList, policy);
const last4Digits = originalMessage.accountNumber?.slice(-4) ?? getBankAccountLastFourDigits(originalMessage.bankAccountID, bankAccountList, policy);
const crossBorderMessage = getCrossBorderReimbursedMessage(translate, originalMessage, last4Digits);
if (wasAutoPaid) {
const translation = crossBorderMessage ?? translate('iou.automaticallyPaidWithBusinessBankAccount', '', last4Digits);
Expand Down
50 changes: 49 additions & 1 deletion tests/ui/ReportActionItemTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';
import * as ReportActionUtils from '@src/libs/ReportActionsUtils';
import ONYXKEYS from '@src/ONYXKEYS';
import type {BankAccountList, ReportAction} from '@src/types/onyx';
import type {BankAccountList, Report, ReportAction} from '@src/types/onyx';
import type {OriginalMessage} from '@src/types/onyx/ReportAction';
import type ReportActionName from '@src/types/onyx/ReportActionName';

Expand Down Expand Up @@ -1949,6 +1949,54 @@ describe('ReportActionItem', () => {
expect(screen.getByText(/paid with bank account/i)).toBeOnTheScreen();
});

it('IOU PAY VBBA manual prefers originalMessage accountNumber over current policy account', async () => {
const policyID = 'snapshot-policy';
await act(async () => {
await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {
id: policyID,
achAccount: {
accountNumber: 'XXXX2222',
},
});
});
await waitForBatchedUpdatesWithAct();

const action = createReportAction(CONST.REPORT.ACTIONS.TYPE.IOU, {
type: CONST.IOU.REPORT_ACTION_TYPE.PAY,
paymentType: CONST.IOU.PAYMENT_TYPE.VBBA,
automaticAction: false,
accountNumber: 'XXXX1111',
});
const report = {
reportID: 'testReport',
ownerAccountID: ACTOR_ACCOUNT_ID,
policyID,
} as Report;

render(
<ComposeProviders components={[OnyxListItemProvider, LocaleContextProvider, HTMLEngineProvider]}>
<ScreenWrapper testID="test">
<PortalProvider>
<ReportActionItem
chatReport={undefined}
report={report}
transactionThreadReport={undefined}
parentReportAction={undefined}
action={action}
displayAsGroup={false}
shouldDisplayNewMarker={false}
isFirstVisibleReportAction={false}
/>
</PortalProvider>
</ScreenWrapper>
</ComposeProviders>,
);
await waitForBatchedUpdatesWithAct();

expect(screen.getByText(/1111/)).toBeOnTheScreen();
expect(screen.queryByText(/2222/)).toBeNull();
});

it('IOU PAY VBBA automatic renders auto-paid message', async () => {
await act(async () => {
// eslint-disable-next-line @typescript-eslint/naming-convention
Expand Down
54 changes: 54 additions & 0 deletions tests/unit/ReportNameUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,60 @@ describe('ReportNameUtils', () => {
);
expect(name).toBe(expected);
});
test('VBBA pay parent action uses action accountNumber before current policy account', () => {
const policyID = '123';
const thread: Report = {
...createWorkspaceThread(61),
policyID,
};
const parentAction: ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.IOU> = {
actionName: CONST.REPORT.ACTIONS.TYPE.IOU,
reportActionID: String(thread.parentReportActionID),
message: [],
created: '',
lastModified: '',
actorAccountID: 1,
person: [],
originalMessage: {
type: CONST.IOU.REPORT_ACTION_TYPE.PAY,
paymentType: CONST.IOU.PAYMENT_TYPE.VBBA,
accountNumber: 'XXXX1111',
},
};

const reportActionsCollection: Record<string, ReportActions> = {
[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${thread.parentReportID}`]: {
[String(thread.parentReportActionID)]: parentAction,
},
};
const policiesCollection: Record<string, Policy> = {
[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`]: {
...createRandomPolicy(Number(policyID), CONST.POLICY.TYPE.TEAM),
id: policyID,
achAccount: {
bankAccountID: 1,
accountNumber: 'XXXX2222',
routingNumber: '',
addressName: '',
bankName: '',
reimburser: '',
},
},
};

const name = computeReportName(
thread,
emptyCollections.reports,
policiesCollection,
undefined,
undefined,
participantsPersonalDetails,
reportActionsCollection,
currentUserAccountID,
);

expect(name).toBe(translate(CONST.LOCALES.EN, 'iou.businessBankAccount', undefined, '1111'));
});
test('Cross-border pay parent action', () => {
// Given a thread on a payment that converted currency for the employee
const thread: Report = createWorkspaceThread(60);
Expand Down
Loading