From c01ceda583e85338e985a261f0e48ac962e578dc Mon Sep 17 00:00:00 2001 From: Vit Horacek Date: Fri, 12 Jun 2026 11:29:34 +0200 Subject: [PATCH 1/4] Fix duplicate broken company card feed time-sensitive tasks Show at most one Fix company card connection task per broken direct OAuth/Plaid feed and exclude commercial feeds that are not user-fixable via bank login. Co-authored-by: Cursor --- ...getBrokenDirectCompanyCardFeedsForAdmin.ts | 64 +++++++++ src/pages/home/TimeSensitiveSection/index.tsx | 40 +----- ...rokenDirectCompanyCardFeedsForAdminTest.ts | 126 ++++++++++++++++++ 3 files changed, 194 insertions(+), 36 deletions(-) create mode 100644 src/pages/home/TimeSensitiveSection/getBrokenDirectCompanyCardFeedsForAdmin.ts create mode 100644 tests/unit/pages/home/TimeSensitiveSection/getBrokenDirectCompanyCardFeedsForAdminTest.ts diff --git a/src/pages/home/TimeSensitiveSection/getBrokenDirectCompanyCardFeedsForAdmin.ts b/src/pages/home/TimeSensitiveSection/getBrokenDirectCompanyCardFeedsForAdmin.ts new file mode 100644 index 000000000000..fbd35dcdc220 --- /dev/null +++ b/src/pages/home/TimeSensitiveSection/getBrokenDirectCompanyCardFeedsForAdmin.ts @@ -0,0 +1,64 @@ +import {getCardFeedWithDomainID, isDirectFeed} from '@libs/CardUtils'; +import type {Card, Policy} from '@src/types/onyx'; + +type BrokenCompanyCardConnection = { + /** The policy ID associated with this connection */ + policyID: string; + + /** The policy name associated with this connection */ + policyName: string; + + /** A representative card ID on this feed, used to render FixCompanyCardConnection */ + cardID: string; + + /** feedNameWithDomainID for this broken direct feed */ + feedKey: string; +}; + +/** + * Returns at most one broken company card connection per direct (OAuth/Plaid) feed for workspaces + * where the current user is an admin. Commercial feeds (vcf/cdf/etc.) are excluded because they + * are file-based and not user-fixable via bank login. + */ +function getBrokenDirectCompanyCardFeedsForAdmin(cardsWithBrokenConnection: Record | undefined, adminPolicies: Policy[] | undefined): BrokenCompanyCardConnection[] { + if (!cardsWithBrokenConnection || !adminPolicies) { + return []; + } + + const brokenCompanyCardConnectionsByFeed = new Map(); + + for (const card of Object.values(cardsWithBrokenConnection)) { + if (!card?.fundID) { + continue; + } + + // Only direct OAuth/Plaid feeds are user-fixable; commercial feeds (vcf/cdf/etc.) are file-based + if (!isDirectFeed(card.bank)) { + continue; + } + + const cardFundID = Number(card.fundID); + const matchingPolicy = adminPolicies.find((policy) => policy.policyAccountID === cardFundID); + + if (!matchingPolicy) { + continue; + } + + const feedKey = getCardFeedWithDomainID(card.bank, card.fundID); + if (brokenCompanyCardConnectionsByFeed.has(feedKey)) { + continue; + } + + brokenCompanyCardConnectionsByFeed.set(feedKey, { + policyID: matchingPolicy.id, + policyName: matchingPolicy.name, + cardID: String(card.cardID), + feedKey, + }); + } + + return Array.from(brokenCompanyCardConnectionsByFeed.values()); +} + +export default getBrokenDirectCompanyCardFeedsForAdmin; +export type {BrokenCompanyCardConnection}; diff --git a/src/pages/home/TimeSensitiveSection/index.tsx b/src/pages/home/TimeSensitiveSection/index.tsx index 05cb8ddfe041..6e83655dade6 100644 --- a/src/pages/home/TimeSensitiveSection/index.tsx +++ b/src/pages/home/TimeSensitiveSection/index.tsx @@ -21,6 +21,7 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {Policy} from '@src/types/onyx'; import type {ConnectionName, PolicyConnectionName} from '@src/types/onyx/Policy'; +import getBrokenDirectCompanyCardFeedsForAdmin from './getBrokenDirectCompanyCardFeedsForAdmin'; import useTimeSensitiveAddPaymentCard from './hooks/useTimeSensitiveAddPaymentCard'; import useTimeSensitiveBilling from './hooks/useTimeSensitiveBilling'; import useTimeSensitiveCards from './hooks/useTimeSensitiveCards'; @@ -52,17 +53,6 @@ type BrokenPolicyConnection = { integrationName: string; }; -type BrokenCompanyCardConnection = { - /** The policy ID associated with this connection */ - policyID: string; - - /** The policy name associated with this connection */ - policyName: string; - - /** The card ID associated with this connection */ - cardID: string; -}; - type BrokenPersonalCardConnection = { /** The card ID associated with this connection */ cardID: string; @@ -132,30 +122,8 @@ function TimeSensitiveSection() { } } - // Get company cards with broken connections (for admins) - const brokenCompanyCardConnections: BrokenCompanyCardConnection[] = []; - const cardsWithBrokenConnection = cardFeedErrors.cardsWithBrokenFeedConnection; - if (cardsWithBrokenConnection && adminPolicies) { - for (const card of Object.values(cardsWithBrokenConnection)) { - if (!card?.fundID) { - continue; - } - - // Find the policy associated with this card's fundID (workspaceAccountID) - const cardFundID = Number(card.fundID); - const matchingPolicy = adminPolicies.find((policy) => policy.policyAccountID === cardFundID); - - if (!matchingPolicy) { - continue; - } - - brokenCompanyCardConnections.push({ - policyID: matchingPolicy.id, - policyName: matchingPolicy.name, - cardID: String(card.cardID), - }); - } - } + // Get direct company card feeds with broken connections (for admins; one task per feed) + const brokenCompanyCardConnections = getBrokenDirectCompanyCardFeedsForAdmin(cardFeedErrors.cardsWithBrokenFeedConnection, adminPolicies); // Get personal cards with broken connections const brokenPersonalCardConnections: BrokenPersonalCardConnection[] = []; @@ -242,7 +210,7 @@ function TimeSensitiveSection() { } items.push( { + const adminPolicies = [createAdminPolicy()]; + + it('returns one connection when multiple broken cards share the same direct feed', () => { + const cardsWithBrokenConnection = { + card1: createBrokenCard(1, OAUTH_CHASE_FEED), + card2: createBrokenCard(2, OAUTH_CHASE_FEED), + card3: createBrokenCard(3, OAUTH_CHASE_FEED), + }; + + const result = getBrokenDirectCompanyCardFeedsForAdmin(cardsWithBrokenConnection, adminPolicies); + + expect(result).toHaveLength(1); + expect(result.at(0)).toStrictEqual({ + policyID: POLICY_ID, + policyName: POLICY_NAME, + cardID: '1', + feedKey: getCardFeedWithDomainID(OAUTH_CHASE_FEED, WORKSPACE_ACCOUNT_ID), + }); + }); + + it('returns one connection per distinct direct feed', () => { + const cardsWithBrokenConnection = { + card1: createBrokenCard(1, OAUTH_CHASE_FEED), + card2: createBrokenCard(2, OAUTH_AMEX_FEED), + }; + + const result = getBrokenDirectCompanyCardFeedsForAdmin(cardsWithBrokenConnection, adminPolicies); + + expect(result).toHaveLength(2); + expect(result.map((connection) => connection.feedKey)).toStrictEqual([ + getCardFeedWithDomainID(OAUTH_CHASE_FEED, WORKSPACE_ACCOUNT_ID), + getCardFeedWithDomainID(OAUTH_AMEX_FEED, WORKSPACE_ACCOUNT_ID), + ]); + }); + + it('returns no connections for commercial feeds', () => { + const cardsWithBrokenConnection = { + card1: createBrokenCard(1, COMMERCIAL_VISA_FEED), + card2: createBrokenCard(2, COMMERCIAL_VISA_FEED), + card3: createBrokenCard(3, COMMERCIAL_VISA_FEED), + }; + + const result = getBrokenDirectCompanyCardFeedsForAdmin(cardsWithBrokenConnection, adminPolicies); + + expect(result).toHaveLength(0); + }); + + it('returns only direct feed connections when direct and commercial feeds are both broken', () => { + const cardsWithBrokenConnection = { + card1: createBrokenCard(1, OAUTH_CHASE_FEED), + card2: createBrokenCard(2, OAUTH_CHASE_FEED), + card3: createBrokenCard(3, COMMERCIAL_VISA_FEED), + card4: createBrokenCard(4, COMMERCIAL_VISA_FEED), + }; + + const result = getBrokenDirectCompanyCardFeedsForAdmin(cardsWithBrokenConnection, adminPolicies); + + expect(result).toHaveLength(1); + expect(result.at(0)?.feedKey).toBe(getCardFeedWithDomainID(OAUTH_CHASE_FEED, WORKSPACE_ACCOUNT_ID)); + }); + + it('returns an empty array when admin policies are undefined', () => { + const cardsWithBrokenConnection = { + card1: createBrokenCard(1, OAUTH_CHASE_FEED), + }; + + expect(getBrokenDirectCompanyCardFeedsForAdmin(cardsWithBrokenConnection, undefined)).toStrictEqual([]); + }); + + it('skips cards without a matching admin workspace policy', () => { + const cardsWithBrokenConnection = { + card1: createBrokenCard(1, OAUTH_CHASE_FEED), + }; + + const result = getBrokenDirectCompanyCardFeedsForAdmin(cardsWithBrokenConnection, [ + { + ...createAdminPolicy(), + policyAccountID: 99999999, + }, + ]); + + expect(result).toStrictEqual([]); + }); +}); From 60ed58718db66dc472ba4383e8dba2bb8ebc98f0 Mon Sep 17 00:00:00 2001 From: Vit Horacek Date: Fri, 12 Jun 2026 12:27:17 +0200 Subject: [PATCH 2/4] Rename broken feed helper to useBrokenDirectCompanyCardFeedsForAdmin Convert to a hook under TimeSensitiveSection/hooks and fix test lint/typing. Co-authored-by: Cursor --- Mobile-Expensify | 2 +- ...getBrokenDirectCompanyCardFeedsForAdmin.ts | 64 ------- ...useBrokenDirectCompanyCardFeedsForAdmin.ts | 70 +++++++ src/pages/home/TimeSensitiveSection/index.tsx | 6 +- ...okenDirectCompanyCardFeedsForAdmin.test.ts | 173 ++++++++++++++++++ ...rokenDirectCompanyCardFeedsForAdminTest.ts | 126 ------------- 6 files changed, 246 insertions(+), 195 deletions(-) delete mode 100644 src/pages/home/TimeSensitiveSection/getBrokenDirectCompanyCardFeedsForAdmin.ts create mode 100644 src/pages/home/TimeSensitiveSection/hooks/useBrokenDirectCompanyCardFeedsForAdmin.ts create mode 100644 tests/unit/hooks/useBrokenDirectCompanyCardFeedsForAdmin.test.ts delete mode 100644 tests/unit/pages/home/TimeSensitiveSection/getBrokenDirectCompanyCardFeedsForAdminTest.ts diff --git a/Mobile-Expensify b/Mobile-Expensify index fdf508981aff..d04040c9f51f 160000 --- a/Mobile-Expensify +++ b/Mobile-Expensify @@ -1 +1 @@ -Subproject commit fdf508981aff5189c5c17c67493a3d1c4535c1a6 +Subproject commit d04040c9f51f31226fb0d48bc1513dd7b15ea526 diff --git a/src/pages/home/TimeSensitiveSection/getBrokenDirectCompanyCardFeedsForAdmin.ts b/src/pages/home/TimeSensitiveSection/getBrokenDirectCompanyCardFeedsForAdmin.ts deleted file mode 100644 index fbd35dcdc220..000000000000 --- a/src/pages/home/TimeSensitiveSection/getBrokenDirectCompanyCardFeedsForAdmin.ts +++ /dev/null @@ -1,64 +0,0 @@ -import {getCardFeedWithDomainID, isDirectFeed} from '@libs/CardUtils'; -import type {Card, Policy} from '@src/types/onyx'; - -type BrokenCompanyCardConnection = { - /** The policy ID associated with this connection */ - policyID: string; - - /** The policy name associated with this connection */ - policyName: string; - - /** A representative card ID on this feed, used to render FixCompanyCardConnection */ - cardID: string; - - /** feedNameWithDomainID for this broken direct feed */ - feedKey: string; -}; - -/** - * Returns at most one broken company card connection per direct (OAuth/Plaid) feed for workspaces - * where the current user is an admin. Commercial feeds (vcf/cdf/etc.) are excluded because they - * are file-based and not user-fixable via bank login. - */ -function getBrokenDirectCompanyCardFeedsForAdmin(cardsWithBrokenConnection: Record | undefined, adminPolicies: Policy[] | undefined): BrokenCompanyCardConnection[] { - if (!cardsWithBrokenConnection || !adminPolicies) { - return []; - } - - const brokenCompanyCardConnectionsByFeed = new Map(); - - for (const card of Object.values(cardsWithBrokenConnection)) { - if (!card?.fundID) { - continue; - } - - // Only direct OAuth/Plaid feeds are user-fixable; commercial feeds (vcf/cdf/etc.) are file-based - if (!isDirectFeed(card.bank)) { - continue; - } - - const cardFundID = Number(card.fundID); - const matchingPolicy = adminPolicies.find((policy) => policy.policyAccountID === cardFundID); - - if (!matchingPolicy) { - continue; - } - - const feedKey = getCardFeedWithDomainID(card.bank, card.fundID); - if (brokenCompanyCardConnectionsByFeed.has(feedKey)) { - continue; - } - - brokenCompanyCardConnectionsByFeed.set(feedKey, { - policyID: matchingPolicy.id, - policyName: matchingPolicy.name, - cardID: String(card.cardID), - feedKey, - }); - } - - return Array.from(brokenCompanyCardConnectionsByFeed.values()); -} - -export default getBrokenDirectCompanyCardFeedsForAdmin; -export type {BrokenCompanyCardConnection}; diff --git a/src/pages/home/TimeSensitiveSection/hooks/useBrokenDirectCompanyCardFeedsForAdmin.ts b/src/pages/home/TimeSensitiveSection/hooks/useBrokenDirectCompanyCardFeedsForAdmin.ts new file mode 100644 index 000000000000..0fbcd7594463 --- /dev/null +++ b/src/pages/home/TimeSensitiveSection/hooks/useBrokenDirectCompanyCardFeedsForAdmin.ts @@ -0,0 +1,70 @@ +import {useMemo} from 'react'; +import useCardFeedErrors from '@hooks/useCardFeedErrors'; +import {getCardFeedWithDomainID, isDirectFeed} from '@libs/CardUtils'; +import type {Policy} from '@src/types/onyx'; + +type BrokenCompanyCardConnection = { + /** The policy ID associated with this connection */ + policyID: string; + + /** The policy name associated with this connection */ + policyName: string; + + /** A representative card ID on this feed, used to render FixCompanyCardConnection */ + cardID: string; + + /** feedNameWithDomainID for this broken direct feed */ + feedKey: string; +}; + +/** + * Returns at most one broken company card connection per direct (OAuth/Plaid) feed for workspaces + * where the current user is an admin. Commercial feeds (vcf/cdf/etc.) are excluded because they + * are file-based and not user-fixable via bank login. + */ +function useBrokenDirectCompanyCardFeedsForAdmin(adminPolicies: Policy[] | undefined): BrokenCompanyCardConnection[] { + const {cardsWithBrokenFeedConnection} = useCardFeedErrors(); + + return useMemo(() => { + if (!cardsWithBrokenFeedConnection || !adminPolicies) { + return []; + } + + const brokenCompanyCardConnectionsByFeed = new Map(); + + for (const card of Object.values(cardsWithBrokenFeedConnection)) { + if (!card?.fundID) { + continue; + } + + // Only direct OAuth/Plaid feeds are user-fixable; commercial feeds (vcf/cdf/etc.) are file-based + if (!isDirectFeed(card.bank)) { + continue; + } + + const cardFundID = Number(card.fundID); + const matchingPolicy = adminPolicies.find((policy) => policy.policyAccountID === cardFundID); + + if (!matchingPolicy) { + continue; + } + + const feedKey = getCardFeedWithDomainID(card.bank, card.fundID); + if (brokenCompanyCardConnectionsByFeed.has(feedKey)) { + continue; + } + + brokenCompanyCardConnectionsByFeed.set(feedKey, { + policyID: matchingPolicy.id, + policyName: matchingPolicy.name, + cardID: String(card.cardID), + feedKey, + }); + } + + return Array.from(brokenCompanyCardConnectionsByFeed.values()); + }, [adminPolicies, cardsWithBrokenFeedConnection]); +} + +export default useBrokenDirectCompanyCardFeedsForAdmin; +export type {BrokenCompanyCardConnection}; diff --git a/src/pages/home/TimeSensitiveSection/index.tsx b/src/pages/home/TimeSensitiveSection/index.tsx index 6e83655dade6..6650746f1a60 100644 --- a/src/pages/home/TimeSensitiveSection/index.tsx +++ b/src/pages/home/TimeSensitiveSection/index.tsx @@ -21,7 +21,7 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {Policy} from '@src/types/onyx'; import type {ConnectionName, PolicyConnectionName} from '@src/types/onyx/Policy'; -import getBrokenDirectCompanyCardFeedsForAdmin from './getBrokenDirectCompanyCardFeedsForAdmin'; +import useBrokenDirectCompanyCardFeedsForAdmin from './hooks/useBrokenDirectCompanyCardFeedsForAdmin'; import useTimeSensitiveAddPaymentCard from './hooks/useTimeSensitiveAddPaymentCard'; import useTimeSensitiveBilling from './hooks/useTimeSensitiveBilling'; import useTimeSensitiveCards from './hooks/useTimeSensitiveCards'; @@ -93,6 +93,7 @@ function TimeSensitiveSection() { // Get card feed errors for company card connections (Release 4) const cardFeedErrors = useCardFeedErrors(); + const brokenCompanyCardConnections = useBrokenDirectCompanyCardFeedsForAdmin(adminPolicies); // Find policies with broken connections (accounting + HR, only for admins) const brokenPolicyConnections: BrokenPolicyConnection[] = []; @@ -122,9 +123,6 @@ function TimeSensitiveSection() { } } - // Get direct company card feeds with broken connections (for admins; one task per feed) - const brokenCompanyCardConnections = getBrokenDirectCompanyCardFeedsForAdmin(cardFeedErrors.cardsWithBrokenFeedConnection, adminPolicies); - // Get personal cards with broken connections const brokenPersonalCardConnections: BrokenPersonalCardConnection[] = []; const personalCardsWithBrokenConnection = cardFeedErrors.personalCardsWithBrokenConnection; diff --git a/tests/unit/hooks/useBrokenDirectCompanyCardFeedsForAdmin.test.ts b/tests/unit/hooks/useBrokenDirectCompanyCardFeedsForAdmin.test.ts new file mode 100644 index 000000000000..13939cfc618b --- /dev/null +++ b/tests/unit/hooks/useBrokenDirectCompanyCardFeedsForAdmin.test.ts @@ -0,0 +1,173 @@ +import {renderHook} from '@testing-library/react-native'; +import {getCardFeedWithDomainID} from '@libs/CardUtils'; +import useBrokenDirectCompanyCardFeedsForAdmin from '@pages/home/TimeSensitiveSection/hooks/useBrokenDirectCompanyCardFeedsForAdmin'; +import CONST from '@src/CONST'; +import type {Card, CardList} from '@src/types/onyx'; +import type {CardFeedWithNumber} from '@src/types/onyx/CardFeeds'; +import type {CardFeedErrors} from '@src/types/onyx/DerivedValues'; +import type Policy from '@src/types/onyx/Policy'; + +const WORKSPACE_ACCOUNT_ID = 44444444; +const POLICY_ID = 'POLICY_1'; +const POLICY_NAME = 'SPS Health'; + +const OAUTH_CHASE_FEED = CONST.COMPANY_CARD.FEED_BANK_NAME.CHASE; +const OAUTH_AMEX_FEED = CONST.COMPANY_CARD.FEED_BANK_NAME.AMEX_DIRECT; +const COMMERCIAL_VISA_FEED = CONST.COMPANY_CARD.FEED_BANK_NAME.VISA; + +const DEFAULT_CARD_FEED_ERROR_STATE = { + shouldShowRBR: false, + hasFeedErrors: false, + hasWorkspaceErrors: false, + isFeedConnectionBroken: false, +}; + +function createDefaultCardFeedErrors(): CardFeedErrors { + return { + cardFeedErrors: {}, + cardsWithBrokenFeedConnection: {}, + personalCardsWithBrokenConnection: {}, + shouldShowRbrForWorkspaceAccountID: {}, + shouldShowRbrForFeedNameWithDomainID: {}, + all: DEFAULT_CARD_FEED_ERROR_STATE, + companyCards: DEFAULT_CARD_FEED_ERROR_STATE, + expensifyCard: DEFAULT_CARD_FEED_ERROR_STATE, + personalCard: DEFAULT_CARD_FEED_ERROR_STATE, + }; +} + +const mockUseCardFeedErrors = jest.fn(); + +jest.mock('@hooks/useCardFeedErrors', () => ({ + __esModule: true, + default: () => mockUseCardFeedErrors(), +})); + +function createAdminPolicy(overrides: Partial & {id: string} = {id: POLICY_ID}): Policy { + // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion + return { + name: POLICY_NAME, + role: CONST.POLICY.ROLE.ADMIN, + type: CONST.POLICY.TYPE.TEAM, + isPolicyExpenseChatEnabled: true, + policyAccountID: WORKSPACE_ACCOUNT_ID, + ...overrides, + } as Policy; +} + +function createBrokenCard(cardID: number, bank: CardFeedWithNumber): Card { + return { + cardID, + accountID: 1, + bank, + cardName: 'Test Card', + domainName: 'test.exfy', + fraud: 'none', + fundID: String(WORKSPACE_ACCOUNT_ID), + lastFourPAN: '1234', + lastScrape: '', + lastScrapeResult: 403, + lastUpdated: '', + state: CONST.EXPENSIFY_CARD.STATE.OPEN, + }; +} + +function setMockBrokenCards(cardsWithBrokenFeedConnection: CardList) { + mockUseCardFeedErrors.mockReturnValue({ + ...createDefaultCardFeedErrors(), + cardsWithBrokenFeedConnection, + }); +} + +describe('useBrokenDirectCompanyCardFeedsForAdmin', () => { + const adminPolicies = [createAdminPolicy()]; + + beforeEach(() => { + mockUseCardFeedErrors.mockReturnValue(createDefaultCardFeedErrors()); + }); + + it('returns one connection when multiple broken cards share the same direct feed', () => { + setMockBrokenCards({ + card1: createBrokenCard(1, OAUTH_CHASE_FEED), + card2: createBrokenCard(2, OAUTH_CHASE_FEED), + card3: createBrokenCard(3, OAUTH_CHASE_FEED), + }); + + const {result} = renderHook(() => useBrokenDirectCompanyCardFeedsForAdmin(adminPolicies)); + + expect(result.current).toHaveLength(1); + expect(result.current.at(0)).toStrictEqual({ + policyID: POLICY_ID, + policyName: POLICY_NAME, + cardID: '1', + feedKey: getCardFeedWithDomainID(OAUTH_CHASE_FEED, WORKSPACE_ACCOUNT_ID), + }); + }); + + it('returns one connection per distinct direct feed', () => { + setMockBrokenCards({ + card1: createBrokenCard(1, OAUTH_CHASE_FEED), + card2: createBrokenCard(2, OAUTH_AMEX_FEED), + }); + + const {result} = renderHook(() => useBrokenDirectCompanyCardFeedsForAdmin(adminPolicies)); + + expect(result.current).toHaveLength(2); + expect(result.current.map((connection) => connection.feedKey)).toStrictEqual([ + getCardFeedWithDomainID(OAUTH_CHASE_FEED, WORKSPACE_ACCOUNT_ID), + getCardFeedWithDomainID(OAUTH_AMEX_FEED, WORKSPACE_ACCOUNT_ID), + ]); + }); + + it('returns no connections for commercial feeds', () => { + setMockBrokenCards({ + card1: createBrokenCard(1, COMMERCIAL_VISA_FEED), + card2: createBrokenCard(2, COMMERCIAL_VISA_FEED), + card3: createBrokenCard(3, COMMERCIAL_VISA_FEED), + }); + + const {result} = renderHook(() => useBrokenDirectCompanyCardFeedsForAdmin(adminPolicies)); + + expect(result.current).toHaveLength(0); + }); + + it('returns only direct feed connections when direct and commercial feeds are both broken', () => { + setMockBrokenCards({ + card1: createBrokenCard(1, OAUTH_CHASE_FEED), + card2: createBrokenCard(2, OAUTH_CHASE_FEED), + card3: createBrokenCard(3, COMMERCIAL_VISA_FEED), + card4: createBrokenCard(4, COMMERCIAL_VISA_FEED), + }); + + const {result} = renderHook(() => useBrokenDirectCompanyCardFeedsForAdmin(adminPolicies)); + + expect(result.current).toHaveLength(1); + expect(result.current.at(0)?.feedKey).toBe(getCardFeedWithDomainID(OAUTH_CHASE_FEED, WORKSPACE_ACCOUNT_ID)); + }); + + it('returns an empty array when admin policies are undefined', () => { + setMockBrokenCards({ + card1: createBrokenCard(1, OAUTH_CHASE_FEED), + }); + + const {result} = renderHook(() => useBrokenDirectCompanyCardFeedsForAdmin(undefined)); + + expect(result.current).toStrictEqual([]); + }); + + it('skips cards without a matching admin workspace policy', () => { + setMockBrokenCards({ + card1: createBrokenCard(1, OAUTH_CHASE_FEED), + }); + + const {result} = renderHook(() => + useBrokenDirectCompanyCardFeedsForAdmin([ + createAdminPolicy({ + policyAccountID: 99999999, + }), + ]), + ); + + expect(result.current).toStrictEqual([]); + }); +}); diff --git a/tests/unit/pages/home/TimeSensitiveSection/getBrokenDirectCompanyCardFeedsForAdminTest.ts b/tests/unit/pages/home/TimeSensitiveSection/getBrokenDirectCompanyCardFeedsForAdminTest.ts deleted file mode 100644 index ea9d74c9587e..000000000000 --- a/tests/unit/pages/home/TimeSensitiveSection/getBrokenDirectCompanyCardFeedsForAdminTest.ts +++ /dev/null @@ -1,126 +0,0 @@ -import {getCardFeedWithDomainID} from '@libs/CardUtils'; -import getBrokenDirectCompanyCardFeedsForAdmin from '@pages/home/TimeSensitiveSection/getBrokenDirectCompanyCardFeedsForAdmin'; -import CONST from '@src/CONST'; -import type {Card, Policy} from '@src/types/onyx'; - -const WORKSPACE_ACCOUNT_ID = 44444444; -const POLICY_ID = 'POLICY_1'; -const POLICY_NAME = 'SPS Health'; - -const OAUTH_CHASE_FEED = CONST.COMPANY_CARD.FEED_BANK_NAME.CHASE; -const OAUTH_AMEX_FEED = CONST.COMPANY_CARD.FEED_BANK_NAME.AMEX_DIRECT; -const COMMERCIAL_VISA_FEED = CONST.COMPANY_CARD.FEED_BANK_NAME.VISA; - -function createAdminPolicy(): Policy { - return { - id: POLICY_ID, - name: POLICY_NAME, - role: CONST.POLICY.ROLE.ADMIN, - type: CONST.POLICY.TYPE.TEAM, - isPolicyExpenseChatEnabled: true, - policyAccountID: WORKSPACE_ACCOUNT_ID, - }; -} - -function createBrokenCard(cardID: number, bank: string): Card { - return { - cardID, - accountID: 1, - bank, - cardName: 'Test Card', - domainName: 'test.exfy', - fraud: 'none', - fundID: String(WORKSPACE_ACCOUNT_ID), - lastFourPAN: '1234', - lastScrape: '', - lastScrapeResult: 403, - lastUpdated: '', - state: CONST.EXPENSIFY_CARD.STATE.OPEN, - }; -} - -describe('getBrokenDirectCompanyCardFeedsForAdmin', () => { - const adminPolicies = [createAdminPolicy()]; - - it('returns one connection when multiple broken cards share the same direct feed', () => { - const cardsWithBrokenConnection = { - card1: createBrokenCard(1, OAUTH_CHASE_FEED), - card2: createBrokenCard(2, OAUTH_CHASE_FEED), - card3: createBrokenCard(3, OAUTH_CHASE_FEED), - }; - - const result = getBrokenDirectCompanyCardFeedsForAdmin(cardsWithBrokenConnection, adminPolicies); - - expect(result).toHaveLength(1); - expect(result.at(0)).toStrictEqual({ - policyID: POLICY_ID, - policyName: POLICY_NAME, - cardID: '1', - feedKey: getCardFeedWithDomainID(OAUTH_CHASE_FEED, WORKSPACE_ACCOUNT_ID), - }); - }); - - it('returns one connection per distinct direct feed', () => { - const cardsWithBrokenConnection = { - card1: createBrokenCard(1, OAUTH_CHASE_FEED), - card2: createBrokenCard(2, OAUTH_AMEX_FEED), - }; - - const result = getBrokenDirectCompanyCardFeedsForAdmin(cardsWithBrokenConnection, adminPolicies); - - expect(result).toHaveLength(2); - expect(result.map((connection) => connection.feedKey)).toStrictEqual([ - getCardFeedWithDomainID(OAUTH_CHASE_FEED, WORKSPACE_ACCOUNT_ID), - getCardFeedWithDomainID(OAUTH_AMEX_FEED, WORKSPACE_ACCOUNT_ID), - ]); - }); - - it('returns no connections for commercial feeds', () => { - const cardsWithBrokenConnection = { - card1: createBrokenCard(1, COMMERCIAL_VISA_FEED), - card2: createBrokenCard(2, COMMERCIAL_VISA_FEED), - card3: createBrokenCard(3, COMMERCIAL_VISA_FEED), - }; - - const result = getBrokenDirectCompanyCardFeedsForAdmin(cardsWithBrokenConnection, adminPolicies); - - expect(result).toHaveLength(0); - }); - - it('returns only direct feed connections when direct and commercial feeds are both broken', () => { - const cardsWithBrokenConnection = { - card1: createBrokenCard(1, OAUTH_CHASE_FEED), - card2: createBrokenCard(2, OAUTH_CHASE_FEED), - card3: createBrokenCard(3, COMMERCIAL_VISA_FEED), - card4: createBrokenCard(4, COMMERCIAL_VISA_FEED), - }; - - const result = getBrokenDirectCompanyCardFeedsForAdmin(cardsWithBrokenConnection, adminPolicies); - - expect(result).toHaveLength(1); - expect(result.at(0)?.feedKey).toBe(getCardFeedWithDomainID(OAUTH_CHASE_FEED, WORKSPACE_ACCOUNT_ID)); - }); - - it('returns an empty array when admin policies are undefined', () => { - const cardsWithBrokenConnection = { - card1: createBrokenCard(1, OAUTH_CHASE_FEED), - }; - - expect(getBrokenDirectCompanyCardFeedsForAdmin(cardsWithBrokenConnection, undefined)).toStrictEqual([]); - }); - - it('skips cards without a matching admin workspace policy', () => { - const cardsWithBrokenConnection = { - card1: createBrokenCard(1, OAUTH_CHASE_FEED), - }; - - const result = getBrokenDirectCompanyCardFeedsForAdmin(cardsWithBrokenConnection, [ - { - ...createAdminPolicy(), - policyAccountID: 99999999, - }, - ]); - - expect(result).toStrictEqual([]); - }); -}); From 1b65b2dbffc5845ac0f4fb9fec926a57ed31ae38 Mon Sep 17 00:00:00 2001 From: Vit Horacek Date: Fri, 12 Jun 2026 12:35:12 +0200 Subject: [PATCH 3/4] Revert accidental Mobile-Expensify submodule bump Reset submodule pointer to match main; unrelated to broken feed task fix. Co-authored-by: Cursor --- Mobile-Expensify | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mobile-Expensify b/Mobile-Expensify index d04040c9f51f..fdf508981aff 160000 --- a/Mobile-Expensify +++ b/Mobile-Expensify @@ -1 +1 @@ -Subproject commit d04040c9f51f31226fb0d48bc1513dd7b15ea526 +Subproject commit fdf508981aff5189c5c17c67493a3d1c4535c1a6 From e455a6ab2b5d7c0e2f6cdeaf4ae8c4cdc0a1a4b1 Mon Sep 17 00:00:00 2001 From: Vit Horacek Date: Fri, 12 Jun 2026 13:24:55 +0200 Subject: [PATCH 4/4] Fix TS error and Knip unused export in useBrokenDirectCompanyCardFeedsForAdmin Co-authored-by: Cursor --- .../hooks/useBrokenDirectCompanyCardFeedsForAdmin.ts | 1 - tests/unit/hooks/useBrokenDirectCompanyCardFeedsForAdmin.test.ts | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/TimeSensitiveSection/hooks/useBrokenDirectCompanyCardFeedsForAdmin.ts b/src/pages/home/TimeSensitiveSection/hooks/useBrokenDirectCompanyCardFeedsForAdmin.ts index 0fbcd7594463..45f3568dd04f 100644 --- a/src/pages/home/TimeSensitiveSection/hooks/useBrokenDirectCompanyCardFeedsForAdmin.ts +++ b/src/pages/home/TimeSensitiveSection/hooks/useBrokenDirectCompanyCardFeedsForAdmin.ts @@ -67,4 +67,3 @@ function useBrokenDirectCompanyCardFeedsForAdmin(adminPolicies: Policy[] | undef } export default useBrokenDirectCompanyCardFeedsForAdmin; -export type {BrokenCompanyCardConnection}; diff --git a/tests/unit/hooks/useBrokenDirectCompanyCardFeedsForAdmin.test.ts b/tests/unit/hooks/useBrokenDirectCompanyCardFeedsForAdmin.test.ts index 13939cfc618b..c1d24ead88a1 100644 --- a/tests/unit/hooks/useBrokenDirectCompanyCardFeedsForAdmin.test.ts +++ b/tests/unit/hooks/useBrokenDirectCompanyCardFeedsForAdmin.test.ts @@ -163,6 +163,7 @@ describe('useBrokenDirectCompanyCardFeedsForAdmin', () => { const {result} = renderHook(() => useBrokenDirectCompanyCardFeedsForAdmin([ createAdminPolicy({ + id: POLICY_ID, policyAccountID: 99999999, }), ]),