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
61 changes: 61 additions & 0 deletions browser_tests/tests/dialogs/pricingTableDeepLink.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,60 @@ const TEAM_SUBSCRIBED_RESPONSE = {
effective_at: '2026-07-21T00:00:00Z'
} satisfies SubscribeResponse

const TEAM_ANNUAL_PLAN = {
slug: 'team_per_credit_annual',
tier: 'TEAM',
duration: 'ANNUAL',
price_cents: 756_000,
credits_cents: 1_772_400,
max_seats: 100,
availability: { available: true },
seat_summary: {
seat_count: 1,
total_cost_cents: 756_000,
total_credits_cents: 1_772_400
}
} satisfies Plan

const TEAM_MONTHLY_PLAN = {
slug: 'team_per_credit_monthly',
tier: 'TEAM',
duration: 'MONTHLY',
price_cents: 39_000,
credits_cents: 84_400,
max_seats: 100,
availability: { available: true },
seat_summary: {
seat_count: 1,
total_cost_cents: 39_000,
total_credits_cents: 84_400
}
} satisfies Plan

const NEW_TEAM_ANNUAL_SUBSCRIPTION = {
allowed: true,
transition_type: 'new_subscription',
effective_at: '2026-07-21T00:00:00Z',
is_immediate: true,
cost_today_cents: 756_000,
cost_next_period_cents: 756_000,
credits_today_cents: 1_772_400,
credits_next_period_cents: 1_772_400,
new_plan: TEAM_ANNUAL_PLAN
} satisfies PreviewSubscribeResponse

const NEW_TEAM_MONTHLY_SUBSCRIPTION = {
allowed: true,
transition_type: 'new_subscription',
effective_at: '2026-07-21T00:00:00Z',
is_immediate: true,
cost_today_cents: 39_000,
cost_next_period_cents: 39_000,
credits_today_cents: 84_400,
credits_next_period_cents: 84_400,
new_plan: TEAM_MONTHLY_PLAN
} satisfies PreviewSubscribeResponse

