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
106 changes: 106 additions & 0 deletions browser_tests/tests/cloudSubscribeDeepLink.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import { expect } from '@playwright/test'
import type { PreviewSubscribeResponse } from '@comfyorg/ingest-types'

import type { BillingPlansResponse } from '@/platform/workspace/api/workspaceApi'

import { cloudAppFixture as test } from '@e2e/fixtures/cloudAppFixture'
import {
DEFAULT_TEAM_MEMBERS,
LEGACY_PERSONAL_BILLING_STATUS
} from '@e2e/fixtures/data/cloudWorkspace'
import { CloudWorkspaceMockHelper } from '@e2e/fixtures/helpers/CloudWorkspaceMockHelper'
import { jsonRoute } from '@e2e/fixtures/utils/jsonRoute'
import { workspace } from '@e2e/fixtures/utils/workspaceMocks'

const APP_URL = process.env.PLAYWRIGHT_TEST_URL || 'http://localhost:8188'

const CREATOR_MONTHLY_PLANS = {
plans: [
{
slug: 'creator-monthly',
tier: 'CREATOR',
duration: 'MONTHLY',
price_cents: 2000,
credits_cents: 2400,
max_seats: 1,
availability: { available: true },
seat_summary: {
seat_count: 1,
total_cost_cents: 2000,
total_credits_cents: 2400
}
}
]
} satisfies BillingPlansResponse

const CREATOR_MONTHLY_PREVIEW = {
allowed: true,
transition_type: 'new_subscription',
is_immediate: true,
effective_at: '2026-08-24T00:00:00Z',
cost_today_cents: 2000,
cost_next_period_cents: 2000,
credits_today_cents: 2400,
credits_next_period_cents: 2400,
new_plan: {
slug: 'creator-monthly',
tier: 'CREATOR',
duration: 'MONTHLY',
price_cents: 2000,
credits_cents: 2400,
seat_summary: {
seat_count: 1,
total_cost_cents: 2000,
total_credits_cents: 2400
}
}
} satisfies PreviewSubscribeResponse

test.describe('Cloud subscribe deep link', { tag: '@cloud' }, () => {
test.describe.configure({ timeout: 60_000 })

test('dismisses the splash loader and opens the unified personal checkout', async ({
page
}) => {
const helper = new CloudWorkspaceMockHelper(page)
await helper.setup(DEFAULT_TEAM_MEMBERS, workspace('personal', 'owner'), {
...LEGACY_PERSONAL_BILLING_STATUS,
billing_rail: 'stripe'
})
await page.route('**/api/billing/plans', (r) =>
r.fulfill(jsonRoute(CREATOR_MONTHLY_PLANS))
)
await page.route('**/api/billing/preview-subscribe', (r) =>
r.fulfill(jsonRoute(CREATOR_MONTHLY_PREVIEW))
)

// The OSS server that hosts the built frontend in CI has no SPA fallback
// for /cloud/subscribe (Chromium treats its response as a download), so
// serve the app shell for the deep-link document request directly. The
// base tag keeps the shell's relative asset paths resolving from the root.
const appShell = await page.request
.get(APP_URL)
.then((response) => response.text())
.then((html) => html.replace('<head>', '<head><base href="/">'))
await page.route('**/cloud/subscribe*', (route) =>
route.request().resourceType() === 'document'
? route.fulfill({ contentType: 'text/html', body: appShell })
: route.fallback()
)

const legacyCheckoutRequests: string[] = []
page.on('request', (request) => {
if (request.url().includes('/customers/')) {
legacyCheckoutRequests.push(request.url())
}
})

await page.goto(`${APP_URL}/cloud/subscribe?tier=creator&cycle=monthly`)

await expect(
page.getByRole('heading', { name: 'Confirm your payment' })
).toBeVisible({ timeout: 45_000 })
await expect(page.locator('#splash-loader')).toHaveCount(0)
expect(legacyCheckoutRequests).toEqual([])
})
})
178 changes: 140 additions & 38 deletions src/platform/cloud/onboarding/CloudSubscriptionRedirectView.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { render, screen } from '@testing-library/vue'
import { beforeEach, describe, expect, test, vi } from 'vitest'
import { createI18n } from 'vue-i18n'

import type { TeamCreditStops } from '@/platform/workspace/api/workspaceApi'

import CloudSubscriptionRedirectView from './CloudSubscriptionRedirectView.vue'

