-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stats: add statTypeToPlan to map stat types to plan in stats upsells (#…
…97159) * Add statTypeToPlan to map stat types to plan in stats upsells * Fix statType for non-modal upsell
- Loading branch information
Showing
6 changed files
with
79 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import config from '@automattic/calypso-config'; | ||
import { PLAN_PERSONAL, PLAN_PREMIUM } from '@automattic/calypso-products'; | ||
import { | ||
STATS_TYPE_DEVICE_STATS, | ||
STATS_FEATURE_UTM_STATS, | ||
STAT_TYPE_SEARCH_TERMS, | ||
STAT_TYPE_VIDEO_PLAYS, | ||
STAT_TYPE_TOP_AUTHORS, | ||
} from './constants'; | ||
|
||
export function statTypeToPlan( statType: string ) { | ||
if ( ! config.isEnabled( 'stats/paid-wpcom-v3' ) ) { | ||
return PLAN_PREMIUM; | ||
} | ||
|
||
// Commercial stats features that require the premium plan | ||
if ( | ||
[ | ||
STAT_TYPE_TOP_AUTHORS, | ||
STAT_TYPE_SEARCH_TERMS, | ||
STAT_TYPE_VIDEO_PLAYS, | ||
STATS_FEATURE_UTM_STATS, | ||
STATS_TYPE_DEVICE_STATS, | ||
].includes( statType ) | ||
) { | ||
return PLAN_PREMIUM; | ||
} | ||
|
||
return PLAN_PERSONAL; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import config from '@automattic/calypso-config'; | ||
import { PLAN_PERSONAL, PLAN_PREMIUM } from '@automattic/calypso-products'; | ||
import { | ||
STAT_TYPE_CLICKS, | ||
STAT_TYPE_SEARCH_TERMS, | ||
STATS_FEATURE_DATE_CONTROL_LAST_7_DAYS, | ||
} from '../constants'; | ||
import { statTypeToPlan } from '../stat-type-to-plan'; | ||
|
||
jest.mock( '@automattic/calypso-config', () => { | ||
const config = () => 'development'; | ||
config.isEnabled = jest.fn(); | ||
return config; | ||
} ); | ||
|
||
describe( 'statTypeToPlan', () => { | ||
it( 'should always return premium when stats/paid-wpcom-v3 is not enabled', () => { | ||
( config.isEnabled as jest.Mock ).mockImplementation( () => false ); | ||
// Search terms is a commercial stats feature that requires the premium plan | ||
expect( statTypeToPlan( STAT_TYPE_SEARCH_TERMS ) ).toEqual( PLAN_PREMIUM ); | ||
// Clicks is a paid stats feature that requires the personal plan, test the fallback on premium anyway when v3 is disabled. | ||
expect( statTypeToPlan( STAT_TYPE_CLICKS ) ).toEqual( PLAN_PREMIUM ); | ||
// 7 Days is a free plan feature, this should not be gated but test we default to premium when the stat type doesn't make sense to query | ||
expect( statTypeToPlan( STATS_FEATURE_DATE_CONTROL_LAST_7_DAYS ) ).toEqual( PLAN_PREMIUM ); | ||
} ); | ||
|
||
it( 'should return personal when stats/paid-wpcom-v3 is enabled and the stat type is a personal plan feature', () => { | ||
( config.isEnabled as jest.Mock ).mockImplementation( () => true ); | ||
// Search terms is a commercial stats feature that requires the premium plan | ||
expect( statTypeToPlan( STAT_TYPE_SEARCH_TERMS ) ).toEqual( PLAN_PREMIUM ); | ||
// Clicks is a paid stats feature that requires the personal plan | ||
expect( statTypeToPlan( STAT_TYPE_CLICKS ) ).toEqual( PLAN_PERSONAL ); | ||
// 7 Days is a free plan feature, this should not be gated but test we default to personal when the stat type doesn't make sense to query | ||
expect( statTypeToPlan( STATS_FEATURE_DATE_CONTROL_LAST_7_DAYS ) ).toEqual( PLAN_PERSONAL ); | ||
} ); | ||
} ); |