From e7646483e80fde8d3696f87962aae46852be3b2e Mon Sep 17 00:00:00 2001 From: huang47 <157390+huang47@users.noreply.github.com> Date: Sat, 12 Sep 2026 00:42:33 -0700 Subject: [PATCH] test: recover Cloud checkout after decline --- .../fixtures/helpers/LiveCloudBilling.ts | 17 ++++++++---- browser_tests/playwrightSelection.test.ts | 2 +- .../disposable/cardDeclineRecovery.spec.ts | 26 +++++++++++++++++++ 3 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 browser_tests/tests/liveCloud/disposable/cardDeclineRecovery.spec.ts diff --git a/browser_tests/fixtures/helpers/LiveCloudBilling.ts b/browser_tests/fixtures/helpers/LiveCloudBilling.ts index 88c8879f5b8..0f78b762521 100644 --- a/browser_tests/fixtures/helpers/LiveCloudBilling.ts +++ b/browser_tests/fixtures/helpers/LiveCloudBilling.ts @@ -220,7 +220,11 @@ export class LiveCloudCheckout { return subscription.billing_op_id } - async completeCheckout(session: LiveCloudBillingSession, testInfo: TestInfo) { + async completeCheckout( + session: LiveCloudBillingSession, + testInfo: TestInfo, + expectedPaymentMethodCount = 1 + ) { const balanceBefore = await session.read( '/api/billing/balance', zBillingBalanceResponse @@ -236,7 +240,8 @@ export class LiveCloudCheckout { balanceBefore.amount_micros, preview, subscription.billing_op_id, - 'checkout-completed.png' + 'checkout-completed.png', + expectedPaymentMethodCount ) } @@ -318,7 +323,8 @@ export class LiveCloudCheckout { '/api/billing/status', zBillingStatusResponse ) - expect(status.subscription_tier).toBe('FREE') + expect(status.is_active).toBe(false) + expect([undefined, 'FREE']).toContain(status.subscription_tier) const balanceAfter = await session.read( '/api/billing/balance', zBillingBalanceResponse @@ -619,7 +625,8 @@ export class LiveCloudCheckout { balanceBeforeCents: number, preview: ReturnType, operationId: string, - screenshotName: string + screenshotName: string, + expectedPaymentMethodCount = 1 ) { await expect .poll( @@ -657,7 +664,7 @@ export class LiveCloudCheckout { '/api/billing/payment-methods', zListSavedPaymentMethodsResponse ) - expect(methods).toHaveLength(1) + expect(methods).toHaveLength(expectedPaymentMethodCount) await testInfo.attach('checkout-completion.json', { body: JSON.stringify({ operationId, diff --git a/browser_tests/playwrightSelection.test.ts b/browser_tests/playwrightSelection.test.ts index 8ac20230f29..fba46d58828 100644 --- a/browser_tests/playwrightSelection.test.ts +++ b/browser_tests/playwrightSelection.test.ts @@ -8,7 +8,7 @@ describe('Live billing opt-in', () => { { enabled: '0', project: 'cloud-live', count: 0 }, { enabled: '1', project: 'cloud-live', count: 3 }, { enabled: '1', project: 'cloud-live-paid', count: 2 }, - { enabled: '1', project: 'cloud-live-disposable', count: 6 } + { enabled: '1', project: 'cloud-live-disposable', count: 7 } ])( 'collects $project only when explicitly enabled ($enabled)', { timeout: 90_000 }, 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..d6662c456fa --- /dev/null +++ b/browser_tests/tests/liveCloud/disposable/cardDeclineRecovery.spec.ts @@ -0,0 +1,26 @@ +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 disposableCheckout.checkout.declineCheckout( + disposableCheckout.billingSession, + testInfo + ) + const completion = await disposableCheckout.checkout.completeCheckout( + disposableCheckout.billingSession, + testInfo, + 2 + ) + expect(completion).toMatchObject({ + planSlug: 'creator-monthly', + paymentMethodCount: 2 + }) + }) +})