Skip to content
Draft
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
21 changes: 21 additions & 0 deletions browser_tests/tests/liveCloud/disposable/cardDecline.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { declineCheckout } from '@e2e/tests/liveCloud/helpers/checkoutScenarios'
import {
expect,
liveCloudDisposableBillingFixture as test
} from '@e2e/fixtures/liveCloudDisposableBillingFixture'

test.describe('Real Cloud checkout failure', { tag: ['@cloud-live'] }, () => {
test('keeps the account on Free after a card decline', async ({
disposableCheckout
}, testInfo) => {
const failure = await declineCheckout(
disposableCheckout.checkout,
disposableCheckout.billingSession,
testInfo
)
expect(failure).toMatchObject({
status: 'failed',
failureKind: 'card_declined_ui'
})
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { declineCheckout } from '@e2e/tests/liveCloud/helpers/checkoutScenarios'
import {
expect,
liveCloudDisposableBillingFixture as test
} from '@e2e/fixtures/liveCloudDisposableBillingFixture'

test.describe('Real Cloud checkout recovery', { tag: ['@cloud-live'] }, () => {
test.setTimeout(240_000)

test('completes checkout after a card decline', async ({
disposableCheckout
}, testInfo) => {
await declineCheckout(
disposableCheckout.checkout,
disposableCheckout.billingSession,
testInfo
)
const completion = await disposableCheckout.checkout.completeCheckout(
disposableCheckout.billingSession,
testInfo,
2
)
expect(completion).toMatchObject({
planSlug: 'creator-monthly',
paymentMethodCount: 2
})
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {
expect,
liveCloudDisposableBillingFixture as test
} from '@e2e/fixtures/liveCloudDisposableBillingFixture'

test.describe(
'Real Cloud checkout completion',
{ tag: ['@cloud-live'] },
() => {
test('activates Creator and grants the quoted credits', async ({
disposableCheckout
}, testInfo) => {
const completion = await disposableCheckout.checkout.completeCheckout(
disposableCheckout.billingSession,
testInfo
)
expect(completion).toMatchObject({
planSlug: 'creator-monthly',
paymentMethodCount: 1
})
})
}
)
68 changes: 68 additions & 0 deletions browser_tests/tests/liveCloud/helpers/checkoutScenarios.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import {
zBillingBalanceResponse,
zBillingStatusResponse,
zBillingOpStatusResponse
} from '@comfyorg/ingest-types/zod'
import { expect } from '@playwright/test'
import type { TestInfo } from '@playwright/test'
import type { LiveCloudBillingSession } from '@e2e/fixtures/helpers/LiveCloudBillingSession'
import type { LiveCloudCheckout } from '@e2e/fixtures/helpers/LiveCloudCheckout'
export async function declineCheckout(
driver: LiveCloudCheckout,
session: LiveCloudBillingSession,
testInfo: TestInfo
) {
const statusBefore = await session.read(
'/api/billing/status',
zBillingStatusResponse
)
const balanceBefore = await session.read(
'/api/billing/balance',
zBillingBalanceResponse
)
await driver.open(true)
const { checkout, subscription } = await driver.startCheckout()
const observeFailure = async () => {
await expect(
driver.page.getByText('Your bank declined this payment', { exact: false })
).toBeVisible({ timeout: 60_000 })
await driver.attachScreenshot('checkout-declined.png')
}
await Promise.all([
observeFailure(),
driver.submitCard(checkout, '4000000000000341')
])
await expect
.poll(async () => {
const operation = await session.read(
`/api/billing/ops/${encodeURIComponent(subscription.billing_op_id)}`,
zBillingOpStatusResponse
)
return {
status: operation.status
}
})
.toMatchObject({ status: 'failed' })
const status = await session.read(
'/api/billing/status',
zBillingStatusResponse
)
expect(status.is_active).toBe(statusBefore.is_active)
expect([undefined, 'FREE']).toContain(status.subscription_tier)
const balanceAfter = await session.read(
'/api/billing/balance',
zBillingBalanceResponse
)
expect(balanceAfter.amount_micros).toBe(balanceBefore.amount_micros)
await testInfo.attach('checkout-decline.json', {
body: JSON.stringify({
operationId: subscription.billing_op_id,
balanceBeforeCents: balanceBefore.amount_micros,
balanceAfterCents: balanceAfter.amount_micros,
status: 'failed',
failureKind: 'card_declined_ui'
}),
contentType: 'application/json'
})
return { status: 'failed', failureKind: 'card_declined_ui' }
}
8 changes: 8 additions & 0 deletions docs/testing/cloud-billing-e2e.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,11 @@ Traces start after permanent-account sign-in and contain authenticated network
traffic. Keep reports private. Disposable accounts require no reusable credentials.
Completed-payment assertions verify saved cards through the real hosted billing
portal, because Staging disables the embedded-checkout saved-card API.

## Checkout completion and decline recovery

PR #17543 depends only on #17481. Run `--project=cloud-live-disposable` for
checkout completion, decline, and decline recovery. Decline assertions belong to
this PR. Each test gets a new sandbox account and verifies authoritative operation,
subscription, balance, and saved-card state through the real hosted billing portal.
A decline must preserve the prior Free state and balance.
Loading