@@ -65,6 +65,7 @@ import {
6565 ResultAccountCustomerFactory ,
6666 MockStripeConfigProvider ,
6767 AccountCustomerManager ,
68+ AccountCustomerNotFoundError ,
6869 StripeConfirmationTokenFactory ,
6970 StripeSetupIntentFactory ,
7071} from '@fxa/payments/stripe' ;
@@ -99,6 +100,7 @@ import {
99100 CartNoTaxAddressError ,
100101 CartUidMismatchError ,
101102} from './cart.error' ;
103+ import { AccountCustomerAlreadyExistsError } from './checkout.error' ;
102104import { CheckoutService } from './checkout.service' ;
103105import { PrePayStepsResultFactory } from './checkout.factories' ;
104106import { AccountManager } from '@fxa/shared/account/account' ;
@@ -502,6 +504,11 @@ describe('CheckoutService', () => {
502504 } )
503505 ) ;
504506
507+ jest
508+ . spyOn ( accountCustomerManager , 'getAccountCustomerByUid' )
509+ . mockRejectedValue (
510+ new AccountCustomerNotFoundError ( uid , new Error ( 'not found' ) )
511+ ) ;
505512 jest
506513 . spyOn ( promotionCodeManager , 'assertValidPromotionCodeNameForPrice' )
507514 . mockRejectedValue (
@@ -528,10 +535,36 @@ describe('CheckoutService', () => {
528535 } )
529536 ) ;
530537
538+ jest
539+ . spyOn ( accountCustomerManager , 'getAccountCustomerByUid' )
540+ . mockRejectedValue (
541+ new AccountCustomerNotFoundError ( uid , new Error ( 'not found' ) )
542+ ) ;
543+
531544 await expect (
532545 checkoutService . prePaySteps ( mockCart , mockCart . uid )
533546 ) . rejects . toBeInstanceOf ( CartTotalMismatchError ) ;
534547 } ) ;
548+
549+ it ( 'throws account customer already exists error' , async ( ) => {
550+ const mockCart = StripeResponseFactory (
551+ ResultCartFactory ( {
552+ uid : uid ,
553+ couponCode : faker . string . uuid ( ) ,
554+ stripeCustomerId : null ,
555+ eligibilityStatus : CartEligibilityStatus . CREATE ,
556+ amount : mockInvoicePreview . subtotal ,
557+ } )
558+ ) ;
559+
560+ jest
561+ . spyOn ( accountCustomerManager , 'getAccountCustomerByUid' )
562+ . mockResolvedValue ( mockAccountCustomer ) ;
563+
564+ await expect (
565+ checkoutService . prePaySteps ( mockCart , mockCart . uid )
566+ ) . rejects . toBeInstanceOf ( AccountCustomerAlreadyExistsError ) ;
567+ } ) ;
535568 } ) ;
536569 } ) ;
537570
0 commit comments