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 apps/billing-web/e2e/fixtures/scenario.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,64 @@ export function defaultScenario(): CloudScenario {
operations: {}
}
}

const CREATOR_YEARLY = {
slug: 'creator_yearly',
tier: 'CREATOR',
duration: 'ANNUAL',
price_cents: 26_880,
credits_cents: 82_800,
max_seats: 1,
availability: { available: true },
seat_summary: {
seat_count: 1,
total_cost_cents: 26_880,
total_credits_cents: 82_800
}
} as const

/**
* The default Creator Monthly subscriber switching to Creator Yearly, quoted
* as the real Cloud quotes it: the reset to yearly charges in full today,
* carries no proration instant, and reports the yearly renewal date, the
* plan's list price and the pre-discount subtotal.
*/
export function switchToYearly(scenario: CloudScenario): void {
const monthly = scenario.plans.plans[0]
scenario.plans = {
...scenario.plans,
plans: [...scenario.plans.plans, CREATOR_YEARLY]
}
scenario.preview = {
...scenario.preview,
transition_type: 'duration_change',
is_immediate: true,
effective_at: new Date().toISOString(),
renewal_at: '2027-09-30T00:00:00.000Z',
cost_today_cents: 26_880,
amount_due_cents: 26_880,
subtotal_cents: 26_880,
cost_next_period_cents: 26_880,
renewal_amount_cents: 26_880,
credits_today_cents: 82_800,
credits_next_period_cents: 82_800,
current_plan: {
slug: monthly.slug,
tier: monthly.tier,
duration: monthly.duration,
price_cents: monthly.price_cents,
credits_cents: monthly.credits_cents,
seat_summary: monthly.seat_summary,
period_end: '2026-10-30T00:00:00.000Z'
},
new_plan: {
slug: CREATOR_YEARLY.slug,
tier: CREATOR_YEARLY.tier,
duration: CREATOR_YEARLY.duration,
price_cents: CREATOR_YEARLY.price_cents,
list_price_cents: 33_600,
credits_cents: CREATOR_YEARLY.credits_cents,
seat_summary: CREATOR_YEARLY.seat_summary
}
}
}
121 changes: 121 additions & 0 deletions apps/billing-web/e2e/full-page-endings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ test('a Pay that goes through names the plan and the workspace, and Close goes b
page.getByText('Your plan for Personal has been successfully updated.')
).toBeVisible()
await expect(page.getByTestId('checkout-ending-plan')).toContainText('Pro')
await expect(page.getByTestId('checkout-ending-paid-today')).toBeHidden()
await expect(code(page)).toBeHidden()
await expect(page.getByText('You can close this tab now.')).toBeVisible()
await expect(page.getByText(/Closing in/)).toBeHidden()
Expand Down Expand Up @@ -109,6 +110,126 @@ test('a reload after its own Pay went through renders Already completed on every
expect(subscribeRequests(cloud)).toHaveLength(1)
})

const RECEIPT_PLAN = { slug: 'pro_monthly', duration: 'MONTHLY' } as const

test('77-4068: a Pay that goes through counts the credits the server says it added', async ({
page,
cloud,
signIn
}) => {
cloud.scenario.operations.op_subscribe = {
...succeededOperation('op_subscribe'),
amount_charged_cents: 5000,
credits_added: 10_000,
plan: RECEIPT_PLAN
}
await signIn(CHECKOUT)
await payButton(page).click()

await expect(heading(page, "You're all set")).toBeVisible()
await expect(page.getByTestId('checkout-ending-plan')).toContainText(
'10,000 credits added'
)
})

const paidToday = (page: Page) => page.getByTestId('checkout-ending-paid-today')

test('758-15763: a Pay under a promo code keeps the plan rate on Success and lists the code, then what was paid today', async ({
page,
cloud,
signIn
}) => {
cloud.scenario.preview = {
...cloud.scenario.preview,
amount_due_cents: 4000,
promotion_code: 'LAUNCH20',
discounts: [
{
kind: 'promotion',
code: 'LAUNCH20',
name: 'Launch 20%',
amount_off_cents: 1000,
duration: 'once'
}
]
}
await signIn(CHECKOUT)
await payButton(page).click()

await expect(heading(page, "You're all set")).toBeVisible()
const card = page.getByTestId('checkout-ending-plan')
await expect(card).toContainText('$50.00')
await expect(paidToday(page)).toHaveText(
/Launch 20%\s*−\$10\.00\s*First month\s*Paid today\s*\$40\.00/
)
})

