@@ -311,6 +311,74 @@ describe('CartService', () => {
311311
312312 expect ( cartManager . createCart ) . not . toHaveBeenCalled ( ) ;
313313 } ) ;
314+
315+ it ( 'returns cart eligibility status downgrade' , async ( ) => {
316+ const mockResultCart = ResultCartFactory ( ) ;
317+ const mockResolvedCurrency = faker . finance . currencyCode ( ) ;
318+
319+ jest
320+ . spyOn ( promotionCodeManager , 'assertValidPromotionCodeNameForPrice' )
321+ . mockResolvedValue ( undefined ) ;
322+ jest
323+ . spyOn ( currencyManager , 'getCurrencyForCountry' )
324+ . mockReturnValue ( mockResolvedCurrency ) ;
325+ jest . spyOn ( cartManager , 'createCart' ) . mockResolvedValue ( mockResultCart ) ;
326+ jest . spyOn ( accountManager , 'getAccounts' ) . mockResolvedValue ( [ ] ) ;
327+ jest
328+ . spyOn ( eligibilityService , 'checkEligibility' )
329+ . mockResolvedValue ( EligibilityStatus . DOWNGRADE ) ;
330+ jest . spyOn ( cartService , 'finalizeCartWithError' ) . mockResolvedValue ( ) ;
331+
332+ const result = await cartService . setupCart ( args ) ;
333+
334+ expect ( cartManager . createCart ) . toHaveBeenCalledWith ( {
335+ interval : args . interval ,
336+ offeringConfigId : args . offeringConfigId ,
337+ amount : mockInvoicePreview . subtotal ,
338+ uid : args . uid ,
339+ stripeCustomerId : mockAccountCustomer . stripeCustomerId ,
340+ experiment : args . experiment ,
341+ taxAddress,
342+ currency : mockResolvedCurrency ,
343+ eligibilityStatus : CartEligibilityStatus . DOWNGRADE ,
344+ couponCode : args . promoCode ,
345+ } ) ;
346+ expect ( result ) . toEqual ( mockResultCart ) ;
347+ } ) ;
348+
349+ it ( 'returns cart eligibility status invalid' , async ( ) => {
350+ const mockResultCart = ResultCartFactory ( ) ;
351+ const mockResolvedCurrency = faker . finance . currencyCode ( ) ;
352+
353+ jest
354+ . spyOn ( promotionCodeManager , 'assertValidPromotionCodeNameForPrice' )
355+ . mockResolvedValue ( undefined ) ;
356+ jest
357+ . spyOn ( currencyManager , 'getCurrencyForCountry' )
358+ . mockReturnValue ( mockResolvedCurrency ) ;
359+ jest . spyOn ( cartManager , 'createCart' ) . mockResolvedValue ( mockResultCart ) ;
360+ jest . spyOn ( accountManager , 'getAccounts' ) . mockResolvedValue ( [ ] ) ;
361+ jest
362+ . spyOn ( eligibilityService , 'checkEligibility' )
363+ . mockResolvedValue ( EligibilityStatus . INVALID ) ;
364+ jest . spyOn ( cartService , 'finalizeCartWithError' ) . mockResolvedValue ( ) ;
365+
366+ const result = await cartService . setupCart ( args ) ;
367+
368+ expect ( cartManager . createCart ) . toHaveBeenCalledWith ( {
369+ interval : args . interval ,
370+ offeringConfigId : args . offeringConfigId ,
371+ amount : mockInvoicePreview . subtotal ,
372+ uid : args . uid ,
373+ stripeCustomerId : mockAccountCustomer . stripeCustomerId ,
374+ experiment : args . experiment ,
375+ taxAddress,
376+ currency : mockResolvedCurrency ,
377+ eligibilityStatus : CartEligibilityStatus . INVALID ,
378+ couponCode : args . promoCode ,
379+ } ) ;
380+ expect ( result ) . toEqual ( mockResultCart ) ;
381+ } ) ;
314382 } ) ;
315383
316384 describe ( 'restartCart' , ( ) => {
@@ -720,7 +788,9 @@ describe('CartService', () => {
720788 } ) ;
721789
722790 it ( 'returns cart and upcomingInvoicePreview' , async ( ) => {
723- const mockCart = ResultCartFactory ( { stripeSubscriptionId : null } ) ;
791+ const mockCart = ResultCartFactory ( {
792+ stripeSubscriptionId : null ,
793+ } ) ;
724794 const mockCustomer = StripeResponseFactory ( StripeCustomerFactory ( ) ) ;
725795 const mockPrice = StripePriceFactory ( ) ;
726796 const mockInvoicePreview = InvoicePreviewFactory ( ) ;
0 commit comments