diff --git a/src/libs/CardUtils.ts b/src/libs/CardUtils.ts index 9a71480019a6..e26618fd3a6d 100644 --- a/src/libs/CardUtils.ts +++ b/src/libs/CardUtils.ts @@ -203,8 +203,8 @@ function getEligibleBankAccountsForCard(bankAccountsList: OnyxEntry, personalDetails: OnyxEntry): Card[] { const {cardList, ...cards} = cardsList ?? {}; return Object.values(cards).sort((cardA: Card, cardB: Card) => { - const userA = personalDetails?.[cardA.accountID ?? '-1'] ?? {}; - const userB = personalDetails?.[cardB.accountID ?? '-1'] ?? {}; + const userA = cardA.accountID ? personalDetails?.[cardA.accountID] ?? {} : {}; + const userB = cardB.accountID ? personalDetails?.[cardB.accountID] ?? {} : {}; const aName = PersonalDetailsUtils.getDisplayNameOrDefault(userA); const bName = PersonalDetailsUtils.getDisplayNameOrDefault(userB); @@ -251,17 +251,15 @@ 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 getCompanyFeeds(cardFeeds: OnyxEntry): CompanyFeeds { - return {...cardFeeds?.settings?.companyCards, ...cardFeeds?.settings?.oAuthAccountDetails}; -} - -function removeExpensifyCardFromCompanyCards(cardFeeds: OnyxEntry): CompanyFeeds { - if (!cardFeeds) { - return {}; - } - - const companyCards = getCompanyFeeds(cardFeeds); - return Object.fromEntries(Object.entries(companyCards).filter(([key]) => key !== CONST.EXPENSIFY_CARD.BANK)); +function getCompanyFeeds(cardFeeds: OnyxEntry, shouldFilterOutRemovedFeeds = false): CompanyFeeds { + return Object.fromEntries( + Object.entries(cardFeeds?.settings?.companyCards ?? {}).filter(([key, value]) => { + if (shouldFilterOutRemovedFeeds && value.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) { + return false; + } + return key !== CONST.EXPENSIFY_CARD.BANK; + }), + ); } function getCardFeedName(feedType: CompanyCardFeed): string { @@ -348,7 +346,7 @@ const getCorrectStepForSelectedBank = (selectedBank: ValueOf, cardFeeds: OnyxEntry): CompanyCardFeed | undefined { - const defaultFeed = Object.keys(removeExpensifyCardFromCompanyCards(cardFeeds)).at(0) as CompanyCardFeed | undefined; + const defaultFeed = Object.keys(getCompanyFeeds(cardFeeds, true)).at(0) as CompanyCardFeed | undefined; return lastSelectedFeed ?? defaultFeed; } @@ -410,7 +408,6 @@ export { getSelectedFeed, getCorrectStepForSelectedBank, getCustomOrFormattedFeedName, - removeExpensifyCardFromCompanyCards, getFilteredCardList, hasOnlyOneCardToAssign, checkIfNewFeedConnected, diff --git a/src/libs/actions/CompanyCards.ts b/src/libs/actions/CompanyCards.ts index 8e83b9192a71..d0e19398c257 100644 --- a/src/libs/actions/CompanyCards.ts +++ b/src/libs/actions/CompanyCards.ts @@ -124,7 +124,6 @@ function setWorkspaceCompanyCardFeedName(policyID: string, workspaceAccountID: n function setWorkspaceCompanyCardTransactionLiability(workspaceAccountID: number, policyID: string, bankName: CompanyCardFeed, liabilityType: string) { const authToken = NetworkStore.getAuthToken(); - const isCustomFeed = CardUtils.isCustomFeed(bankName); const feedUpdates = { [bankName]: {liabilityType}, }; @@ -135,7 +134,7 @@ function setWorkspaceCompanyCardTransactionLiability(workspaceAccountID: number, onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER}${workspaceAccountID}`, value: { - settings: isCustomFeed ? {companyCards: feedUpdates} : {oAuthAccountDetails: feedUpdates}, + settings: {companyCards: feedUpdates}, }, }, ], @@ -151,10 +150,14 @@ function setWorkspaceCompanyCardTransactionLiability(workspaceAccountID: number, API.write(WRITE_COMMANDS.SET_COMPANY_CARD_TRANSACTION_LIABILITY, parameters, onyxData); } -function deleteWorkspaceCompanyCardFeed(policyID: string, workspaceAccountID: number, bankName: CompanyCardFeed, feedToOpen?: CompanyCardFeed) { +function deleteWorkspaceCompanyCardFeed(policyID: string, workspaceAccountID: number, bankName: CompanyCardFeed, cardIDs: string[], feedToOpen?: CompanyCardFeed) { const authToken = NetworkStore.getAuthToken(); const isCustomFeed = CardUtils.isCustomFeed(bankName); - const feedUpdates = {[bankName]: null}; + const optimisticFeedUpdates = {[bankName]: {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE}}; + const successFeedUpdates = {[bankName]: null}; + const failureFeedUpdates = {[bankName]: {pendingAction: null, errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage')}}; + const optimisticCardUpdates = Object.fromEntries(cardIDs.map((cardID) => [cardID, {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE}])); + const successAndFailureCardUpdates = Object.fromEntries(cardIDs.map((cardID) => [cardID, {pendingAction: null}])); const optimisticData: OnyxUpdate[] = [ { @@ -162,22 +165,74 @@ function deleteWorkspaceCompanyCardFeed(policyID: string, workspaceAccountID: nu key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER}${workspaceAccountID}`, value: { settings: { - ...(isCustomFeed ? {companyCards: feedUpdates} : {oAuthAccountDetails: feedUpdates}), + companyCards: optimisticFeedUpdates, + }, + }, + }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${bankName}`, + value: optimisticCardUpdates, + }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.CARD_LIST, + value: optimisticCardUpdates, + }, + ]; + + const successData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER}${workspaceAccountID}`, + value: { + settings: { + ...(isCustomFeed ? {companyCards: successFeedUpdates} : {oAuthAccountDetails: successFeedUpdates, companyCards: successFeedUpdates}), companyCardNicknames: { [bankName]: null, }, }, }, }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${bankName}`, + value: successAndFailureCardUpdates, + }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.CARD_LIST, + value: successAndFailureCardUpdates, + }, ]; - if (feedToOpen) { - optimisticData.push({ + const failureData: OnyxUpdate[] = [ + { onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.LAST_SELECTED_FEED}${policyID}`, - value: feedToOpen, - }); - } + key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER}${workspaceAccountID}`, + value: { + settings: { + companyCards: failureFeedUpdates, + }, + }, + }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${bankName}`, + value: successAndFailureCardUpdates, + }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.CARD_LIST, + value: successAndFailureCardUpdates, + }, + ]; + + optimisticData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.LAST_SELECTED_FEED}${policyID}`, + value: feedToOpen ?? null, + }); const parameters = { authToken, @@ -185,7 +240,7 @@ function deleteWorkspaceCompanyCardFeed(policyID: string, workspaceAccountID: nu bankName, }; - API.write(WRITE_COMMANDS.DELETE_COMPANY_CARD_FEED, parameters, {optimisticData}); + API.write(WRITE_COMMANDS.DELETE_COMPANY_CARD_FEED, parameters, {optimisticData, successData, failureData}); } function assignWorkspaceCompanyCard(policyID: string, data?: Partial) { @@ -194,7 +249,7 @@ function assignWorkspaceCompanyCard(policyID: string, data?: Partial { if (!policyID) { return; diff --git a/src/pages/workspace/companyCards/WorkspaceCompanyCardDetailsPage.tsx b/src/pages/workspace/companyCards/WorkspaceCompanyCardDetailsPage.tsx index 015d018afb76..fb49ece0feb0 100644 --- a/src/pages/workspace/companyCards/WorkspaceCompanyCardDetailsPage.tsx +++ b/src/pages/workspace/companyCards/WorkspaceCompanyCardDetailsPage.tsx @@ -58,13 +58,15 @@ function WorkspaceCompanyCardDetailsPage({route}: WorkspaceCompanyCardDetailsPag const card = allBankCards?.[cardID]; const cardBank = card?.bank ?? ''; - const cardholder = personalDetails?.[card?.accountID ?? -1]; + const cardholder = personalDetails?.[card?.accountID ?? CONST.DEFAULT_NUMBER_ID]; const displayName = PersonalDetailsUtils.getDisplayNameOrDefault(cardholder); const exportMenuItem = getExportMenuItem(connectedIntegration, policyID, translate, policy, card); const unassignCard = () => { setIsUnassignModalVisible(false); - CompanyCards.unassignWorkspaceCompanyCard(workspaceAccountID, bank, card); + if (card) { + CompanyCards.unassignWorkspaceCompanyCard(workspaceAccountID, bank, card); + } Navigation.goBack(); }; diff --git a/src/pages/workspace/companyCards/WorkspaceCompanyCardFeedSelectorPage.tsx b/src/pages/workspace/companyCards/WorkspaceCompanyCardFeedSelectorPage.tsx index 723242c55494..29d0dfb0c6af 100644 --- a/src/pages/workspace/companyCards/WorkspaceCompanyCardFeedSelectorPage.tsx +++ b/src/pages/workspace/companyCards/WorkspaceCompanyCardFeedSelectorPage.tsx @@ -42,13 +42,14 @@ function WorkspaceCompanyCardFeedSelectorPage({route}: WorkspaceCompanyCardFeedS const [lastSelectedFeed] = useOnyx(`${ONYXKEYS.COLLECTION.LAST_SELECTED_FEED}${policyID}`); const selectedFeed = CardUtils.getSelectedFeed(lastSelectedFeed, cardFeeds); const companyFeeds = CardUtils.getCompanyFeeds(cardFeeds); - const availableCards = CardUtils.removeExpensifyCardFromCompanyCards(cardFeeds); - const feeds: CardFeedListItem[] = (Object.keys(availableCards) as CompanyCardFeed[]).map((feed) => ({ + const feeds: CardFeedListItem[] = (Object.keys(companyFeeds) as CompanyCardFeed[]).map((feed) => ({ value: feed, text: CardUtils.getCustomOrFormattedFeedName(feed, cardFeeds?.settings?.companyCardNicknames), keyForList: feed, isSelected: feed === selectedFeed, + isDisabled: companyFeeds[feed]?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, + pendingAction: companyFeeds[feed]?.pendingAction, brickRoadIndicator: companyFeeds[feed]?.errors ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined, canShowSeveralIndicators: !!companyFeeds[feed]?.errors, leftElement: ( diff --git a/src/pages/workspace/companyCards/WorkspaceCompanyCardsPage.tsx b/src/pages/workspace/companyCards/WorkspaceCompanyCardsPage.tsx index 392138a2d8d1..ea3a0e0f7071 100644 --- a/src/pages/workspace/companyCards/WorkspaceCompanyCardsPage.tsx +++ b/src/pages/workspace/companyCards/WorkspaceCompanyCardsPage.tsx @@ -49,9 +49,9 @@ function WorkspaceCompanyCardPage({route}: WorkspaceCompanyCardPageProps) { const filteredCardList = CardUtils.getFilteredCardList(cardsList, selectedFeed ? cardFeeds?.settings?.oAuthAccountDetails?.[selectedFeed] : undefined); - const companyCards = CardUtils.removeExpensifyCardFromCompanyCards(cardFeeds); + const companyCards = CardUtils.getCompanyFeeds(cardFeeds); const selectedFeedData = selectedFeed && companyCards[selectedFeed]; - const isNoFeed = isEmptyObject(companyCards) && !selectedFeedData; + const isNoFeed = !selectedFeedData; const isPending = !!selectedFeedData?.pending; const isFeedAdded = !isPending && !isNoFeed; diff --git a/src/pages/workspace/companyCards/WorkspaceCompanyCardsSettingsPage.tsx b/src/pages/workspace/companyCards/WorkspaceCompanyCardsSettingsPage.tsx index 58c79d41d3c9..60774c448546 100644 --- a/src/pages/workspace/companyCards/WorkspaceCompanyCardsSettingsPage.tsx +++ b/src/pages/workspace/companyCards/WorkspaceCompanyCardsSettingsPage.tsx @@ -35,13 +35,14 @@ function WorkspaceCompanyCardsSettingsPage({ const styles = useThemeStyles(); const {translate} = useLocalize(); const policy = usePolicy(policyID); - const workspaceAccountID = policy?.workspaceAccountID ?? -1; + const workspaceAccountID = policy?.workspaceAccountID ?? CONST.DEFAULT_NUMBER_ID; const [deleteCompanyCardConfirmModalVisible, setDeleteCompanyCardConfirmModalVisible] = useState(false); const [cardFeeds] = useOnyx(`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER}${workspaceAccountID}`); const [lastSelectedFeed] = useOnyx(`${ONYXKEYS.COLLECTION.LAST_SELECTED_FEED}${policyID}`); // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps -- we want to run the hook only once to escape unexpected feed change const selectedFeed = useMemo(() => CardUtils.getSelectedFeed(lastSelectedFeed, cardFeeds), []); + const [cardsList] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${selectedFeed}`); const feedName = CardUtils.getCustomOrFormattedFeedName(selectedFeed, cardFeeds?.settings?.companyCardNicknames); const companyFeeds = CardUtils.getCompanyFeeds(cardFeeds); const liabilityType = selectedFeed && companyFeeds[selectedFeed]?.liabilityType; @@ -53,8 +54,12 @@ function WorkspaceCompanyCardsSettingsPage({ const deleteCompanyCardFeed = () => { if (selectedFeed) { - const feedToOpen = (Object.keys(companyFeeds) as CompanyCardFeed[]).filter((feed) => feed !== selectedFeed).at(0); - CompanyCards.deleteWorkspaceCompanyCardFeed(policyID, workspaceAccountID, selectedFeed, feedToOpen); + const {cardList, ...cards} = cardsList ?? {}; + const cardIDs = Object.keys(cards); + const feedToOpen = (Object.keys(companyFeeds) as CompanyCardFeed[]) + .filter((feed) => feed !== selectedFeed && companyFeeds[feed]?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) + .at(0); + CompanyCards.deleteWorkspaceCompanyCardFeed(policyID, workspaceAccountID, selectedFeed, cardIDs, feedToOpen); } setDeleteCompanyCardConfirmModalVisible(false); Navigation.setNavigationActionToMicrotaskQueue(Navigation.goBack); diff --git a/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx b/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx index 85a5d2372ee9..c53fe1fb2e7f 100644 --- a/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx +++ b/src/pages/workspace/members/WorkspaceMemberDetailsPage.tsx @@ -81,10 +81,10 @@ function WorkspaceMemberDetailsPage({personalDetails, policy, route}: WorkspaceM const isSelectedMemberCurrentUser = accountID === currentUserPersonalDetails?.accountID; const isCurrentUserAdmin = policy?.employeeList?.[personalDetails?.[currentUserPersonalDetails?.accountID]?.login ?? '']?.role === CONST.POLICY.ROLE.ADMIN; const isCurrentUserOwner = policy?.owner === currentUserPersonalDetails?.login; - const ownerDetails = personalDetails?.[policy?.ownerAccountID ?? -1] ?? ({} as PersonalDetails); + const ownerDetails = personalDetails?.[policy?.ownerAccountID ?? CONST.DEFAULT_NUMBER_ID] ?? ({} as PersonalDetails); const policyOwnerDisplayName = formatPhoneNumber(PersonalDetailsUtils.getDisplayNameOrDefault(ownerDetails)) ?? policy?.owner ?? ''; const hasMultipleFeeds = Object.values(CardUtils.getCompanyFeeds(cardFeeds)).filter((feed) => !feed.pending).length > 0; - const paymentAccountID = cardSettings?.paymentBankAccountID ?? 0; + const paymentAccountID = cardSettings?.paymentBankAccountID ?? CONST.DEFAULT_NUMBER_ID; useEffect(() => { CompanyCards.openPolicyCompanyCardsPage(policyID, workspaceAccountID); diff --git a/src/pages/workspace/members/WorkspaceMemberNewCardPage.tsx b/src/pages/workspace/members/WorkspaceMemberNewCardPage.tsx index d53d8a558276..afa76e63a815 100644 --- a/src/pages/workspace/members/WorkspaceMemberNewCardPage.tsx +++ b/src/pages/workspace/members/WorkspaceMemberNewCardPage.tsx @@ -49,7 +49,7 @@ function WorkspaceMemberNewCardPage({route, personalDetails}: WorkspaceMemberNew const accountID = Number(route.params.accountID); const memberLogin = personalDetails?.[accountID]?.login ?? ''; const memberName = personalDetails?.[accountID]?.firstName ? personalDetails?.[accountID]?.firstName : personalDetails?.[accountID]?.login; - const availableCompanyCards = CardUtils.removeExpensifyCardFromCompanyCards(cardFeeds); + const companyFeeds = CardUtils.getCompanyFeeds(cardFeeds); const [list] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${selectedFeed}`); const filteredCardList = CardUtils.getFilteredCardList(list, cardFeeds?.settings?.oAuthAccountDetails?.[selectedFeed as CompanyCardFeed]); @@ -97,10 +97,12 @@ function WorkspaceMemberNewCardPage({route, personalDetails}: WorkspaceMemberNew setShouldShowError(false); }; - const companyCardFeeds: CardFeedListItem[] = (Object.keys(availableCompanyCards) as CompanyCardFeed[]).map((key) => ({ + const companyCardFeeds: CardFeedListItem[] = (Object.keys(companyFeeds) as CompanyCardFeed[]).map((key) => ({ value: key, text: CardUtils.getCustomOrFormattedFeedName(key, cardFeeds?.settings?.companyCardNicknames), keyForList: key, + isDisabled: companyFeeds[key]?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, + pendingAction: companyFeeds[key]?.pendingAction, isSelected: selectedFeed === key, leftElement: ( ; /** Direct card feed data */ -type DirectCardFeedData = { +type DirectCardFeedData = OnyxCommon.OnyxValueWithOfflineFeedback<{ /** List of accounts */ accountList: string[]; @@ -58,7 +58,7 @@ type DirectCardFeedData = { /** Broken connection errors */ errors?: OnyxCommon.Errors; -}; +}>; /** Card feed data */ type CardFeedData = CustomCardFeedData | DirectCardFeedData; diff --git a/tests/unit/CardUtilsTest.ts b/tests/unit/CardUtilsTest.ts index c294b068a62d..2685a77836b3 100644 --- a/tests/unit/CardUtilsTest.ts +++ b/tests/unit/CardUtilsTest.ts @@ -2,7 +2,6 @@ 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 {CompanyFeeds} from '@src/types/onyx/CardFeeds'; const shortDate = '0924'; const shortDateSlashed = '09/24'; @@ -13,7 +12,7 @@ const longDateHyphen = '09-2024'; const expectedMonth = '09'; const expectedYear = '2024'; -const customFeeds = { +const companyCardsCustomFeedSettings = { [CONST.COMPANY_CARD.FEED_BANK_NAME.MASTER_CARD]: { pending: true, }, @@ -24,7 +23,7 @@ const customFeeds = { liabilityType: 'personal', }, }; -const customFeedsWithoutExpensifyBank = { +const companyCardsCustomFeedSettingsWithoutExpensifyBank = { [CONST.COMPANY_CARD.FEED_BANK_NAME.MASTER_CARD]: { pending: true, }, @@ -32,7 +31,25 @@ const customFeedsWithoutExpensifyBank = { liabilityType: 'personal', }, }; -const directFeeds = { +const companyCardsDirectFeedSettings = { + [CONST.COMPANY_CARD.FEED_BANK_NAME.CHASE]: { + liabilityType: 'personal', + }, + [CONST.COMPANY_CARD.FEED_BANK_NAME.CAPITAL_ONE]: { + liabilityType: 'personal', + }, +}; +const companyCardsSettingsWithoutExpensifyBank = { + [CONST.COMPANY_CARD.FEED_BANK_NAME.MASTER_CARD]: { + pending: true, + }, + [CONST.COMPANY_CARD.FEED_BANK_NAME.VISA]: { + liabilityType: 'personal', + }, + ...companyCardsDirectFeedSettings, +}; + +const oAuthAccountDetails = { [CONST.COMPANY_CARD.FEED_BANK_NAME.CHASE]: { accountList: ['CREDIT CARD...6607', 'CREDIT CARD...5501'], credentials: 'xxxxx', @@ -115,27 +132,30 @@ const customFeedCardsList = { '480801XXXXXX2566': 'ENCRYPTED_CARD_NUMBER', }, } as unknown as OnyxTypes.WorkspaceCardsList; -const allFeeds: CompanyFeeds = {...customFeeds, ...directFeeds}; const customFeedName = 'Custom feed name'; const cardFeedsCollection: OnyxCollection = { + // Policy with both custom and direct feeds FAKE_ID_1: { settings: { companyCardNicknames: { [CONST.COMPANY_CARD.FEED_BANK_NAME.VISA]: customFeedName, }, - companyCards: customFeeds, - oAuthAccountDetails: directFeeds, + companyCards: {...companyCardsCustomFeedSettings, ...companyCardsDirectFeedSettings}, + oAuthAccountDetails, }, }, + // Policy with direct feeds only FAKE_ID_2: { settings: { - oAuthAccountDetails: directFeeds, + companyCards: companyCardsDirectFeedSettings, + oAuthAccountDetails, }, }, + // Policy with custom feeds only FAKE_ID_3: { settings: { - companyCards: customFeeds, + companyCards: companyCardsCustomFeedSettings, }, }, }; @@ -198,19 +218,19 @@ describe('CardUtils', () => { }); describe('getCompanyFeeds', () => { - it('Should return both custom and direct feeds if exists', () => { + it('Should return both custom and direct feeds with filtered out "Expensify Card" bank', () => { const companyFeeds = CardUtils.getCompanyFeeds(cardFeedsCollection.FAKE_ID_1); - expect(companyFeeds).toStrictEqual(allFeeds); + expect(companyFeeds).toStrictEqual(companyCardsSettingsWithoutExpensifyBank); }); it('Should return direct feeds only since custom feeds are not exist', () => { const companyFeeds = CardUtils.getCompanyFeeds(cardFeedsCollection.FAKE_ID_2); - expect(companyFeeds).toStrictEqual(directFeeds); + expect(companyFeeds).toStrictEqual(companyCardsDirectFeedSettings); }); - it('Should return custom feeds only since direct feeds are not exist', () => { + it('Should return custom feeds only with filtered out "Expensify Card" bank since direct feeds are not exist', () => { const companyFeeds = CardUtils.getCompanyFeeds(cardFeedsCollection.FAKE_ID_3); - expect(companyFeeds).toStrictEqual(customFeeds); + expect(companyFeeds).toStrictEqual(companyCardsCustomFeedSettingsWithoutExpensifyBank); }); it('Should return empty object if undefined is passed', () => { @@ -219,23 +239,6 @@ describe('CardUtils', () => { }); }); - describe('removeExpensifyCardFromCompanyCards', () => { - it('Should return custom feeds without filtered out "Expensify Card" bank', () => { - const companyFeeds = CardUtils.removeExpensifyCardFromCompanyCards(cardFeedsCollection.FAKE_ID_3); - expect(companyFeeds).toStrictEqual(customFeedsWithoutExpensifyBank); - }); - - it('Should return direct feeds without any updates, since there were no "Expensify Card" bank', () => { - const companyFeeds = CardUtils.removeExpensifyCardFromCompanyCards(cardFeedsCollection.FAKE_ID_2); - expect(companyFeeds).toStrictEqual(directFeeds); - }); - - it('Should return empty object if undefined is passed', () => { - const companyFeeds = CardUtils.removeExpensifyCardFromCompanyCards(undefined); - expect(companyFeeds).toStrictEqual({}); - }); - }); - describe('getSelectedFeed', () => { it('Should return last selected custom feed', () => { const lastSelectedCustomFeed = CONST.COMPANY_CARD.FEED_BANK_NAME.VISA; @@ -357,13 +360,13 @@ describe('CardUtils', () => { }); it('Should return filtered direct feed cards list with a single card', () => { - const cardsList = CardUtils.getFilteredCardList(directFeedCardsSingleList, directFeeds[CONST.COMPANY_CARD.FEED_BANK_NAME.CHASE]); + const cardsList = CardUtils.getFilteredCardList(directFeedCardsSingleList, oAuthAccountDetails[CONST.COMPANY_CARD.FEED_BANK_NAME.CHASE]); // eslint-disable-next-line @typescript-eslint/naming-convention expect(cardsList).toStrictEqual({'CREDIT CARD...6607': 'CREDIT CARD...6607'}); }); it('Should return filtered direct feed cards list with multiple cards', () => { - const cardsList = CardUtils.getFilteredCardList(directFeedCardsMultipleList, directFeeds[CONST.COMPANY_CARD.FEED_BANK_NAME.CAPITAL_ONE]); + const cardsList = CardUtils.getFilteredCardList(directFeedCardsMultipleList, oAuthAccountDetails[CONST.COMPANY_CARD.FEED_BANK_NAME.CAPITAL_ONE]); // eslint-disable-next-line @typescript-eslint/naming-convention expect(cardsList).toStrictEqual({'CREDIT CARD...1233': 'CREDIT CARD...1233', 'CREDIT CARD...3333': 'CREDIT CARD...3333', 'CREDIT CARD...7788': 'CREDIT CARD...7788'}); });