@@ -2013,6 +2013,7 @@ describe('CartService', () => {
20132013 } ,
20142014 hasActiveSubscriptions : true ,
20152015 freeTrialEligibility : null ,
2016+ isUpgradeFromTrial : false ,
20162017 } ) ;
20172018
20182019 expect ( cartManager . fetchCartById ) . toHaveBeenCalledWith ( mockCart . id ) ;
@@ -2029,6 +2030,123 @@ describe('CartService', () => {
20292030 } ) ;
20302031 } ) ;
20312032
2033+ it ( 'returns cart with isUpgradeFromTrial true and uses previewUpcomingForUpgrade with trialEnd when subscription is trialing with payment method' , async ( ) => {
2034+ const mockCart = ResultCartFactory ( {
2035+ state : CartState . START ,
2036+ stripeSubscriptionId : null ,
2037+ eligibilityStatus : CartEligibilityStatus . UPGRADE ,
2038+ } ) ;
2039+ const mockCustomer = StripeResponseFactory ( StripeCustomerFactory ( ) ) ;
2040+ const mockPrice = StripePriceFactory ( { currency : mockCart . currency } ) ;
2041+ const mockInvoicePreviewForUpgrade = InvoicePreviewFactory ( ) ;
2042+ const mockFromOfferingId = faker . string . uuid ( ) ;
2043+ const mockFromPrice = StripePriceFactory ( {
2044+ recurring : StripePriceRecurringFactory ( { interval : 'month' } ) ,
2045+ } ) ;
2046+ const mockPricingForCurrency = PricingForCurrencyFactory ( {
2047+ price : mockFromPrice ,
2048+ } ) ;
2049+ const mockTrialingSubscription = StripeSubscriptionFactory ( {
2050+ status : 'trialing' ,
2051+ } ) ;
2052+
2053+ jest . spyOn ( cartManager , 'fetchCartById' ) . mockResolvedValue ( mockCart ) ;
2054+ jest
2055+ . spyOn ( productConfigurationManager , 'retrieveStripePrice' )
2056+ . mockResolvedValue ( mockPrice ) ;
2057+ jest . spyOn ( customerManager , 'retrieve' ) . mockResolvedValue ( mockCustomer ) ;
2058+ jest
2059+ . spyOn ( invoiceManager , 'previewUpcomingForUpgrade' )
2060+ . mockResolvedValue ( mockInvoicePreviewForUpgrade ) ;
2061+ jest . spyOn ( eligibilityService , 'checkEligibility' ) . mockResolvedValue ( {
2062+ subscriptionEligibilityResult : EligibilityStatus . UPGRADE ,
2063+ fromOfferingConfigId : mockFromOfferingId ,
2064+ fromPrice : mockFromPrice ,
2065+ } ) ;
2066+ jest
2067+ . spyOn ( subscriptionManager , 'retrieveForCustomerAndPrice' )
2068+ . mockResolvedValue ( mockTrialingSubscription ) ;
2069+ jest
2070+ . spyOn ( priceManager , 'retrievePricingForCurrency' )
2071+ . mockResolvedValue ( mockPricingForCurrency ) ;
2072+
2073+ const result = await cartService . getCart ( mockCart . id ) ;
2074+ expect ( invoiceManager . previewUpcomingForUpgrade ) . toHaveBeenCalledWith (
2075+ expect . objectContaining ( {
2076+ trialEnd : expect . any ( Number ) ,
2077+ } )
2078+ ) ;
2079+ expect ( result ) . toEqual (
2080+ expect . objectContaining ( {
2081+ isUpgradeFromTrial : true ,
2082+ } )
2083+ ) ;
2084+ } ) ;
2085+
2086+ it ( 'uses previewUpcoming for trialing upgrade with no payment method' , async ( ) => {
2087+ const mockCart = ResultCartFactory ( {
2088+ state : CartState . START ,
2089+ stripeSubscriptionId : null ,
2090+ eligibilityStatus : CartEligibilityStatus . UPGRADE ,
2091+ } ) ;
2092+ const mockCustomerNoPaymentMethod = StripeResponseFactory (
2093+ StripeCustomerFactory ( {
2094+ invoice_settings : {
2095+ custom_fields : null ,
2096+ default_payment_method : null ,
2097+ footer : null ,
2098+ rendering_options : null ,
2099+ } ,
2100+ } )
2101+ ) ;
2102+ const mockPrice = StripePriceFactory ( { currency : mockCart . currency } ) ;
2103+ const mockInvoicePreview = InvoicePreviewFactory ( ) ;
2104+ const mockFromOfferingId = faker . string . uuid ( ) ;
2105+ const mockFromPrice = StripePriceFactory ( {
2106+ recurring : StripePriceRecurringFactory ( { interval : 'month' } ) ,
2107+ } ) ;
2108+ const mockPricingForCurrency = PricingForCurrencyFactory ( {
2109+ price : mockFromPrice ,
2110+ } ) ;
2111+ const mockTrialingSubscription = StripeSubscriptionFactory ( {
2112+ status : 'trialing' ,
2113+ } ) ;
2114+
2115+ jest . spyOn ( cartManager , 'fetchCartById' ) . mockResolvedValue ( mockCart ) ;
2116+ jest
2117+ . spyOn ( productConfigurationManager , 'retrieveStripePrice' )
2118+ . mockResolvedValue ( mockPrice ) ;
2119+ jest
2120+ . spyOn ( customerManager , 'retrieve' )
2121+ . mockResolvedValue ( mockCustomerNoPaymentMethod ) ;
2122+ const previewUpcomingSpy = jest
2123+ . spyOn ( invoiceManager , 'previewUpcoming' )
2124+ . mockResolvedValue ( mockInvoicePreview ) ;
2125+ const previewUpgradespy = jest
2126+ . spyOn ( invoiceManager , 'previewUpcomingForUpgrade' )
2127+ . mockResolvedValue ( mockInvoicePreview ) ;
2128+ jest . spyOn ( eligibilityService , 'checkEligibility' ) . mockResolvedValue ( {
2129+ subscriptionEligibilityResult : EligibilityStatus . UPGRADE ,
2130+ fromOfferingConfigId : mockFromOfferingId ,
2131+ fromPrice : mockFromPrice ,
2132+ } ) ;
2133+ jest
2134+ . spyOn ( subscriptionManager , 'retrieveForCustomerAndPrice' )
2135+ . mockResolvedValue ( mockTrialingSubscription ) ;
2136+ jest
2137+ . spyOn ( priceManager , 'retrievePricingForCurrency' )
2138+ . mockResolvedValue ( mockPricingForCurrency ) ;
2139+
2140+ const result = await cartService . getCart ( mockCart . id ) ;
2141+ expect ( previewUpcomingSpy ) . toHaveBeenCalled ( ) ;
2142+ expect ( previewUpgradespy ) . not . toHaveBeenCalled ( ) ;
2143+ expect ( result ) . toEqual (
2144+ expect . objectContaining ( {
2145+ isUpgradeFromTrial : true ,
2146+ } )
2147+ ) ;
2148+ } ) ;
2149+
20322150 it ( 'throws error if offeringPrice could not be retrieved' , async ( ) => {
20332151 const mockCart = ResultCartFactory ( {
20342152 state : CartState . START ,
0 commit comments