@@ -34,6 +34,8 @@ import {
3434 getCustomOrFormattedFeedName ,
3535 getDefaultExpensifyCardLimitType ,
3636 getDisplayableExpensifyCards ,
37+ getEligibleBankAccountsForCard ,
38+ getEligibleBankAccountsForUkEuCard ,
3739 getFeedNameForDisplay ,
3840 getFeedType ,
3941 getFilteredCardList ,
@@ -60,7 +62,18 @@ import {
6062 splitCardFeedWithDomainID ,
6163 splitMaskedCardNumber ,
6264} from '@src/libs/CardUtils' ;
63- import type { Card , CardFeeds , CardList , CompanyCardFeed , CompanyCardFeedWithDomainID , ExpensifyCardSettings , PersonalDetailsList , Policy , WorkspaceCardsList } from '@src/types/onyx' ;
65+ import type {
66+ BankAccountList ,
67+ Card ,
68+ CardFeeds ,
69+ CardList ,
70+ CompanyCardFeed ,
71+ CompanyCardFeedWithDomainID ,
72+ ExpensifyCardSettings ,
73+ PersonalDetailsList ,
74+ Policy ,
75+ WorkspaceCardsList ,
76+ } from '@src/types/onyx' ;
6477import type { CardFeedWithDomainID , CardFeedWithNumber , CompanyCardFeedWithNumber } from '@src/types/onyx/CardFeeds' ;
6578import type IconAsset from '@src/types/utils/IconAsset' ;
6679import { localeCompare , translateLocal } from '../utils/TestHelper' ;
@@ -3491,3 +3504,84 @@ describe('formatMaskedCardName', () => {
34913504 expect ( formatMaskedCardName ( 'J. SMITH...4306' ) ) . toBe ( 'J. SMITH...4306' ) ;
34923505 } ) ;
34933506} ) ;
3507+
3508+ describe ( 'getEligibleBankAccountsForCard' , ( ) => {
3509+ const openBusinessAccount : BankAccountList = {
3510+ '1' : {
3511+ accountData : { type : CONST . BANK_ACCOUNT . TYPE . BUSINESS , allowDebit : true , state : CONST . BANK_ACCOUNT . STATE . OPEN } ,
3512+ bankCurrency : 'USD' ,
3513+ bankCountry : 'US' ,
3514+ } ,
3515+ } ;
3516+
3517+ const setupBusinessAccount : BankAccountList = {
3518+ '2' : {
3519+ accountData : { type : CONST . BANK_ACCOUNT . TYPE . BUSINESS , allowDebit : true , state : CONST . BANK_ACCOUNT . STATE . SETUP } ,
3520+ bankCurrency : 'USD' ,
3521+ bankCountry : 'US' ,
3522+ } ,
3523+ } ;
3524+
3525+ const verifyingBusinessAccount : BankAccountList = {
3526+ '3' : {
3527+ accountData : { type : CONST . BANK_ACCOUNT . TYPE . BUSINESS , allowDebit : true , state : CONST . BANK_ACCOUNT . STATE . VERIFYING } ,
3528+ bankCurrency : 'USD' ,
3529+ bankCountry : 'US' ,
3530+ } ,
3531+ } ;
3532+
3533+ const pendingBusinessAccount : BankAccountList = {
3534+ '4' : {
3535+ accountData : { type : CONST . BANK_ACCOUNT . TYPE . BUSINESS , allowDebit : true , state : CONST . BANK_ACCOUNT . STATE . PENDING } ,
3536+ bankCurrency : 'USD' ,
3537+ bankCountry : 'US' ,
3538+ } ,
3539+ } ;
3540+
3541+ it ( 'includes bank accounts with OPEN state' , ( ) => {
3542+ expect ( getEligibleBankAccountsForCard ( openBusinessAccount ) ) . toHaveLength ( 1 ) ;
3543+ } ) ;
3544+
3545+ it ( 'excludes bank accounts with SETUP state' , ( ) => {
3546+ expect ( getEligibleBankAccountsForCard ( setupBusinessAccount ) ) . toHaveLength ( 0 ) ;
3547+ } ) ;
3548+
3549+ it ( 'excludes bank accounts with VERIFYING state' , ( ) => {
3550+ expect ( getEligibleBankAccountsForCard ( verifyingBusinessAccount ) ) . toHaveLength ( 0 ) ;
3551+ } ) ;
3552+
3553+ it ( 'excludes bank accounts with PENDING state' , ( ) => {
3554+ expect ( getEligibleBankAccountsForCard ( pendingBusinessAccount ) ) . toHaveLength ( 0 ) ;
3555+ } ) ;
3556+
3557+ it ( 'filters partially set up accounts from a mixed list' , ( ) => {
3558+ const mixedList : BankAccountList = {
3559+ ...openBusinessAccount ,
3560+ ...setupBusinessAccount ,
3561+ ...pendingBusinessAccount ,
3562+ } ;
3563+ const result = getEligibleBankAccountsForCard ( mixedList ) ;
3564+ expect ( result ) . toHaveLength ( 1 ) ;
3565+ expect ( result . at ( 0 ) ?. accountData ?. state ) . toBe ( CONST . BANK_ACCOUNT . STATE . OPEN ) ;
3566+ } ) ;
3567+ } ) ;
3568+
3569+ describe ( 'getEligibleBankAccountsForUkEuCard' , ( ) => {
3570+ it ( 'excludes partially set up accounts' , ( ) => {
3571+ const bankAccounts : BankAccountList = {
3572+ '1' : {
3573+ accountData : { type : CONST . BANK_ACCOUNT . TYPE . BUSINESS , allowDebit : true , state : CONST . BANK_ACCOUNT . STATE . OPEN } ,
3574+ bankCurrency : 'GBP' ,
3575+ bankCountry : 'GB' ,
3576+ } ,
3577+ '2' : {
3578+ accountData : { type : CONST . BANK_ACCOUNT . TYPE . BUSINESS , allowDebit : true , state : CONST . BANK_ACCOUNT . STATE . SETUP } ,
3579+ bankCurrency : 'GBP' ,
3580+ bankCountry : 'GB' ,
3581+ } ,
3582+ } ;
3583+ const result = getEligibleBankAccountsForUkEuCard ( bankAccounts , 'GBP' ) ;
3584+ expect ( result ) . toHaveLength ( 1 ) ;
3585+ expect ( result . at ( 0 ) ?. accountData ?. state ) . toBe ( CONST . BANK_ACCOUNT . STATE . OPEN ) ;
3586+ } ) ;
3587+ } ) ;
0 commit comments