Skip to content

Commit

Permalink
Merge pull request #34677 from Expensify/georgia-formatExpiration
Browse files Browse the repository at this point in the history
Fix card number previews and expiration date format on expensify card page
  • Loading branch information
Joel Bettner authored Jan 19, 2024
2 parents e6b0761 + ed9fa1e commit 991a4e2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
17 changes: 17 additions & 0 deletions src/libs/CardUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,22 @@ function getYearFromExpirationDateString(expirationDateString: string) {
return cardYear.length === 2 ? `20${cardYear}` : cardYear;
}

/**
* @returns string with a month in MM/YYYY format
*/
function formatCardExpiration(expirationDateString: string) {
// already matches MM/YYYY format
const dateFormat = /^\d{2}\/\d{4}$/;
if (dateFormat.test(expirationDateString)) {
return expirationDateString;
}

const expirationMonth = getMonthFromExpirationDateString(expirationDateString);
const expirationYear = getYearFromExpirationDateString(expirationDateString);

return `${expirationMonth}/${expirationYear}`;
}

/**
* @param cardList - collection of assigned cards
* @returns collection of assigned cards grouped by domain
Expand Down Expand Up @@ -120,6 +136,7 @@ export {
isExpensifyCard,
isCorporateCard,
getDomainCards,
formatCardExpiration,
getMonthFromExpirationDateString,
getYearFromExpirationDateString,
maskCard,
Expand Down
6 changes: 3 additions & 3 deletions src/pages/settings/Wallet/ExpensifyCardPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ function ExpensifyCardPage({
{details.pan ? (
<CardDetails
pan={details.pan}
expiration={details.expiration}
expiration={CardUtils.formatCardExpiration(details.expiration)}
cvv={details.cvv}
privatePersonalDetails={{address: details.address}}
domain={domain}
Expand All @@ -235,7 +235,7 @@ function ExpensifyCardPage({
<>
<MenuItemWithTopDescription
description={translate('cardPage.virtualCardNumber')}
title={CardUtils.maskCard(virtualCard.lastFourPAN)}
title={CardUtils.maskCard('')}
interactive={false}
titleStyle={styles.walletCardNumber}
shouldShowRightComponent
Expand Down Expand Up @@ -271,7 +271,7 @@ function ExpensifyCardPage({
description={translate('cardPage.physicalCardNumber')}
title={CardUtils.maskCard(physicalCard.lastFourPAN)}
interactive={false}
titleStyle={styles.walletCardMenuItem}
titleStyle={styles.walletCardNumber}
/>
<MenuItem
title={translate('reportCardLostOrDamaged.report')}
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/CardUtilsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,14 @@ describe('CardUtils', () => {
expect(cardUtils.getMonthFromExpirationDateString(shortDate)).toBe(expectedMonth);
expect(cardUtils.getYearFromExpirationDateString(shortDate)).toBe(expectedYear);
});

it('Test MM/YYYY format given MM/YY', () => {
expect(cardUtils.formatCardExpiration(shortDateSlashed)).toBe(longDateSlashed);
expect(cardUtils.formatCardExpiration(shortDateSlashed)).toBe(longDateSlashed);
});

it('Test MM/YYYY format given MMYY', () => {
expect(cardUtils.formatCardExpiration(shortDate)).toBe(longDateSlashed);
expect(cardUtils.formatCardExpiration(shortDate)).toBe(longDateSlashed);
});
});

0 comments on commit 991a4e2

Please sign in to comment.