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
4 changes: 4 additions & 0 deletions browser_tests/tests/cloudSubscribeDeepLink.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ test.describe('Cloud subscribe deep link', { tag: '@cloud' }, () => {
await expect(
page.getByRole('heading', { name: 'Confirm your payment' })
).toBeVisible({ timeout: 45_000 })
await expect(page.getByText('$20.00', { exact: true })).toBeVisible()
await expect(
page.getByText('Renews at $20.00. Cancel anytime.')
).toBeVisible()
await expect(page.locator('#splash-loader')).toHaveCount(0)
expect(legacyCheckoutRequests).toEqual([])
})
Expand Down
1 change: 1 addition & 0 deletions src/locales/en/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -3117,6 +3117,7 @@
"quoteStale": "Your quote changed. Review the updated amount and try again.",
"quoteRefreshFailed": "Your quote expired and couldn't be refreshed. Choose your plan again.",
"renewsAt": "Renews at {amount} on {date}. Cancel anytime.",
"renewsAtAmount": "Renews at {amount}. Cancel anytime.",
"discountComposition": "Discounts",
"discount": {
"plan": "Plan discount",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import type { PreviewSubscribeResponse } from '@comfyorg/ingest-types'
import { describe, expect, it } from 'vitest'

import {
formatAmountDueToday,
formatRenewalAmount,
resolveRenewalDate
} from './subscriptionQuoteFormatting'

function legacyPreview(
overrides: Partial<PreviewSubscribeResponse> = {}
): PreviewSubscribeResponse {
return {
allowed: true,
transition_type: 'new_subscription',
effective_at: '2026-06-19T00:00:00Z',
is_immediate: true,
cost_today_cents: 2000,
cost_next_period_cents: 3000,
credits_today_cents: 0,
credits_next_period_cents: 0,
new_plan: {
slug: 'creator',
tier: 'CREATOR',
duration: 'MONTHLY',
price_cents: 2000,
credits_cents: 0,
seat_summary: {
seat_count: 1,
total_cost_cents: 2000,
total_credits_cents: 0
}
},
...overrides
}
}

function exactPreview(
overrides: Partial<PreviewSubscribeResponse> = {}
): PreviewSubscribeResponse {
return legacyPreview({
amount_due_cents: 1500,
currency: 'usd',
renewal_amount_cents: 2500,
renewal_at: '2026-07-19T00:00:00Z',
...overrides
})
}

describe('formatAmountDueToday', () => {
it('prices the exact quote when the server sent one', () => {
expect(formatAmountDueToday(exactPreview(), 'en')).toBe('$15.00')
})

it('falls back to the legacy cost when the exact quote is absent', () => {
expect(formatAmountDueToday(legacyPreview(), 'en')).toBe('$20.00')
})

it('honours a non-USD exact quote', () => {
const preview = exactPreview({ currency: 'eur' })
expect(formatAmountDueToday(preview, 'en')).toBe('€15.00')
})
})

describe('formatRenewalAmount', () => {
it('prices the exact renewal when the server sent one', () => {
expect(formatRenewalAmount(exactPreview(), 'en')).toBe('$25.00')
})

it('falls back to the legacy next-period cost', () => {
expect(formatRenewalAmount(legacyPreview(), 'en')).toBe('$30.00')
})
})

describe('resolveRenewalDate', () => {
it('prefers the exact renewal instant', () => {
expect(resolveRenewalDate(exactPreview())).toBe('2026-07-19T00:00:00Z')
})

it('falls back to the target plan period end', () => {
const preview = legacyPreview()
const withPeriodEnd = {
...preview,
new_plan: { ...preview.new_plan, period_end: '2026-08-19T00:00:00Z' }
}
expect(resolveRenewalDate(withPeriodEnd)).toBe('2026-08-19T00:00:00Z')
})

it('reports no date when the server supplied none', () => {
expect(resolveRenewalDate(legacyPreview())).toBeUndefined()
})
})
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import type { PreviewSubscribeResponse } from '@comfyorg/ingest-types'

// Legacy previews price in USD and carry no currency field.
const LEGACY_QUOTE_CURRENCY = 'usd'

export function formatQuoteMoney(
cents: number,
currency: string | undefined,
Expand All @@ -9,3 +14,43 @@ export function formatQuoteMoney(
currency: currency.toUpperCase()
}).format(cents / 100)
}

