@@ -1427,6 +1427,73 @@ describe('CartService', () => {
14271427 ) ;
14281428 } ) ;
14291429
1430+ it ( 'returns cart with success state' , async ( ) => {
1431+ const mockCart = ResultCartFactory ( {
1432+ state : CartState . SUCCESS ,
1433+ stripeSubscriptionId : mockSubscription . id ,
1434+ } ) ;
1435+ const mockCustomer = StripeResponseFactory ( StripeCustomerFactory ( ) ) ;
1436+ const mockPrice = StripePriceFactory ( ) ;
1437+ const mockUpcomingInvoicePreview = InvoicePreviewFactory ( ) ;
1438+ const mockLatestInvoicePreview = InvoicePreviewFactory ( ) ;
1439+ const mockPaymentMethod = StripeResponseFactory (
1440+ StripePaymentMethodFactory ( { } )
1441+ ) ;
1442+ jest . spyOn ( eligibilityService , 'checkEligibility' ) . mockResolvedValue ( {
1443+ subscriptionEligibilityResult : EligibilityStatus . CREATE ,
1444+ } ) ;
1445+
1446+ jest . spyOn ( cartManager , 'fetchCartById' ) . mockResolvedValue ( mockCart ) ;
1447+ jest
1448+ . spyOn ( productConfigurationManager , 'retrieveStripePrice' )
1449+ . mockResolvedValue ( mockPrice ) ;
1450+ jest . spyOn ( customerManager , 'retrieve' ) . mockResolvedValue ( mockCustomer ) ;
1451+ jest
1452+ . spyOn ( invoiceManager , 'previewUpcoming' )
1453+ . mockResolvedValue ( mockUpcomingInvoicePreview ) ;
1454+ jest
1455+ . spyOn ( invoiceManager , 'preview' )
1456+ . mockResolvedValue ( mockLatestInvoicePreview ) ;
1457+ jest
1458+ . spyOn ( paymentMethodManager , 'retrieve' )
1459+ . mockResolvedValue ( mockPaymentMethod ) ;
1460+
1461+ const result = await cartService . getCart ( mockCart . id ) ;
1462+ expect ( result ) . toEqual ( {
1463+ ...mockCart ,
1464+ upcomingInvoicePreview : mockUpcomingInvoicePreview ,
1465+ latestInvoicePreview : mockLatestInvoicePreview ,
1466+ metricsOptedOut : false ,
1467+ paymentInfo : {
1468+ type : mockPaymentMethod . type ,
1469+ last4 : mockPaymentMethod . card ?. last4 ,
1470+ brand : mockPaymentMethod . card ?. brand ,
1471+ customerSessionClientSecret : mockCustomerSession . client_secret ,
1472+ } ,
1473+ hasActiveSubscriptions : true ,
1474+ } ) ;
1475+ expect (
1476+ 'latestInvoicePreview' in result && result . latestInvoicePreview
1477+ ) . not . toEqual ( result . upcomingInvoicePreview ) ;
1478+
1479+ expect ( cartManager . fetchCartById ) . toHaveBeenCalledWith ( mockCart . id ) ;
1480+ expect (
1481+ productConfigurationManager . retrieveStripePrice
1482+ ) . toHaveBeenCalledWith ( mockCart . offeringConfigId , mockCart . interval ) ;
1483+ expect ( customerManager . retrieve ) . toHaveBeenCalledWith (
1484+ mockCart . stripeCustomerId
1485+ ) ;
1486+ expect ( invoiceManager . previewUpcoming ) . toHaveBeenCalledWith ( {
1487+ priceId : mockPrice . id ,
1488+ currency : mockCart . currency ,
1489+ customer : mockCustomer ,
1490+ taxAddress : mockCart . taxAddress ,
1491+ } ) ;
1492+ expect ( invoiceManager . preview ) . toHaveBeenCalledWith (
1493+ mockSubscription . latest_invoice
1494+ ) ;
1495+ } ) ;
1496+
14301497 it ( 'returns cart and upcomingInvoicePreview if customer is undefined' , async ( ) => {
14311498 const mockCart = ResultCartFactory ( {
14321499 stripeCustomerId : null ,
0 commit comments