Skip to content
Merged
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
81 changes: 9 additions & 72 deletions browser_tests/tests/dialogs/topUpNoPaymentMethod.spec.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
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).
* 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
Expand All @@ -32,25 +26,13 @@ test.describe('Top-up without a saved payment method', () => {
return topUpDialog
}

test('offers Manage billing and explains a refused purchase', async ({
comfyPage
}) => {
test('explains a refused purchase', async ({ comfyPage }) => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: The modified refusal test still passes if the removed saved-payment lookup is reintroduced. In this isolated head I restored the pre-PR component and lookup: all 27 existing component tests stayed green. An independent guard passed with the patch (28 tests), then failed only its no-read assertion without it (1 failed/27 passed), observing one listSavedPaymentMethods call; an actual production-browser probe likewise caught the payment-method GET. Could we keep one behavioral regression proving that a usable confirmation dialog no longer starts this lookup (legacy and SDK rows on 1.55)? The obsolete note/portal tests can remain removed. This is a missing safety net for the PR's stated behavior, rather than a claim that the current head still reads the endpoint.

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' })
)
const paymentMethodReads: string[] = []
await page.route('**/api/billing/payment-methods', (route) => {
paymentMethodReads.push(route.request().url())
return route.fulfill({ json: [] })
})
await page.route('**/api/billing/topup', (route) =>
route.fulfill({
status: 400,
Expand All @@ -68,18 +50,7 @@ test.describe('Top-up without a saved payment method', () => {
.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()

expect(paymentMethodReads).toHaveLength(0)
await topUpDialog.root.getByRole('button', { name: 'Pay $50.00' }).click()

await expect(
Expand All @@ -88,38 +59,4 @@ test.describe('Top-up without a saved payment method', () => {
.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)
})
})
3 changes: 0 additions & 3 deletions src/locales/en/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -2742,10 +2742,7 @@
"addMoreCreditsToRun": "Add more credits to run",
"insufficientWorkflowMessage": "You don't have enough credits to run this workflow.",
"creditsDescription": "Credits are used to run workflows or partner nodes.",
"chargedImmediatelyNote": "Your saved payment method is charged immediately.",
"paymentDetailsRequiredNote": "You'll be asked to add a payment method to complete this purchase.",
"noPaymentMethodError": "No payment method is saved for this workspace. Add one via Settings → Plan & Credits → Manage billing, then retry the top-up.",
"manageBillingError": "Failed to open the billing portal. Please try again.",
"confirmSubtitle": "Credits are added to this workspace as soon as payment completes.",
"confirmTitle": "Confirm",
"howManyCredits": "How many credits would you like to add?",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ import TopUpCreditsDialogContentWorkspace from './TopUpCreditsDialogContentWorks

const mockFetchBalance = vi.fn()
const mockFetchStatus = vi.fn()
const mockManageSubscription = vi.fn<() => Promise<void>>()
const mockReportError = vi.hoisted(() => vi.fn())

vi.mock('@/platform/telemetry/reportError', () => ({
reportError: mockReportError
}))

vi.mock(import('firebase/auth'), { spy: true })
const mockTopup =
vi.fn<(amountCents: number) => Promise<CreateTopupResponse | void>>()
Expand All @@ -60,23 +53,6 @@ const mockDistributionTypes = vi.hoisted(() => ({ isCloud: true }))

vi.mock('@/platform/distribution/types', () => mockDistributionTypes)

const mockHasSavedPaymentMethod = vi.hoisted(() => ({
ref: undefined as { value: boolean | null } | undefined
}))

vi.mock(
'@/platform/workspace/composables/useHasSavedPaymentMethod',
async () => {
const { ref } = await import('vue')
mockHasSavedPaymentMethod.ref = ref<boolean | null>(null)
return {
useHasSavedPaymentMethod: () => ({
hasSavedPaymentMethod: mockHasSavedPaymentMethod.ref
})
}
}
)

interface MockTopupOperation {
opId: string
status: 'pending' | 'reconciliation_needed'
Expand All @@ -98,7 +74,6 @@ vi.mock('@/composables/billing/useBillingContext', () => ({
useBillingContext: () => ({
fetchBalance: mockFetchBalance,
fetchStatus: mockFetchStatus,
manageSubscription: mockManageSubscription,
topup: (amountCents: number) => mockTopup(amountCents)
})
}))
Expand Down Expand Up @@ -221,13 +196,6 @@ function setTopupActionOperation(operation: MockTopupOperation | undefined) {
mockBillingOperationState.topupActionOperation.value = operation
}

function setHasSavedPaymentMethod(value: boolean | null) {
if (!mockHasSavedPaymentMethod.ref) {
throw new Error('Payment method mock not initialized')
}
mockHasSavedPaymentMethod.ref.value = value
}

async function clickAddCredits() {
const user = userEvent.setup()
await user.click(screen.getByRole('button', { name: 'Add credits' }))
Expand All @@ -251,7 +219,6 @@ describe('TopUpCreditsDialogContentWorkspace', () => {
setTopupActionOperation(undefined)
mockFetchBalance.mockResolvedValue(undefined)
mockFetchStatus.mockResolvedValue(undefined)
setHasSavedPaymentMethod(true)
mockStartOperation.mockImplementation(() => {
setIsAddingCredits(true)
return new Promise(() => {})
Expand Down Expand Up @@ -393,71 +360,7 @@ describe('TopUpCreditsDialogContentWorkspace', () => {
expect(mockTopup).not.toHaveBeenCalled()
})

it('shows the saved-card note when a payment method is on file', async () => {
renderDialog()

await clickAddCredits()

expect(
await screen.findByText(
'Your saved payment method is charged immediately.'
)
).toBeInTheDocument()
})

it('asks for payment details when no payment method is saved', async () => {
setHasSavedPaymentMethod(false)

renderDialog()
await clickAddCredits()

expect(
await screen.findByText(
"You'll be asked to add a payment method to complete this purchase."
)
).toBeInTheDocument()
})

it('opens the billing portal from the no-payment-method note', async () => {
setHasSavedPaymentMethod(false)
mockManageSubscription.mockResolvedValue(undefined)

renderDialog()
await clickAddCredits()

await userEvent.click(
await screen.findByRole('button', { name: 'Manage billing' })
)

expect(mockManageSubscription).toHaveBeenCalledTimes(1)
})

it('reports and surfaces a billing-portal opening failure', async () => {
setHasSavedPaymentMethod(false)
const failure = new Error('portal down')
mockManageSubscription.mockRejectedValue(failure)

renderDialog()
await clickAddCredits()

await userEvent.click(
await screen.findByRole('button', { name: 'Manage billing' })
)

await waitFor(() =>
expect(mockReportError).toHaveBeenCalledWith(failure, {
errorType: 'billing_portal_open_failure'
})
)
expect(mockToastAdd).toHaveBeenCalledWith(
expect.objectContaining({
summary: 'Failed to open the billing portal. Please try again.'
})
)
})

it('explains how to add a payment method when the purchase is refused', async () => {
setHasSavedPaymentMethod(false)
mockTopup.mockRejectedValue(
new WorkspaceApiError(
'No default payment method is selected.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,6 @@
{{ displayTotal }}
</span>
</div>
<p
v-if="hasSavedPaymentMethod !== null"
class="m-0 text-xs text-muted-foreground"
>
{{ paymentNote }}
<button
v-if="hasSavedPaymentMethod === false"
class="cursor-pointer border-none bg-transparent p-0 text-xs text-base-foreground underline"
@click="openManageBilling"
>
{{ $t('subscription.manageBilling') }}
</button>
</p>
</div>
</template>

Expand Down Expand Up @@ -300,10 +287,8 @@ import { isCloud } from '@/platform/distribution/types'
import type { CheckoutJourneyPhaseEvent } from '@/platform/telemetry/types'
import { categorizeBillingApiError } from '@/platform/telemetry/utils/billingFailureCategory'
import { useSettingsDialog } from '@/platform/settings/composables/useSettingsDialog'
import { reportError } from '@/platform/telemetry/reportError'
import { WorkspaceApiError } from '@/platform/workspace/api/workspaceApi'
import { useBillingCapabilities } from '@/platform/workspace/composables/useBillingCapabilities'
import { useHasSavedPaymentMethod } from '@/platform/workspace/composables/useHasSavedPaymentMethod'
import { useBillingOperationStore } from '@/platform/workspace/stores/billingOperationStore'
import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore'
import {
Expand All @@ -330,8 +315,7 @@ const settingsDialog = useSettingsDialog()
const telemetry = useTelemetry()
const toast = useToast()
const { buildDocsUrl, docsPaths } = useExternalLink()
const { fetchBalance, fetchStatus, manageSubscription, topup } =
useBillingContext()
const { fetchBalance, fetchStatus, topup } = useBillingContext()
const { canTopUp } = useBillingCapabilities()

const billingOperationStore = useBillingOperationStore()
Expand Down Expand Up @@ -403,19 +387,11 @@ const step = ref<'amount' | 'confirm' | 'verifying'>(
topupOperation.value && canTopUp.value ? 'verifying' : 'amount'
)

const { hasSavedPaymentMethod } = useHasSavedPaymentMethod()

// Computed
const pricingUrl = computed(() =>
buildDocsUrl(docsPaths.partnerNodesPricing, { includeLocale: true })
)

const paymentNote = computed(() =>
hasSavedPaymentMethod.value
? t('credits.topUp.chargedImmediatelyNote')
: t('credits.topUp.paymentDetailsRequiredNote')
)

const creditsModel = computed({
get: () => usdToCredits(payAmount.value),
set: (newCredits: number) => {
Expand Down Expand Up @@ -498,17 +474,6 @@ function handlePrimaryAction() {
void handleBuy()
}

function openManageBilling() {
void manageSubscription().catch((error) => {
reportError(error, { errorType: 'billing_portal_open_failure' })
toast.add({
severity: 'error',
summary: t('credits.topUp.manageBillingError'),
life: 5000
})
})
}

function openTopupVerification() {
if (!topupActionUrl.value) return
window.open(topupActionUrl.value, '_blank', 'noopener,noreferrer')
Expand Down
Loading
Loading