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
61 changes: 61 additions & 0 deletions browser_tests/tests/billing/cloudCreditsLockedRefusal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,64 @@ test.describe('Run refused for locked credits', { tag: '@cloud' }, () => {
).toHaveCount(0)
})
})

async function arrangeEndedPlan(page: Page, hasFunds: boolean) {
await new CloudWorkspaceMockHelper(page).setup(
DEFAULT_TEAM_MEMBERS,
workspace('personal', 'owner'),
{
...PERSONAL_BILLING_STATUS,
subscription_state: 'ended',
has_funds: hasFunds
}
)
await page.route('**/api/features', (route) =>
route.fulfill(jsonRoute({ subscription_required: true }))
)
}

async function clickSubscribeToRun(page: Page) {
await page.goto(APP_URL)
await waitForCloudApp(page)
await page.getByTestId(TestIds.topbar.subscribeToRunButton).click()
}

test.describe(
'Subscribe to Run for an ended plan with funds',
{ tag: '@cloud' },
() => {
test.beforeEach(async ({ page }) => {
await arrangeEndedPlan(page, true)
})

test('says why credits did not help', async ({ page }) => {
await clickSubscribeToRun(page)

await expect(
page.getByTestId(TestIds.dialogs.creditsLockedNotice)
).toHaveText(
"Buying credits doesn't restart your Cloud plan. Resubscribe to run workflows on Cloud.",
{ timeout: 30_000 }
)
})
}
)

