LCOV - code coverage report
Current view: top level - src/platform/billing/composables - useAutoTopUpSetupOffer.ts Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 36.4 % 11 4
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : import { canSetUpAutoTopUp } from '@comfyorg/account-core/billing'
       2              : 
       3              : import { useTelemetry } from '@comfyorg/telemetry'
       4              : import { billingApi } from '@/platform/billing/api/billingApi'
       5              : import { useBillingCapabilities } from '@/platform/billing/composables/useBillingCapabilities'
       6              : import {
       7              :   openPlatformBilling,
       8              :   usePlatformHandoff
       9              : } from '@/platform/billing/composables/usePlatformHandoff'
      10              : import { platformAutoTopUpPath } from '@/platform/billing/platformAutoTopUpPath'
      11              : 
      12              : /** Platform Billing's Turn on auto top-up link while the served facts offer it, and the offer's telemetry. */
      13            4 : export function useAutoTopUpSetupOffer() {
      14            4 :   const { autoTopUpEnabled, canManageAutoTopUp, autoTopUpSetup } =
      15              :     useBillingCapabilities()
      16            4 :   const { href, track } = usePlatformHandoff(platformAutoTopUpPath('turn_on'), {
      17              :     target: 'auto_top_up',
      18              :     action: 'turn_on'
      19              :   })
      20              : 
      21            0 :   function trackOffer(stage: 'viewed' | 'declined') {
      22            0 :     useTelemetry()?.trackBillingEvent({
      23              :       operation: 'auto_top_up_offer',
      24              :       stage,
      25              :       outcome: 'pending'
      26              :     })
      27              :   }
      28              : 
      29            0 :   async function setupUrl(): Promise<string | null> {
      30              :     const canSetUp = canSetUpAutoTopUp({
      31              :       autoTopUpEnabled: autoTopUpEnabled.value,
      32              :       canManageAutoTopUp: canManageAutoTopUp.value,
      33              :       setup: autoTopUpSetup.value
      34              :     })
      35            0 :     if (!canSetUp) return null
      36              :     const settings = await billingApi.getBillingAutoReload()
      37            0 :     if (settings.status !== 'off') return null
      38            0 :     trackOffer('viewed')
      39            0 :     return href.value
      40              :   }
      41              : 
      42            4 :   return {
      43              :     setupUrl,
      44              :     open: () => openPlatformBilling(track),
      45              :     trackDeclined: () => trackOffer('declined')
      46              :   }
      47              : }
        

Generated by: LCOV version 2.0-1