diff --git a/src/libs/ExpensifyCardFeedSelectorUtils.ts b/src/libs/ExpensifyCardFeedSelectorUtils.ts index e7ec58afaa90..313df167c495 100644 --- a/src/libs/ExpensifyCardFeedSelectorUtils.ts +++ b/src/libs/ExpensifyCardFeedSelectorUtils.ts @@ -46,6 +46,10 @@ function hasConfiguredExpensifyCardFeed(settings: ExpensifyCardSettings | undefi continue; } if (programKey === CONST.TRAVEL.PROGRAM_TRAVEL_US) { + // Linking a disabled travel feed doesn't turn it back on, so it goes through the enable flow. + if (nested.isEnabled === false) { + continue; + } if (hasTravelBillingSettlementAccount(nested) || getIsTravelBillingPayByInvoice(nested)) { return true; } diff --git a/tests/unit/ExpensifyCardFeedSelectorUtilsTest.ts b/tests/unit/ExpensifyCardFeedSelectorUtilsTest.ts index 600b01b8b903..ea8337b1ead1 100644 --- a/tests/unit/ExpensifyCardFeedSelectorUtilsTest.ts +++ b/tests/unit/ExpensifyCardFeedSelectorUtilsTest.ts @@ -195,6 +195,23 @@ describe('getAdminExpensifyCardFeedEntries', () => { expect(currentEntries.map((entry) => entry.fundID)).toEqual([feedFundID]); }); + it('hides a travel feed that was turned off', () => { + // Given a travel feed that keeps its settlement account after Consolidated Travel Billing is turned off + const travelSettings = (isEnabled: boolean): OnyxCollection => ({ + [`${ONYXKEYS.COLLECTION.PRIVATE_EXPENSIFY_CARD_SETTINGS}${feedFundID}`]: { + [CONST.TRAVEL.PROGRAM_TRAVEL_US]: {paymentBankAccountID: 23242, isEnabled}, + }, + }); + + // When the travel feeds are listed for the off and on states + const disabledEntries = getAdminExpensifyCardFeedEntries(travelSettings(false), adminPolicyForFund, {}, currentUserAccountID, [CONST.TRAVEL.PROGRAM_TRAVEL_US]); + const enabledEntries = getAdminExpensifyCardFeedEntries(travelSettings(true), adminPolicyForFund, {}, currentUserAccountID, [CONST.TRAVEL.PROGRAM_TRAVEL_US]); + + // Then only the enabled feed is offered, because linking a disabled one would leave the toggle off + expect(disabledEntries).toHaveLength(0); + expect(enabledEntries.map((entry) => entry.fundID)).toEqual([feedFundID]); + }); + it('hides a feed when the user is neither a domain admin nor a workspace admin for the fund', () => { const nonAdminPolicy = createPolicyCollection([createAdminPolicy({id: workspacePolicyID, policyAccountID: 9999})]);