test('765-15713: a prorated upgrade reads Paid today and why, without itemizing the proration', async ({
page,
cloud,
signIn
}) => {
const preview = cloud.scenario.preview
cloud.scenario.preview = {
...preview,
transition_type: 'upgrade',
proration_at: '2026-07-10T09:30:00.000Z',
amount_due_cents: 3250,
cost_today_cents: 3250,
credits_today_cents: 3250,
credits_next_period_cents: 10_000,
renewal_amount_cents: 10_000,
current_plan: {
...preview.new_plan,
slug: 'creator_monthly',
tier: 'CREATOR',
price_cents: 3500
}
}
await signIn(CHECKOUT)
await payButton(page).click()

await expect(heading(page, "You're all set")).toBeVisible()
await expect(paidToday(page)).toHaveText(
/^\s*Paid today\s*\$32\.50\s*Prorated for the rest of this billing period\s*$/
)
})

test('390-4947 / 328-4444: a charge whose credits are still landing reads Payment received, then Already completed names the plan once they land', async ({
page,
cloud,
signIn
}) => {
cloud.scenario.operations.op_subscribe = {
...succeededOperation('op_subscribe'),
amount_charged_cents: 5000,
plan: RECEIPT_PLAN
}
await signIn(CHECKOUT)
await payButton(page).click()

await expect(heading(page, 'Payment received')).toBeVisible()
const receipt = page.getByTestId('checkout-ending-receipt')
await expect(receipt).toContainText('Payment$50.00')
await expect(receipt).toContainText('Credits addedAdding…')
await expect(receipt).toContainText('PlanPro')
await expect(code(page)).toHaveText('op_subscribe')

cloud.scenario.operations.op_subscribe = {
...cloud.scenario.operations.op_subscribe,
credits_added: 10_000
}
settleOnServer(cloud)
await page.reload()

await expect(heading(page, 'Already completed')).toBeVisible()
await expect(page.getByTestId('checkout-ending-plan')).toContainText(
'Pro$50.00 USD / mo10,000 credits added'
)
await expect(code(page)).toBeHidden()
expect(subscribeRequests(cloud)).toHaveLength(1)
})

test('a later checkout in the same tab for a plan still for sale opens the form, not the old payment', async ({
page,
signIn
Expand Down
86 changes: 86 additions & 0 deletions apps/billing-web/e2e/full-page-summary.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Page } from '@playwright/test'

import { switchToYearly } from './fixtures/scenario'
import { installFakeStripe } from './fixtures/stripe'
import { entryPath, expect, test as base } from './fixtures/test'

Expand Down Expand Up @@ -179,3 +180,88 @@ test('a held discount and an entered code read as rows, with no Subtotal the quo
await expect(summary).not.toContainText('−$9.99')
await expect(summary).not.toContainText('Subtotal')
})

const YEARLY_CHECKOUT = entryPath('checkout', { plan: 'creator_yearly' })

test('a monthly to yearly switch reads its renewal date and struck-through list price from the quote', async ({
page,
cloud,
signIn
}) => {
switchToYearly(cloud.scenario)
await signIn(YEARLY_CHECKOUT)

await expectSummary(page, [
'Switch to Creator Yearly · Personal',
'$268.80 USD',
'Creator Yearly$268.80',
'$268.80 $336 /yr, billed yearly',
'Renews at $268.80 on September 30, 2027',
"This month's credits stay valid until October 30, 2026"
])
const summary = page.getByRole('region', { name: 'Order summary' })
await expect(summary.locator('s')).toHaveText('$336')
await expect(summary).not.toContainText('Subtotal')
})

test('a promo code on a yearly switch is bounded to the first year', async ({
page,
cloud,
signIn
}) => {
switchToYearly(cloud.scenario)
cloud.scenario.preview = {
...cloud.scenario.preview,
amount_due_cents: 21_504,
promotion_code: 'COMFY20',
discounts: [
{
kind: 'promotion',
code: 'COMFY20',
amount_off_cents: 5376,
duration: 'once'
}
]
}
await signIn(YEARLY_CHECKOUT)

await expectSummary(page, [
'Promo code−$53.76',
'First year',
'Total due today$215.04'
])
})

test('744-15697: an account balance the server applied is the last deduction, and keeps the prorated row it explains', async ({
page,
cloud,
signIn
}) => {
const preview = cloud.scenario.preview
cloud.scenario.preview = {
...preview,
transition_type: 'upgrade',
proration_at: '2026-07-10T09:30:00.000Z',
amount_due_cents: 2750,
cost_today_cents: 3250,
balance_applied_cents: 500,
credits_today_cents: 3250,
credits_next_period_cents: 10_000,
renewal_amount_cents: 10_000,
renewal_at: RENEWAL_AT,
current_plan: {
...preview.new_plan,
slug: 'creator_monthly',
tier: 'CREATOR',
price_cents: 3500
}
}
await signIn(CHECKOUT)

await expectSummary(page, [
'Pro Plan - Prorated$32.50',
'Account balance−$5.00',
'Credit already on your account',
'Total due today$27.50'
])
})
Loading
Loading