From f3de12db23c3a8ee50e72d5f0e4a9ce0693bbca0 Mon Sep 17 00:00:00 2001 From: Wildan Muhlis Date: Sat, 23 May 2026 01:30:48 +0700 Subject: [PATCH 1/5] Stop surfacing broken card task and RBR after 90 days while keeping the error --- src/CONST/index.ts | 3 +++ src/libs/CardUtils.ts | 19 +++++++++++++++++++ .../OnyxDerived/configs/cardFeedErrors.ts | 10 +++++++--- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/CONST/index.ts b/src/CONST/index.ts index 64af334faba6..dcaaccd98b7b 100644 --- a/src/CONST/index.ts +++ b/src/CONST/index.ts @@ -4347,6 +4347,9 @@ const CONST = { }, COMPANY_CARDS: { BROKEN_CONNECTION_IGNORED_STATUSES: brokenConnectionScrapeStatuses, + // After a card connection has been broken and unresolved for this many days, stop actively + // prompting the user: the time-sensitive home task and the RBR are removed (the error itself is kept). + BROKEN_CONNECTION_DISMISS_AFTER_DAYS: 90, CONNECTION_ERROR: 'connectionError', WORKSPACE_FEEDS_LOAD_ERROR: 'workspaceFeedsLoadError', FEED_LOAD_ERROR: 'feedLoadError', diff --git a/src/libs/CardUtils.ts b/src/libs/CardUtils.ts index ae3f23b01390..374342c141f1 100644 --- a/src/libs/CardUtils.ts +++ b/src/libs/CardUtils.ts @@ -1247,6 +1247,24 @@ function isCardConnectionBroken(card: Card): boolean { return !!card.lastScrapeResult && !CONST.COMPANY_CARDS.BROKEN_CONNECTION_IGNORED_STATUSES.includes(card.lastScrapeResult); } +/** + * Check whether a broken card connection has been unresolved long enough that we should stop + * actively prompting the user (remove the time-sensitive task and the RBR). The error itself is + * kept, so this is only used to gate the proactive surfacing, not the underlying broken state. + * + * `lastScrape` is the last successful update timestamp (a separate `lastImportAttempt` tracks + * attempts), so for a broken connection its age equals how long the connection has been failing. + * + * @param card the card to check + * @returns true if the connection is broken and has been unresolved for at least the grace period + */ +function isBrokenConnectionPastDismissThreshold(card: Card): boolean { + if (!isCardConnectionBroken(card) || !card.lastScrape) { + return false; + } + return DateUtils.getDifferenceInDaysFromNow(new Date(card.lastScrape)) >= CONST.COMPANY_CARDS.BROKEN_CONNECTION_DISMISS_AFTER_DAYS; +} + /** * Checks if an Expensify Card was issued for a given workspace. */ @@ -1863,6 +1881,7 @@ export { getFeedType, flattenWorkspaceCardsList, isCardConnectionBroken, + isBrokenConnectionPastDismissThreshold, isSmartLimitEnabled, lastFourNumbersFromCardName, isMatchingCard, diff --git a/src/libs/actions/OnyxDerived/configs/cardFeedErrors.ts b/src/libs/actions/OnyxDerived/configs/cardFeedErrors.ts index dcf5d9378f8c..4fb872b7efbc 100644 --- a/src/libs/actions/OnyxDerived/configs/cardFeedErrors.ts +++ b/src/libs/actions/OnyxDerived/configs/cardFeedErrors.ts @@ -1,6 +1,6 @@ import {buildFeedKeysWithAssignedCards} from '@selectors/Card'; import {getCombinedCardFeedsFromAllFeeds, getWorkspaceCardFeedsStatus} from '@libs/CardFeedUtils'; -import {filterInactiveCards, getCardFeedWithDomainID, isCardConnectionBroken, isPersonalCard} from '@libs/CardUtils'; +import {filterInactiveCards, getCardFeedWithDomainID, isBrokenConnectionPastDismissThreshold, isCardConnectionBroken, isPersonalCard} from '@libs/CardUtils'; import createOnyxDerivedValueConfig from '@userActions/OnyxDerived/createOnyxDerivedValueConfig'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -61,7 +61,9 @@ export default createOnyxDerivedValueConfig({ : {}), } as Record; - const isFeedConnectionBroken = isCardConnectionBroken(card); + // Stop surfacing the broken connection (task + RBR) once it has been unresolved past the + // grace period; the underlying error on the card is kept so the user can still fix it. + const isFeedConnectionBroken = isCardConnectionBroken(card) && !isBrokenConnectionPastDismissThreshold(card); // Track personal cards with broken feed connection if (isFeedConnectionBroken) { personalCardsWithBrokenConnection[card.cardID] = card; @@ -116,7 +118,9 @@ export default createOnyxDerivedValueConfig({ : {}), } as Record; - const isFeedConnectionBroken = isCardConnectionBroken(card); + // Stop surfacing the broken connection (task + RBR) once it has been unresolved past the + // grace period; the underlying error on the card is kept so the user can still fix it. + const isFeedConnectionBroken = isCardConnectionBroken(card) && !isBrokenConnectionPastDismissThreshold(card); const newFeedState: Omit = { isFeedConnectionBroken: isFeedConnectionBroken || previousFeedErrors.isFeedConnectionBroken, From 9df0102b8591d3175e93f0696e048d8ec06dc3ac Mon Sep 17 00:00:00 2001 From: Wildan Muhlis Date: Sat, 13 Jun 2026 17:01:49 +0700 Subject: [PATCH 2/5] Add unit tests for the broken-connection 90-day grace period --- tests/unit/CardFeedErrorsDerivedValueTest.ts | 49 ++++++++++++++++++++ tests/unit/CardUtilsTest.ts | 32 +++++++++++++ 2 files changed, 81 insertions(+) diff --git a/tests/unit/CardFeedErrorsDerivedValueTest.ts b/tests/unit/CardFeedErrorsDerivedValueTest.ts index 5436fd8ce667..3499225013d0 100644 --- a/tests/unit/CardFeedErrorsDerivedValueTest.ts +++ b/tests/unit/CardFeedErrorsDerivedValueTest.ts @@ -160,6 +160,55 @@ describe('CardFeedErrors Derived Value', () => { expect(result.all.isFeedConnectionBroken).toBe(false); }); + + it('should NOT surface a broken company card connection once it is unresolved past the grace period', () => { + const cardFeed = CARD_FEEDS[CONST.COMPANY_CARD.FEED_BANK_NAME.CHASE]; + const card = createCard({ + cardID: CARD_IDS.card1, + bank: cardFeed.feedName, + fundID: String(cardFeed.policyAccountID), + lastScrapeResult: 403, // Broken connection + lastScrape: '2020-01-01', // Last successful scrape is well beyond the grace period + }); + + const globalCardList: CardList = {card1: card}; + + const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}], DERIVED_VALUE_CONTEXT); + + expect(result.all.isFeedConnectionBroken).toBe(false); + expect(result.all.shouldShowRBR).toBe(false); + expect(result.cardsWithBrokenFeedConnection).toEqual({}); + }); + + it('should surface a broken personal card connection when there is no last successful scrape (fail safe)', () => { + const card = createCard({ + cardID: CARD_IDS.card1, + lastScrapeResult: 403, // Broken connection + lastScrape: '', // No successful scrape recorded — keep prompting + }); + + const globalCardList: CardList = {card1: card}; + + const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}], DERIVED_VALUE_CONTEXT); + + expect(result.personalCard.isFeedConnectionBroken).toBe(true); + expect(result.personalCardsWithBrokenConnection[CARD_IDS.card1]).toEqual(card); + }); + + it('should NOT surface a broken personal card connection once it is unresolved past the grace period', () => { + const card = createCard({ + cardID: CARD_IDS.card1, + lastScrapeResult: 403, // Broken connection + lastScrape: '2020-01-01', // Last successful scrape is well beyond the grace period + }); + + const globalCardList: CardList = {card1: card}; + + const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}], DERIVED_VALUE_CONTEXT); + + expect(result.personalCard.isFeedConnectionBroken).toBe(false); + expect(result.personalCardsWithBrokenConnection).toEqual({}); + }); }); describe('processing cards from workspace cards collection', () => { diff --git a/tests/unit/CardUtilsTest.ts b/tests/unit/CardUtilsTest.ts index 9372e51529c0..126acb3ecd15 100644 --- a/tests/unit/CardUtilsTest.ts +++ b/tests/unit/CardUtilsTest.ts @@ -56,6 +56,7 @@ import { getYearFromExpirationDateString, hasIssuedExpensifyCard, hasOnlyOneCardToAssign, + isBrokenConnectionPastDismissThreshold, isCardAlreadyAssigned, isCardFrozen, isCSVFeedOrExpensifyCard, @@ -91,6 +92,7 @@ import type { import type {CardFeedWithDomainID, CardFeedWithNumber, CompanyCardFeedWithNumber, CompanyFeeds} from '@src/types/onyx/CardFeeds'; import type {Connections} from '@src/types/onyx/Policy'; import type IconAsset from '@src/types/utils/IconAsset'; +import createRandomCard from '../utils/collections/card'; import {localeCompare, translateLocal} from '../utils/TestHelper'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; @@ -4265,6 +4267,36 @@ describe('CardUtils', () => { }); }); + describe('isBrokenConnectionPastDismissThreshold', () => { + afterEach(() => { + jest.restoreAllMocks(); + }); + + it('returns false when the connection is not broken', () => { + const spy = jest.spyOn(DateUtils, 'getDifferenceInDaysFromNow'); + const card: Card = {...createRandomCard(1), lastScrapeResult: 200, lastScrape: '2020-01-01'}; + expect(isBrokenConnectionPastDismissThreshold(card)).toBe(false); + expect(spy).not.toHaveBeenCalled(); + }); + + it('returns false when the connection is broken but lastScrape is missing', () => { + const card: Card = {...createRandomCard(1), lastScrapeResult: 403, lastScrape: ''}; + expect(isBrokenConnectionPastDismissThreshold(card)).toBe(false); + }); + + it('returns true when broken and unresolved for at least the grace period', () => { + jest.spyOn(DateUtils, 'getDifferenceInDaysFromNow').mockReturnValue(CONST.COMPANY_CARDS.BROKEN_CONNECTION_DISMISS_AFTER_DAYS); + const card: Card = {...createRandomCard(1), lastScrapeResult: 403, lastScrape: '2020-01-01'}; + expect(isBrokenConnectionPastDismissThreshold(card)).toBe(true); + }); + + it('returns false when broken but still within the grace period', () => { + jest.spyOn(DateUtils, 'getDifferenceInDaysFromNow').mockReturnValue(CONST.COMPANY_CARDS.BROKEN_CONNECTION_DISMISS_AFTER_DAYS - 1); + const card: Card = {...createRandomCard(1), lastScrapeResult: 403, lastScrape: '2020-01-01'}; + expect(isBrokenConnectionPastDismissThreshold(card)).toBe(false); + }); + }); + describe('getFeedConnectionBrokenCard', () => { it('Should return undefined when feedCards is undefined', () => { expect(getFeedConnectionBrokenCard(undefined)).toBeUndefined(); From 85431d7120541b2a3407d64a28bdc30fa2b4221c Mon Sep 17 00:00:00 2001 From: Wildan Muhlis Date: Fri, 26 Jun 2026 05:39:44 +0700 Subject: [PATCH 3/5] fix: re-derive card feed errors at day rollover for 90-day broken-connection grace CARD_FEED_ERRORS depends on the current date via isBrokenConnectionPastDismissThreshold, but its Onyx dependencies were only card/feed keys. A connection crossing the 90-day threshold while the app stayed open with no card/feed update would not recompute, so the home task/RBR could linger. Add CURRENT_DATE (day-granularity) as a trigger-only dependency so the value re-derives when the day changes; the compute body already reads the live clock. Update compute() test call sites for the resulting 4-tuple input. Addresses Codex automated-review feedback on PR #93523. --- .../OnyxDerived/configs/cardFeedErrors.ts | 4 +- tests/unit/CardFeedErrorsDerivedValueTest.ts | 58 +++++++++---------- tests/unit/CompanyCardsRBRTest.ts | 32 +++++----- 3 files changed, 48 insertions(+), 46 deletions(-) diff --git a/src/libs/actions/OnyxDerived/configs/cardFeedErrors.ts b/src/libs/actions/OnyxDerived/configs/cardFeedErrors.ts index 4fb872b7efbc..2cdf1da9a551 100644 --- a/src/libs/actions/OnyxDerived/configs/cardFeedErrors.ts +++ b/src/libs/actions/OnyxDerived/configs/cardFeedErrors.ts @@ -29,7 +29,9 @@ function getShouldShowRBR(state: Partial): boolean { export default createOnyxDerivedValueConfig({ key: ONYXKEYS.DERIVED.CARD_FEED_ERRORS, - dependencies: [ONYXKEYS.CARD_LIST, ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST, ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER], + // CURRENT_DATE (day-granularity) is a trigger-only dependency: it makes this value recompute when the day rolls over so the + // 90-day broken-connection grace period (isBrokenConnectionPastDismissThreshold) is re-evaluated even if no card/feed data changes. + dependencies: [ONYXKEYS.CARD_LIST, ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST, ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER, ONYXKEYS.CURRENT_DATE], compute: ([globalCardList, allWorkspaceCards, cardFeeds]) => { const feedKeysWithCards = buildFeedKeysWithAssignedCards(allWorkspaceCards); const combinedCompanyCardFeeds = getCombinedCardFeedsFromAllFeeds(cardFeeds, undefined, feedKeysWithCards); diff --git a/tests/unit/CardFeedErrorsDerivedValueTest.ts b/tests/unit/CardFeedErrorsDerivedValueTest.ts index 3499225013d0..e1db6361c8d6 100644 --- a/tests/unit/CardFeedErrorsDerivedValueTest.ts +++ b/tests/unit/CardFeedErrorsDerivedValueTest.ts @@ -74,7 +74,7 @@ function createWorkspaceCardsList(cards: Record, cardList?: Record describe('CardFeedErrors Derived Value', () => { describe('compute function', () => { it('should return empty errors when no cards exist', () => { - const result = cardFeedErrorsConfig.compute([{}, {}, {}], DERIVED_VALUE_CONTEXT); + const result = cardFeedErrorsConfig.compute([{}, {}, {}, undefined], DERIVED_VALUE_CONTEXT); expect(result.cardFeedErrors).toEqual({}); expect(result.cardsWithBrokenFeedConnection).toEqual({}); @@ -87,7 +87,7 @@ describe('CardFeedErrors Derived Value', () => { }); it('should return empty errors when all inputs are undefined', () => { - const result = cardFeedErrorsConfig.compute([undefined, undefined, undefined], DERIVED_VALUE_CONTEXT); + const result = cardFeedErrorsConfig.compute([undefined, undefined, undefined, undefined], DERIVED_VALUE_CONTEXT); expect(result.cardFeedErrors).toEqual({}); expect(result.all.shouldShowRBR).toBe(false); @@ -105,7 +105,7 @@ describe('CardFeedErrors Derived Value', () => { const globalCardList: CardList = {card1: card}; - const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}], DERIVED_VALUE_CONTEXT); + const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}, undefined], DERIVED_VALUE_CONTEXT); expect(result.all.isFeedConnectionBroken).toBe(true); expect(result.all.shouldShowRBR).toBe(true); @@ -123,7 +123,7 @@ describe('CardFeedErrors Derived Value', () => { const globalCardList: CardList = {card1: card}; - const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}], DERIVED_VALUE_CONTEXT); + const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}, undefined], DERIVED_VALUE_CONTEXT); expect(result.all.isFeedConnectionBroken).toBe(false); expect(result.cardsWithBrokenFeedConnection).toEqual({}); @@ -140,7 +140,7 @@ describe('CardFeedErrors Derived Value', () => { const globalCardList: CardList = {card1: card}; - const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}], DERIVED_VALUE_CONTEXT); + const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}, undefined], DERIVED_VALUE_CONTEXT); expect(result.all.isFeedConnectionBroken).toBe(false); }); @@ -156,7 +156,7 @@ describe('CardFeedErrors Derived Value', () => { const globalCardList: CardList = {card1: card}; - const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}], DERIVED_VALUE_CONTEXT); + const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}, undefined], DERIVED_VALUE_CONTEXT); expect(result.all.isFeedConnectionBroken).toBe(false); }); @@ -173,7 +173,7 @@ describe('CardFeedErrors Derived Value', () => { const globalCardList: CardList = {card1: card}; - const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}], DERIVED_VALUE_CONTEXT); + const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}, undefined], DERIVED_VALUE_CONTEXT); expect(result.all.isFeedConnectionBroken).toBe(false); expect(result.all.shouldShowRBR).toBe(false); @@ -189,7 +189,7 @@ describe('CardFeedErrors Derived Value', () => { const globalCardList: CardList = {card1: card}; - const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}], DERIVED_VALUE_CONTEXT); + const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}, undefined], DERIVED_VALUE_CONTEXT); expect(result.personalCard.isFeedConnectionBroken).toBe(true); expect(result.personalCardsWithBrokenConnection[CARD_IDS.card1]).toEqual(card); @@ -204,7 +204,7 @@ describe('CardFeedErrors Derived Value', () => { const globalCardList: CardList = {card1: card}; - const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}], DERIVED_VALUE_CONTEXT); + const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}, undefined], DERIVED_VALUE_CONTEXT); expect(result.personalCard.isFeedConnectionBroken).toBe(false); expect(result.personalCardsWithBrokenConnection).toEqual({}); @@ -225,7 +225,7 @@ describe('CardFeedErrors Derived Value', () => { [`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${cardFeed.policyAccountID}_${cardFeed.feedNameWithDomainID}`]: createWorkspaceCardsList({card2: card}), }; - const result = cardFeedErrorsConfig.compute([{}, allWorkspaceCards, {}], DERIVED_VALUE_CONTEXT); + const result = cardFeedErrorsConfig.compute([{}, allWorkspaceCards, {}, undefined], DERIVED_VALUE_CONTEXT); expect(result.all.isFeedConnectionBroken).toBe(true); expect(result.cardsWithBrokenFeedConnection[CARD_IDS.card2]).toEqual(card); @@ -275,7 +275,7 @@ describe('CardFeedErrors Derived Value', () => { }), }; - const result = cardFeedErrorsConfig.compute([{}, allWorkspaceCards, {}], DERIVED_VALUE_CONTEXT); + const result = cardFeedErrorsConfig.compute([{}, allWorkspaceCards, {}, undefined], DERIVED_VALUE_CONTEXT); // Only the active card should be processed and detected as broken expect(result.cardsWithBrokenFeedConnection).toHaveProperty(String(CARD_IDS.card4)); @@ -312,7 +312,7 @@ describe('CardFeedErrors Derived Value', () => { }, }; - const result = cardFeedErrorsConfig.compute([globalCardList, {}, cardFeeds], DERIVED_VALUE_CONTEXT); + const result = cardFeedErrorsConfig.compute([globalCardList, {}, cardFeeds, undefined], DERIVED_VALUE_CONTEXT); expect(result.all.hasFeedErrors).toBe(true); expect(result.all.shouldShowRBR).toBe(true); @@ -348,7 +348,7 @@ describe('CardFeedErrors Derived Value', () => { // }, // }; - // const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}, cardFeeds], DERIVED_VALUE_CONTEXT); + // const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}, cardFeeds, undefined], DERIVED_VALUE_CONTEXT); // expect(result.all.hasWorkspaceErrors).toBe(true); // expect(result.cardFeedErrors[cardFeed.feedNameWithDomainID]?.hasWorkspaceErrors).toBe(true); @@ -370,7 +370,7 @@ describe('CardFeedErrors Derived Value', () => { const globalCardList: CardList = {[CARD_IDS.card1]: card}; - const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}], DERIVED_VALUE_CONTEXT); + const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}, undefined], DERIVED_VALUE_CONTEXT); expect(result.cardFeedErrors[cardFeed.feedNameWithDomainID]?.cardErrors[CARD_IDS.card1]).toEqual({ errors: {cardError: 'Card sync failed'}, @@ -393,7 +393,7 @@ describe('CardFeedErrors Derived Value', () => { const globalCardList: CardList = {[CARD_IDS.card1]: card}; - const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}], DERIVED_VALUE_CONTEXT); + const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}, undefined], DERIVED_VALUE_CONTEXT); expect(result.cardFeedErrors[cardFeed.feedNameWithDomainID]?.cardErrors[CARD_IDS.card1]?.errorFields).toEqual({ cardName: {error: 'Invalid card name'}, @@ -412,7 +412,7 @@ describe('CardFeedErrors Derived Value', () => { const globalCardList: CardList = {[CARD_IDS.card1]: card}; - const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}], DERIVED_VALUE_CONTEXT); + const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}, undefined], DERIVED_VALUE_CONTEXT); expect(result.cardFeedErrors[cardFeed.feedNameWithDomainID]?.cardErrors[CARD_IDS.card1]?.pendingAction).toBe(CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE); }); @@ -431,7 +431,7 @@ describe('CardFeedErrors Derived Value', () => { const globalCardList: CardList = {[CARD_IDS.card1]: card}; - const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}], DERIVED_VALUE_CONTEXT); + const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}, undefined], DERIVED_VALUE_CONTEXT); expect(result.shouldShowRbrForWorkspaceAccountID[cardFeed.policyAccountID]).toBe(true); }); @@ -448,7 +448,7 @@ describe('CardFeedErrors Derived Value', () => { const globalCardList: CardList = {[CARD_IDS.card1]: card}; - const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}], DERIVED_VALUE_CONTEXT); + const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}, undefined], DERIVED_VALUE_CONTEXT); expect(result.shouldShowRbrForFeedNameWithDomainID[cardFeed.feedNameWithDomainID]).toBe(true); }); @@ -465,7 +465,7 @@ describe('CardFeedErrors Derived Value', () => { const globalCardList: CardList = {[CARD_IDS.card1]: card}; - const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}], DERIVED_VALUE_CONTEXT); + const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}, undefined], DERIVED_VALUE_CONTEXT); expect(result.shouldShowRbrForWorkspaceAccountID[cardFeed.policyAccountID]).toBe(false); expect(result.shouldShowRbrForFeedNameWithDomainID[cardFeed.feedNameWithDomainID]).toBe(false); @@ -493,7 +493,7 @@ describe('CardFeedErrors Derived Value', () => { const globalCardList: CardList = {[CARD_IDS.card1]: card1, [CARD_IDS.card2]: card2}; - const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}], DERIVED_VALUE_CONTEXT); + const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}, undefined], DERIVED_VALUE_CONTEXT); expect(result.shouldShowRbrForWorkspaceAccountID[cardFeed1.policyAccountID]).toBe(true); expect(result.shouldShowRbrForWorkspaceAccountID[cardFeed2.policyAccountID]).toBe(false); @@ -526,7 +526,7 @@ describe('CardFeedErrors Derived Value', () => { }), }; - const result = cardFeedErrorsConfig.compute([globalCardList, allWorkspaceCards, {}], DERIVED_VALUE_CONTEXT); + const result = cardFeedErrorsConfig.compute([globalCardList, allWorkspaceCards, {}, undefined], DERIVED_VALUE_CONTEXT); expect(result.cardsWithBrokenFeedConnection).toHaveProperty(String(CARD_IDS.card1)); expect(result.cardsWithBrokenFeedConnection).toHaveProperty(String(CARD_IDS.card2)); @@ -561,7 +561,7 @@ describe('CardFeedErrors Derived Value', () => { }, }; - const result = cardFeedErrorsConfig.compute([globalCardList, {}, cardFeeds], DERIVED_VALUE_CONTEXT); + const result = cardFeedErrorsConfig.compute([globalCardList, {}, cardFeeds, undefined], DERIVED_VALUE_CONTEXT); expect(result.all.shouldShowRBR).toBe(true); }); @@ -578,7 +578,7 @@ describe('CardFeedErrors Derived Value', () => { const globalCardList: CardList = {[CARD_IDS.card1]: card}; - const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}], DERIVED_VALUE_CONTEXT); + const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}, undefined], DERIVED_VALUE_CONTEXT); expect(result.all.shouldShowRBR).toBe(true); }); @@ -595,7 +595,7 @@ describe('CardFeedErrors Derived Value', () => { const globalCardList: CardList = {[CARD_IDS.card1]: card}; - const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}], DERIVED_VALUE_CONTEXT); + const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}, undefined], DERIVED_VALUE_CONTEXT); expect(result.all.shouldShowRBR).toBe(false); }); @@ -633,7 +633,7 @@ describe('CardFeedErrors Derived Value', () => { [CARD_IDS.card2]: healthyCard, }; - const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}], DERIVED_VALUE_CONTEXT); + const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}, undefined], DERIVED_VALUE_CONTEXT); expect(result.shouldShowRbrForFeedNameWithDomainID[CHASE_FEED.feedNameWithDomainID]).toBe(true); expect(result.shouldShowRbrForFeedNameWithDomainID[AMEX_FEED.feedNameWithDomainID]).toBe(false); @@ -658,7 +658,7 @@ describe('CardFeedErrors Derived Value', () => { [CARD_IDS.card2]: fixedAmexCard, }; - const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}], DERIVED_VALUE_CONTEXT); + const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}, undefined], DERIVED_VALUE_CONTEXT); expect(result.shouldShowRbrForFeedNameWithDomainID[CHASE_FEED.feedNameWithDomainID]).toBe(true); expect(result.shouldShowRbrForFeedNameWithDomainID[AMEX_FEED.feedNameWithDomainID]).toBe(false); @@ -684,7 +684,7 @@ describe('CardFeedErrors Derived Value', () => { [CARD_IDS.card2]: healthyAmexCard, }; - const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}], DERIVED_VALUE_CONTEXT); + const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}, undefined], DERIVED_VALUE_CONTEXT); expect(result.shouldShowRbrForFeedNameWithDomainID[CHASE_FEED.feedNameWithDomainID]).toBe(false); expect(result.shouldShowRbrForFeedNameWithDomainID[AMEX_FEED.feedNameWithDomainID]).toBe(false); @@ -710,7 +710,7 @@ describe('CardFeedErrors Derived Value', () => { [CARD_IDS.card2]: brokenAmexCard, }; - const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}], DERIVED_VALUE_CONTEXT); + const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}, undefined], DERIVED_VALUE_CONTEXT); expect(result.shouldShowRbrForFeedNameWithDomainID[CHASE_FEED.feedNameWithDomainID]).toBe(true); expect(result.shouldShowRbrForFeedNameWithDomainID[AMEX_FEED.feedNameWithDomainID]).toBe(true); @@ -755,7 +755,7 @@ describe('CardFeedErrors Derived Value', () => { }, }; - const result = cardFeedErrorsConfig.compute([globalCardList, {}, cardFeeds], DERIVED_VALUE_CONTEXT); + const result = cardFeedErrorsConfig.compute([globalCardList, {}, cardFeeds, undefined], DERIVED_VALUE_CONTEXT); expect(result.shouldShowRbrForFeedNameWithDomainID[AMEX_FEED.feedNameWithDomainID]).toBe(true); expect(result.shouldShowRbrForFeedNameWithDomainID[CHASE_FEED.feedNameWithDomainID]).toBe(false); diff --git a/tests/unit/CompanyCardsRBRTest.ts b/tests/unit/CompanyCardsRBRTest.ts index 8f82cff4481b..56fe51c58773 100644 --- a/tests/unit/CompanyCardsRBRTest.ts +++ b/tests/unit/CompanyCardsRBRTest.ts @@ -59,7 +59,7 @@ describe('Company Cards RBR - broken bank/Plaid connection', () => { }); const globalCardList: CardList = {card1: card}; - const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}], DERIVED_VALUE_CONTEXT); + const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}, undefined], DERIVED_VALUE_CONTEXT); expect(result.shouldShowRbrForWorkspaceAccountID[WORKSPACE_ACCOUNT_ID]).toBe(true); expect(result.all.isFeedConnectionBroken).toBe(true); @@ -81,7 +81,7 @@ describe('Company Cards RBR - broken bank/Plaid connection', () => { }), }; - const result = cardFeedErrorsConfig.compute([{}, allWorkspaceCards, {}], DERIVED_VALUE_CONTEXT); + const result = cardFeedErrorsConfig.compute([{}, allWorkspaceCards, {}, undefined], DERIVED_VALUE_CONTEXT); expect(result.shouldShowRbrForWorkspaceAccountID[WORKSPACE_ACCOUNT_ID]).toBe(true); expect(result.all.isFeedConnectionBroken).toBe(true); @@ -97,7 +97,7 @@ describe('Company Cards RBR - broken bank/Plaid connection', () => { }); const globalCardList: CardList = {card1: card}; - const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}], DERIVED_VALUE_CONTEXT); + const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}, undefined], DERIVED_VALUE_CONTEXT); expect(result.shouldShowRbrForWorkspaceAccountID[WORKSPACE_ACCOUNT_ID]).toBe(false); expect(result.all.isFeedConnectionBroken).toBe(false); @@ -115,7 +115,7 @@ describe('Company Cards RBR - broken bank/Plaid connection', () => { }); const globalCardList: CardList = {card3: card}; - const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}], DERIVED_VALUE_CONTEXT); + const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}, undefined], DERIVED_VALUE_CONTEXT); expect(result.shouldShowRbrForWorkspaceAccountID[WORKSPACE_ACCOUNT_ID]).toBe(true); expect(result.all.isFeedConnectionBroken).toBe(true); @@ -135,7 +135,7 @@ describe('Company Cards RBR - broken bank/Plaid connection', () => { [`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${PLAID_FEED.policyAccountID}_${PLAID_FEED.feedNameWithDomainID}`]: createWorkspaceCardsList({card4: card}), }; - const result = cardFeedErrorsConfig.compute([{}, allWorkspaceCards, {}], DERIVED_VALUE_CONTEXT); + const result = cardFeedErrorsConfig.compute([{}, allWorkspaceCards, {}, undefined], DERIVED_VALUE_CONTEXT); expect(result.shouldShowRbrForWorkspaceAccountID[WORKSPACE_ACCOUNT_ID]).toBe(true); expect(result.all.isFeedConnectionBroken).toBe(true); @@ -151,7 +151,7 @@ describe('Company Cards RBR - broken bank/Plaid connection', () => { }); const globalCardList: CardList = {card3: card}; - const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}], DERIVED_VALUE_CONTEXT); + const result = cardFeedErrorsConfig.compute([globalCardList, {}, {}, undefined], DERIVED_VALUE_CONTEXT); expect(result.shouldShowRbrForWorkspaceAccountID[WORKSPACE_ACCOUNT_ID]).toBe(false); expect(result.all.isFeedConnectionBroken).toBe(false); @@ -185,7 +185,7 @@ describe('Company Cards RBR - broken bank/Plaid connection', () => { }, }; - const result = cardFeedErrorsConfig.compute([globalCardList, {}, cardFeeds], DERIVED_VALUE_CONTEXT); + const result = cardFeedErrorsConfig.compute([globalCardList, {}, cardFeeds, undefined], DERIVED_VALUE_CONTEXT); expect(result.shouldShowRbrForWorkspaceAccountID[WORKSPACE_ACCOUNT_ID]).toBe(true); expect(result.all.hasFeedErrors).toBe(true); @@ -217,7 +217,7 @@ describe('Company Cards RBR - broken bank/Plaid connection', () => { }, }; - const result = cardFeedErrorsConfig.compute([globalCardList, {}, cardFeeds], DERIVED_VALUE_CONTEXT); + const result = cardFeedErrorsConfig.compute([globalCardList, {}, cardFeeds, undefined], DERIVED_VALUE_CONTEXT); expect(result.shouldShowRbrForWorkspaceAccountID[WORKSPACE_ACCOUNT_ID]).toBe(true); expect(result.all.hasFeedErrors).toBe(true); @@ -235,7 +235,7 @@ describe('Company Cards RBR - broken bank/Plaid connection', () => { lastScrapeResult: 403, }); - const brokenResult = cardFeedErrorsConfig.compute([{card1: brokenCard}, {}, {}], DERIVED_VALUE_CONTEXT); + const brokenResult = cardFeedErrorsConfig.compute([{card1: brokenCard}, {}, {}, undefined], DERIVED_VALUE_CONTEXT); expect(brokenResult.shouldShowRbrForWorkspaceAccountID[WORKSPACE_ACCOUNT_ID]).toBe(true); // Then: connection is fixed (lastScrapeResult returns to 200) @@ -246,7 +246,7 @@ describe('Company Cards RBR - broken bank/Plaid connection', () => { lastScrapeResult: 200, }); - const fixedResult = cardFeedErrorsConfig.compute([{card1: fixedCard}, {}, {}], DERIVED_VALUE_CONTEXT); + const fixedResult = cardFeedErrorsConfig.compute([{card1: fixedCard}, {}, {}, undefined], DERIVED_VALUE_CONTEXT); expect(fixedResult.shouldShowRbrForWorkspaceAccountID[WORKSPACE_ACCOUNT_ID]).toBe(false); expect(fixedResult.all.shouldShowRBR).toBe(false); expect(fixedResult.cardsWithBrokenFeedConnection).toEqual({}); @@ -261,7 +261,7 @@ describe('Company Cards RBR - broken bank/Plaid connection', () => { lastScrapeResult: 401, }); - const brokenResult = cardFeedErrorsConfig.compute([{card3: brokenCard}, {}, {}], DERIVED_VALUE_CONTEXT); + const brokenResult = cardFeedErrorsConfig.compute([{card3: brokenCard}, {}, {}, undefined], DERIVED_VALUE_CONTEXT); expect(brokenResult.shouldShowRbrForWorkspaceAccountID[WORKSPACE_ACCOUNT_ID]).toBe(true); // Then: Plaid re-authenticated successfully @@ -272,7 +272,7 @@ describe('Company Cards RBR - broken bank/Plaid connection', () => { lastScrapeResult: 200, }); - const fixedResult = cardFeedErrorsConfig.compute([{card3: fixedCard}, {}, {}], DERIVED_VALUE_CONTEXT); + const fixedResult = cardFeedErrorsConfig.compute([{card3: fixedCard}, {}, {}, undefined], DERIVED_VALUE_CONTEXT); expect(fixedResult.shouldShowRbrForWorkspaceAccountID[WORKSPACE_ACCOUNT_ID]).toBe(false); expect(fixedResult.all.shouldShowRBR).toBe(false); expect(fixedResult.cardsWithBrokenFeedConnection).toEqual({}); @@ -295,7 +295,7 @@ describe('Company Cards RBR - broken bank/Plaid connection', () => { }), }; - const result = cardFeedErrorsConfig.compute([{}, allWorkspaceCards, {}], DERIVED_VALUE_CONTEXT); + const result = cardFeedErrorsConfig.compute([{}, allWorkspaceCards, {}, undefined], DERIVED_VALUE_CONTEXT); expect(result.cardsWithBrokenFeedConnection).not.toHaveProperty('1'); }); @@ -315,7 +315,7 @@ describe('Company Cards RBR - broken bank/Plaid connection', () => { }), }; - const result = cardFeedErrorsConfig.compute([{}, allWorkspaceCards, {}], DERIVED_VALUE_CONTEXT); + const result = cardFeedErrorsConfig.compute([{}, allWorkspaceCards, {}, undefined], DERIVED_VALUE_CONTEXT); expect(result.cardsWithBrokenFeedConnection).not.toHaveProperty('3'); }); @@ -330,7 +330,7 @@ describe('Company Cards RBR - broken bank/Plaid connection', () => { lastScrapeResult: status, }); - const result = cardFeedErrorsConfig.compute([{card1: card}, {}, {}], DERIVED_VALUE_CONTEXT); + const result = cardFeedErrorsConfig.compute([{card1: card}, {}, {}, undefined], DERIVED_VALUE_CONTEXT); expect(result.all.isFeedConnectionBroken).toBe(false); expect(result.cardsWithBrokenFeedConnection).toEqual({}); @@ -344,7 +344,7 @@ describe('Company Cards RBR - broken bank/Plaid connection', () => { lastScrapeResult: status, }); - const result = cardFeedErrorsConfig.compute([{card3: card}, {}, {}], DERIVED_VALUE_CONTEXT); + const result = cardFeedErrorsConfig.compute([{card3: card}, {}, {}, undefined], DERIVED_VALUE_CONTEXT); expect(result.all.isFeedConnectionBroken).toBe(false); expect(result.cardsWithBrokenFeedConnection).toEqual({}); From 1969d61acd8ebe1c99e9bc4027aaa88ba1fe0980 Mon Sep 17 00:00:00 2001 From: Wildan Muhlis Date: Wed, 1 Jul 2026 20:18:49 +0700 Subject: [PATCH 4/5] fix: parse lastScrape with explicit DB format for cross-engine safety card.lastScrape uses the Expensify DB datetime format ("yyyy-MM-dd HH:mm:ss"). Relying on new Date() for that non-ISO string is not portable across JS engines (Safari/JSC, Hermes) and can produce an invalid date, making getDifferenceInDaysFromNow return NaN so the 90-day grace would never dismiss the task/RBR. Parse explicitly with date-fns and guard against an unparseable value (fail-safe: keep surfacing the task). Also adds an unmocked test that exercises the real parsing. Addresses Codex review feedback on PR #93523. --- src/libs/CardUtils.ts | 11 +++++++++-- tests/unit/CardUtilsTest.ts | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/libs/CardUtils.ts b/src/libs/CardUtils.ts index 2c88216e45ea..e85012d16d35 100644 --- a/src/libs/CardUtils.ts +++ b/src/libs/CardUtils.ts @@ -1,4 +1,4 @@ -import {format, fromUnixTime, isBefore} from 'date-fns'; +import {format, fromUnixTime, isBefore, parse} from 'date-fns'; import groupBy from 'lodash/groupBy'; import lodashSortBy from 'lodash/sortBy'; import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; @@ -1300,7 +1300,14 @@ function isBrokenConnectionPastDismissThreshold(card: Card): boolean { if (!isCardConnectionBroken(card) || !card.lastScrape) { return false; } - return DateUtils.getDifferenceInDaysFromNow(new Date(card.lastScrape)) >= CONST.COMPANY_CARDS.BROKEN_CONNECTION_DISMISS_AFTER_DAYS; + // `card.lastScrape` uses the Expensify DB datetime format (e.g. "2024-11-27 11:00:53"). Parse it explicitly with the + // matching format instead of relying on `new Date()`, whose handling of this non-ISO string is not portable across JS + // engines — an invalid parse would make the difference NaN, so the comparison would always be false and never dismiss. + const lastScrapeDate = parse(card.lastScrape, 'yyyy-MM-dd HH:mm:ss', new Date()); + if (Number.isNaN(lastScrapeDate.getTime())) { + return false; + } + return DateUtils.getDifferenceInDaysFromNow(lastScrapeDate) >= CONST.COMPANY_CARDS.BROKEN_CONNECTION_DISMISS_AFTER_DAYS; } /** diff --git a/tests/unit/CardUtilsTest.ts b/tests/unit/CardUtilsTest.ts index d82d1662ab72..908d0b2ddf87 100644 --- a/tests/unit/CardUtilsTest.ts +++ b/tests/unit/CardUtilsTest.ts @@ -4290,15 +4290,22 @@ describe('CardUtils', () => { it('returns true when broken and unresolved for at least the grace period', () => { jest.spyOn(DateUtils, 'getDifferenceInDaysFromNow').mockReturnValue(CONST.COMPANY_CARDS.BROKEN_CONNECTION_DISMISS_AFTER_DAYS); - const card: Card = {...createRandomCard(1), lastScrapeResult: 403, lastScrape: '2020-01-01'}; + const card: Card = {...createRandomCard(1), lastScrapeResult: 403, lastScrape: '2020-01-01 00:00:00'}; expect(isBrokenConnectionPastDismissThreshold(card)).toBe(true); }); it('returns false when broken but still within the grace period', () => { jest.spyOn(DateUtils, 'getDifferenceInDaysFromNow').mockReturnValue(CONST.COMPANY_CARDS.BROKEN_CONNECTION_DISMISS_AFTER_DAYS - 1); - const card: Card = {...createRandomCard(1), lastScrapeResult: 403, lastScrape: '2020-01-01'}; + const card: Card = {...createRandomCard(1), lastScrapeResult: 403, lastScrape: '2020-01-01 00:00:00'}; expect(isBrokenConnectionPastDismissThreshold(card)).toBe(false); }); + + // Uses the real DateUtils (no mock) to prove the DB-format string is parsed correctly, since new Date() on + // "yyyy-MM-dd HH:mm:ss" is not portable across JS engines and an invalid parse would silently never dismiss. + it('parses the DB datetime format and dismisses a long-broken connection without mocking', () => { + const card: Card = {...createRandomCard(1), lastScrapeResult: 403, lastScrape: '2020-01-01 00:00:00'}; + expect(isBrokenConnectionPastDismissThreshold(card)).toBe(true); + }); }); describe('getFeedConnectionBrokenCard', () => { From 00765f5a4e1935cebef8509de1c78a3a4d759496 Mon Sep 17 00:00:00 2001 From: Wildan Muhlis Date: Wed, 1 Jul 2026 20:35:37 +0700 Subject: [PATCH 5/5] test: use full DB datetime format in grace-period fixtures Follow-up to the lastScrape parse fix: the derived-value grace-period tests used a date-only 'yyyy-MM-dd' lastScrape, which the stricter parse('yyyy-MM-dd HH:mm:ss') now treats as unparseable (NaN guard -> not dismissed). Use the real DB format so the past-grace company and personal card tests exercise a valid parse. --- tests/unit/CardFeedErrorsDerivedValueTest.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/CardFeedErrorsDerivedValueTest.ts b/tests/unit/CardFeedErrorsDerivedValueTest.ts index e1db6361c8d6..beb634757ba6 100644 --- a/tests/unit/CardFeedErrorsDerivedValueTest.ts +++ b/tests/unit/CardFeedErrorsDerivedValueTest.ts @@ -168,7 +168,7 @@ describe('CardFeedErrors Derived Value', () => { bank: cardFeed.feedName, fundID: String(cardFeed.policyAccountID), lastScrapeResult: 403, // Broken connection - lastScrape: '2020-01-01', // Last successful scrape is well beyond the grace period + lastScrape: '2020-01-01 00:00:00', // Last successful scrape is well beyond the grace period }); const globalCardList: CardList = {card1: card}; @@ -199,7 +199,7 @@ describe('CardFeedErrors Derived Value', () => { const card = createCard({ cardID: CARD_IDS.card1, lastScrapeResult: 403, // Broken connection - lastScrape: '2020-01-01', // Last successful scrape is well beyond the grace period + lastScrape: '2020-01-01 00:00:00', // Last successful scrape is well beyond the grace period }); const globalCardList: CardList = {card1: card};