const NEW_CREATOR_SUBSCRIPTION = {
allowed: true,
transition_type: 'new_subscription',
Expand Down Expand Up @@ -711,6 +765,9 @@ test.describe('Pricing table deep link', { tag: '@cloud' }, () => {
await page.route('**/api/billing/plans', (route) =>
route.fulfill(jsonRoute(TEAM_CATALOG_PLANS))
)
await page.route('**/api/billing/preview-subscribe', (route) =>
route.fulfill(jsonRoute(NEW_TEAM_ANNUAL_SUBSCRIPTION))
)
await page.route('**/api/billing/subscribe', (route) => {
subscribeRequests.push(route.request())
return route.fulfill(jsonRoute(TEAM_SUBSCRIBED_RESPONSE))
Expand Down Expand Up @@ -759,6 +816,10 @@ test.describe('Pricing table deep link', { tag: '@cloud' }, () => {
route.fulfill(jsonRoute(TEAM_CATALOG_PLANS))
)

await page.route('**/api/billing/preview-subscribe', (route) =>
route.fulfill(jsonRoute(NEW_TEAM_MONTHLY_SUBSCRIPTION))
)

await page.goto(`${APP_URL}/?pricing=team&stop=team_400&cycle=monthly`)

await cloudAppExpect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,18 @@ describe('SubscriptionAddPaymentPreviewWorkspace', () => {
expect(emitted().back).toBeTruthy()
})

it('omits the total row entirely when no quote is available to price it', () => {
render(SubscriptionAddPaymentPreviewWorkspace, {
props: {
teamPlan: { usd: 700, credits: 147_700, discountedUsd: 665 },
previewData: null
},
global: globalOptions
})

expect(screen.queryByText('subscription.preview.totalDueToday')).toBeNull()
})

it('prices a legacy preview from the server costs instead of rendering a blank total', () => {
const {
amount_due_cents,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@

<!-- Total Due Section -->
<div
v-if="totalDueToday"
:class="
cn(
'flex flex-col gap-2 border-t border-border-subtle pt-8',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { render, screen } from '@testing-library/vue'
import userEvent from '@testing-library/user-event'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { computed, ref } from 'vue'
import { computed, nextTick, ref } from 'vue'
import { createI18n } from 'vue-i18n'

import SubscriptionRequiredDialogContentUnified from './SubscriptionRequiredDialogContentUnified.vue'
Expand Down Expand Up @@ -116,7 +116,9 @@ function renderComponent(props: Record<string, unknown> = {}) {
<button aria-label="Back" @click="$emit('back')">Back</button>
</div>`
},
SubscriptionTransitionPreviewWorkspace: { template: '<div />' },
SubscriptionTransitionPreviewWorkspace: {
template: '<div data-testid="transition-preview" />'
},
SubscriptionSuccessWorkspace: { template: '<div />' }
}
}
Expand Down Expand Up @@ -251,6 +253,25 @@ describe('SubscriptionRequiredDialogContentUnified team-plan subscribe', () => {
expect(mockHandleSubscribeClick).not.toHaveBeenCalled()
})

it.for(['team-change', 'personal-change'])(
'withholds the transition confirm until its preview arrives (%s)',
async (previewVariant) => {
mockCheckoutStep.value = 'preview'
mockPreviewVariant.value = previewVariant
mockSelectedTeamStop.value = TEAM_PAYLOAD.stop
mockPreviewData.value = null

renderComponent()

expect(screen.queryByTestId('transition-preview')).toBeNull()

mockPreviewData.value = { amount_due_cents: 1600, currency: 'usd' }
await nextTick()

expect(screen.getByTestId('transition-preview')).toBeTruthy()
}
)

it.for([true, false])(
'leaves the confirm step its own header and back action (embedded: %s)',
async (embeddedCheckoutEnabled) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@

<template v-if="checkoutStep === 'preview'">
<SubscriptionTransitionPreviewWorkspace
v-if="previewVariant === 'team-change'"
:preview-data="previewData!"
v-if="previewVariant === 'team-change' && previewData"
:preview-data="previewData"
:team-plan="selectedTeamStop!"
:is-loading="isLoadingPreview || isSubscribing || isPolling"
:action-url="activeCheckoutActionUrl"
Expand Down Expand Up @@ -151,8 +151,8 @@
/>

<SubscriptionTransitionPreviewWorkspace
v-else-if="previewVariant === 'personal-change'"
:preview-data="previewData!"
v-else-if="previewVariant === 'personal-change' && previewData"
:preview-data="previewData"
:is-loading="isSubscribing || isPolling"
:action-url="activeCheckoutActionUrl"
:force-reactivation="reactivationRequired"
Expand Down
79 changes: 79 additions & 0 deletions src/platform/workspace/composables/useSubscriptionCheckout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,85 @@ describe('useSubscriptionCheckout', () => {
return { checkout, selection }
}

describe('with embedded checkout off', () => {
const setupLegacyTeam = () => setup(undefined, 'team', false)

it('prices a new team subscription from the server preview', async () => {
const checkout = await setupLegacyTeam()

await checkout.handleSubscribeTeamClick({
stop: teamStop,
billingCycle: 'monthly'
})

expect(mockPreviewSubscribe).toHaveBeenCalledWith(
'team_per_credit_monthly',
{ teamCreditStopId: 'team_1400' }
)
expect(checkout.previewData.value?.allowed).toBe(true)
expect(checkout.checkoutStep.value).toBe('preview')
})

it('holds the pricing table until the preview resolves', async () => {
let resolvePreview!: (
preview: Partial<PreviewSubscribeResponse>
) => void
mockPreviewSubscribe.mockImplementationOnce(
() =>
new Promise<Partial<PreviewSubscribeResponse>>((resolve) => {
resolvePreview = resolve
})
)
const checkout = await setupLegacyTeam()

const selection = checkout.handleSubscribeTeamClick({
stop: teamStop,
billingCycle: 'monthly'
})

expect(checkout.checkoutStep.value).toBe('pricing')
expect(checkout.previewData.value).toBeNull()

resolvePreview({ allowed: true, transition_type: 'new_subscription' })
await selection

expect(checkout.checkoutStep.value).toBe('preview')
expect(checkout.previewData.value).not.toBeNull()
})

it('reports failure instead of confirming a change it cannot price', async () => {
const checkout = await setupLegacyTeam()

await checkout.handleSubscribeTeamClick({
stop: teamStop,
billingCycle: 'monthly',
isChange: true
})

expect(checkout.checkoutStep.value).toBe('pricing')
expect(checkout.previewData.value).toBeNull()
expect(mockToastAdd).toHaveBeenCalledOnce()
})

it.for([false, true])(
'reports a stop the backend cannot quote rather than confirming it (isChange: %s)',
async (isChange) => {
const checkout = await setupLegacyTeam()

await checkout.handleSubscribeTeamClick({
stop: { usd: 1400, credits: 295_400, discountedUsd: 1295 },
billingCycle: 'monthly',
isChange
})

expect(mockPreviewSubscribe).not.toHaveBeenCalled()
expect(checkout.checkoutStep.value).toBe('pricing')
expect(checkout.selectedTeamStop.value).toBeNull()
expect(mockToastAdd).toHaveBeenCalledOnce()
}
)
})

it('transitions to preview with the selected team stop and cycle', async () => {
const checkout = await setup()

Expand Down
38 changes: 25 additions & 13 deletions src/platform/workspace/composables/useSubscriptionCheckout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,16 @@ export function useSubscriptionCheckout(
)
}

function isUsableTeamPreview(
preview: PreviewSubscribeResponse | null | undefined,
checkoutType: SubscriptionCheckoutType
): preview is PreviewSubscribeResponse & { allowed: true } {
if (isSubscriptionCancelled()) return isReactivationCapablePreview(preview)
return checkoutType === 'change'
? isExistingPlanPreview(preview)
: Boolean(preview?.allowed)
}

function reactivationMaterialSnapshot(
preview: PreviewSubscribeResponse,
ignoreTimeDerivedTodayValues = false
Expand Down Expand Up @@ -766,19 +776,24 @@ export function useSubscriptionCheckout(
quoteIsCurrent.value = false

if (!embeddedCheckoutEnabled) {
checkoutStep.value = 'preview'
const needsPreview = payload.isChange || isSubscriptionCancelled()
isLoadingPreview.value = needsPreview && !!payload.stop.id
if (!needsPreview || !payload.stop.id) return
const teamCreditStopId = payload.stop.id
if (!teamCreditStopId) {
toast.add({
severity: 'error',
summary: t('subscription.teamPlan.name'),
detail: t('subscription.teamPlan.unavailable')
})
resetToPricing()
return
}
isLoadingPreview.value = true

let response: PreviewSubscribeResponse | null = null
let previewError: unknown
try {
response = await previewSubscribe(
getTeamPlanSlug(payload.billingCycle),
{
teamCreditStopId: payload.stop.id
}
{ teamCreditStopId }
)
} catch (error) {
previewError = error
Expand All @@ -798,14 +813,11 @@ export function useSubscriptionCheckout(
}

if (previewRequestId !== teamPreviewRequestId) return
if (
(isSubscriptionCancelled() && isReactivationCapablePreview(response)) ||
(!isSubscriptionCancelled() && isExistingPlanPreview(response))
) {
if (response) installPreview(response)
if (isUsableTeamPreview(response, checkoutType)) {
installPreview(response)
checkoutStep.value = 'preview'
return
}
if (!isSubscriptionCancelled()) return
toast.add({
severity: 'error',
summary: t('subscription.teamPlan.name'),
Expand Down
Loading