@@ -671,6 +671,9 @@ describe('CartService', () => {
671671 jest . spyOn ( eligibilityService , 'checkEligibility' ) . mockResolvedValue ( {
672672 subscriptionEligibilityResult : EligibilityStatus . CREATE ,
673673 } ) ;
674+ jest
675+ . spyOn ( checkoutService , 'getFreeTrialEligibility' )
676+ . mockResolvedValue ( null ) ;
674677 } ) ;
675678
676679 it ( 'calls createCart with expected parameters' , async ( ) => {
@@ -699,6 +702,7 @@ describe('CartService', () => {
699702 currency : mockResolvedCurrency ,
700703 eligibilityStatus : CartEligibilityStatus . CREATE ,
701704 couponCode : args . promoCode ,
705+ isFreeTrial : false ,
702706 } ) ;
703707 expect ( result ) . toEqual ( mockResultCart ) ;
704708 } ) ;
@@ -773,6 +777,7 @@ describe('CartService', () => {
773777 taxAddress,
774778 currency : mockResolvedCurrency ,
775779 eligibilityStatus : CartEligibilityStatus . UPGRADE ,
780+ isFreeTrial : false ,
776781 } ) ;
777782 expect ( result ) . toEqual ( mockResultCart ) ;
778783 expect ( result . couponCode ) . toBeNull ( ) ;
@@ -835,6 +840,7 @@ describe('CartService', () => {
835840 currency : mockResolvedCurrency ,
836841 eligibilityStatus : CartEligibilityStatus . BLOCKED_IAP ,
837842 couponCode : args . promoCode ,
843+ isFreeTrial : false ,
838844 } ,
839845 CartErrorReasonId . IAP_BLOCKED_CONTACT_SUPPORT
840846 ) ;
@@ -877,6 +883,7 @@ describe('CartService', () => {
877883 currency : mockResolvedCurrency ,
878884 eligibilityStatus : CartEligibilityStatus . DOWNGRADE ,
879885 couponCode : args . promoCode ,
886+ isFreeTrial : false ,
880887 } ,
881888 CartErrorReasonId . CART_ELIGIBILITY_STATUS_DOWNGRADE
882889 ) ;
@@ -917,6 +924,7 @@ describe('CartService', () => {
917924 currency : mockResolvedCurrency ,
918925 eligibilityStatus : CartEligibilityStatus . INVALID ,
919926 couponCode : args . promoCode ,
927+ isFreeTrial : false ,
920928 } ,
921929 CartErrorReasonId . CART_ELIGIBILITY_STATUS_INVALID
922930 ) ;
@@ -957,6 +965,7 @@ describe('CartService', () => {
957965 currency : mockResolvedCurrency ,
958966 eligibilityStatus : CartEligibilityStatus . INVALID ,
959967 couponCode : args . promoCode ,
968+ isFreeTrial : false ,
960969 } ,
961970 CartErrorReasonId . CART_ELIGIBILITY_STATUS_SAME
962971 ) ;
@@ -1053,6 +1062,7 @@ describe('CartService', () => {
10531062 stripeCustomerId : mockAccountCustomer . stripeCustomerId ,
10541063 amount : mockOldCart . amount ,
10551064 eligibilityStatus : mockOldCart . eligibilityStatus ,
1065+ isFreeTrial : mockOldCart . isFreeTrial ,
10561066 } ) ;
10571067 expect ( result ) . toEqual ( mockNewCart ) ;
10581068 } ) ;
@@ -1348,6 +1358,7 @@ describe('CartService', () => {
13481358 const mockCart = ResultCartFactory ( {
13491359 stripeSubscriptionId : undefined ,
13501360 currency : mockCurrency ,
1361+ eligibilityStatus : CartEligibilityStatus . INVALID ,
13511362 } ) ;
13521363 const mockUpdateCartInput = UpdateCartInputFactory ( {
13531364 taxAddress : {
@@ -1360,6 +1371,7 @@ describe('CartService', () => {
13601371 const expectedUpdateCart = {
13611372 ...mockUpdateCartInput ,
13621373 currency : mockCurrency ,
1374+ isFreeTrial : false ,
13631375 } ;
13641376 const mockCustomer = StripeResponseFactory ( StripeCustomerFactory ( ) ) ;
13651377
@@ -1380,6 +1392,9 @@ describe('CartService', () => {
13801392 jest
13811393 . spyOn ( invoiceManager , 'previewUpcoming' )
13821394 . mockResolvedValue ( mockPreviewInvoice ) ;
1395+ jest
1396+ . spyOn ( checkoutService , 'getFreeTrialEligibility' )
1397+ . mockResolvedValue ( null ) ;
13831398 } ) ;
13841399
13851400 it ( 'calls cartManager.updateFreshCart with no currency change' , async ( ) => {
@@ -1487,6 +1502,7 @@ describe('CartService', () => {
14871502 } ) ;
14881503 const expectedUpdateCart = {
14891504 ...mockUpdateCartInput ,
1505+ isFreeTrial : false ,
14901506 } ;
14911507
14921508 beforeEach ( async ( ) => {
@@ -1497,12 +1513,16 @@ describe('CartService', () => {
14971513 . spyOn ( promotionCodeManager , 'assertValidForPriceAndCustomer' )
14981514 . mockResolvedValue ( undefined ) ;
14991515 jest . spyOn ( cartManager , 'updateFreshCart' ) . mockResolvedValue ( ) ;
1516+ jest
1517+ . spyOn ( checkoutService , 'getFreeTrialEligibility' )
1518+ . mockResolvedValue ( null ) ;
15001519 } ) ;
15011520
15021521 it ( 'success if coupon is valid for new customer' , async ( ) => {
15031522 const mockCart = ResultCartFactory ( {
15041523 stripeCustomerId : undefined ,
15051524 stripeSubscriptionId : undefined ,
1525+ eligibilityStatus : CartEligibilityStatus . INVALID ,
15061526 } ) ;
15071527
15081528 jest . spyOn ( cartManager , 'fetchCartById' ) . mockResolvedValue ( mockCart ) ;
@@ -1525,6 +1545,7 @@ describe('CartService', () => {
15251545 stripeCustomerId : mockCustomer . id ,
15261546 stripeSubscriptionId : undefined ,
15271547 taxAddress : TaxAddressFactory ( ) ,
1548+ eligibilityStatus : CartEligibilityStatus . INVALID ,
15281549 } ) ;
15291550 const mockPreviewInvoice = InvoicePreviewFactory ( ) ;
15301551
@@ -2445,6 +2466,7 @@ describe('CartService', () => {
24452466 state : CartState . START ,
24462467 stripeSubscriptionId : null ,
24472468 eligibilityStatus : CartEligibilityStatus . CREATE ,
2469+ isFreeTrial : true ,
24482470 } ) ;
24492471 const mockInvoicePreview = InvoicePreviewFactory ( ) ;
24502472
@@ -2470,6 +2492,33 @@ describe('CartService', () => {
24702492 } ) ;
24712493 } ) ;
24722494
2495+ it ( 'does not call getFreeTrialEligibility when cart was not promised a trial' , async ( ) => {
2496+ const mockFreeTrial = FreeTrialFactory ( { trialLengthDays : 7 } ) ;
2497+ const mockCart = ResultCartFactory ( {
2498+ uid : faker . string . uuid ( ) ,
2499+ state : CartState . START ,
2500+ stripeSubscriptionId : null ,
2501+ eligibilityStatus : CartEligibilityStatus . CREATE ,
2502+ isFreeTrial : false ,
2503+ } ) ;
2504+ const mockInvoicePreview = InvoicePreviewFactory ( ) ;
2505+
2506+ jest . spyOn ( cartManager , 'fetchCartById' ) . mockResolvedValue ( mockCart ) ;
2507+ jest . spyOn ( eligibilityService , 'checkEligibility' ) . mockResolvedValue ( {
2508+ subscriptionEligibilityResult : EligibilityStatus . CREATE ,
2509+ } ) ;
2510+ jest
2511+ . spyOn ( invoiceManager , 'previewUpcoming' )
2512+ . mockResolvedValue ( mockInvoicePreview ) ;
2513+ jest
2514+ . spyOn ( checkoutService , 'getFreeTrialEligibility' )
2515+ . mockResolvedValue ( mockFreeTrial ) ;
2516+
2517+ const result = await cartService . getCart ( mockCart . id ) ;
2518+ expect ( result . freeTrialEligibility ) . toBeNull ( ) ;
2519+ expect ( checkoutService . getFreeTrialEligibility ) . not . toHaveBeenCalled ( ) ;
2520+ } ) ;
2521+
24732522 it ( 'sets freeTrialEligibility to null when cart has no uid' , async ( ) => {
24742523 const mockCart = ResultCartFactory ( {
24752524 uid : undefined ,
0 commit comments