test.describe(
'Subscribe to Run for an ended plan without funds',
{ tag: '@cloud' },
() => {
test.beforeEach(async ({ page }) => {
await arrangeEndedPlan(page, false)
})

test('stays out of the dialog', async ({ page }) => {
await clickSubscribeToRun(page)

await expect(page.getByRole('dialog')).toBeVisible({ timeout: 30_000 })
await expect(
page.getByTestId(TestIds.dialogs.creditsLockedNotice)
).toHaveCount(0)
})
}
)
34 changes: 32 additions & 2 deletions src/composables/useCoreCommands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ vi.mock(import('@/platform/billing/subscription/composables/useSubscription'))
const mockBillingState = vi.hoisted(() => ({
canAccessSubscriptionFeatures: true,
subscriptionTier: null as string | null,
hasFunds: false,
subscriptionState: null as string | null,
initialized: true,
routing: 'workspace' as 'workspace' | 'unknown',
onInitialize: null as (() => void) | null
Expand All @@ -180,10 +182,19 @@ vi.mock<unknown>(
return mockBillingState.canAccessSubscriptionFeatures
}
},
subscriptionState: {
get value() {
return mockBillingState.subscriptionState
}
},
subscription: {
get value() {
return mockBillingState.subscriptionTier
? { tier: mockBillingState.subscriptionTier }
return mockBillingState.subscriptionTier || mockBillingState.hasFunds
? {
tier: mockBillingState.subscriptionTier,
isActive: false,
hasFunds: mockBillingState.hasFunds
}
: null
}
}
Expand Down Expand Up @@ -253,6 +264,8 @@ describe('useCoreCommands', () => {
mockDistributionState.isCloud = false
mockBillingState.canAccessSubscriptionFeatures = true
mockBillingState.subscriptionTier = null
mockBillingState.hasFunds = false
mockBillingState.subscriptionState = null
mockBillingState.initialized = true
mockBillingState.routing = 'workspace'
mockBillingState.onInitialize = null
Expand Down Expand Up @@ -902,6 +915,23 @@ describe('useCoreCommands', () => {
}
)

it('explains locked credits when an inactive Cloud account holds funds', async () => {
mockDistributionState.isCloud = true
mockBillingState.canAccessSubscriptionFeatures = false
mockBillingState.hasFunds = true
mockBillingState.subscriptionState = 'ended'

await findCmd('Comfy.QueuePrompt').function()

expect(app.queuePrompt).not.toHaveBeenCalled()
expect(
useSubscriptionPaywall().showSubscriptionDialog
).toHaveBeenCalledWith({
reason: 'subscribe_to_run',
creditsLocked: true
})
})

it.for(['ENTERPRISE', 'GALACTIC'] as const)(
'explains the block instead of a subscribe dialog on a sales-managed %s plan',
async (tier) => {
Expand Down
9 changes: 8 additions & 1 deletion src/composables/useCoreCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { useBillingContext } from '@/platform/billing/composables/useBillingCont
import { useSubscriptionPaywall } from '@/platform/billing/composables/useSubscriptionPaywall'
import { openModelLibraryBrowser } from '@/platform/assets/composables/openModelLibraryBrowser'
import { isSalesManagedTier } from '@/platform/billing/subscription/constants/tierPricing'
import { subscribeToRunDialogOptions } from '@/platform/billing/subscription/utils/subscribeToRunDialogOptions'
import { isCloud } from '@/platform/distribution/types'
import { useMissingModelStore } from '@/platform/workflowErrors/missingModel/missingModelStore'
import { resetOnboardingState } from '@/platform/onboarding/onboardingReset'
Expand Down Expand Up @@ -91,6 +92,7 @@ export function useCoreCommands(): ComfyCommand[] {
const {
canAccessSubscriptionFeatures,
subscription,
subscriptionState,
isInitialized,
initialize,
type: billingType
Expand All @@ -108,7 +110,12 @@ export function useCoreCommands(): ComfyCommand[] {
duration: 5000
})
} else {
showSubscriptionDialog({ reason: 'subscribe_to_run' })
showSubscriptionDialog(
subscribeToRunDialogOptions({
subscriptionState: subscriptionState.value,
hasFunds: subscription.value?.hasFunds
})
)
}
return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import { computed, ref } from 'vue'
import { createI18n } from 'vue-i18n'

import { useTelemetry } from '@comfyorg/telemetry'
import { useBillingContext } from '@/platform/billing/composables/useBillingContext'
import { useBillingUI } from '@/platform/billing/composables/useBillingUI'
import type { SubscriptionInfo } from '@/platform/billing/composables/types'
import { receiveServerFact } from '@/platform/serverFacts/serverFact'
import { fromPartial } from '@total-typescript/shoehorn'

import SubscribeToRun from './SubscribeToRun.vue'

Expand All @@ -18,6 +21,8 @@ vi.mock(import('@/platform/billing/composables/useSubscriptionPaywall'))

vi.mock(import('@/platform/billing/composables/useBillingUI'))

vi.mock(import('@/platform/billing/composables/useBillingContext'))

vi.mock(import('@/platform/distribution/types'), () => ({
isCloud: true
}))
Expand Down Expand Up @@ -104,6 +109,27 @@ describe('SubscribeToRun', () => {
).toHaveBeenCalledExactlyOnceWith({ reason: 'subscribe_to_run' })
})

it('says why credits did not help when the inactive account holds funds', async () => {
const context = useBillingContext()
vi.mocked(useBillingContext).mockReturnValue({
...context,
subscription: computed(() =>
fromPartial<SubscriptionInfo>({ isActive: false, hasFunds: true })
),
subscriptionState: computed(() => 'never_subscribed' as const)
})
const { user } = renderButton()

await user.click(screen.getByTestId('subscribe-to-run-button'))

expect(
useSubscriptionPaywall().showSubscriptionDialog
).toHaveBeenCalledExactlyOnceWith({
reason: 'subscribe_to_run',
creditsLocked: true
})
})

it('routes members to the same role-aware dialog on click', async () => {
mockCanManageSubscription.value = false
const { user } = renderButton()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ import Button from '@comfyorg/design-system/button/Button'
import { useSubscriptionPaywall } from '@/platform/billing/composables/useSubscriptionPaywall'
import { useRunButtonTelemetry } from '@/composables/useRunButtonTelemetry'
import { isCloud } from '@/platform/distribution/types'
import { useBillingContext } from '@/platform/billing/composables/useBillingContext'
import { useBillingUI } from '@/platform/billing/composables/useBillingUI'
import { subscribeToRunDialogOptions } from '@/platform/billing/subscription/utils/subscribeToRunDialogOptions'

const { t } = useI18n()

Expand All @@ -36,6 +38,7 @@ const breakpoints = useBreakpoints(breakpointsTailwind)
const isMdOrLarger = breakpoints.greaterOrEqual('md')

const { permissions } = useBillingUI()
const { subscription, subscriptionState } = useBillingContext()
const { showSubscriptionDialog } = useSubscriptionPaywall()
const { trackRunButton } = useRunButtonTelemetry()

Expand All @@ -59,6 +62,11 @@ function handleSubscribeToRun() {
trackRunButton({ subscribe_to_run: true })
}

showSubscriptionDialog({ reason: 'subscribe_to_run' })
showSubscriptionDialog(
subscribeToRunDialogOptions({
subscriptionState: subscriptionState.value,
hasFunds: subscription.value?.hasFunds
})
)
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { describe, expect, it } from 'vitest'

import { subscribeToRunDialogOptions } from './subscribeToRunDialogOptions'

describe('subscribeToRunDialogOptions', () => {
it.for(['never_subscribed', 'ended'] as const)(
'says the credits are locked for a funded account in state %s',
(subscriptionState) => {
expect(
subscribeToRunDialogOptions({ subscriptionState, hasFunds: true })
).toEqual({ reason: 'subscribe_to_run', creditsLocked: true })
}
)

it.for([
{
name: 'no funds',
subscriptionState: 'never_subscribed',
hasFunds: false
},
{ name: 'a paused plan', subscriptionState: 'paused', hasFunds: true },
{ name: 'a past-due plan', subscriptionState: 'past_due', hasFunds: true },
{ name: 'an active plan', subscriptionState: 'active', hasFunds: true },
{ name: 'an unknown state', subscriptionState: null, hasFunds: true },
{
name: 'billing not loaded',
subscriptionState: null,
hasFunds: undefined
}
] as const)(
'opens the plain subscribe dialog with $name',
({ subscriptionState, hasFunds }) => {
expect(
subscribeToRunDialogOptions({ subscriptionState, hasFunds })
).toEqual({ reason: 'subscribe_to_run' })
}
)
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { SubscriptionState } from '@comfyorg/ingest-types'

import type { SubscriptionDialogOptions } from '@/platform/billing/composables/types'
import { pendingServerFact } from '@/platform/serverFacts/pendingServerFact'

/** Subscribe to Run paywall options; flags locked credits for a funded account with no plan. */
export function subscribeToRunDialogOptions(facts: {
subscriptionState: SubscriptionState | null
hasFunds: boolean | undefined
}): SubscriptionDialogOptions {
const creditsLocked = pendingServerFact(
'BE-24447',
facts.hasFunds === true &&
(facts.subscriptionState === 'never_subscribed' ||
facts.subscriptionState === 'ended')
)
return {
reason: 'subscribe_to_run',
...(creditsLocked && { creditsLocked: true })
}
}
Loading