function resolveQuoteMoney(
exactCents: number | undefined,
exactCurrency: string | undefined,
legacyCents: number
): { cents: number; currency: string | undefined } {
return exactCents === undefined
? { cents: legacyCents, currency: LEGACY_QUOTE_CURRENCY }
: { cents: exactCents, currency: exactCurrency }
}

export function formatAmountDueToday(
preview: PreviewSubscribeResponse,
locale: string
): string {
const { cents, currency } = resolveQuoteMoney(
preview.amount_due_cents,
preview.currency,
preview.cost_today_cents
)
return formatQuoteMoney(cents, currency, locale)
}

export function formatRenewalAmount(
preview: PreviewSubscribeResponse,
locale: string
): string {
const { cents, currency } = resolveQuoteMoney(
preview.renewal_amount_cents,
preview.currency,
preview.cost_next_period_cents
)
return formatQuoteMoney(cents, currency, locale)
}

export function resolveRenewalDate(
preview: PreviewSubscribeResponse
): string | undefined {
return preview.renewal_at ?? preview.new_plan.period_end
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,16 @@ function previewFixture(
}
}

// Interpolation values are appended so assertions can verify what a message
// was given, not just which message was chosen.
vi.mock('vue-i18n', () => ({
useI18n: () => ({
t: (key: string) => key,
t: (key: string, named?: Record<string, unknown>) =>
named
? `${key}|${Object.entries(named)
.map(([name, value]) => `${name}=${String(value)}`)
.join(',')}`
: key,
n: (value: number) => value.toLocaleString('en-US'),
locale: { value: 'en' }
})
Expand Down Expand Up @@ -403,4 +410,28 @@ describe('SubscriptionAddPaymentPreviewWorkspace', () => {
})
).toBeNull()
})

