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
29 changes: 27 additions & 2 deletions src/platform/workspace/components/UnifiedPricingTable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ const mockCurrentTeamCreditStop = ref<MockTeamStop | null>(null)
const mockIsTeamPlan = ref(false)
const mockCanManageSubscription = ref(true)
const mockCanDowngradeToPersonal = ref(true)
const mockCanReactivatePlan = ref(true)
// the raw server capability, kept separate so a test can prove the component
// follows the derived policy rather than this value
const mockRawCanReactivate = ref(true)
const mockPermissions = ref({
canManageSubscription: true,
canManageSubscriptionLifecycle: true,
Expand All @@ -53,15 +57,16 @@ vi.mock('@/platform/distribution/types', () => mockDistributionTypes)
vi.mock('@/platform/workspace/composables/useBillingCapabilities', () => ({
useBillingCapabilities: () => ({
canSubscribeSelfServe: computed(() => mockCanManageSubscription.value),
canReactivate: computed(() => mockCanManageSubscription.value),
canReactivate: computed(() => mockRawCanReactivate.value),
canChangeSeats: computed(() => mockCanManageSubscription.value),
canDowngradeToPersonal: computed(() => mockCanDowngradeToPersonal.value)
})
}))

vi.mock('@/platform/workspace/composables/useWorkspaceUI', () => ({
useWorkspaceUI: () => ({
permissions: computed(() => mockPermissions.value)
permissions: computed(() => mockPermissions.value),
canReactivatePlan: computed(() => mockCanReactivatePlan.value)
})
}))

Expand Down Expand Up @@ -93,6 +98,8 @@ function renderComponent(props: Record<string, unknown> = {}) {

describe('UnifiedPricingTable plan CTA labels', () => {
beforeEach(() => {
mockCanReactivatePlan.value = true
mockRawCanReactivate.value = true
mockSubscription.value = null
mockSubscriptionStatus.value = null
mockCurrentPlanSlug.value = null
Expand Down Expand Up @@ -222,6 +229,8 @@ describe('UnifiedPricingTable team plan CTA', () => {
}

beforeEach(() => {
mockCanReactivatePlan.value = true
mockRawCanReactivate.value = true
mockSubscription.value = null
mockSubscriptionStatus.value = null
mockCurrentPlanSlug.value = null
Expand Down Expand Up @@ -309,6 +318,20 @@ describe('UnifiedPricingTable team plan CTA', () => {
expect(emitted().resubscribe).toBeTruthy()
})

it('disables Resubscribe when the workspace may not reactivate', () => {
mockSubscription.value = {
tier: 'TEAM',
duration: 'ANNUAL',
isCancelled: true
}
mockCurrentTeamCreditStop.value = TEAM_STOP
mockCanReactivatePlan.value = false

renderComponent({ initialPlanMode: 'team' })

expect(screen.getByRole('button', { name: 'Resubscribe' })).toBeDisabled()
})

it('lets a cancelled sub change to a different stop (not re-subscribe)', async () => {
const user = userEvent.setup()
mockSubscription.value = {
Expand Down Expand Up @@ -368,6 +391,8 @@ describe('UnifiedPricingTable outside Cloud', () => {
}

beforeEach(() => {
mockCanReactivatePlan.value = true
mockRawCanReactivate.value = true
mockSubscription.value = null
mockSubscriptionStatus.value = null
mockCurrentPlanSlug.value = null
Expand Down
11 changes: 3 additions & 8 deletions src/platform/workspace/components/UnifiedPricingTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -469,18 +469,13 @@ const emit = defineEmits<{

const { t, n } = useI18n()
const capabilities = useBillingCapabilities()
const { permissions } = useWorkspaceUI()
const { permissions, canReactivatePlan } = useWorkspaceUI()

const canSubscribeSelfServe = computed(() =>
isCloud
? capabilities.canSubscribeSelfServe.value
: permissions.value.canManageSubscription
)
const canReactivate = computed(() =>
isCloud
? capabilities.canReactivate.value
: permissions.value.canManageSubscriptionLifecycle
)
const canChangeSeats = computed(() =>
isCloud
? capabilities.canChangeSeats.value
Expand Down Expand Up @@ -770,7 +765,7 @@ const isTeamButtonDisabled = computed(() => {
if (isLoading) return true
if (!isTeamSubscribed.value) return !canSubscribeSelfServe.value
if (isTeamCurrentPlanSelected.value) {
return !isCancelled.value || !canReactivate.value
return !isCancelled.value || !canReactivatePlan.value
}
return !canChangeSeats.value
})
Expand Down Expand Up @@ -861,7 +856,7 @@ const canUsePersonalPlanAction = (tierKey: CheckoutTierKey): boolean => {
if (!canSelectPersonalPlan.value) return false
if (isTeamPlan.value) return canDowngradeToPersonal.value
if (isCurrentPlan(tierKey)) {
return isCancelled.value && canReactivate.value
return isCancelled.value && canReactivatePlan.value
}
return hasActivePaidPlan(currentAccountTier.value)
? canChangeSeats.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ const {
mockSetActiveWorkspaceIdImpl,
mockSetActiveWorkspaceId,
mockPermissions,
mockCanReactivatePlan,
mockCapabilities,
mockSubscription
} = vi.hoisted(() => ({
Expand Down Expand Up @@ -218,6 +219,7 @@ const {
canDowngradeToPersonal: true
}
},
mockCanReactivatePlan: { value: true },
mockCapabilities: {
value: {
canSubscribeSelfServe: true,
Expand Down Expand Up @@ -282,6 +284,11 @@ vi.mock('@/platform/workspace/composables/useWorkspaceUI', () => ({
get value() {
return mockPermissions.value
}
},
canReactivatePlan: {
get value() {
return mockCanReactivatePlan.value
}
}
})
}))
Expand Down Expand Up @@ -503,6 +510,7 @@ describe('useSubscriptionCheckout', () => {
canChangeSeats: true,
canDowngradeToPersonal: true
}
mockCanReactivatePlan.value = true
mockSubscription.value = null
sessionStorage.clear()
emit = vi.fn()
Expand Down Expand Up @@ -3876,9 +3884,29 @@ describe('useSubscriptionCheckout', () => {
})
})

it('resubscribes on the legacy rail even though the server withholds can_reactivate', async () => {
// legacy_stripe workspaces have no capability projection row, so the
// raw capability is false while the workspace may still reactivate.
mockCapabilities.value.canReactivate = false
mockCanReactivatePlan.value = true
const checkout = await setup()
mockResubscribe.mockResolvedValueOnce({
billing_op_id: 'op-legacy-rail',
status: 'active'
})
mockFetchStatus.mockResolvedValueOnce(undefined)
mockFetchBalance.mockResolvedValueOnce(undefined)

await checkout.handleResubscribe()

expect(emit).toHaveBeenCalledWith('close', true)
expect(mockResubscribe).toHaveBeenCalled()
})
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

it('does not resubscribe for a member', async () => {
mockPermissions.value.canManageSubscriptionLifecycle = false
mockCapabilities.value.canReactivate = false
mockCanReactivatePlan.value = false
const checkout = await setup()

await checkout.handleResubscribe()
Expand All @@ -3889,6 +3917,7 @@ describe('useSubscriptionCheckout', () => {

it('does not resubscribe when the server denies reactivation to a client-side owner', async () => {
mockCapabilities.value.canReactivate = false
mockCanReactivatePlan.value = false
const checkout = await setup()

await checkout.handleResubscribe()
Expand Down
17 changes: 4 additions & 13 deletions src/platform/workspace/composables/useSubscriptionCheckout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,9 @@ export function useSubscriptionCheckout(
subscription
} = useBillingContext()
const { shouldUseWorkspaceBilling } = useBillingRouting()
const {
canSubscribeSelfServe,
canReactivate,
canChangeSeats,
canDowngradeToPersonal
} = useBillingCapabilities()
const { permissions } = useWorkspaceUI()
const { canSubscribeSelfServe, canChangeSeats, canDowngradeToPersonal } =
useBillingCapabilities()
const { permissions, canReactivatePlan } = useWorkspaceUI()
const telemetry = useTelemetry()
const billingOperationStore = useBillingOperationStore()
const workspaceStore = useTeamWorkspaceStore()
Expand Down Expand Up @@ -1459,12 +1455,7 @@ export function useSubscriptionCheckout(
}

async function handleResubscribe() {
if (
!(isCloud
? canReactivate.value
: permissions.value.canManageSubscriptionLifecycle)
)
return
if (!canReactivatePlan.value) return
Comment thread
wei-hai marked this conversation as resolved.
Resolved

const source = 'pricing_dialog' as const

Expand Down
Loading