Skip to content

Commit 69df4b9

Browse files
Address review: tighten lastFourPAN fallback comment and pin behavior with tests
Clarify the third-party `cardName` fallback in `useYourSpendData` so the space requirement and no-space fall-through behavior are explicit, and add two cases to `lastFourNumbersFromCardName` to lock that behavior in.
1 parent 15f3281 commit 69df4b9

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

src/pages/home/YourSpendSection/useYourSpendData.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,9 @@ function useYourSpendData(): UseYourSpendDataReturn {
221221
const total = snapshot?.count ? snapshot.total : cached?.total;
222222
const currency = snapshot?.count ? snapshot.currency : cached?.currency;
223223

224-
// Some third-party cards leave `lastFourPAN` empty and stash the digits in
225-
// `cardName` (e.g. "CREDIT CARD...1234"). Ternary, not `??`, so empty
226-
// strings fall through.
224+
// Fallback for third-party cards with empty `lastFourPAN` and digits in `cardName`
225+
// (e.g. "CREDIT CARD...1234"; no-space names fall through to ""). Ternary so
226+
// empty-string `lastFourPAN` also falls through.
227227
const lastFour = card.lastFourPAN ? card.lastFourPAN : lastFourNumbersFromCardName(card.cardName);
228228
if (!lastFour) {
229229
return acc;

tests/unit/CardUtilsTest.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,6 +1578,16 @@ describe('CardUtils', () => {
15781578
const lastFour = lastFourNumbersFromCardName('Business Card Cash - Business');
15791579
expect(lastFour).toBe('');
15801580
});
1581+
1582+
it('Should return last 4 numbers for an ellipsis name with a space (e.g. "CREDIT CARD...1234")', () => {
1583+
const lastFour = lastFourNumbersFromCardName('CREDIT CARD...1234');
1584+
expect(lastFour).toBe('1234');
1585+
});
1586+
1587+
it('Should return empty string for an ellipsis name without a space (e.g. "CREDITCARD...1234")', () => {
1588+
const lastFour = lastFourNumbersFromCardName('CREDITCARD...1234');
1589+
expect(lastFour).toBe('');
1590+
});
15811591
});
15821592

15831593
describe('maskCardNumber', () => {

0 commit comments

Comments
 (0)