Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the isCustom name method #55738

Merged
merged 3 commits into from
Jan 24, 2025
Merged
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
4 changes: 2 additions & 2 deletions src/libs/CardUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ function getCardFeedIcon(cardFeed: CompanyCardFeed | typeof CONST.EXPENSIFY_CARD
/**
* Verify if the feed is a custom feed. Those are also refered to as commercial feeds.
*/
function isCustomFeed(feed: CompanyCardFeed): boolean {
return [CONST.COMPANY_CARD.FEED_BANK_NAME.MASTER_CARD, CONST.COMPANY_CARD.FEED_BANK_NAME.VISA, CONST.COMPANY_CARD.FEED_BANK_NAME.AMEX].some((value) => value === feed);
function isCustomFeed(feed: CompanyCardFeedWithNumber): boolean {
return [CONST.COMPANY_CARD.FEED_BANK_NAME.MASTER_CARD, CONST.COMPANY_CARD.FEED_BANK_NAME.VISA, CONST.COMPANY_CARD.FEED_BANK_NAME.AMEX].some((value) => feed.startsWith(value));
}

function getCompanyFeeds(cardFeeds: OnyxEntry<CardFeeds>, shouldFilterOutRemovedFeeds = false): CompanyFeeds {
Expand Down
47 changes: 44 additions & 3 deletions tests/unit/CardUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type {OnyxCollection} from 'react-native-onyx';
import CONST from '@src/CONST';
import * as CardUtils from '@src/libs/CardUtils';
import type * as OnyxTypes from '@src/types/onyx';
import type {CompanyCardFeedWithNumber} from '@src/types/onyx/CardFeeds';

const shortDate = '0924';
const shortDateSlashed = '09/24';
Expand All @@ -12,6 +13,17 @@ const longDateHyphen = '09-2024';
const expectedMonth = '09';
const expectedYear = '2024';

const directFeedBanks = [
CONST.COMPANY_CARD.FEED_BANK_NAME.AMEX_DIRECT,
CONST.COMPANY_CARD.FEED_BANK_NAME.BANK_OF_AMERICA,
CONST.COMPANY_CARD.FEED_BANK_NAME.BREX,
CONST.COMPANY_CARD.FEED_BANK_NAME.CAPITAL_ONE,
CONST.COMPANY_CARD.FEED_BANK_NAME.CHASE,
CONST.COMPANY_CARD.FEED_BANK_NAME.CITIBANK,
CONST.COMPANY_CARD.FEED_BANK_NAME.STRIPE,
CONST.COMPANY_CARD.FEED_BANK_NAME.WELLS_FARGO,
];

const companyCardsCustomFeedSettings = {
[CONST.COMPANY_CARD.FEED_BANK_NAME.MASTER_CARD]: {
pending: true,
Expand Down Expand Up @@ -232,14 +244,43 @@ describe('CardUtils', () => {
});

describe('isCustomFeed', () => {
it('Should return true for the custom feed', () => {
it('Should return true for the custom visa feed with no number', () => {
const customFeed = CONST.COMPANY_CARD.FEED_BANK_NAME.VISA;
const isCustomFeed = CardUtils.isCustomFeed(customFeed);
expect(isCustomFeed).toBe(true);
});

it('Should return false for the direct feed', () => {
const directFeed = CONST.COMPANY_CARD.FEED_BANK_NAME.CHASE;
it('Should return true for the custom visa feed with a number', () => {
const customFeed = `${CONST.COMPANY_CARD.FEED_BANK_NAME.VISA}1` as CompanyCardFeedWithNumber;
const isCustomFeed = CardUtils.isCustomFeed(customFeed);
expect(isCustomFeed).toBe(true);
});

it('Should return true for the custom mastercard feed with no number', () => {
const customFeed = CONST.COMPANY_CARD.FEED_BANK_NAME.MASTER_CARD;
const isCustomFeed = CardUtils.isCustomFeed(customFeed);
expect(isCustomFeed).toBe(true);
});

it('Should return true for the custom mastercard feed with a number', () => {
const customFeed = `${CONST.COMPANY_CARD.FEED_BANK_NAME.MASTER_CARD}3` as CompanyCardFeedWithNumber;
const isCustomFeed = CardUtils.isCustomFeed(customFeed);
expect(isCustomFeed).toBe(true);
});

it('Should return true for the custom amex feed with no number', () => {
const customFeed = CONST.COMPANY_CARD.FEED_BANK_NAME.AMEX;
const isCustomFeed = CardUtils.isCustomFeed(customFeed);
expect(isCustomFeed).toBe(true);
});

it('Should return true for the custom amex feed with a number', () => {
const customFeed = `${CONST.COMPANY_CARD.FEED_BANK_NAME.AMEX}2` as CompanyCardFeedWithNumber;
const isCustomFeed = CardUtils.isCustomFeed(customFeed);
expect(isCustomFeed).toBe(true);
});

test.each(directFeedBanks)('Should return false for the direct feed %s', (directFeed) => {
const isCustomFeed = CardUtils.isCustomFeed(directFeed);
expect(isCustomFeed).toBe(false);
});
Expand Down
Loading