Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions browser_tests/tests/billingFacadeConsumers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ test.describe('Billing facade consumers (FE-933)', { tag: '@cloud' }, () => {
expect(billingRequests.legacyBalance).toBeGreaterThan(0)
})

test('rollout flag migrates a legacy Stripe workspace to workspace billing', async ({
test('legacy Stripe workspaces retain legacy billing with stale config', async ({
Comment thread
wei-hai marked this conversation as resolved.
Resolved
page
}) => {
test.setTimeout(60_000)
Expand All @@ -226,10 +226,13 @@ test.describe('Billing facade consumers (FE-933)', { tag: '@cloud' }, () => {
await bootApp(page)

await expect
.poll(() => billingRequests.workspaceBalance, { timeout: 30_000 })
.poll(() => billingRequests.legacyBalance, { timeout: 30_000 })
.toBeGreaterThan(0)
await page.getByRole('button', { name: 'Current user' }).click()
const popover = page.getByTestId('current-user-popover')
await expect(popover.getByText('12,660')).toBeVisible()
await expect(popover.getByText('0', { exact: true })).toHaveCount(0)
expect(billingRequests.legacyStatus).toBe(0)
Comment thread
wei-hai marked this conversation as resolved.
Resolved
expect(billingRequests.legacyBalance).toBe(0)
})

test('subscribe-to-run routes an inactive FREE user to the pricing table', async ({
Expand Down
1 change: 0 additions & 1 deletion src/composables/__mocks__/useFeatureFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const defaultFlags: FeatureFlags = {
ssoEnabled: false,
billingControlEnabled: false,
memberCreditLimitsEnabled: false,
legacyBillingMigrationEnabled: false,
embeddedCheckoutEnabled: false,
billingSdkTopupEnabled: false,
billingSdkTopupRailEnabled: false,
Expand Down
5 changes: 2 additions & 3 deletions src/composables/billing/useBillingContext.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,11 +466,10 @@ describe('useBillingContext', () => {
expect(useAuthActions().purchaseCreditsDirect).toHaveBeenCalledWith(5)
})

it('routes migrated legacy Stripe topups through workspace billing', async () => {
remoteConfig.value = { legacy_billing_migration_enabled: true }
it('routes migrated Stripe topups through workspace billing', async () => {
remoteConfigState.value = 'authenticated'
authenticatedRemoteConfigState.value = 'authenticated'
mockBillingRail.value = 'legacy_stripe'
mockBillingRail.value = 'stripe'

const context = useBillingContext()
await nextTick()
Expand Down
29 changes: 10 additions & 19 deletions src/composables/billing/useBillingRouting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { storeToRefs } from 'pinia'
import type { Ref } from 'vue'
import { fromPartial } from '@total-typescript/shoehorn'

import { useFeatureFlags } from '@/composables/useFeatureFlags'
import type { BillingRail } from '@/platform/workspace/api/workspaceApi'

import { useBillingRouting } from './useBillingRouting'
Expand All @@ -16,7 +15,6 @@ let mockActiveWorkspace: Ref<
>
let mockActiveWorkspaceBillingRail: Ref<BillingRail | null>

vi.mock(import('@/composables/useFeatureFlags'))
vi.mock(import('@/platform/distribution/types'), () => ({
get isCloud() {
return mockIsCloud.value
Expand Down Expand Up @@ -78,25 +76,18 @@ describe('useBillingRouting', () => {
expect(shouldUseUnifiedPricing.value).toBe(true)
})

it('migrates legacy Stripe personal workspaces behind the rollout flag', () => {
vi.mocked(useFeatureFlags().flags).legacyBillingMigrationEnabled = true
mockActiveWorkspaceBillingRail.value = 'legacy_stripe'
it.for(['stripe', 'metronome'] as const)(
'uses workspace billing for personal workspaces on %s',
(rail) => {
mockActiveWorkspace.value = personal
mockActiveWorkspaceBillingRail.value = rail

const { type, shouldUseWorkspaceBilling } = useBillingRouting()
const { type, shouldUseWorkspaceBilling } = useBillingRouting()

expect(type.value).toBe('workspace')
expect(shouldUseWorkspaceBilling.value).toBe(true)
})

it('uses workspace billing for migrated Stripe personal workspaces', () => {
mockActiveWorkspace.value = personal
mockActiveWorkspaceBillingRail.value = 'stripe'

const { type, shouldUseWorkspaceBilling } = useBillingRouting()

expect(type.value).toBe('workspace')
expect(shouldUseWorkspaceBilling.value).toBe(true)
})
expect(type.value).toBe('workspace')
expect(shouldUseWorkspaceBilling.value).toBe(true)
}
)

it('uses workspace billing for team workspaces', () => {
mockActiveWorkspace.value = team
Expand Down
13 changes: 1 addition & 12 deletions src/composables/billing/useBillingRouting.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
import { computed } from 'vue'

import { useFeatureFlags } from '@/composables/useFeatureFlags'
import { isCloud } from '@/platform/distribution/types'
import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore'

import { usesLegacyAccountOperations } from './billingRail'
import type { BillingType } from './types'

/**
* Selects the billing backend for the active workspace: legacy user-scoped
* (`/customers/*`) or workspace-scoped (`/api/billing/*`). Personal workspaces
* use workspace billing unless an explicit legacy Stripe rail selects legacy
* account operations and its migration flag is off. Until a workspace loads
* the type is `unknown`; Local/Desktop resolves to workspace billing once its
* Cloud-backed workspace context loads.
*/
export function useBillingRouting() {
const { flags } = useFeatureFlags()
const workspaceStore = useTeamWorkspaceStore()

const shouldUseUnifiedPricing = computed(() => {
Expand All @@ -29,8 +19,7 @@ export function useBillingRouting() {

if (
workspaceType === 'personal' &&
usesLegacyAccountOperations(workspaceStore.activeWorkspaceBillingRail) &&
!flags.legacyBillingMigrationEnabled
usesLegacyAccountOperations(workspaceStore.activeWorkspaceBillingRail)
) {
return 'legacy'
}
Expand Down
66 changes: 0 additions & 66 deletions src/composables/useFeatureFlags.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import * as distributionTypes from '@/platform/distribution/types'
import {
authenticatedRemoteConfigState,
cachedBillingControlEnabled,
cachedLegacyBillingMigrationEnabled,
cachedV1PaymentRecovery,
remoteConfig,
remoteConfigState,
Expand Down Expand Up @@ -560,66 +559,6 @@ describe('useFeatureFlags', () => {
})
})

describe('legacyBillingMigrationEnabled', () => {
beforeEach(() => {
vi.mocked(distributionTypes).isCloud = true
authenticatedRemoteConfigState.value = 'authenticated'
remoteConfigState.value = 'authenticated'
})

afterEach(() => {
vi.mocked(distributionTypes).isCloud = false
authenticatedRemoteConfigState.value = 'unloaded'
remoteConfigState.value = 'unloaded'
remoteConfig.value = {}
cachedLegacyBillingMigrationEnabled.value = undefined
})

it('migrates legacy billing when enabled by remote config', () => {
remoteConfig.value = { legacy_billing_migration_enabled: true }

const { flags } = useFeatureFlags()

expect(flags.legacyBillingMigrationEnabled).toBe(true)
})

it('keeps migration off when remote config explicitly disables it', () => {
remoteConfig.value = { legacy_billing_migration_enabled: false }
vi.mocked(api.getServerFeature).mockReturnValue(true)

const { flags } = useFeatureFlags()

expect(flags.legacyBillingMigrationEnabled).toBe(false)
})

it('uses the server feature when authenticated config leaves it unset', () => {
vi.mocked(api.getServerFeature).mockImplementation(
(path, defaultValue) =>
path === ServerFeatureFlag.LEGACY_BILLING_MIGRATION_ENABLED
? true
: defaultValue
)

const { flags } = useFeatureFlags()

expect(flags.legacyBillingMigrationEnabled).toBe(true)
expect(api.getServerFeature).toHaveBeenCalledWith(
ServerFeatureFlag.LEGACY_BILLING_MIGRATION_ENABLED,
false
)
})

it('keeps legacy billing when the rollout flag is unset', () => {
vi.mocked(api.getServerFeature).mockImplementation(
(_path, defaultValue) => defaultValue
)

const { flags } = useFeatureFlags()

expect(flags.legacyBillingMigrationEnabled).toBe(false)
})
})

describe('onboardingTourEnabled', () => {
afterEach(() => {
remoteConfig.value = {}
Expand Down Expand Up @@ -709,7 +648,6 @@ describe('useFeatureFlags', () => {
remoteConfigState.value = 'unloaded'
remoteConfig.value = {}
cachedBillingControlEnabled.value = undefined
cachedLegacyBillingMigrationEnabled.value = undefined
cachedV1PaymentRecovery.value = undefined
})

Expand All @@ -718,25 +656,21 @@ describe('useFeatureFlags', () => {
remoteConfigState.value = 'unloaded'
remoteConfig.value = {}
cachedBillingControlEnabled.value = undefined
cachedLegacyBillingMigrationEnabled.value = undefined
cachedV1PaymentRecovery.value = undefined
})

it('returns the cached session value during the auth window', () => {
cachedBillingControlEnabled.value = true
cachedLegacyBillingMigrationEnabled.value = true
cachedV1PaymentRecovery.value = true

const { flags } = useFeatureFlags()
expect(flags.billingControlEnabled).toBe(true)
expect(flags.legacyBillingMigrationEnabled).toBe(true)
expect(flags.v1PaymentRecovery).toBe(true)
})

it('defaults to false during the auth window when nothing is cached', () => {
const { flags } = useFeatureFlags()
expect(flags.billingControlEnabled).toBe(false)
expect(flags.legacyBillingMigrationEnabled).toBe(false)
expect(flags.v1PaymentRecovery).toBe(false)
})

Expand Down
11 changes: 0 additions & 11 deletions src/composables/useFeatureFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { normalizeHostedBillingDestination } from '@/config/billingWeb'
import { isCloud, isNightly } from '@/platform/distribution/types'
import {
cachedBillingControlEnabled,
cachedLegacyBillingMigrationEnabled,
cachedV1PaymentRecovery,
isAuthenticatedConfigLoaded,
remoteConfig,
Expand Down Expand Up @@ -44,7 +43,6 @@ export enum ServerFeatureFlag {
SSO_ENABLED = 'sso_enabled',
BILLING_CONTROL_ENABLED = 'billing_control_enabled',
MEMBER_CREDIT_LIMITS_ENABLED = 'member_credit_limits_enabled',
LEGACY_BILLING_MIGRATION_ENABLED = 'legacy_billing_migration_enabled',
EMBEDDED_CHECKOUT_ENABLED = 'embedded_checked_enabled',
BILLING_SDK_TOPUP_ENABLED = 'billing_sdk_topup_enabled',
BILLING_SDK_SUBSCRIPTION_ENABLED = 'billing_sdk_subscription_enabled',
Expand Down Expand Up @@ -317,13 +315,6 @@ export function useFeatureFlags() {
remoteConfig.value.member_credit_limits_enabled
)
},
get legacyBillingMigrationEnabled() {
return resolveAuthGatedFlag(
ServerFeatureFlag.LEGACY_BILLING_MIGRATION_ENABLED,
remoteConfig.value.legacy_billing_migration_enabled,
cachedLegacyBillingMigrationEnabled
)
},
get embeddedCheckoutEnabled() {
return resolveStrictBooleanFlag(
ServerFeatureFlag.EMBEDDED_CHECKOUT_ENABLED,
Expand Down Expand Up @@ -445,8 +436,6 @@ export function startFeatureFlagTelemetry() {
[ServerFeatureFlag.BILLING_CONTROL_ENABLED]: flags.billingControlEnabled,
[ServerFeatureFlag.MEMBER_CREDIT_LIMITS_ENABLED]:
flags.memberCreditLimitsEnabled,
[ServerFeatureFlag.LEGACY_BILLING_MIGRATION_ENABLED]:
flags.legacyBillingMigrationEnabled,
[ServerFeatureFlag.EMBEDDED_CHECKOUT_ENABLED]:
flags.embeddedCheckoutEnabled,
[ServerFeatureFlag.BILLING_SDK_TOPUP_ENABLED]:
Expand Down
2 changes: 0 additions & 2 deletions src/platform/remoteConfig/__mocks__/remoteConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ const remoteConfigModule: typeof realRemoteConfig = {
return remoteConfig[key] || defaultValue
},
cachedBillingControlEnabled: testScopedRemovableRef(undefined),
cachedLegacyBillingMigrationEnabled: testScopedRef(undefined),
cachedV1PaymentRecovery: testScopedRemovableRef(undefined),
sessionAgentGrant: testScopedRef(undefined),
sessionAgentGrantValidUntil: testScopedRef(undefined)
Expand All @@ -69,7 +68,6 @@ export const {
remoteConfig,
configValueOrDefault,
cachedBillingControlEnabled,
cachedLegacyBillingMigrationEnabled,
sessionAgentGrant,
sessionAgentGrantValidUntil,
cachedV1PaymentRecovery
Expand Down
Loading
Loading