From 2f0c4717a9da62afa55d0e5ceeb3845ca861a1bc Mon Sep 17 00:00:00 2001 From: Carlos Miceli Date: Tue, 10 Feb 2026 15:50:29 -0300 Subject: [PATCH 1/2] add tests --- tests/unit/CardUtilsTest.ts | 79 +++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/tests/unit/CardUtilsTest.ts b/tests/unit/CardUtilsTest.ts index 6727ae71574f..d91a89c95cb2 100644 --- a/tests/unit/CardUtilsTest.ts +++ b/tests/unit/CardUtilsTest.ts @@ -1629,4 +1629,83 @@ describe('CardUtils', () => { }); }); }); + + describe('isMatchingCard', () => { + it('should match by encryptedCardNumber for exact match', () => { + const card: Card = { + encryptedCardNumber: 'encrypted123', + cardName: 'Test Card - 1234', + } as Card; + + expect(isMatchingCard(card, 'encrypted123', 'Different Name')).toBe(true); + }); + + it('should match by normalized card name when encryptedCardNumber does not match', () => { + const card: Card = { + encryptedCardNumber: 'encrypted123', + cardName: 'Business Platinum Card® - JOHN SMITH - 1234', + } as Card; + + // Name without ® should still match + expect(isMatchingCard(card, 'wrongEncrypted', 'Business Platinum Card - JOHN SMITH - 1234')).toBe(true); + }); + + it('should handle special characters (®, ™, ©) in card names', () => { + const card: Card = { + cardName: 'Business Platinum Card® - JOHN SMITH™ - 1234©', + } as Card; + + // All special characters should be normalized + expect(isMatchingCard(card, '', 'Business Platinum Card - JOHN SMITH - 1234')).toBe(true); + }); + + it('should not match cards with different names after normalization', () => { + const card: Card = { + cardName: 'Business Platinum Card® - JOHN SMITH - 1234', + } as Card; + + expect(isMatchingCard(card, '', 'Business Gold Card - JANE DOE - 5678')).toBe(false); + }); + + it('should return false when card.cardName is undefined', () => { + const card: Card = { + encryptedCardNumber: 'encrypted123', + } as Card; + + expect(isMatchingCard(card, 'wrongEncrypted', 'Some Card Name')).toBe(false); + }); + + it('should return false when cardName parameter is empty', () => { + const card: Card = { + cardName: 'Test Card - 1234', + } as Card; + + expect(isMatchingCard(card, '', '')).toBe(false); + }); + + it('should handle cards with only numbers and dashes', () => { + const card: Card = { + cardName: 'Card - 1234', + } as Card; + + expect(isMatchingCard(card, '', 'Card - 1234')).toBe(true); + }); + + it('should trim whitespace when comparing', () => { + const card: Card = { + cardName: ' Business Card - 1234 ', + } as Card; + + expect(isMatchingCard(card, '', 'Business Card - 1234')).toBe(true); + }); + + it('should not match cards with same last 4 digits but different names', () => { + const card: Card = { + cardName: 'Business Platinum Card® - JOHN SMITH - 1234', + } as Card; + + // Different card name but same last 4 digits - should NOT match + expect(isMatchingCard(card, '', 'Business Gold Card - JANE DOE - 1234')).toBe(false); + }); + }); }); From db953640ecce0dc7613b2314bf323b058e7f137d Mon Sep 17 00:00:00 2001 From: MelvinBot Date: Tue, 10 Feb 2026 19:31:32 +0000 Subject: [PATCH 2/2] Add missing isMatchingCard import in CardUtilsTest Co-authored-by: Carlos Miceli --- tests/unit/CardUtilsTest.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/CardUtilsTest.ts b/tests/unit/CardUtilsTest.ts index d91a89c95cb2..a56fa54e673f 100644 --- a/tests/unit/CardUtilsTest.ts +++ b/tests/unit/CardUtilsTest.ts @@ -40,6 +40,7 @@ import { isCustomFeed as isCustomFeedCardUtils, isExpensifyCard, isExpensifyCardFullySetUp, + isMatchingCard, lastFourNumbersFromCardName, maskCardNumber, sortCardsByCardholderName,