From f885821c0e98c5bc37e2f09a1309966edc64eadc Mon Sep 17 00:00:00 2001 From: comfydesigner Date: Thu, 5 Nov 2026 12:16:33 -0800 Subject: [PATCH 1/2] fix(billing): show one billing action at a time in the profile menu The credits row in the profile menu could show Add credits next to Subscribe for a Cloud workspace with no plan, which suggested buying credits would let workflows run. It now shows a single action: - Payment recovery available: Update payment only, and the add-credits refusal line is hidden with the button. - No plan or an ended plan on Cloud: Subscribe (or Resubscribe) only. - Ending plan that can still run: Add credits; Resubscribe only when Add credits isn't offered. Resubscribe stays on the Billing tab. - Nothing shows until capabilities resolve and, on Cloud, until the billing status has loaded, so the row no longer flips from Add credits to Subscribe while loading. Temporary until the profile menu redesign (DES-1243) removes these buttons from the menu. --- .../CurrentUserPopoverWorkspace.test.ts | 65 +++++++++++++++++-- .../CurrentUserPopoverWorkspace.vue | 34 ++++++++-- 2 files changed, 88 insertions(+), 11 deletions(-) diff --git a/src/platform/account/components/CurrentUserPopoverWorkspace.test.ts b/src/platform/account/components/CurrentUserPopoverWorkspace.test.ts index 6a740d72cfe..78bb6cc2fae 100644 --- a/src/platform/account/components/CurrentUserPopoverWorkspace.test.ts +++ b/src/platform/account/components/CurrentUserPopoverWorkspace.test.ts @@ -203,6 +203,7 @@ describe('CurrentUserPopoverWorkspace', () => { () => ({ amountMicros: 100, currency: 'USD' }) satisfies BalanceInfo ) billingContext.isLoading = ref(false) + billingContext.isInitialized = ref(true) vi.mocked(useBillingContext).mockReturnValue(billingContext) const workspaceUI = vi.mocked(useAccountUI()) workspaceUI.permissions = computed(() => ({ @@ -491,18 +492,60 @@ describe('CurrentUserPopoverWorkspace', () => { ).toHaveBeenCalledExactlyOnceWith({ source: 'avatar_menu_plans' }) }) - it('offers add-credits alongside Subscribe for an unsubscribed Cloud owner', () => { + it.for(['personal', 'team'] as const)( + 'offers only Subscribe, not Add credits, to an unsubscribed Cloud owner in a %s workspace', + (workspaceType) => { + state.canAccessSubscriptionFeatures = false + useBillingCapabilities().canTopUp = computed(() => true) + useBillingCapabilities().canSubscribeSelfServe = computed(() => true) + state.canManageSubscription = true + + renderComponent(workspaceType) + + expect( + screen.getByRole('button', { name: 'Subscribe' }) + ).toBeInTheDocument() + expect(screen.queryByTestId('add-credits-button')).not.toBeInTheDocument() + } + ) + + it('shows no billing action until capabilities resolve', () => { state.canAccessSubscriptionFeatures = false useBillingCapabilities().canTopUp = computed(() => true) useBillingCapabilities().canSubscribeSelfServe = computed(() => true) - state.canManageSubscription = true + useBillingCapabilities().hasResolvedCapabilities = computed(() => false) renderComponent('personal') - expect(screen.getByTestId('add-credits-button')).toBeInTheDocument() expect( - screen.getByRole('button', { name: 'Subscribe' }) + screen.queryByRole('button', { name: 'Subscribe' }) + ).not.toBeInTheDocument() + expect(screen.queryByTestId('add-credits-button')).not.toBeInTheDocument() + }) + + it('shows no billing action on Cloud until the billing status loads', () => { + useBillingCapabilities().canTopUp = computed(() => true) + vi.mocked(useBillingContext()).isInitialized = ref(false) + + renderComponent('personal') + + expect(screen.queryByTestId('add-credits-button')).not.toBeInTheDocument() + }) + + it('offers Update payment alone, without the add-credits refusal, to a past-due owner', () => { + useBillingCapabilities().topUpDenial = computed(() => 'payment_past_due') + useBillingCapabilities().paymentRecoveryAvailable = + paymentRecoveryAvailableFact(true) + + renderComponent('team') + + expect( + screen.getByRole('button', { name: 'Update payment' }) ).toBeInTheDocument() + expect(screen.queryByTestId('add-credits-button')).not.toBeInTheDocument() + expect( + screen.queryByText('Update your payment method to add credits.') + ).not.toBeInTheDocument() }) it('offers add-credits instead of the upgrade upsell on the Local free tier', () => { @@ -687,8 +730,7 @@ describe('CurrentUserPopoverWorkspace', () => { } ) - it('keeps billing controls and resubscribe available to a promoted owner', async () => { - const user = userEvent.setup() + it('keeps billing controls available to a promoted owner and prefers Add credits over Resubscribe on an ending plan', () => { state.isCancelled = true useBillingCapabilities().canTopUp = computed(() => true) state.canManageSubscription = true @@ -701,6 +743,17 @@ describe('CurrentUserPopoverWorkspace', () => { expect(screen.getByTestId('add-credits-button')).toBeInTheDocument() expect(screen.getByTestId('plans-pricing-menu-item')).toBeInTheDocument() expect(screen.getByTestId('manage-plan-menu-item')).toBeInTheDocument() + expect( + screen.queryByRole('button', { name: 'Resubscribe' }) + ).not.toBeInTheDocument() + }) + + it('opens the pricing table from Resubscribe when the ending plan has no Add credits', async () => { + const user = userEvent.setup() + state.isCancelled = true + state.canManageSubscriptionLifecycle = true + state.canReactivatePlan = true + renderComponent('team') await user.click(screen.getByRole('button', { name: 'Resubscribe' })) diff --git a/src/platform/account/components/CurrentUserPopoverWorkspace.vue b/src/platform/account/components/CurrentUserPopoverWorkspace.vue index dae693e910f..3ff48450291 100644 --- a/src/platform/account/components/CurrentUserPopoverWorkspace.vue +++ b/src/platform/account/components/CurrentUserPopoverWorkspace.vue @@ -95,7 +95,7 @@