diff --git a/src/platform/billing/composables/deriveBillingBanner.test.ts b/src/platform/billing/composables/deriveBillingBanner.test.ts index 18ab585b34b..2e4d118f1c0 100644 --- a/src/platform/billing/composables/deriveBillingBanner.test.ts +++ b/src/platform/billing/composables/deriveBillingBanner.test.ts @@ -14,6 +14,7 @@ const funded: BillingBannerInputs = { hasFunds: true, isCancelled: false, endDate: null, + withinEnterpriseEndingNotice: false, canManage: true, isPlanEnded: false, isPlanTerminal: false, @@ -27,8 +28,8 @@ const funded: BillingBannerInputs = { isActive: true } -function derive(overrides: Partial, now?: number) { - return deriveBillingBanner({ ...funded, ...overrides }, now) +function derive(overrides: Partial) { + return deriveBillingBanner({ ...funded, ...overrides }) } describe('deriveBillingBanner', () => { @@ -357,132 +358,73 @@ describe('deriveBillingBanner', () => { ) }) - describe('enterprise ending notice window', () => { - const NOW = new Date('2026-09-03T12:00:00Z').getTime() - - function daysFromNow(days: number): string { - return new Date(NOW + days * 24 * 60 * 60 * 1000).toISOString() - } - + describe('enterprise ending notice', () => { const enterprise: Partial = { isTeamPlan: false, - isEnterprise: true + isEnterprise: true, + isCancelled: true, + endDate: '2026-09-13T12:00:00Z' } - it('stays quiet while the end date is beyond the notice window', () => { - expect( - derive( - { ...enterprise, isCancelled: true, endDate: daysFromNow(30) }, - NOW - ) - ).toBeNull() - }) - - it('surfaces the ending notice once the end date is near', () => { - expect( - derive( - { ...enterprise, isCancelled: true, endDate: daysFromNow(10) }, - NOW - ) - ).toBe('ending') - }) - - it('includes the window boundary itself', () => { - expect( - derive( - { ...enterprise, isCancelled: true, endDate: daysFromNow(14) }, - NOW - ) - ).toBe('ending') - }) - - it('shows the notice to members inside the window', () => { - expect( - derive( - { - ...enterprise, - isCancelled: true, - endDate: daysFromNow(10), - canManage: false - }, - NOW - ) - ).toBe('ending') - }) - - it('needs a populated end date, like the self-serve notice', () => { - expect(derive({ ...enterprise, isCancelled: true }, NOW)).toBeNull() - }) - - it('shows nothing for a passed end date once access is gone', () => { - // The window is unbounded below by design; this is the upstream gate - // that keeps a stale payload from pinning a perpetual past-date banner. - expect( - derive( - { - ...enterprise, - isCancelled: true, - endDate: daysFromNow(-5), - canAccessSubscriptionFeatures: false - }, - NOW - ) - ).toBeNull() - }) - - it('does not leak team-only banners into enterprise workspaces', () => { - expect(derive({ ...enterprise, hasFunds: false }, NOW)).toBeNull() - }) - - it('lets enterprise take precedence if a subscription reads as both', () => { - expect( - derive( - { - ...enterprise, - isTeamPlan: true, - isCancelled: true, - endDate: daysFromNow(60) - }, - NOW - ) - ).toBeNull() - expect( - derive({ ...enterprise, isTeamPlan: true, hasFunds: false }, NOW) - ).toBeNull() + it.for([ + { + case: 'outside the notice window', + inputs: { withinEnterpriseEndingNotice: false }, + kind: null + }, + { + case: 'inside the notice window', + inputs: { withinEnterpriseEndingNotice: true }, + kind: 'ending' + }, + { + case: 'inside the window for a member', + inputs: { withinEnterpriseEndingNotice: true, canManage: false }, + kind: 'ending' + }, + { + case: 'inside the window without a cancellation', + inputs: { withinEnterpriseEndingNotice: true, isCancelled: false }, + kind: null + }, + { + case: 'inside the window once access is gone', + inputs: { + withinEnterpriseEndingNotice: true, + canAccessSubscriptionFeatures: false + }, + kind: null + }, + { + case: 'out of credits', + inputs: { hasFunds: false }, + kind: null + }, + { + case: 'a plan that also reads as team', + inputs: { withinEnterpriseEndingNotice: false, isTeamPlan: true }, + kind: null + } + ] as const)('shows $kind $case', ({ inputs, kind }) => { + expect(derive({ ...enterprise, ...inputs })).toBe(kind) }) - it('gives an unrecognized tier no banner at all, as before this window', () => { + it('gives an unrecognized tier no banner at all', () => { expect( - derive( - { - isTeamPlan: false, - isEnterprise: false, - isCancelled: true, - endDate: daysFromNow(10) - }, - NOW - ) + derive({ + isTeamPlan: false, + isEnterprise: false, + isCancelled: true, + endDate: '2026-09-13T12:00:00Z', + withinEnterpriseEndingNotice: true + }) ).toBeNull() }) - it('reverts cleanly when a webhook outage clears the end date', () => { - // cancel_at can disappear between polls; nothing latches, so the same - // inputs minus the cancellation must derive back to no banner. + it('never applies the window to a self-serve team cancellation', () => { expect( - derive( - { ...enterprise, isCancelled: true, endDate: daysFromNow(10) }, - NOW - ) + derive({ isCancelled: true, endDate: '2026-11-02T12:00:00Z' }) ).toBe('ending') - expect( - derive({ ...enterprise, isCancelled: false, endDate: null }, NOW) - ).toBeNull() - }) - - it('never applies the window to a self-serve team cancellation', () => { - expect(derive({ isCancelled: true, endDate: daysFromNow(60) }, NOW)).toBe( - 'ending' - ) }) }) }) diff --git a/src/platform/billing/composables/useBillingBanner.test.ts b/src/platform/billing/composables/useBillingBanner.test.ts index 9057c6ac460..1ec272311f5 100644 --- a/src/platform/billing/composables/useBillingBanner.test.ts +++ b/src/platform/billing/composables/useBillingBanner.test.ts @@ -43,7 +43,11 @@ describe('useBillingBanner', () => { isTeamPlan: ref(true), billingStatus: ref('paid'), tier: ref(null), - subscription: ref | null>({ + subscription: ref< + | (Pick & + Partial>) + | null + >({ hasFunds: true }) } @@ -178,4 +182,55 @@ describe('useBillingBanner', () => { expect(kind.value).toBe('outOfCredits') }) + it.for([ + { tier: 'PRO', isTeamPlan: false, audience: 'personal' }, + { tier: 'FOUNDERS_EDITION', isTeamPlan: false, audience: 'personal' }, + { tier: null, isTeamPlan: true, audience: 'team' }, + { tier: 'ENTERPRISE', isTeamPlan: false, audience: null }, + { tier: 'ENTERPRISE', isTeamPlan: true, audience: null }, + { tier: null, isTeamPlan: false, audience: null } + ] as const)( + 'reads the $tier tier with team plan $isTeamPlan as the $audience audience', + async ({ tier, isTeamPlan, audience }) => { + const billing = setupBilling() + const banner = useBillingBanner() + + billing.tier.value = tier + billing.isTeamPlan.value = isTeamPlan + await nextTick() + + expect(banner.audience.value).toBe(audience) + } + ) + + describe('the Enterprise ending notice', () => { + const NOW = new Date('2026-09-03T12:00:00Z').getTime() + + beforeEach(() => { + vi.useFakeTimers({ now: NOW }) + }) + + it.for([ + { days: 30, kind: null }, + { days: 14, kind: 'ending' }, + { days: 10, kind: 'ending' } + ])( + 'shows $kind for a cancellation $days days out', + async ({ days, kind: expected }) => { + const billing = setupBilling() + const { kind } = useBillingBanner() + + billing.tier.value = 'ENTERPRISE' + billing.isTeamPlan.value = false + billing.subscription.value = { + hasFunds: true, + isCancelled: true, + endDate: new Date(NOW + days * 24 * 60 * 60 * 1000).toISOString() + } + await nextTick() + + expect(kind.value).toBe(expected) + } + ) + }) }) diff --git a/src/platform/billing/composables/useBillingBanner.ts b/src/platform/billing/composables/useBillingBanner.ts index f860c324032..1b0630ce9db 100644 --- a/src/platform/billing/composables/useBillingBanner.ts +++ b/src/platform/billing/composables/useBillingBanner.ts @@ -6,6 +6,7 @@ import { useBillingContext } from '@/platform/billing/composables/useBillingCont import { useFeatureFlags } from '@/composables/useFeatureFlags' import { isWithinEnterpriseEndingNotice } from '@/platform/billing/subscription/constants/tierPricing' import { isCloud } from '@/platform/distribution/types' +import { pendingServerFact } from '@/platform/serverFacts/pendingServerFact' import type { SubscriptionInfo } from '@/platform/billing/composables/types' import type { SubscriptionTier } from '@comfyorg/billing-core' import { useBillingCapabilities } from '@/platform/billing/composables/useBillingCapabilities' @@ -33,6 +34,7 @@ export interface BillingBannerInputs { hasFunds: boolean | null isCancelled: boolean endDate: string | null + withinEnterpriseEndingNotice: boolean canManage: boolean isPlanEnded: boolean isPlanTerminal: boolean @@ -54,14 +56,13 @@ export interface BillingBannerInputs { // Decision recorded on FE-2035. Enterprise payment and credit lifecycles // are handled by sales, so outOfCredits never applies. function deriveEnterpriseBanner( - inputs: BillingBannerInputs, - now: number + inputs: BillingBannerInputs ): BillingBannerKind | null { if (!inputs.canAccessSubscriptionFeatures) return null if (!inputs.billingControlEnabled) return null - const withinEndingNotice = - inputs.isCancelled && isWithinEnterpriseEndingNotice(inputs.endDate, now) - return withinEndingNotice ? 'ending' : null + return inputs.isCancelled && inputs.withinEnterpriseEndingNotice + ? 'ending' + : null } const PERSONAL_TIERS: ReadonlySet = new Set([ @@ -145,8 +146,7 @@ function hasPlanEnded( } export function deriveBillingBanner( - inputs: BillingBannerInputs, - now: number = Date.now() + inputs: BillingBannerInputs ): BillingBannerKind | null { if (inputs.billingStatus === 'paused') return 'paused' if (!inputs.isLoaded) return null @@ -154,7 +154,7 @@ export function deriveBillingBanner( if (hasPlanEnded(inputs, audience)) { return inputs.planEndedDismissed ? null : 'planEnded' } - if (inputs.isEnterprise) return deriveEnterpriseBanner(inputs, now) + if (inputs.isEnterprise) return deriveEnterpriseBanner(inputs) return audience ? deriveNoticeBanner(inputs, audience) : null } @@ -162,8 +162,11 @@ function classifyTier( tier: SubscriptionTier | null | undefined ): Pick { return { - isEnterprise: tier === 'ENTERPRISE', - isKnownPersonalTier: tier != null && PERSONAL_TIERS.has(tier) + isEnterprise: pendingServerFact('BE-25244', tier === 'ENTERPRISE'), + isKnownPersonalTier: pendingServerFact( + 'BE-25244', + tier != null && PERSONAL_TIERS.has(tier) + ) } } @@ -209,7 +212,7 @@ function useBillingBannerInternal() { const bannerInputs = computed(() => ({ billingControlEnabled: flags.billingControlEnabled, - isTeamPlan: isTeamPlan.value, + isTeamPlan: pendingServerFact('BE-25244', isTeamPlan.value), billingStatus: billingStatus.value, canAccessSubscriptionFeatures: canAccessSubscriptionFeatures.value, canManage: permissions.value.canManageSubscription, @@ -222,25 +225,26 @@ function useBillingBannerInternal() { runDeniedPastDue: runDeniedPaymentPastDue.value, unifiedBillingSettingsEnabled: flags.unifiedBillingSettingsEnabled, isActive: subscription.value?.isActive === true, + withinEnterpriseEndingNotice: pendingServerFact( + 'BE-25244', + isWithinEnterpriseEndingNotice(subscription.value?.endDate, now.value) + ), ...readSubscriptionInputs(subscription.value) })) const kind = computed(() => - isCloud ? deriveBillingBanner(bannerInputs.value, now.value) : null + isCloud ? deriveBillingBanner(bannerInputs.value) : null ) const lifecycleKind = computed(() => isCloud - ? deriveBillingBanner( - { - ...bannerInputs.value, - hasFunds: true, - topUpDeniedPastDue: false, - runDeniedPastDue: false, - planEndedDismissed: false, - planChangeDismissed: false - }, - now.value - ) + ? deriveBillingBanner({ + ...bannerInputs.value, + hasFunds: true, + topUpDeniedPastDue: false, + runDeniedPastDue: false, + planEndedDismissed: false, + planChangeDismissed: false + }) : null ) const audience = computed(() => billingBannerAudience(bannerInputs.value))