it('prices a legacy preview from the server costs instead of rendering a blank total', () => {
const {
amount_due_cents,
currency,
renewal_amount_cents,
renewal_at,
quote_id,
quote_version,
...legacy
} = previewFixture('MONTHLY', 2000)

render(SubscriptionAddPaymentPreviewWorkspace, {
props: { tierKey: 'creator', previewData: legacy },
global: globalOptions
})

expect(screen.getByText('$20.00')).toBeTruthy()
expect(
screen.getByText(
'subscription.preview.renewsAt|amount=$20.00,date=Jun 19, 2027'
)
).toBeTruthy()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,12 @@ import {
} from '@/platform/cloud/subscription/constants/tierPricing'
import type { TierKey } from '@/platform/cloud/subscription/constants/tierPricing'
import { isYearlyCheckout } from '@/platform/cloud/subscription/utils/planDuration'
import { formatQuoteMoney } from '@/platform/cloud/subscription/utils/subscriptionQuoteFormatting'
import {
formatAmountDueToday,
formatQuoteMoney,
formatRenewalAmount,
resolveRenewalDate
} from '@/platform/cloud/subscription/utils/subscriptionQuoteFormatting'
import type { BillingCycle } from '@/platform/cloud/subscription/utils/subscriptionTierRank'
import type {
BillingAuthenticationState,
Expand Down Expand Up @@ -560,35 +565,21 @@ const creditsRefillLabelKey = computed(() =>
)

const totalDueToday = computed(() =>
previewData?.amount_due_cents === undefined
? ''
: formatQuoteMoney(
previewData.amount_due_cents,
previewData.currency,
locale.value
)
previewData ? formatAmountDueToday(previewData, locale.value) : ''
)

const renewalTerms = computed(() => {
if (
previewData?.renewal_amount_cents === undefined ||
!previewData.renewal_at
) {
return ''
}
const date = new Date(previewData.renewal_at).toLocaleDateString(undefined, {
if (!previewData) return ''
const amount = formatRenewalAmount(previewData, locale.value)
if (!amount) return ''
const renewsAt = resolveRenewalDate(previewData)
if (!renewsAt) return t('subscription.preview.renewsAtAmount', { amount })
const date = new Date(renewsAt).toLocaleDateString(locale.value, {
month: 'short',
day: 'numeric',
year: 'numeric',
timeZone: 'UTC'
})
return t('subscription.preview.renewsAt', {
amount: formatQuoteMoney(
previewData.renewal_amount_cents,
previewData.currency,
locale.value
),
date
})
return t('subscription.preview.renewsAt', { amount, date })
})
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,21 @@ vi.mock('@/composables/billing/useBillingContext', () => ({
})
}))

// Only the renewal messages are supplied, so the renewal assertions verify
// real interpolated output while every other key still renders as itself.
const i18n = createI18n({
legacy: false,
locale: 'en',
messages: { en: {} }
messages: {
en: {
subscription: {
preview: {
renewsAt: 'Renews at {amount} on {date}. Cancel anytime.',
renewsAtAmount: 'Renews at {amount}. Cancel anytime.'
}
}
}
}
})

const globalOptions = {
Expand Down Expand Up @@ -77,6 +88,23 @@ function preview(
}
}

// Shape returned while embedded checkout is disabled: every exact-quote field
// is absent and only the legacy cost fields are populated.
function legacyPreview(
overrides: Partial<PreviewSubscribeResponse>
): PreviewSubscribeResponse {
const {
amount_due_cents,
currency,
renewal_amount_cents,
renewal_at,
quote_id,
quote_version,
...legacy
} = preview(overrides)
return legacy
}

describe('SubscriptionTransitionPreviewWorkspace', () => {
it('renders an immediate yearly upgrade with proration and upfront credits', () => {
render(SubscriptionTransitionPreviewWorkspace, {
Expand Down Expand Up @@ -310,4 +338,65 @@ describe('SubscriptionTransitionPreviewWorkspace', () => {
})
expect(screen.getByText(/Some Future Tier/)).toBeTruthy()
})

it('prices a legacy preview from the server costs instead of reporting the quote unavailable', () => {
render(SubscriptionTransitionPreviewWorkspace, {
props: {
previewData: legacyPreview({
cost_today_cents: 31_850,
cost_next_period_cents: 33_600,
new_plan: plan('CREATOR', 'ANNUAL', 33_600)
})
},
global: globalOptions
})

expect(screen.getByText('$318.50')).toBeTruthy()
expect(
screen.getByText('Renews at $336.00 on Jun 28, 2027. Cancel anytime.')
).toBeTruthy()
expect(
screen.queryByText('subscription.preview.quoteUnavailable')
).toBeNull()
})

it('states legacy renewal terms without a date when the server supplies no period end', () => {
const { period_end, ...planWithoutPeriodEnd } = plan(
'CREATOR',
'ANNUAL',
33_600
)
render(SubscriptionTransitionPreviewWorkspace, {
props: {
previewData: legacyPreview({
cost_today_cents: 31_850,
cost_next_period_cents: 33_600,
new_plan: planWithoutPeriodEnd
})
},
global: globalOptions
})

expect(screen.getByText('Renews at $336.00. Cancel anytime.')).toBeTruthy()
expect(
screen.queryByText('subscription.preview.quoteUnavailable')
).toBeNull()
})

it('withholds an exact quote that arrives without a currency to price it in', () => {
render(SubscriptionTransitionPreviewWorkspace, {
props: {
previewData: preview({
cost_today_cents: 31_850,
new_plan: plan('CREATOR', 'ANNUAL', 33_600),
currency: undefined
})
},
global: globalOptions
})

expect(
screen.getAllByText('subscription.preview.quoteUnavailable')
).toHaveLength(2)
})
})
Loading
Loading