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..2f26f84467e --- /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({ 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' } +} diff --git a/docs/testing/cloud-billing-e2e.md b/docs/testing/cloud-billing-e2e.md index 96bdcab10e3..b8007d0d310 100644 --- a/docs/testing/cloud-billing-e2e.md +++ b/docs/testing/cloud-billing-e2e.md @@ -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.