Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,43 @@ describe('BillingLocalCreditBanner', () => {
).not.toBeInTheDocument()
})

it('renders nothing on cloud', () => {
it('renders nothing on cloud without an active plan', () => {
arrange({
isCloud: true,
subscription: {
...personalSubscription,
hasFunds: false,
isCancelled: true,
endDate: '2026-08-01T00:00:00Z'
isActive: false,
hasFunds: false
},
balance: { amountMicros: 500, currency: 'usd', lowBalance: true }
})

expect(
screen.queryByTestId('billing-local-credit-banner')
).not.toBeInTheDocument()
expect(screen.queryByText('Subscription paused')).not.toBeInTheDocument()
})

it('shows out of credits on an active cloud plan', () => {
arrange({
isCloud: true,
subscription: { ...personalSubscription, hasFunds: false },
renewalDate: '2026-10-01T00:00:00Z'
})

expect(screen.getByTestId('billing-local-credit-banner')).toHaveTextContent(
'Out of credits'
)
})

it('shows low credits on an active cloud plan', () => {
arrange({
isCloud: true,
balance: { amountMicros: 500, currency: 'usd', lowBalance: true }
})

expect(screen.getByTestId('billing-local-credit-banner')).toHaveTextContent(
'Credits are low'
)
})

it.for([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ const balance = computed(() => billing.balance?.value ?? null)
const isTeamPlan = computed(() => billing.isTeamPlan?.value ?? false)

const kind = computed(() => {
if (isCloud) return null
return deriveLocalCreditBanner({
unifiedBillingSettingsEnabled: flags.unifiedBillingSettingsEnabled,
isCloud,
isActive: subscription.value?.isActive === true,
hasFunds: subscription.value?.hasFunds ?? null,
lowBalance: balance.value?.lowBalance,
outOfCreditsDismissed: outOfCreditsDismissed.value,
Expand Down
25 changes: 24 additions & 1 deletion src/platform/workspace/composables/deriveBillingBanner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ const funded: BillingBannerInputs = {
planChangeDismissed: false,
hasScheduledChange: false,
topUpDeniedPastDue: false,
runDeniedPastDue: false
runDeniedPastDue: false,
unifiedBillingSettingsEnabled: false,
isActive: true
}

function derive(overrides: Partial<BillingBannerInputs>, now?: number) {
Expand Down Expand Up @@ -168,6 +170,27 @@ describe('deriveBillingBanner', () => {
expect(derive({ hasFunds: false })).toBe('outOfCredits')
})

it('hides cloud credit banners when unified billing is on and the plan is not active', () => {
expect(
derive({
unifiedBillingSettingsEnabled: true,
isActive: false,
hasFunds: false,
topUpDeniedPastDue: true
})
).toBeNull()
})

it('keeps cloud credit banners when unified billing is on and the plan is active', () => {
expect(
derive({
unifiedBillingSettingsEnabled: true,
isActive: true,
hasFunds: false
})
).toBe('outOfCredits')
})

it('shows out of credits to members too', () => {
expect(derive({ hasFunds: false, canManage: false })).toBe('outOfCredits')
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { deriveLocalCreditBanner } from './deriveLocalCreditBanner'

const open: LocalCreditBannerInput = {
unifiedBillingSettingsEnabled: true,
isCloud: false,
isActive: false,
hasFunds: true,
lowBalance: undefined,
outOfCreditsDismissed: false,
Expand All @@ -16,6 +18,35 @@ function derive(overrides: Partial<LocalCreditBannerInput>) {
}

describe('deriveLocalCreditBanner', () => {
it('stays hidden on cloud until the served plan is active', () => {
expect(
derive({
isCloud: true,
isActive: false,
hasFunds: false,
lowBalance: true
})
).toBeNull()
})

it.for([
{
name: 'out of credits',
input: { isCloud: true, isActive: true, hasFunds: false },
expected: 'outOfCredits' as const
},
{
name: 'low credits',
input: { isCloud: true, isActive: true, lowBalance: true },
expected: 'lowCredits' as const
}
])(
'shows the $name cloud banner when the served plan is active',
({ input, expected }) => {
expect(derive(input)).toBe(expected)
}
)

it('stays hidden when unified billing settings is off', () => {
expect(
derive({
Expand All @@ -26,6 +57,12 @@ describe('deriveLocalCreditBanner', () => {
).toBeNull()
})

it('keeps local credit banners when the plan is not active', () => {
expect(derive({ isCloud: false, isActive: false, hasFunds: false })).toBe(
'outOfCredits'
)
})

it.for([
{ lowBalance: undefined, kind: null },
{ lowBalance: false, kind: null },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ export type LocalCreditBannerKind = 'outOfCredits' | 'lowCredits'

export interface LocalCreditBannerInput {
unifiedBillingSettingsEnabled: boolean
isCloud: boolean
isActive: boolean
hasFunds: boolean | null
lowBalance: boolean | undefined
outOfCreditsDismissed: boolean
Expand All @@ -12,6 +14,7 @@ export function deriveLocalCreditBanner(
input: LocalCreditBannerInput
): LocalCreditBannerKind | null {
if (!input.unifiedBillingSettingsEnabled) return null
if (input.isCloud && !input.isActive) return null
if (input.hasFunds === false && !input.outOfCreditsDismissed) {
return 'outOfCredits'
}
Expand Down
18 changes: 16 additions & 2 deletions src/platform/workspace/composables/useBillingBanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export interface BillingBannerInputs {
hasScheduledChange: boolean
topUpDeniedPastDue: boolean
runDeniedPastDue: boolean
unifiedBillingSettingsEnabled: boolean
isActive: boolean
}

// An Enterprise cancel_at is an agreed end date — an operator pilot term or
Expand Down Expand Up @@ -108,14 +110,24 @@ function showsPastDueOutOfCredits(inputs: BillingBannerInputs): boolean {
)
}

function cloudCreditBannersOpen(inputs: BillingBannerInputs): boolean {
if (!inputs.unifiedBillingSettingsEnabled) return true
return inputs.isActive
}

function deriveNoticeBanner(
inputs: BillingBannerInputs,
audience: BillingBannerAudience
): BillingBannerKind | null {
if (!inputs.billingControlEnabled) return null
if (showsPastDueOutOfCredits(inputs)) return 'outOfCredits'
const creditsOpen = cloudCreditBannersOpen(inputs)
if (creditsOpen && showsPastDueOutOfCredits(inputs)) return 'outOfCredits'
if (!inputs.canAccessSubscriptionFeatures) return null
if (inputs.hasFunds === false && !inputs.outOfCreditsDismissed) {
if (
creditsOpen &&
inputs.hasFunds === false &&
!inputs.outOfCreditsDismissed
) {
return 'outOfCredits'
}
return deriveLifecycleNotice(inputs, audience)
Expand Down Expand Up @@ -208,6 +220,8 @@ function useBillingBannerInternal() {
planChangeDismissed: planChangeDismissed.value,
topUpDeniedPastDue: isTopUpDeniedPastDue(topUpDenial.value),
runDeniedPastDue: runDeniedPaymentPastDue.value,
unifiedBillingSettingsEnabled: flags.unifiedBillingSettingsEnabled,
isActive: subscription.value?.isActive === true,
...readSubscriptionInputs(subscription.value)
}))

Expand Down
Loading