Repository navigation
fix(billing): stop claiming a saved card exists in the top-up confirm step #16049
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
83885db
fix(billing): stop claiming a saved card exists in the top-up confirm…
dante01yoon ec10c81
feat(billing): guide users to add a payment method before top-up
dante01yoon 70f1f1b
test(e2e): cover top-up without a saved payment method
dante01yoon f18d739
fix(billing): address review — observability and typed test fixtures
dante01yoon 495cdd1
test(billing): address review — portal failure coverage and typed mocks
dante01yoon dd0a851
refactor(billing): adopt useAsyncState and the real locale dict in tests
dante01yoon dcce3fb
fix(billing): gate the saved-card claim on a usable default method
dante01yoon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
125 changes: 125 additions & 0 deletions
125
browser_tests/tests/dialogs/topUpNoPaymentMethod.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| import { expect } from '@playwright/test' | ||
| import type { Page } from '@playwright/test' | ||
|
|
||
| import type { | ||
| PaymentPortalResponse, | ||
| SavedPaymentMethod | ||
| } from '@comfyorg/ingest-types' | ||
|
|
||
| import { TopUpCreditsDialog } from '@e2e/fixtures/components/TopUpCreditsDialog' | ||
| import { TestIds } from '@e2e/fixtures/selectors' | ||
| import { workspaceRailAuthFixture as test } from '@e2e/fixtures/workspaceRailAuthFixture' | ||
|
|
||
| /** | ||
| * Regression coverage for the 1.51 QA finding: with no payment method saved, | ||
| * the confirm step claimed "Your saved payment method is charged immediately" | ||
| * and a refused purchase surfaced the raw NO_PAYMENT_METHOD server error with | ||
| * no path forward (FE-1908). | ||
| * | ||
| * Entered through the user popover like a real user: workspace-rail routing | ||
| * needs the billing context loaded before the dialog opens, and the popover's | ||
| * Add credits button only renders once it is. | ||
| */ | ||
| test.describe('Top-up without a saved payment method', () => { | ||
| async function openTopUpDialog(page: Page) { | ||
| const topUpDialog = new TopUpCreditsDialog(page) | ||
| await page.getByTestId(TestIds.user.currentUserButton).click() | ||
| await page | ||
| .getByTestId(TestIds.user.currentUserPopover) | ||
| .getByTestId('add-credits-button') | ||
| .click() | ||
| await expect(topUpDialog.heading).toBeVisible() | ||
| return topUpDialog | ||
| } | ||
|
|
||
| test('offers Manage billing and explains a refused purchase', async ({ | ||
| comfyPage | ||
| }) => { | ||
| const page = comfyPage.page | ||
| await page.route('**/api/billing/payment-methods', (route) => | ||
| route.fulfill({ json: [] satisfies SavedPaymentMethod[] }) | ||
| ) | ||
| await page.route('**/api/billing/payment-portal', (route) => | ||
| route.fulfill({ | ||
| json: { | ||
| url: 'https://billing.example/portal' | ||
| } satisfies PaymentPortalResponse | ||
| }) | ||
| ) | ||
| await page | ||
| .context() | ||
| .route('https://billing.example/**', (route) => | ||
| route.fulfill({ contentType: 'text/html', body: 'portal stub' }) | ||
| ) | ||
| await page.route('**/api/billing/topup', (route) => | ||
| route.fulfill({ | ||
| status: 400, | ||
| json: { | ||
| code: 'NO_PAYMENT_METHOD', | ||
| message: | ||
| 'No default payment method is selected. Please select one in the payment portal.' | ||
| } | ||
| }) | ||
| ) | ||
|
|
||
| const topUpDialog = await openTopUpDialog(page) | ||
|
|
||
| await topUpDialog.root | ||
| .getByRole('button', { name: 'Add credits', exact: true }) | ||
| .click() | ||
|
|
||
| await expect( | ||
| topUpDialog.root.getByText( | ||
| "You'll be asked to add a payment method to complete this purchase." | ||
| ) | ||
| ).toBeVisible() | ||
| const [portalPage] = await Promise.all([ | ||
| page.context().waitForEvent('page'), | ||
| topUpDialog.root.getByRole('button', { name: 'Manage billing' }).click() | ||
| ]) | ||
| await expect(portalPage).toHaveURL('https://billing.example/portal') | ||
| await portalPage.close() | ||
|
|
||
| await topUpDialog.root.getByRole('button', { name: 'Pay $50.00' }).click() | ||
|
|
||
| await expect( | ||
| page | ||
| .locator('.p-toast-message.p-toast-message-error') | ||
| .getByText(/Add one via Settings → Plan & Credits → Manage billing/) | ||
| ).toBeVisible() | ||
| }) | ||
|
|
||
| test('keeps the saved-card note when a payment method is on file', async ({ | ||
| comfyPage | ||
| }) => { | ||
| const page = comfyPage.page | ||
| await page.route('**/api/billing/payment-methods', (route) => | ||
| route.fulfill({ | ||
| json: [ | ||
| { | ||
| id: 'pm-1', | ||
| type: 'card', | ||
| brand: 'visa', | ||
| last4: '4242', | ||
| is_default: true | ||
| } | ||
| ] satisfies SavedPaymentMethod[] | ||
| }) | ||
| ) | ||
|
|
||
| const topUpDialog = await openTopUpDialog(page) | ||
|
|
||
| await topUpDialog.root | ||
| .getByRole('button', { name: 'Add credits', exact: true }) | ||
| .click() | ||
|
|
||
| await expect( | ||
| topUpDialog.root.getByText( | ||
| 'Your saved payment method is charged immediately.' | ||
| ) | ||
| ).toBeVisible() | ||
| await expect( | ||
| topUpDialog.root.getByRole('button', { name: 'Manage billing' }) | ||
| ).toHaveCount(0) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we want to use i18n dict rather than raw strings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed — importing the real en dict into the test fixture also permanently kills the locale-drift problem CodeRabbit flagged. Taking it in the FE-1908 follow-up together with the composable refactor so this fix can ride the 1.51 backport now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in dd0a851 — the test now renders the production en dict (import with { type: json }), so any copy drift fails the test directly. Dropped the 70-line hand-written fixture.