Skip to content

Commit

Permalink
undo type change, fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Bianca Yang committed Jan 26, 2024
1 parent 86fe852 commit 5d8117f
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 50 deletions.
56 changes: 28 additions & 28 deletions frontend/src/lib/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,35 +208,35 @@ export const FEATURE_FLAGS = {
export type FeatureFlagKey = (typeof FEATURE_FLAGS)[keyof typeof FEATURE_FLAGS]

/** Which self-hosted plan's features are available with Cloud's "Standard" plan (aka card attached). */
export const POSTHOG_CLOUD_STANDARD_PLAN = 'scale'
export const POSTHOG_CLOUD_STANDARD_PLAN = LicensePlan.Scale
export const FEATURE_MINIMUM_PLAN: Partial<Record<AvailableFeature, LicensePlan>> = {
[AvailableFeature.ZAPIER]: 'scale',
[AvailableFeature.ORGANIZATIONS_PROJECTS]: 'scale',
[AvailableFeature.SOCIAL_SSO]: 'scale',
[AvailableFeature.DASHBOARD_COLLABORATION]: 'scale',
[AvailableFeature.INGESTION_TAXONOMY]: 'scale',
[AvailableFeature.PATHS_ADVANCED]: 'scale',
[AvailableFeature.CORRELATION_ANALYSIS]: 'scale',
[AvailableFeature.GROUP_ANALYTICS]: 'scale',
[AvailableFeature.MULTIVARIATE_FLAGS]: 'scale',
[AvailableFeature.EXPERIMENTATION]: 'scale',
[AvailableFeature.TAGGING]: 'scale',
[AvailableFeature.BEHAVIORAL_COHORT_FILTERING]: 'scale',
[AvailableFeature.WHITE_LABELLING]: 'scale',
[AvailableFeature.DASHBOARD_PERMISSIONING]: 'enterprise',
[AvailableFeature.PROJECT_BASED_PERMISSIONING]: 'enterprise',
[AvailableFeature.SAML]: 'enterprise',
[AvailableFeature.SSO_ENFORCEMENT]: 'enterprise',
[AvailableFeature.SUBSCRIPTIONS]: 'scale',
[AvailableFeature.APP_METRICS]: 'scale',
[AvailableFeature.RECORDINGS_PLAYLISTS]: 'scale',
[AvailableFeature.ROLE_BASED_ACCESS]: 'enterprise',
[AvailableFeature.RECORDINGS_FILE_EXPORT]: 'scale',
[AvailableFeature.RECORDINGS_PERFORMANCE]: 'scale',
[AvailableFeature.SURVEYS_STYLING]: 'scale',
[AvailableFeature.SURVEYS_MULTIPLE_QUESTIONS]: 'scale',
[AvailableFeature.SURVEYS_TEXT_HTML]: 'scale',
[AvailableFeature.DATA_PIPELINES]: 'scale',
[AvailableFeature.ZAPIER]: LicensePlan.Scale,
[AvailableFeature.ORGANIZATIONS_PROJECTS]: LicensePlan.Scale,
[AvailableFeature.SOCIAL_SSO]: LicensePlan.Scale,
[AvailableFeature.DASHBOARD_COLLABORATION]: LicensePlan.Scale,
[AvailableFeature.INGESTION_TAXONOMY]: LicensePlan.Scale,
[AvailableFeature.PATHS_ADVANCED]: LicensePlan.Scale,
[AvailableFeature.CORRELATION_ANALYSIS]: LicensePlan.Scale,
[AvailableFeature.GROUP_ANALYTICS]: LicensePlan.Scale,
[AvailableFeature.MULTIVARIATE_FLAGS]: LicensePlan.Scale,
[AvailableFeature.EXPERIMENTATION]: LicensePlan.Scale,
[AvailableFeature.TAGGING]: LicensePlan.Scale,
[AvailableFeature.BEHAVIORAL_COHORT_FILTERING]: LicensePlan.Scale,
[AvailableFeature.WHITE_LABELLING]: LicensePlan.Scale,
[AvailableFeature.DASHBOARD_PERMISSIONING]: LicensePlan.Enterprise,
[AvailableFeature.PROJECT_BASED_PERMISSIONING]: LicensePlan.Enterprise,
[AvailableFeature.SAML]: LicensePlan.Enterprise,
[AvailableFeature.SSO_ENFORCEMENT]: LicensePlan.Enterprise,
[AvailableFeature.SUBSCRIPTIONS]: LicensePlan.Scale,
[AvailableFeature.APP_METRICS]: LicensePlan.Scale,
[AvailableFeature.RECORDINGS_PLAYLISTS]: LicensePlan.Scale,
[AvailableFeature.ROLE_BASED_ACCESS]: LicensePlan.Enterprise,
[AvailableFeature.RECORDINGS_FILE_EXPORT]: LicensePlan.Scale,
[AvailableFeature.RECORDINGS_PERFORMANCE]: LicensePlan.Scale,
[AvailableFeature.SURVEYS_STYLING]: LicensePlan.Scale,
[AvailableFeature.SURVEYS_MULTIPLE_QUESTIONS]: LicensePlan.Scale,
[AvailableFeature.SURVEYS_TEXT_HTML]: LicensePlan.Scale,
[AvailableFeature.DATA_PIPELINES]: LicensePlan.Scale,
}

export const ENTITY_MATCH_TYPE = 'entities'
Expand Down
3 changes: 0 additions & 3 deletions frontend/src/mocks/fixtures/_billing_v2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import { dayjs } from 'lib/dayjs'
import { BillingV2Type } from '~/types'

export const billingJson: BillingV2Type = {
license: {
plan: 'dev',
},
customer_id: 'cus_PRQtW3VM1Kiw7e',
deactivated: false,
has_active_subscription: true,
Expand Down
36 changes: 18 additions & 18 deletions frontend/src/scenes/billing/billing-utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { dayjs } from 'lib/dayjs'
import tk from 'timekeeper'

import billingJson from '~/mocks/fixtures/_billing_v2'
import { billingJson } from '~/mocks/fixtures/_billing_v2'
import billingJsonWithFlatFee from '~/mocks/fixtures/_billing_v2_with_flat_fee.json'

import {
Expand Down Expand Up @@ -64,32 +64,32 @@ describe('projectUsage', () => {
const amountToUsageMapping = [
{ usage: 0, amount: '0.00' },
{ usage: 1_000_000, amount: '0.00' },
{ usage: 1_500_000, amount: '225.00' },
{ usage: 2_000_000, amount: '450.00' },
{ usage: 6_000_000, amount: '1350.00' },
{ usage: 10_000_000, amount: '2250.00' },
{ usage: 230_000_000, amount: '12250.00' },
{ usage: 1_500_000, amount: '155.00' },
{ usage: 2_000_000, amount: '310.00' },
{ usage: 6_000_000, amount: '830.00' },
{ usage: 10_000_000, amount: '1350.00' },
{ usage: 230_000_000, amount: '10183.50' },
]

const amountToUsageMappingWithAddons = [
{ usage: 0, amount: '0.00' },
{ usage: 1_000_000, amount: '0.00' },
{ usage: 1_409_091, amount: '225.00' },
{ usage: 1_818_182, amount: '450.00' },
{ usage: 4_888_087, amount: '1350.00' },
{ usage: 8_137_184, amount: '2250.00' },
{ usage: 139_090_909, amount: '12250.00' },
{ usage: 1_409_086, amount: '155.78' },
{ usage: 1_818_172, amount: '311.56' },
{ usage: 4_888_063, amount: '842.89' },
{ usage: 8_137_188, amount: '1362.75' },
{ usage: 139_090_972, amount: '9914.62' },
]

// 20% discount
const amountToUsageMappingWithPercentDiscount = [
{ usage: 0, amount: '0.00' },
{ usage: 1_000_000, amount: '0.00' },
{ usage: 1_625_000, amount: '225.00' }, // $281.25 worth of units
{ usage: 2_500_000, amount: '450.00' }, // $562.50 worth of units
{ usage: 7_500_000, amount: '1350.00' }, // $1687.50 worth of units
{ usage: 17_500_000, amount: '2250.00' }, // $2812.50 worth of units
{ usage: 352_500_000, amount: '12250.00' }, // $15,312.50 worth of units
{ usage: 1_625_000, amount: '155.00' },
{ usage: 2_500_000, amount: '300.00' },
{ usage: 7_500_000, amount: '820.00' },
{ usage: 17_500_000, amount: '1763.80' },
{ usage: 352_500_000, amount: '8947.60' },
]

describe('convertUsageToAmount', () => {
Expand All @@ -105,7 +105,7 @@ describe('convertUsageToAmountWithAddons', () => {
expect(
convertUsageToAmount(mapping.usage, [
billingJson.products[0].tiers,
billingJson.products[0].addons[0].tiers,
billingJson.products[0].addons[0].tiers || [],
])
).toEqual(mapping.amount)
}
Expand All @@ -132,7 +132,7 @@ describe('convertAmountToUsageWithAddons', () => {
expect(
convertAmountToUsage(mapping.amount, [
billingJson.products[0].tiers,
billingJson.products[0].addons[0].tiers,
billingJson.products[0].addons[0].tiers || [],
])
).toEqual(mapping.usage)
}
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,12 @@ export enum ProductKey {

type ProductKeyUnion = `${ProductKey}`

export type LicensePlan = 'scale' | 'enterprise' | 'cloud' | 'dev'
export enum LicensePlan {
Scale = 'scale',
Enterprise = 'enterprise',
Dev = 'dev',
Cloud = 'cloud',
}

export enum Realm {
Cloud = 'cloud',
Expand Down

0 comments on commit 5d8117f

Please sign in to comment.