Skip to content

Commit

Permalink
Merge pull request #34939 from Expensify/vit-fixWrongAmount
Browse files Browse the repository at this point in the history
[wave6] Polish the modified expense message when changing from partial amount
  • Loading branch information
mountiny committed Jan 23, 2024
2 parents 6040dd3 + 1f89da3 commit 203a5cf
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/libs/ModifiedExpenseMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ function getForReportAction(reportAction: ReportAction): string {
const hasModifiedMerchant = reportActionOriginalMessage && 'oldMerchant' in reportActionOriginalMessage && 'merchant' in reportActionOriginalMessage;
if (hasModifiedAmount) {
const oldCurrency = reportActionOriginalMessage?.oldCurrency ?? '';
const oldAmount = CurrencyUtils.convertToDisplayString(reportActionOriginalMessage?.oldAmount ?? 0, oldCurrency);
const oldAmountValue = reportActionOriginalMessage?.oldAmount ?? 0;
const oldAmount = oldAmountValue > 0 ? CurrencyUtils.convertToDisplayString(reportActionOriginalMessage?.oldAmount ?? 0, oldCurrency) : '';

const currency = reportActionOriginalMessage?.currency ?? '';
const amount = CurrencyUtils.convertToDisplayString(reportActionOriginalMessage?.amount ?? 0, currency);
Expand Down
40 changes: 40 additions & 0 deletions tests/unit/ModifiedExpenseMessageTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,27 @@ describe('ModifiedExpenseMessage', () => {
});
});

describe('when the amount is changed while the original value was partial', () => {
const reportAction = {
...createRandomReportAction(1),
actionName: CONST.REPORT.ACTIONS.TYPE.MODIFIEDEXPENSE,
originalMessage: {
amount: 1800,
currency: CONST.CURRENCY.USD,
oldAmount: 0,
oldCurrency: CONST.CURRENCY.USD,
},
};

it('returns the correct text message', () => {
const expectedResult = `set the amount to $18.00.`;

const result = ModifiedExpenseMessage.getForReportAction(reportAction);

expect(result).toEqual(expectedResult);
});
});

describe('when the amount is changed and the description is removed', () => {
const reportAction = {
...createRandomReportAction(1),
Expand Down Expand Up @@ -169,6 +190,25 @@ describe('ModifiedExpenseMessage', () => {
});
});

describe('when the merchant is changed while the previous merchant was partial', () => {
const reportAction = {
...createRandomReportAction(1),
actionName: CONST.REPORT.ACTIONS.TYPE.MODIFIEDEXPENSE,
originalMessage: {
merchant: 'KFC',
oldMerchant: CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT,
},
};

it('returns the correct text message', () => {
const expectedResult = `set the merchant to "KFC".`;

const result = ModifiedExpenseMessage.getForReportAction(reportAction);

expect(result).toEqual(expectedResult);
});
});

describe('when the merchant and the description are removed', () => {
const reportAction = {
...createRandomReportAction(1),
Expand Down

0 comments on commit 203a5cf

Please sign in to comment.