Skip to content
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
2 changes: 1 addition & 1 deletion src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const connectionsVideoPaths = {
// Explicit type annotation is required
const cardActiveStates: number[] = [2, 3, 4, 7];

const brokenConnectionScrapeStatuses: number[] = [200, 531, 530, 500, 666];
const brokenConnectionScrapeStatuses: number[] = [200, 434, 531, 530, 500, 666];

// Hide not issued or not activated cards (states 2, 4) from card filter options in search, as no transactions can be made on cards in these states
const cardHiddenFromSearchStates: number[] = [2, 4];
Expand Down
2 changes: 1 addition & 1 deletion src/libs/CardUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,7 @@ function getFeedConnectionBrokenCard(feedCards: CardList | undefined, feedToExcl
return undefined;
}

return Object.values(feedCards).find((card) => !isEmptyObject(card) && card.bank !== feedToExclude && card.lastScrapeResult !== 200);
return Object.values(feedCards).find((card) => !isEmptyObject(card) && card.bank !== feedToExclude && isCardConnectionBroken(card));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MelvinBot can you add unit test for getFeedConnectionBrokenCard?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added 9 unit tests for getFeedConnectionBrokenCard covering:

  • undefined / empty feedCards
  • card with a broken connection status (e.g. 403)
  • cards with ignored statuses only (200, 434)
  • cards with no lastScrapeResult
  • feedToExclude filtering
  • empty card objects being skipped

All tests pass locally (da2d66f).

}

/** Extract feed from feed with domainID */
Expand Down
70 changes: 70 additions & 0 deletions tests/unit/CardUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
getDisplayableExpensifyCards,
getEligibleBankAccountsForCard,
getEligibleBankAccountsForUkEuCard,
getFeedConnectionBrokenCard,
getFeedNameForDisplay,
getFeedType,
getFilteredCardList,
Expand Down Expand Up @@ -3501,6 +3502,75 @@ describe('CardUtils', () => {
expect(result?.domainName).toBe('legacy.com');
});
});

describe('getFeedConnectionBrokenCard', () => {
it('Should return undefined when feedCards is undefined', () => {
expect(getFeedConnectionBrokenCard(undefined)).toBeUndefined();
});

it('Should return undefined when feedCards is empty', () => {
expect(getFeedConnectionBrokenCard({})).toBeUndefined();
});

it('Should return the card with a broken connection status', () => {
const feedCards: CardList = {
card1: {bank: 'oauth.chase.com', lastScrapeResult: 403, cardID: 1, state: CONST.EXPENSIFY_CARD.STATE.OPEN} as unknown as Card,
};
const result = getFeedConnectionBrokenCard(feedCards);
expect(result).toBeDefined();
expect(result?.cardID).toBe(1);
});

it('Should return undefined when all cards have ignored statuses (200, 434, etc.)', () => {
const feedCards: CardList = {
card1: {bank: 'oauth.chase.com', lastScrapeResult: 200, cardID: 1, state: CONST.EXPENSIFY_CARD.STATE.OPEN} as unknown as Card,
card2: {bank: 'oauth.chase.com', lastScrapeResult: 434, cardID: 2, state: CONST.EXPENSIFY_CARD.STATE.OPEN} as unknown as Card,
};
expect(getFeedConnectionBrokenCard(feedCards)).toBeUndefined();
});

it('Should return undefined when cards have no lastScrapeResult', () => {
const feedCards: CardList = {
card1: {bank: 'oauth.chase.com', cardID: 1, state: CONST.EXPENSIFY_CARD.STATE.OPEN} as unknown as Card,
};
expect(getFeedConnectionBrokenCard(feedCards)).toBeUndefined();
});

it('Should exclude cards matching feedToExclude', () => {
const feedCards: CardList = {
card1: {bank: 'oauth.chase.com', lastScrapeResult: 403, cardID: 1, state: CONST.EXPENSIFY_CARD.STATE.OPEN} as unknown as Card,
};
expect(getFeedConnectionBrokenCard(feedCards, 'oauth.chase.com')).toBeUndefined();
});

it('Should return a broken card from a different feed when feedToExclude is set', () => {
const feedCards: CardList = {
card1: {bank: 'oauth.chase.com', lastScrapeResult: 403, cardID: 1, state: CONST.EXPENSIFY_CARD.STATE.OPEN} as unknown as Card,
card2: {bank: 'oauth.amex.com', lastScrapeResult: 403, cardID: 2, state: CONST.EXPENSIFY_CARD.STATE.OPEN} as unknown as Card,
};
const result = getFeedConnectionBrokenCard(feedCards, 'oauth.chase.com');
expect(result).toBeDefined();
expect(result?.cardID).toBe(2);
});

it('Should skip empty card objects', () => {
const feedCards: CardList = {
card1: {} as unknown as Card,
card2: {bank: 'oauth.chase.com', lastScrapeResult: 403, cardID: 2, state: CONST.EXPENSIFY_CARD.STATE.OPEN} as unknown as Card,
};
const result = getFeedConnectionBrokenCard(feedCards);
expect(result).toBeDefined();
expect(result?.cardID).toBe(2);
});

it('Should return undefined when all non-ignored statuses belong to excluded feed', () => {
const feedCards: CardList = {
card1: {bank: 'oauth.chase.com', lastScrapeResult: 403, cardID: 1, state: CONST.EXPENSIFY_CARD.STATE.OPEN} as unknown as Card,
card2: {bank: 'oauth.amex.com', lastScrapeResult: 200, cardID: 2, state: CONST.EXPENSIFY_CARD.STATE.OPEN} as unknown as Card,
};
expect(getFeedConnectionBrokenCard(feedCards, 'oauth.chase.com')).toBeUndefined();
});
});
});

describe('formatMaskedCardName', () => {
Expand Down
Loading