const flushPromises = () => new Promise((resolve) => setTimeout(resolve, 0))
Expand Down Expand Up @@ -41,33 +43,53 @@ vi.mock('@/composables/useErrorHandling', () => ({
const subscriptionMocks = vi.hoisted(() => ({
canAccessSubscriptionFeatures: { value: false },
isInitialized: { value: true },
subscriptionStatus: { value: null }
}))

vi.mock('@/platform/cloud/subscription/composables/useSubscription', () => ({
useSubscription: () => subscriptionMocks
teamCreditStops: { value: null as TeamCreditStops | null },
initialize: vi.fn(),
fetchPlans: vi.fn(),
manageSubscription: vi.fn()
}))

vi.mock('@/composables/billing/useBillingContext', () => ({
useBillingContext: () => subscriptionMocks
}))

// Avoid real network / isCloud behavior
const mockPerformSubscriptionCheckout = vi.fn()
const mockShowPricingTable = vi.hoisted(() => vi.fn())
vi.mock(
'@/platform/cloud/subscription/composables/useSubscriptionDialog',
() => ({
useSubscriptionDialog: () => ({ showPricingTable: mockShowPricingTable })
})
)

const legacyCheckoutMocks = vi.hoisted(() => ({
performSubscriptionCheckout: vi.fn(),
performTeamSubscriptionCheckout: vi.fn()
}))

vi.mock('@/platform/cloud/subscription/utils/subscriptionCheckoutUtil', () => ({
performSubscriptionCheckout: (...args: unknown[]) =>
mockPerformSubscriptionCheckout(...args)
performSubscriptionCheckout: legacyCheckoutMocks.performSubscriptionCheckout
}))

const mockPerformTeamSubscriptionCheckout = vi.fn()
vi.mock(
'@/platform/cloud/subscription/utils/teamSubscriptionCheckoutUtil',
() => ({
performTeamSubscriptionCheckout: (...args: unknown[]) =>
mockPerformTeamSubscriptionCheckout(...args)
performTeamSubscriptionCheckout:
legacyCheckoutMocks.performTeamSubscriptionCheckout
})
)

const TEAM_CREDIT_STOPS = {
default_stop_index: 0,
stops: [
{
id: 'team_700',
credits: 147700,
monthly: { list_price_cents: 70000, price_cents: 69000 },
yearly: { list_price_cents: 70000, price_cents: 63000 }
}
]
} satisfies TeamCreditStops

const createI18nInstance = () =>
createI18n({
legacy: false,
Expand All @@ -86,7 +108,8 @@ const createI18nInstance = () =>
tiers: {
standard: { name: 'Standard' },
creator: { name: 'Creator' },
pro: { name: 'Pro' }
pro: { name: 'Pro' },
founder: { name: 'Founder' }
}
}
}
Expand All @@ -112,6 +135,10 @@ describe('CloudSubscriptionRedirectView', () => {
mockQuery = {}
subscriptionMocks.canAccessSubscriptionFeatures.value = false
subscriptionMocks.isInitialized.value = true
subscriptionMocks.teamCreditStops.value = TEAM_CREDIT_STOPS
subscriptionMocks.initialize.mockResolvedValue(undefined)
subscriptionMocks.fetchPlans.mockResolvedValue(undefined)
subscriptionMocks.manageSubscription.mockResolvedValue(undefined)
})

test('redirects to home when subscriptionType is missing', async () => {
Expand All @@ -135,15 +162,18 @@ describe('CloudSubscriptionRedirectView', () => {
// Shows copy under logo
expect(screen.getByText('Subscribe to Creator')).toBeInTheDocument()

// Triggers checkout flow
expect(mockPerformSubscriptionCheckout).toHaveBeenCalledWith(
'creator',
'monthly',
{
openInNewTab: false,
paymentIntentSource: 'deep_link'
expect(mockShowPricingTable).toHaveBeenCalledWith({
reason: 'deep_link',
planMode: 'personal',
initialCheckout: {
planMode: 'personal',
tierKey: 'creator',
billingCycle: 'monthly'
}
)
})
expect(
legacyCheckoutMocks.performSubscriptionCheckout
).not.toHaveBeenCalled()

// Shows loading affordances
expect(
Expand All @@ -157,8 +187,9 @@ describe('CloudSubscriptionRedirectView', () => {
await mountView({ tier: 'creator' })

expect(mockRouterPush).not.toHaveBeenCalledWith('/')
expect(authActionMocks.accessBillingPortal).toHaveBeenCalledTimes(1)
expect(mockPerformSubscriptionCheckout).not.toHaveBeenCalled()
expect(subscriptionMocks.manageSubscription).toHaveBeenCalledTimes(1)
expect(authActionMocks.accessBillingPortal).not.toHaveBeenCalled()
expect(mockShowPricingTable).not.toHaveBeenCalled()
})

test('uses first value when subscriptionType is an array', async () => {
Expand All @@ -168,13 +199,10 @@ describe('CloudSubscriptionRedirectView', () => {

expect(mockRouterPush).not.toHaveBeenCalledWith('/')
expect(screen.getByText('Subscribe to Creator')).toBeInTheDocument()
expect(mockPerformSubscriptionCheckout).toHaveBeenCalledWith(
'creator',
'monthly',
{
openInNewTab: false,
paymentIntentSource: 'deep_link'
}
expect(mockShowPricingTable).toHaveBeenCalledWith(
expect.objectContaining({
initialCheckout: expect.objectContaining({ tierKey: 'creator' })
})
)
})

Expand All @@ -183,19 +211,93 @@ describe('CloudSubscriptionRedirectView', () => {

expect(mockRouterPush).not.toHaveBeenCalledWith('/')
expect(screen.getByText('Subscribe to Team Plan')).toBeInTheDocument()
expect(mockPerformTeamSubscriptionCheckout).toHaveBeenCalledWith(
'team_700',
'yearly',
{ paymentIntentSource: 'deep_link' }
)
// Team never goes through the personal checkout path
expect(mockPerformSubscriptionCheckout).not.toHaveBeenCalled()
expect(mockShowPricingTable).toHaveBeenCalledWith({
reason: 'deep_link',
planMode: 'team',
initialCheckout: {
planMode: 'team',
stop: {
id: 'team_700',
credits: 147700,
usd: 700,
discountedUsd: 630
},
billingCycle: 'yearly'
}
})
expect(
legacyCheckoutMocks.performTeamSubscriptionCheckout
).not.toHaveBeenCalled()
})

test('opens the generic team pricing table when plan loading fails', async () => {
subscriptionMocks.teamCreditStops.value = null
const plansError = new Error('plans down')
subscriptionMocks.fetchPlans.mockRejectedValue(plansError)

await mountView({ tier: 'team', stop: 'team_700', cycle: 'yearly' })

expect(authActionMocks.reportError).toHaveBeenCalledWith(plansError)
expect(mockShowPricingTable).toHaveBeenCalledWith({
reason: 'deep_link',
planMode: 'team',
initialCheckout: undefined
})
expect(mockRouterPush).not.toHaveBeenCalled()
expect(
legacyCheckoutMocks.performTeamSubscriptionCheckout
).not.toHaveBeenCalled()
})

test('removes the pre-Vue splash loader on mount', async () => {
const splashLoader = document.createElement('div')
splashLoader.id = 'splash-loader'
document.body.append(splashLoader)

await mountView({ tier: 'creator' })

expect(splashLoader).not.toBeInTheDocument()
})

test('redirects to home for a team link with no stop', async () => {
await mountView({ tier: 'team', cycle: 'yearly' })

expect(mockRouterPush).toHaveBeenCalledWith('/')
expect(mockPerformTeamSubscriptionCheckout).not.toHaveBeenCalled()
expect(mockShowPricingTable).not.toHaveBeenCalled()
})

test('routes a personal tier in an active Team workspace to workspace subscription management', async () => {
subscriptionMocks.canAccessSubscriptionFeatures.value = true

await mountView({ tier: 'creator', cycle: 'yearly' })

expect(subscriptionMocks.manageSubscription).toHaveBeenCalledTimes(1)
expect(authActionMocks.accessBillingPortal).not.toHaveBeenCalled()
expect(
legacyCheckoutMocks.performSubscriptionCheckout
).not.toHaveBeenCalled()
expect(mockShowPricingTable).not.toHaveBeenCalled()
})

test('routes an active founder subscription to facade management', async () => {
subscriptionMocks.canAccessSubscriptionFeatures.value = true

await mountView({ tier: 'founder' })

expect(subscriptionMocks.manageSubscription).toHaveBeenCalledTimes(1)
expect(mockRouterPush).not.toHaveBeenCalled()
expect(mockShowPricingTable).not.toHaveBeenCalled()
})

test('opens personal pricing without unsupported direct checkout for an inactive founder link', async () => {
await mountView({ tier: 'founder' })

expect(mockShowPricingTable).toHaveBeenCalledWith({
reason: 'deep_link',
planMode: 'personal'
})
expect(
legacyCheckoutMocks.performSubscriptionCheckout
).not.toHaveBeenCalled()
})
})
Loading
Loading