@@ -19,6 +19,7 @@ import {
1919import {
2020 CouponErrorExpired ,
2121 CustomerManager ,
22+ CustomerSessionManager ,
2223 InvoiceManager ,
2324 InvoicePreviewFactory ,
2425 PaymentIntentManager ,
@@ -41,6 +42,8 @@ import {
4142 StripeSubscriptionFactory ,
4243 StripePaymentMethodFactory ,
4344 StripePaymentIntentFactory ,
45+ StripeCustomerSessionFactory ,
46+ StripeApiListFactory ,
4447} from '@fxa/payments/stripe' ;
4548import {
4649 MockProfileClientConfigProvider ,
@@ -116,6 +119,7 @@ describe('CartService', () => {
116119 let cartManager : CartManager ;
117120 let checkoutService : CheckoutService ;
118121 let customerManager : CustomerManager ;
122+ let customerSessionManager : CustomerSessionManager ;
119123 let currencyManager : CurrencyManager ;
120124 let paymentIntentManager : PaymentIntentManager ;
121125 let promotionCodeManager : PromotionCodeManager ;
@@ -140,6 +144,7 @@ describe('CartService', () => {
140144 CartService ,
141145 CheckoutService ,
142146 CustomerManager ,
147+ CustomerSessionManager ,
143148 EligibilityManager ,
144149 EligibilityService ,
145150 GeoDBManager ,
@@ -184,6 +189,7 @@ describe('CartService', () => {
184189 cartService = moduleRef . get ( CartService ) ;
185190 checkoutService = moduleRef . get ( CheckoutService ) ;
186191 customerManager = moduleRef . get ( CustomerManager ) ;
192+ customerSessionManager = moduleRef . get ( CustomerSessionManager ) ;
187193 currencyManager = moduleRef . get ( CurrencyManager ) ;
188194 paymentIntentManager = moduleRef . get ( PaymentIntentManager ) ;
189195 promotionCodeManager = moduleRef . get ( PromotionCodeManager ) ;
@@ -694,6 +700,27 @@ describe('CartService', () => {
694700 } ) ;
695701
696702 describe ( 'getCart' , ( ) => {
703+ const mockCustomerSession = StripeResponseFactory (
704+ StripeCustomerSessionFactory ( )
705+ ) ;
706+ const mockSubscription = StripeSubscriptionFactory ( ) ;
707+ const mockListSubscriptions = StripeApiListFactory ( [ mockSubscription ] ) ;
708+ const mockPaymentMethod = StripeResponseFactory (
709+ StripePaymentMethodFactory ( { } )
710+ ) ;
711+
712+ beforeEach ( ( ) => {
713+ jest
714+ . spyOn ( customerSessionManager , 'create' )
715+ . mockResolvedValue ( mockCustomerSession ) ;
716+ jest
717+ . spyOn ( subscriptionManager , 'listForCustomer' )
718+ . mockResolvedValue ( mockListSubscriptions . data ) ;
719+ jest
720+ . spyOn ( paymentMethodManager , 'retrieve' )
721+ . mockResolvedValue ( mockPaymentMethod ) ;
722+ } ) ;
723+
697724 it ( 'returns cart and upcomingInvoicePreview' , async ( ) => {
698725 const mockCart = ResultCartFactory ( { stripeSubscriptionId : null } ) ;
699726 const mockCustomer = StripeResponseFactory ( StripeCustomerFactory ( ) ) ;
@@ -713,6 +740,12 @@ describe('CartService', () => {
713740 expect ( result ) . toEqual ( {
714741 ...mockCart ,
715742 upcomingInvoicePreview : mockInvoicePreview ,
743+ paymentInfo : {
744+ type : mockPaymentMethod . type ,
745+ last4 : mockPaymentMethod . card ?. last4 ,
746+ brand : mockPaymentMethod . card ?. brand ,
747+ customerSessionClientSecret : mockCustomerSession . client_secret ,
748+ } ,
716749 metricsOptedOut : false ,
717750 } ) ;
718751
@@ -732,9 +765,6 @@ describe('CartService', () => {
732765 } ) ;
733766
734767 it ( 'returns cart and upcomingInvoicePreview and latestInvoicePreview' , async ( ) => {
735- const mockSubscription = StripeResponseFactory (
736- StripeSubscriptionFactory ( )
737- ) ;
738768 const mockCart = ResultCartFactory ( {
739769 stripeSubscriptionId : mockSubscription . id ,
740770 } ) ;
@@ -754,9 +784,6 @@ describe('CartService', () => {
754784 jest
755785 . spyOn ( invoiceManager , 'previewUpcoming' )
756786 . mockResolvedValue ( mockUpcomingInvoicePreview ) ;
757- jest
758- . spyOn ( subscriptionManager , 'retrieve' )
759- . mockResolvedValue ( mockSubscription ) ;
760787 jest
761788 . spyOn ( invoiceManager , 'preview' )
762789 . mockResolvedValue ( mockLatestInvoicePreview ) ;
@@ -774,6 +801,7 @@ describe('CartService', () => {
774801 type : mockPaymentMethod . type ,
775802 last4 : mockPaymentMethod . card ?. last4 ,
776803 brand : mockPaymentMethod . card ?. brand ,
804+ customerSessionClientSecret : mockCustomerSession . client_secret ,
777805 } ,
778806 } ) ;
779807 expect ( result . latestInvoicePreview ) . not . toEqual (
0 commit comments