@@ -3,6 +3,7 @@ import {renderHook} from '@testing-library/react-native';
33import Onyx from 'react-native-onyx' ;
44import useHasTeam2025Pricing from '@hooks/useHasTeam2025Pricing' ;
55import useSubscriptionPlan from '@hooks/useSubscriptionPlan' ;
6+ import { getOwnedPaidPolicies } from '@libs/PolicyUtils' ;
67import { calculateRemainingFreeTrialDays , doesUserHavePaymentCardAdded , getEarlyDiscountInfo , isUserOnFreeTrial , shouldShowDiscountBanner } from '@libs/SubscriptionUtils' ;
78import useFreeTrial from '@pages/home/FreeTrialSection/useFreeTrial' ;
89import ONYXKEYS from '@src/ONYXKEYS' ;
@@ -18,6 +19,10 @@ jest.mock('@hooks/useSubscriptionPlan', () => ({
1819 default : jest . fn ( ( ) => 'corporate' ) ,
1920} ) ) ;
2021
22+ jest . mock ( '@libs/PolicyUtils' , ( ) => ( {
23+ getOwnedPaidPolicies : jest . fn ( ( ) => [ { id : 'policyID' } ] ) ,
24+ } ) ) ;
25+
2126jest . mock ( '@libs/SubscriptionUtils' , ( ) => ( {
2227 shouldShowDiscountBanner : jest . fn ( ( ) => false ) ,
2328 getEarlyDiscountInfo : jest . fn ( ( ) => null ) ,
@@ -28,6 +33,7 @@ jest.mock('@libs/SubscriptionUtils', () => ({
2833
2934const mockedUseHasTeam2025Pricing = useHasTeam2025Pricing as jest . Mock ;
3035const mockedUseSubscriptionPlan = useSubscriptionPlan as jest . Mock ;
36+ const mockedGetOwnedPaidPolicies = getOwnedPaidPolicies as jest . Mock ;
3137const mockedShouldShowDiscountBanner = shouldShowDiscountBanner as jest . Mock ;
3238const mockedGetEarlyDiscountInfo = getEarlyDiscountInfo as jest . Mock ;
3339const mockedIsUserOnFreeTrial = isUserOnFreeTrial as jest . Mock ;
@@ -43,6 +49,7 @@ describe('useFreeTrial', () => {
4349 await Onyx . clear ( ) ;
4450 await waitForBatchedUpdates ( ) ;
4551 jest . clearAllMocks ( ) ;
52+ mockedGetOwnedPaidPolicies . mockReturnValue ( [ { id : 'policyID' } ] ) ;
4653 } ) ;
4754
4855 afterEach ( async ( ) => {
@@ -77,6 +84,16 @@ describe('useFreeTrial', () => {
7784
7885 expect ( result . current . shouldShowFreeTrialSection ) . toBe ( true ) ;
7986 } ) ;
87+
88+ it ( "should not show section when user doesn't own any paid workspaces" , ( ) => {
89+ mockedIsUserOnFreeTrial . mockReturnValue ( true ) ;
90+ mockedDoesUserHavePaymentCardAdded . mockReturnValue ( false ) ;
91+ mockedGetOwnedPaidPolicies . mockReturnValue ( [ ] ) ;
92+
93+ const { result} = renderHook ( ( ) => useFreeTrial ( ) ) ;
94+
95+ expect ( result . current . shouldShowFreeTrialSection ) . toBe ( false ) ;
96+ } ) ;
8097 } ) ;
8198
8299 describe ( 'discount state - 50% off (first 24 hours)' , ( ) => {
0 commit comments