LCOV - code coverage report
Current view: top level - src/platform/billing/stores - workspaceBillingStateStore.ts Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 100.0 % 13 13
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : import type {
       2              :   SubscriptionTier,
       3              :   WorkspaceWithRole
       4              : } from '@comfyorg/ingest-types'
       5              : import { defineStore } from 'pinia'
       6              : import { computed, shallowRef, watch } from 'vue'
       7              : 
       8              : import { useWorkspaceIdentity } from '@/platform/workspace/ports/workspaceIdentity'
       9              : 
      10              : interface WorkspaceBillingSummary {
      11              :   isSubscribed: boolean
      12              :   subscriptionPlan: string | null
      13              :   subscriptionTier: SubscriptionTier | null
      14              : }
      15              : 
      16         2356 : export const useWorkspaceBillingStateStore = defineStore(
      17              :   'workspaceBillingState',
      18              :   () => {
      19          118 :     const workspace = useWorkspaceIdentity()
      20          118 :     const summaries = shallowRef<
      21              :       Readonly<Record<string, Partial<WorkspaceBillingSummary>>>
      22              :     >({})
      23              : 
      24           58 :     function getSummary(
      25              :       workspace: Pick<WorkspaceWithRole, 'id' | 'type' | 'subscription_tier'>
      26              :     ): WorkspaceBillingSummary {
      27           58 :       return {
      28              :         isSubscribed:
      29              :           workspace.type === 'personal' || !!workspace.subscription_tier,
      30              :         subscriptionPlan: null,
      31              :         subscriptionTier: workspace.subscription_tier ?? null,
      32              :         ...summaries.value[workspace.id]
      33              :       }
      34              :     }
      35              : 
      36          118 :     const activeSummary = computed(() =>
      37              :       workspace.activeWorkspace ? getSummary(workspace.activeWorkspace) : null
      38              :     )
      39          118 :     const isWorkspaceSubscribed = computed(
      40              :       () => activeSummary.value?.isSubscribed ?? false
      41              :     )
      42              : 
      43           19 :     function updateSummary(
      44              :       id: string,
      45              :       summary: Partial<WorkspaceBillingSummary>
      46              :     ): void {
      47           19 :       summaries.value = {
      48              :         ...summaries.value,
      49              :         [id]: { ...summaries.value[id], ...summary }
      50              :       }
      51              :     }
      52              : 
      53            2 :     function reset(): void {
      54            2 :       summaries.value = {}
      55              :     }
      56              : 
      57          118 :     watch(() => workspace.identityGeneration, reset, { flush: 'sync' })
      58              : 
      59          118 :     return {
      60              :       getSummary,
      61              :       activeSummary,
      62              :       isWorkspaceSubscribed,
      63              :       updateSummary
      64              :     }
      65              :   }
      66              : )
        

Generated by: LCOV version 2.0-1