From 3e7a288102cd9114b3069ab2174ddda7185d7f8f Mon Sep 17 00:00:00 2001 From: huang47 <157390+huang47@users.noreply.github.com> Date: Wed, 16 Sep 2026 16:48:01 -0700 Subject: [PATCH 1/2] test: isolate checkout success and decline scenarios --- .../liveCloud/disposable/cardDecline.spec.ts | 21 ++++++ .../disposable/cardDeclineRecovery.spec.ts | 28 ++++++++ .../disposable/checkoutCompletion.spec.ts | 23 +++++++ .../liveCloud/helpers/checkoutScenarios.ts | 68 +++++++++++++++++++ docs/testing/cloud-billing-e2e.md | 9 +++ 5 files changed, 149 insertions(+) create mode 100644 browser_tests/tests/liveCloud/disposable/cardDecline.spec.ts create mode 100644 browser_tests/tests/liveCloud/disposable/cardDeclineRecovery.spec.ts create mode 100644 browser_tests/tests/liveCloud/disposable/checkoutCompletion.spec.ts create mode 100644 browser_tests/tests/liveCloud/helpers/checkoutScenarios.ts diff --git a/browser_tests/tests/liveCloud/disposable/cardDecline.spec.ts b/browser_tests/tests/liveCloud/disposable/cardDecline.spec.ts new file mode 100644 index 00000000000..28c27540acf --- /dev/null +++ b/browser_tests/tests/liveCloud/disposable/cardDecline.spec.ts @@ -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' + }) + }) +}) diff --git a/browser_tests/tests/liveCloud/disposable/cardDeclineRecovery.spec.ts b/browser_tests/tests/liveCloud/disposable/cardDeclineRecovery.spec.ts new file mode 100644 index 00000000000..0581977e36e --- /dev/null +++ b/browser_tests/tests/liveCloud/disposable/cardDeclineRecovery.spec.ts @@ -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 + }) + }) +}) diff --git a/browser_tests/tests/liveCloud/disposable/checkoutCompletion.spec.ts b/browser_tests/tests/liveCloud/disposable/checkoutCompletion.spec.ts new file mode 100644 index 00000000000..df4ea4e3d5e --- /dev/null +++ b/browser_tests/tests/liveCloud/disposable/checkoutCompletion.spec.ts @@ -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 + }) + }) + } +) diff --git a/browser_tests/tests/liveCloud/helpers/checkoutScenarios.ts b/browser_tests/tests/liveCloud/helpers/checkoutScenarios.ts new file mode 100644 index 00000000000..3c5e4907c48 --- /dev/null +++ b/browser_tests/tests/liveCloud/helpers/checkoutScenarios.ts @@ -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() + 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' } +} diff --git a/docs/testing/cloud-billing-e2e.md b/docs/testing/cloud-billing-e2e.md index 96bdcab10e3..a2bf5f02b0c 100644 --- a/docs/testing/cloud-billing-e2e.md +++ b/docs/testing/cloud-billing-e2e.md @@ -82,3 +82,12 @@ 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. Staging's saved-card endpoint currently +returns HTTP 400; keep that assertion strict. A decline must preserve the prior +Free state and balance. From 01642879ee694ca46835d24ac1150f6582f4853a Mon Sep 17 00:00:00 2001 From: huang47 <157390+huang47@users.noreply.github.com> Date: Wed, 16 Sep 2026 17:33:30 -0700 Subject: [PATCH 2/2] test: wait for parked checkout decline polling --- browser_tests/tests/liveCloud/helpers/checkoutScenarios.ts | 2 +- docs/testing/cloud-billing-e2e.md | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/browser_tests/tests/liveCloud/helpers/checkoutScenarios.ts b/browser_tests/tests/liveCloud/helpers/checkoutScenarios.ts index 3c5e4907c48..2f26f84467e 100644 --- a/browser_tests/tests/liveCloud/helpers/checkoutScenarios.ts +++ b/browser_tests/tests/liveCloud/helpers/checkoutScenarios.ts @@ -25,7 +25,7 @@ export async function declineCheckout( const observeFailure = async () => { await expect( driver.page.getByText('Your bank declined this payment', { exact: false }) - ).toBeVisible() + ).toBeVisible({ timeout: 60_000 }) await driver.attachScreenshot('checkout-declined.png') } await Promise.all([ diff --git a/docs/testing/cloud-billing-e2e.md b/docs/testing/cloud-billing-e2e.md index a2bf5f02b0c..b8007d0d310 100644 --- a/docs/testing/cloud-billing-e2e.md +++ b/docs/testing/cloud-billing-e2e.md @@ -88,6 +88,5 @@ portal, because Staging disables the embedded-checkout saved-card API. 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. Staging's saved-card endpoint currently -returns HTTP 400; keep that assertion strict. A decline must preserve the prior -Free state and balance. +subscription, balance, and saved-card state through the real hosted billing portal. +A decline must preserve the prior Free state and balance.