diff --git a/.fallowrc.jsonc b/.fallowrc.jsonc index f138ebc4694..f1d2223650a 100644 --- a/.fallowrc.jsonc +++ b/.fallowrc.jsonc @@ -5,6 +5,7 @@ // scripts / CI / tool CLIs / Storybook), not imported from the app graph. "entry": [ "src/main.ts", + "src/platform/telemetry/__mocks__/index.ts", "index.html", "scripts/**/*.{js,ts}", "apps/website/src/scripts/**/*.ts", diff --git a/src/components/TopMenuSection.test.ts b/src/components/TopMenuSection.test.ts index f17b98c8fd1..9e0e8285a92 100644 --- a/src/components/TopMenuSection.test.ts +++ b/src/components/TopMenuSection.test.ts @@ -10,6 +10,8 @@ import { computed, defineComponent, h, nextTick, onMounted, ref } from 'vue' import type { Component } from 'vue' import { createI18n } from 'vue-i18n' +import { useTelemetry } from '@/platform/telemetry' + import QueueNotificationBannerHost from '@/components/queue/QueueNotificationBannerHost.vue' import TopMenuSection from '@/components/TopMenuSection.vue' import type { @@ -80,13 +82,7 @@ vi.mock(import('@/scripts/app'), () => ({ } })) -const mockTrackUiButtonClicked = vi.hoisted(() => vi.fn()) - -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackUiButtonClicked: mockTrackUiButtonClicked - }) -})) +vi.mock(import('@/platform/telemetry')) type WrapperOptions = { pinia?: Pinia @@ -284,7 +280,7 @@ describe('TopMenuSection', () => { screen.getByRole('button', { name: 'Toggle properties panel' }) ) - expect(mockTrackUiButtonClicked).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackUiButtonClicked).toHaveBeenCalledWith({ button_id: 'right_side_panel_opened', element_group: 'top_menu' }) diff --git a/src/components/builder/builderViewOptions.test.ts b/src/components/builder/builderViewOptions.test.ts index 6b0e5807f49..708e2495a6e 100644 --- a/src/components/builder/builderViewOptions.test.ts +++ b/src/components/builder/builderViewOptions.test.ts @@ -1,17 +1,15 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' +import { useTelemetry } from '@/platform/telemetry' + import { app } from '@/scripts/app' import { createMockLoadedWorkflow } from '@/utils/__tests__/litegraphTestUtils' import { setWorkflowDefaultView } from './builderViewOptions' -const mockTrackDefaultViewSet = vi.hoisted(() => vi.fn()) - vi.mock(import('@/i18n'), () => ({ t: (key: string) => key })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ trackDefaultViewSet: mockTrackDefaultViewSet }) -})) +vi.mock(import('@/platform/telemetry')) vi.mock(import('@/scripts/app'), () => { const rootGraph = { extra: {} } @@ -53,12 +51,12 @@ describe('setWorkflowDefaultView', () => { it('tracks telemetry with correct default_view', () => { const workflow = createMockLoadedWorkflow() setWorkflowDefaultView(workflow, true) - expect(mockTrackDefaultViewSet).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackDefaultViewSet).toHaveBeenCalledWith({ default_view: 'app' }) setWorkflowDefaultView(workflow, false) - expect(mockTrackDefaultViewSet).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackDefaultViewSet).toHaveBeenCalledWith({ default_view: 'graph' }) }) diff --git a/src/components/builder/useBuilderSave.test.ts b/src/components/builder/useBuilderSave.test.ts index 669f45f33a5..3b65dce5108 100644 --- a/src/components/builder/useBuilderSave.test.ts +++ b/src/components/builder/useBuilderSave.test.ts @@ -2,6 +2,8 @@ import { fromPartial } from '@total-typescript/shoehorn' import { beforeEach, describe, expect, it, vi } from 'vitest' import { ref } from 'vue' +import { useTelemetry } from '@/platform/telemetry' + import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore' import { useAppModeStore } from '@/stores/appModeStore' import { useDialogStore } from '@/stores/dialogStore' @@ -15,8 +17,7 @@ beforeEach(() => { const mockSetMode = vi.hoisted(() => vi.fn()) const mockToastErrorHandler = vi.hoisted(() => vi.fn()) -const mockTrackEnterLinear = vi.hoisted(() => vi.fn()) -const mockTrackDefaultViewSet = vi.hoisted(() => vi.fn()) + const mockSaveWorkflow = vi.hoisted(() => vi.fn<() => Promise>()) const mockSaveWorkflowAs = vi.hoisted(() => vi.fn<() => Promise>() @@ -38,12 +39,7 @@ vi.mock(import('@/composables/useErrorHandling'), () => ({ useErrorHandling: () => ({ toastErrorHandler: mockToastErrorHandler }) })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackEnterLinear: mockTrackEnterLinear, - trackDefaultViewSet: mockTrackDefaultViewSet - }) -})) +vi.mock(import('@/platform/telemetry')) vi.mock( import('@/platform/workflow/core/services/workflowService'), @@ -214,7 +210,7 @@ describe('useBuilderSave', () => { isApp: true } ) - expect(mockTrackDefaultViewSet).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackDefaultViewSet).toHaveBeenCalledWith({ default_view: 'app' }) }) @@ -232,7 +228,7 @@ describe('useBuilderSave', () => { isApp: false } ) - expect(mockTrackDefaultViewSet).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackDefaultViewSet).toHaveBeenCalledWith({ default_view: 'graph' }) }) @@ -243,7 +239,7 @@ describe('useBuilderSave', () => { await onSave('new-name', false) - expect(mockTrackDefaultViewSet).not.toHaveBeenCalled() + expect(useTelemetry()?.trackDefaultViewSet).not.toHaveBeenCalled() expect(useDialogStore().closeDialog).not.toHaveBeenCalled() }) @@ -355,7 +351,7 @@ describe('useBuilderSave', () => { expect(useDialogStore().closeDialog).toHaveBeenCalledWith({ key: SUCCESS_DIALOG_KEY }) - expect(mockTrackEnterLinear).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackEnterLinear).toHaveBeenCalledWith({ source: 'app_builder' }) expect(mockSetMode).toHaveBeenCalledWith('app') diff --git a/src/components/common/WorkflowActionsDropdown.test.ts b/src/components/common/WorkflowActionsDropdown.test.ts index 38409dfc746..1b87236f259 100644 --- a/src/components/common/WorkflowActionsDropdown.test.ts +++ b/src/components/common/WorkflowActionsDropdown.test.ts @@ -4,6 +4,8 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' import { nextTick } from 'vue' import { createI18n } from 'vue-i18n' +import { useTelemetry } from '@/platform/telemetry' + import { KeybindingImpl } from '@/platform/keybindings/keybinding' import { useKeybindingStore } from '@/platform/keybindings/keybindingStore' import { useAppModeStore } from '@/stores/appModeStore' @@ -22,13 +24,10 @@ beforeEach(() => { }) const spies = vi.hoisted(() => ({ - trackUiButtonClicked: vi.fn(), markAsSeen: vi.fn() })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ trackUiButtonClicked: spies.trackUiButtonClicked }) -})) +vi.mock(import('@/platform/telemetry')) vi.mock(import('@/composables/useWorkflowActionsMenu'), async () => { const { ref } = await import('vue') @@ -159,7 +158,7 @@ describe('WorkflowActionsDropdown', () => { expect( screen.getByRole('button', { name: /workflow actions/ }) ).toHaveAttribute('aria-expanded', 'false') - expect(spies.trackUiButtonClicked).not.toHaveBeenCalled() + expect(useTelemetry()?.trackUiButtonClicked).not.toHaveBeenCalled() expect(spies.markAsSeen).not.toHaveBeenCalled() }) @@ -172,7 +171,7 @@ describe('WorkflowActionsDropdown', () => { expect(vi.mocked(useCommandStore().execute)).not.toHaveBeenCalled() expect(active).toHaveAttribute('aria-expanded', 'true') expect(spies.markAsSeen).toHaveBeenCalled() - expect(spies.trackUiButtonClicked).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackUiButtonClicked).toHaveBeenCalledWith({ button_id: 'test', element_group: 'workflow_actions' }) @@ -205,7 +204,7 @@ describe('WorkflowActionsDropdown', () => { expect( screen.getByRole('button', { name: /workflow actions/ }) ).toHaveAttribute('aria-expanded', 'false') - expect(spies.trackUiButtonClicked).not.toHaveBeenCalled() + expect(useTelemetry()?.trackUiButtonClicked).not.toHaveBeenCalled() }) it('lets non-trigger keys bubble past the inactive segment', async () => { diff --git a/src/components/dialog/content/TopUpCreditsDialogContentLegacy.test.ts b/src/components/dialog/content/TopUpCreditsDialogContentLegacy.test.ts index 340316bea41..a5b27ae54e2 100644 --- a/src/components/dialog/content/TopUpCreditsDialogContentLegacy.test.ts +++ b/src/components/dialog/content/TopUpCreditsDialogContentLegacy.test.ts @@ -3,6 +3,8 @@ import { render, screen } from '@testing-library/vue' import { beforeEach, describe, expect, it, vi } from 'vitest' import { createI18n } from 'vue-i18n' +import { useTelemetry } from '@/platform/telemetry' + import { AuthStoreError } from '@/stores/authStore' import { useDialogStore } from '@/stores/dialogStore' @@ -11,8 +13,7 @@ import TopUpCreditsDialogContentLegacy from './TopUpCreditsDialogContentLegacy.v const mockPurchaseCreditsDirect = vi.fn() const mockShowSettings = vi.fn() const mockToastAdd = vi.fn() -const mockTrackTopUpPurchase = vi.fn() -const mockTrackBillingEvent = vi.fn() + const mockIsSubscriptionEnabled = vi.fn(() => true) const mockShouldUseWorkspaceBilling = vi.hoisted(() => ({ value: false })) @@ -48,12 +49,7 @@ vi.mock( }) ) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackApiCreditTopupButtonPurchaseClicked: mockTrackTopUpPurchase, - trackBillingEvent: mockTrackBillingEvent - }) -})) +vi.mock(import('@/platform/telemetry')) const mockClearPendingTopup = vi.hoisted(() => vi.fn()) vi.mock(import('@/composables/billing/usePendingTopup'), () => ({ @@ -185,7 +181,7 @@ describe('TopUpCreditsDialogContentLegacy', () => { renderDialog() await clickBuyCredits() - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'topup', stage: 'failed', outcome: 'failure', @@ -210,7 +206,7 @@ describe('TopUpCreditsDialogContentLegacy', () => { renderDialog() await clickBuyCredits() - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'topup', stage: 'failed', outcome: 'failure', @@ -225,7 +221,7 @@ describe('TopUpCreditsDialogContentLegacy', () => { renderDialog() await clickBuyCredits() - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'topup', stage: 'failed', outcome: 'failure', @@ -239,7 +235,7 @@ describe('TopUpCreditsDialogContentLegacy', () => { renderDialog() await clickBuyCredits() - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'topup', stage: 'failed', outcome: 'failure', diff --git a/src/components/dialog/content/setting/CreditsPanel.test.ts b/src/components/dialog/content/setting/CreditsPanel.test.ts index 10f125ec936..5f4bb29194a 100644 --- a/src/components/dialog/content/setting/CreditsPanel.test.ts +++ b/src/components/dialog/content/setting/CreditsPanel.test.ts @@ -47,9 +47,7 @@ vi.mock( }) ) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ trackHelpResourceClicked: vi.fn() }) -})) +vi.mock(import('@/platform/telemetry')) vi.mock(import('@/composables/useExternalLink'), () => ({ useExternalLink: () => ({ diff --git a/src/components/dialog/content/subscription/CancelSubscriptionDialogContent.test.ts b/src/components/dialog/content/subscription/CancelSubscriptionDialogContent.test.ts index 8962e9d9bf9..45ea1f41a5d 100644 --- a/src/components/dialog/content/subscription/CancelSubscriptionDialogContent.test.ts +++ b/src/components/dialog/content/subscription/CancelSubscriptionDialogContent.test.ts @@ -3,6 +3,8 @@ import { render, screen, waitFor } from '@testing-library/vue' import { beforeEach, describe, expect, it, vi } from 'vitest' import { createI18n } from 'vue-i18n' +import { useTelemetry } from '@/platform/telemetry' + import enMessages from '@/locales/en/main.json' with { type: 'json' } import { useDialogStore } from '@/stores/dialogStore' @@ -53,7 +55,7 @@ const mockFetchStatus = vi.hoisted(() => vi.fn()) const mockToastAdd = vi.hoisted(() => vi.fn()) const mockTier = vi.hoisted(() => ({ value: 'STANDARD' as string | null })) -const mockTrackCancellation = vi.hoisted(() => vi.fn()) + const mockShouldUseWorkspaceBilling = vi.hoisted(() => ({ value: false })) const mockCanCancel = vi.hoisted(() => ({ value: true })) const mockCanManageSubscriptionLifecycle = vi.hoisted(() => ({ value: true })) @@ -101,11 +103,7 @@ vi.mock( }) ) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackSubscriptionCancellation: mockTrackCancellation - }) -})) +vi.mock(import('@/platform/telemetry')) vi.mock( import('primevue/usetoast'), // eslint-disable-line primevue-removal/no-imports @@ -158,7 +156,9 @@ describe('CancelSubscriptionDialogContent', () => { renderComponent() - expect(mockTrackCancellation).toHaveBeenCalledWith('flow_opened', { + expect( + useTelemetry()?.trackSubscriptionCancellation + ).toHaveBeenCalledWith('flow_opened', { source: 'cancel_plan_menu', current_tier: 'standard', cycle: 'yearly', @@ -171,10 +171,9 @@ describe('CancelSubscriptionDialogContent', () => { renderComponent({ flowAlreadyOpened: true }) - expect(mockTrackCancellation).not.toHaveBeenCalledWith( - 'flow_opened', - expect.anything() - ) + expect( + useTelemetry()?.trackSubscriptionCancellation + ).not.toHaveBeenCalledWith('flow_opened', expect.anything()) }) it('tracks confirmed before the cancel request and no abandoned on success', async () => { @@ -190,14 +189,15 @@ describe('CancelSubscriptionDialogContent', () => { expect(vi.mocked(useDialogStore().closeDialog)).toHaveBeenCalled() ) unmount() - expect(mockTrackCancellation).toHaveBeenCalledWith( + expect( + useTelemetry()?.trackSubscriptionCancellation + ).toHaveBeenCalledWith( 'confirmed', expect.objectContaining({ current_tier: 'standard' }) ) - expect(mockTrackCancellation).not.toHaveBeenCalledWith( - 'abandoned', - expect.anything() - ) + expect( + useTelemetry()?.trackSubscriptionCancellation + ).not.toHaveBeenCalledWith('abandoned', expect.anything()) }) it('tracks confirmed and failed with message-carrying rejection values', async () => { @@ -210,15 +210,16 @@ describe('CancelSubscriptionDialogContent', () => { ) await waitFor(() => - expect(mockTrackCancellation).toHaveBeenCalledWith( + expect( + useTelemetry()?.trackSubscriptionCancellation + ).toHaveBeenCalledWith( 'failed', expect.not.objectContaining({ error_message: expect.anything() }) ) ) - expect(mockTrackCancellation).toHaveBeenCalledWith( - 'confirmed', - expect.anything() - ) + expect( + useTelemetry()?.trackSubscriptionCancellation + ).toHaveBeenCalledWith('confirmed', expect.anything()) }) it('leaves workspace terminal failure telemetry to the billing poller', async () => { @@ -236,10 +237,9 @@ describe('CancelSubscriptionDialogContent', () => { expect.objectContaining({ severity: 'error' }) ) ) - expect(mockTrackCancellation).not.toHaveBeenCalledWith( - 'failed', - expect.anything() - ) + expect( + useTelemetry()?.trackSubscriptionCancellation + ).not.toHaveBeenCalledWith('failed', expect.anything()) }) it('tracks abandoned when the user keeps the subscription', async () => { @@ -254,7 +254,9 @@ describe('CancelSubscriptionDialogContent', () => { key: 'cancel-subscription' }) unmount() - expect(mockTrackCancellation).toHaveBeenCalledWith( + expect( + useTelemetry()?.trackSubscriptionCancellation + ).toHaveBeenCalledWith( 'abandoned', expect.objectContaining({ current_tier: 'standard' }) ) @@ -265,10 +267,12 @@ describe('CancelSubscriptionDialogContent', () => { mockSubscription.value = null const { unmount } = renderComponent() - mockTrackCancellation.mockClear() + vi.mocked(useTelemetry()?.trackSubscriptionCancellation)?.mockClear() unmount() - expect(mockTrackCancellation).toHaveBeenCalledWith( + expect( + useTelemetry()?.trackSubscriptionCancellation + ).toHaveBeenCalledWith( 'abandoned', expect.objectContaining({ current_tier: 'standard' }) ) @@ -330,10 +334,9 @@ describe('CancelSubscriptionDialogContent', () => { ) expect(mockCancelSubscription).not.toHaveBeenCalled() - expect(mockTrackCancellation).not.toHaveBeenCalledWith( - 'confirmed', - expect.anything() - ) + expect( + useTelemetry()?.trackSubscriptionCancellation + ).not.toHaveBeenCalledWith('confirmed', expect.anything()) expect(mockToastAdd).not.toHaveBeenCalled() expect(vi.mocked(useDialogStore().closeDialog)).not.toHaveBeenCalled() }) @@ -367,10 +370,9 @@ describe('CancelSubscriptionDialogContent', () => { ) expect(mockCancelSubscription).not.toHaveBeenCalled() - expect(mockTrackCancellation).not.toHaveBeenCalledWith( - 'confirmed', - expect.anything() - ) + expect( + useTelemetry()?.trackSubscriptionCancellation + ).not.toHaveBeenCalledWith('confirmed', expect.anything()) }) it('does not track cancellation failure when status refresh fails after cancellation succeeds', async () => { @@ -392,14 +394,15 @@ describe('CancelSubscriptionDialogContent', () => { key: 'cancel-subscription' }) expect( - mockTrackCancellation.mock.calls.some(([stage]) => stage === 'failed') + vi + .mocked(useTelemetry()?.trackSubscriptionCancellation) + ?.mock.calls.some(([stage]) => stage === 'failed') ).toBe(false) unmount() - expect(mockTrackCancellation).not.toHaveBeenCalledWith( - 'abandoned', - expect.anything() - ) + expect( + useTelemetry()?.trackSubscriptionCancellation + ).not.toHaveBeenCalledWith('abandoned', expect.anything()) }) }) diff --git a/src/components/graph/selectionToolbox/InfoButton.test.ts b/src/components/graph/selectionToolbox/InfoButton.test.ts index 282c77e5fb2..c9bd02bfe8a 100644 --- a/src/components/graph/selectionToolbox/InfoButton.test.ts +++ b/src/components/graph/selectionToolbox/InfoButton.test.ts @@ -5,12 +5,13 @@ import Tooltip from 'primevue/tooltip' import { beforeEach, describe, expect, it, vi } from 'vitest' import { createI18n } from 'vue-i18n' +import { useTelemetry } from '@/platform/telemetry' + import InfoButton from '@/components/graph/selectionToolbox/InfoButton.vue' import Button from '@/components/ui/button/Button.vue' -const { openNodeInfoMock, trackUiButtonClickedMock } = vi.hoisted(() => ({ - openNodeInfoMock: vi.fn(), - trackUiButtonClickedMock: vi.fn() +const { openNodeInfoMock } = vi.hoisted(() => ({ + openNodeInfoMock: vi.fn() })) vi.mock(import('@/composables/graph/useSelectionState'), () => ({ @@ -19,11 +20,7 @@ vi.mock(import('@/composables/graph/useSelectionState'), () => ({ }) })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackUiButtonClicked: trackUiButtonClickedMock - }) -})) +vi.mock(import('@/platform/telemetry')) describe('InfoButton', () => { const i18n = createI18n({ @@ -63,7 +60,7 @@ describe('InfoButton', () => { await clickNodeInfoButton() expect(openNodeInfoMock).toHaveBeenCalled() - expect(trackUiButtonClickedMock).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackUiButtonClicked).toHaveBeenCalledWith({ button_id: 'selection_toolbox_node_info_opened', element_group: 'selection_toolbox' }) @@ -76,6 +73,6 @@ describe('InfoButton', () => { await clickNodeInfoButton() expect(openNodeInfoMock).toHaveBeenCalled() - expect(trackUiButtonClickedMock).not.toHaveBeenCalled() + expect(useTelemetry()?.trackUiButtonClicked).not.toHaveBeenCalled() }) }) diff --git a/src/components/helpcenter/HelpCenterMenuContent.test.ts b/src/components/helpcenter/HelpCenterMenuContent.test.ts index 1c31441c69e..dc6b5471f4b 100644 --- a/src/components/helpcenter/HelpCenterMenuContent.test.ts +++ b/src/components/helpcenter/HelpCenterMenuContent.test.ts @@ -44,13 +44,7 @@ vi.mock(import('@/composables/useExternalLink'), () => ({ }) })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackHelpResourceClicked: vi.fn(), - trackHelpCenterOpened: vi.fn(), - trackHelpCenterClosed: vi.fn() - }) -})) +vi.mock(import('@/platform/telemetry')) vi.mock(import('@/utils/envUtil'), () => ({ electronAPI: () => null diff --git a/src/components/rightSidePanel/RightSidePanel.test.ts b/src/components/rightSidePanel/RightSidePanel.test.ts index b7bd926953e..205ce60dc5e 100644 --- a/src/components/rightSidePanel/RightSidePanel.test.ts +++ b/src/components/rightSidePanel/RightSidePanel.test.ts @@ -32,9 +32,7 @@ vi.mock(import('@/composables/graph/useGraphHierarchy'), () => ({ useGraphHierarchy: () => ({ findParentGroup: vi.fn(() => null) }) })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => undefined -})) +vi.mock(import('@/platform/telemetry')) function createPanelI18n() { return createI18n({ diff --git a/src/components/rightSidePanel/errors/ErrorNodeCard.test.ts b/src/components/rightSidePanel/errors/ErrorNodeCard.test.ts index 75889bc2426..4fb0630e40e 100644 --- a/src/components/rightSidePanel/errors/ErrorNodeCard.test.ts +++ b/src/components/rightSidePanel/errors/ErrorNodeCard.test.ts @@ -5,6 +5,8 @@ import PrimeVue from 'primevue/config' import { beforeEach, describe, expect, it, vi } from 'vitest' import { createI18n } from 'vue-i18n' +import { useTelemetry } from '@/platform/telemetry' + import { resolveRunErrorMessage } from '@/platform/errorCatalog/errorMessageResolver' import { useCommandStore } from '@/stores/commandStore' import { useSystemStatsStore } from '@/stores/systemStatsStore' @@ -39,14 +41,7 @@ vi.mock(import('@/utils/errorReportUtil'), () => ({ generateErrorReport: (data: unknown) => mockGenerateErrorReport(data) })) -const mockTrackHelpResourceClicked = vi.fn() - -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: vi.fn(() => ({ - trackUiButtonClicked: vi.fn(), - trackHelpResourceClicked: mockTrackHelpResourceClicked - })) -})) +vi.mock(import('@/platform/telemetry')) vi.mock(import('@/composables/useExternalLink'), () => ({ useExternalLink: vi.fn(() => ({ @@ -404,7 +399,7 @@ describe('ErrorNodeCard.vue', () => { expect(useCommandStore().execute).toHaveBeenCalledWith( 'Comfy.ContactSupport' ) - expect(mockTrackHelpResourceClicked).toHaveBeenCalledWith( + expect(useTelemetry()?.trackHelpResourceClicked).toHaveBeenCalledWith( expect.objectContaining({ resource_type: 'help_feedback', source: 'error_dialog' diff --git a/src/components/rightSidePanel/parameters/SectionWidgets.test.ts b/src/components/rightSidePanel/parameters/SectionWidgets.test.ts index 423c880f4c4..7504bea5561 100644 --- a/src/components/rightSidePanel/parameters/SectionWidgets.test.ts +++ b/src/components/rightSidePanel/parameters/SectionWidgets.test.ts @@ -5,6 +5,8 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' import { defineComponent } from 'vue' import { createI18n } from 'vue-i18n' +import { useTelemetry } from '@/platform/telemetry' + import { promoteValueWidgetViaSubgraphInput } from '@/core/graph/subgraph/promotionUtils' import { LGraphNode } from '@/lib/litegraph/src/litegraph' import type { LGraph } from '@/lib/litegraph/src/litegraph' @@ -23,19 +25,11 @@ import { getExecutionIdByNode } from '@/utils/graphTraversalUtil' import SectionWidgets from './SectionWidgets.vue' -const { mockTrackUiButtonClicked } = vi.hoisted(() => ({ - mockTrackUiButtonClicked: vi.fn() -})) - const setDirty = vi.fn() const getNodeById = vi.fn() const animateToBounds = vi.fn() -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackUiButtonClicked: mockTrackUiButtonClicked - }) -})) +vi.mock(import('@/platform/telemetry')) const WidgetItemStub = defineComponent({ inheritAttrs: false, @@ -238,7 +232,9 @@ describe('SectionWidgets', () => { await user.click(screen.getByRole('button', { name: 'Locate' })) - expect(mockTrackUiButtonClicked).toHaveBeenCalledExactlyOnceWith({ + expect( + useTelemetry()?.trackUiButtonClicked + ).toHaveBeenCalledExactlyOnceWith({ button_id: 'right_side_panel_locate_node_clicked', element_group: 'right_side_panel_nodes' }) @@ -270,7 +266,9 @@ describe('SectionWidgets', () => { await user.click(screen.getByRole('button', { name: 'Reset all' })) - expect(mockTrackUiButtonClicked).toHaveBeenCalledExactlyOnceWith({ + expect( + useTelemetry()?.trackUiButtonClicked + ).toHaveBeenCalledExactlyOnceWith({ button_id: 'right_side_panel_reset_all_parameters_clicked', element_group: 'right_side_panel_nodes' }) diff --git a/src/components/rightSidePanel/parameters/WidgetActions.test.ts b/src/components/rightSidePanel/parameters/WidgetActions.test.ts index a67b935afbd..a10ba64a0d7 100644 --- a/src/components/rightSidePanel/parameters/WidgetActions.test.ts +++ b/src/components/rightSidePanel/parameters/WidgetActions.test.ts @@ -6,6 +6,8 @@ import type { Slots } from 'vue' import { h } from 'vue' import { createI18n } from 'vue-i18n' +import { useTelemetry } from '@/platform/telemetry' + import { promoteWidget } from '@/core/graph/subgraph/promotionUtils' import type { LGraphNode } from '@/lib/litegraph/src/litegraph' import type { SubgraphNode } from '@/lib/litegraph/src/subgraph/SubgraphNode' @@ -18,19 +20,11 @@ import { widgetId } from '@/types/widgetId' import WidgetActions from './WidgetActions.vue' -const { mockTrackWidgetFavoriteToggled } = vi.hoisted(() => ({ - mockTrackWidgetFavoriteToggled: vi.fn() -})) - vi.mock(import('@/core/graph/subgraph/promotionUtils'), () => ({ promoteWidget: vi.fn() })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackWidgetFavoriteToggled: mockTrackWidgetFavoriteToggled - }) -})) +vi.mock(import('@/platform/telemetry')) vi.mock(import('@/services/dialogService'), () => ({ useDialogService: () => ({ @@ -228,7 +222,9 @@ describe('WidgetActions', () => { await user.click(screen.getByRole('button', { name: /Favorite/ })) - expect(mockTrackWidgetFavoriteToggled).toHaveBeenCalledExactlyOnceWith({ + expect( + useTelemetry()?.trackWidgetFavoriteToggled + ).toHaveBeenCalledExactlyOnceWith({ node_type: 'TestNode', widget_name: 'test_widget', widget_type: 'number', @@ -250,7 +246,9 @@ describe('WidgetActions', () => { await user.click(screen.getByRole('button', { name: /Unfavorite/ })) - expect(mockTrackWidgetFavoriteToggled).toHaveBeenCalledExactlyOnceWith({ + expect( + useTelemetry()?.trackWidgetFavoriteToggled + ).toHaveBeenCalledExactlyOnceWith({ node_type: 'TestNode', widget_name: 'test_widget', widget_type: 'number', diff --git a/src/components/rightSidePanel/rightSidePanelTabTelemetry.test.ts b/src/components/rightSidePanel/rightSidePanelTabTelemetry.test.ts index 24f7fff5df9..51c58c96fe1 100644 --- a/src/components/rightSidePanel/rightSidePanelTabTelemetry.test.ts +++ b/src/components/rightSidePanel/rightSidePanelTabTelemetry.test.ts @@ -1,14 +1,8 @@ import { describe, expect, it, vi } from 'vitest' -const { mockTrackUiButtonClicked } = vi.hoisted(() => ({ - mockTrackUiButtonClicked: vi.fn() -})) +import { useTelemetry } from '@/platform/telemetry' -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackUiButtonClicked: mockTrackUiButtonClicked - }) -})) +vi.mock(import('@/platform/telemetry')) import { trackRightSidePanelTabOpened } from './rightSidePanelTabTelemetry' @@ -16,7 +10,9 @@ describe('trackRightSidePanelTabOpened', () => { it('tracks opening the settings tab', () => { trackRightSidePanelTabOpened('settings') - expect(mockTrackUiButtonClicked).toHaveBeenCalledExactlyOnceWith({ + expect( + useTelemetry()?.trackUiButtonClicked + ).toHaveBeenCalledExactlyOnceWith({ button_id: 'right_side_panel_settings_tab_opened', element_group: 'right_side_panel' }) @@ -25,7 +21,9 @@ describe('trackRightSidePanelTabOpened', () => { it('tracks opening the info tab', () => { trackRightSidePanelTabOpened('info') - expect(mockTrackUiButtonClicked).toHaveBeenCalledExactlyOnceWith({ + expect( + useTelemetry()?.trackUiButtonClicked + ).toHaveBeenCalledExactlyOnceWith({ button_id: 'right_side_panel_info_tab_opened', element_group: 'right_side_panel' }) @@ -36,7 +34,7 @@ describe('trackRightSidePanelTabOpened', () => { (tab) => { trackRightSidePanelTabOpened(tab) - expect(mockTrackUiButtonClicked).not.toHaveBeenCalled() + expect(useTelemetry()?.trackUiButtonClicked).not.toHaveBeenCalled() } ) }) diff --git a/src/components/sidebar/SideToolbar.test.ts b/src/components/sidebar/SideToolbar.test.ts index d381a73e6f0..1550f544728 100644 --- a/src/components/sidebar/SideToolbar.test.ts +++ b/src/components/sidebar/SideToolbar.test.ts @@ -5,6 +5,8 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' import type { ComponentProps } from 'vue-component-type-helpers' import { createI18n } from 'vue-i18n' +import { useTelemetry } from '@/platform/telemetry' + import { useSettingStore } from '@/platform/settings/settingStore' import { useCommandStore } from '@/stores/commandStore' import { useUserStore } from '@/stores/userStore' @@ -29,7 +31,6 @@ beforeEach(() => { }) const spies = vi.hoisted(() => ({ - trackUiButtonClicked: vi.fn(), toggleAssets: vi.fn() })) @@ -39,9 +40,7 @@ vi.mock(import('@/platform/distribution/types'), () => ({ isNightly: false })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ trackUiButtonClicked: spies.trackUiButtonClicked }) -})) +vi.mock(import('@/platform/telemetry')) const i18n = createI18n({ legacy: false, @@ -148,7 +147,7 @@ describe('SideToolbar', () => { await user.click(screen.getByRole('button', { name: 'Assets' })) - expect(spies.trackUiButtonClicked).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackUiButtonClicked).toHaveBeenCalledWith({ button_id: 'sidebar_tab_assets_media_selected', element_group: 'sidebar' }) diff --git a/src/components/topbar/CurrentUserPopoverLegacy.test.ts b/src/components/topbar/CurrentUserPopoverLegacy.test.ts index 3c5f82e6675..a70abe4a721 100644 --- a/src/components/topbar/CurrentUserPopoverLegacy.test.ts +++ b/src/components/topbar/CurrentUserPopoverLegacy.test.ts @@ -119,11 +119,7 @@ vi.mock(import('@/composables/useExternalLink'), () => ({ })) })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: vi.fn(() => ({ - trackAddApiCreditButtonClicked: vi.fn() - })) -})) +vi.mock(import('@/platform/telemetry')) describe('CurrentUserPopoverLegacy', () => { beforeEach(() => { diff --git a/src/composables/auth/useAuthActions.test.ts b/src/composables/auth/useAuthActions.test.ts index 141d2546a28..c7258379940 100644 --- a/src/composables/auth/useAuthActions.test.ts +++ b/src/composables/auth/useAuthActions.test.ts @@ -12,6 +12,8 @@ import type { UserCredential } from 'firebase/auth' import { fromPartial } from '@total-typescript/shoehorn' import { beforeEach, describe, expect, it, vi } from 'vitest' +import { useTelemetry } from '@/platform/telemetry' + import { useAuthActions } from '@/composables/auth/useAuthActions' import enLocale from '@/locales/en/main.json' import type { ComfyWorkflow } from '@/platform/workflow/management/stores/workflowStore' @@ -35,7 +37,7 @@ const mockDialogService = vi.hoisted(() => ({ })) const mockToastErrorHandler = vi.hoisted(() => vi.fn()) -const mockTrackAuthFailed = vi.hoisted(() => vi.fn()) + const mockStartPendingTopup = vi.hoisted(() => vi.fn()) const mockDistributionState = vi.hoisted(() => ({ isCloud: false })) const mockBillingState = vi.hoisted(() => ({ @@ -77,11 +79,7 @@ vi.mock(import('@/platform/distribution/types'), () => ({ } })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: vi.fn(() => ({ - trackAuthFailed: mockTrackAuthFailed - })) -})) +vi.mock(import('@/platform/telemetry')) vi.mock(import('@/composables/billing/usePendingTopup'), () => ({ usePendingTopup: () => ({ startPendingTopup: mockStartPendingTopup }) @@ -386,7 +384,7 @@ describe('useAuthActions auth flow error telemetry', () => { signInWithEmail('user@example.com', 'password') ).resolves.toBeUndefined() - expect(mockTrackAuthFailed).toHaveBeenCalledExactlyOnceWith({ + expect(useTelemetry()?.trackAuthFailed).toHaveBeenCalledExactlyOnceWith({ error_code: 'auth/user-not-found', auth_action: 'email_sign_in' }) @@ -406,7 +404,7 @@ describe('useAuthActions auth flow error telemetry', () => { signUpWithEmail('user@example.com', 'password') ).resolves.toBeUndefined() - expect(mockTrackAuthFailed).toHaveBeenCalledExactlyOnceWith({ + expect(useTelemetry()?.trackAuthFailed).toHaveBeenCalledExactlyOnceWith({ error_code: 'unknown', auth_action: 'email_sign_up' }) @@ -419,7 +417,7 @@ describe('useAuthActions auth flow error telemetry', () => { await expect(signInWithGoogle({ isNewUser: true })).resolves.toBeUndefined() - expect(mockTrackAuthFailed).toHaveBeenCalledExactlyOnceWith({ + expect(useTelemetry()?.trackAuthFailed).toHaveBeenCalledExactlyOnceWith({ error_code: 'auth/popup-closed-by-user', auth_action: 'google_sign_up' }) @@ -432,7 +430,7 @@ describe('useAuthActions auth flow error telemetry', () => { await expect(signInWithGithub({ isNewUser: true })).resolves.toBeUndefined() - expect(mockTrackAuthFailed).toHaveBeenCalledExactlyOnceWith({ + expect(useTelemetry()?.trackAuthFailed).toHaveBeenCalledExactlyOnceWith({ error_code: 'auth/popup-closed-by-user', auth_action: 'github_sign_up' }) @@ -445,7 +443,7 @@ describe('useAuthActions auth flow error telemetry', () => { await logout() - expect(mockTrackAuthFailed).not.toHaveBeenCalled() + expect(useTelemetry()?.trackAuthFailed).not.toHaveBeenCalled() }) }) diff --git a/src/composables/canvas/visibleCanvasViewport.test.ts b/src/composables/canvas/visibleCanvasViewport.test.ts index 00d331f95f9..a1052359479 100644 --- a/src/composables/canvas/visibleCanvasViewport.test.ts +++ b/src/composables/canvas/visibleCanvasViewport.test.ts @@ -5,9 +5,7 @@ import { useAgentPanelStore } from '@/workbench/extensions/agent/stores/agent/ag import { visibleCanvasViewport } from './visibleCanvasViewport' -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => undefined -})) +vi.mock(import('@/platform/telemetry')) describe('visibleCanvasViewport', () => { beforeEach(() => { diff --git a/src/composables/useCoreCommands.test.ts b/src/composables/useCoreCommands.test.ts index c46da96a7ae..a0badf8d003 100644 --- a/src/composables/useCoreCommands.test.ts +++ b/src/composables/useCoreCommands.test.ts @@ -1,6 +1,8 @@ import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore' import { beforeEach, describe, expect, it, vi } from 'vitest' +import { useTelemetry } from '@/platform/telemetry' + import { useCoreCommands } from '@/composables/useCoreCommands' import { useExternalLink } from '@/composables/useExternalLink' import type { LGraphNode } from '@/lib/litegraph/src/litegraph' @@ -116,14 +118,7 @@ vi.mock(import('@/services/litegraphService'), () => ({ })) })) -const mockTrackHelpResourceClicked = vi.hoisted(() => vi.fn()) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: vi.fn(() => ({ - trackHelpResourceClicked: mockTrackHelpResourceClicked, - trackRunButton: vi.fn(), - trackWorkflowExecution: vi.fn() - })) -})) +vi.mock(import('@/platform/telemetry')) const mockShowAbout = vi.hoisted(() => vi.fn()) const mockShowSettings = vi.hoisted(() => vi.fn()) @@ -746,7 +741,7 @@ describe('useCoreCommands', () => { it('Comfy.Help.OpenComfyUIIssues opens the GitHub issues URL and tracks telemetry', async () => { await findCmd('Comfy.Help.OpenComfyUIIssues').function() - expect(mockTrackHelpResourceClicked).toHaveBeenCalledWith( + expect(useTelemetry()?.trackHelpResourceClicked).toHaveBeenCalledWith( expect.objectContaining({ resource_type: 'github', is_external: true, @@ -759,7 +754,7 @@ describe('useCoreCommands', () => { it('Comfy.Help.OpenComfyOrgDiscord opens the Discord URL and tracks telemetry', async () => { await findCmd('Comfy.Help.OpenComfyOrgDiscord').function() - expect(mockTrackHelpResourceClicked).toHaveBeenCalledWith( + expect(useTelemetry()?.trackHelpResourceClicked).toHaveBeenCalledWith( expect.objectContaining({ resource_type: 'discord' }) diff --git a/src/composables/useTemplateFiltering.test.ts b/src/composables/useTemplateFiltering.test.ts index 6a99235d5a6..87e23c64d3a 100644 --- a/src/composables/useTemplateFiltering.test.ts +++ b/src/composables/useTemplateFiltering.test.ts @@ -6,6 +6,8 @@ import { nextTick, ref } from 'vue' import { fromPartial } from '@total-typescript/shoehorn' import { until } from '@vueuse/core' +import { useTelemetry } from '@/platform/telemetry' + import type { TemplateInfo } from '@/platform/workflow/templates/types/template' import { TemplateIncludeOnDistributionEnum } from '@/platform/workflow/templates/types/template' import { useTemplateFiltering } from '@/composables/useTemplateFiltering' @@ -17,13 +19,7 @@ let defaultRankingStore: ReturnType let mockSystemStatsStore: ReturnType -const trackTemplateFilterChanged = vi.hoisted(() => vi.fn()) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: vi.fn(() => ({ - trackTemplateFilterChanged, - trackSearchQuery: vi.fn() - })) -})) +vi.mock(import('@/platform/telemetry')) vi.mock( import('@/platform/telemetry/searchQuery/useSearchQueryTracking'), @@ -612,7 +608,7 @@ describe('useTemplateFiltering', () => { await vi.runOnlyPendingTimersAsync() expect( - trackTemplateFilterChanged, + useTelemetry()?.trackTemplateFilterChanged, 'telemetry must report the search default, not the persisted browse sort' ).toHaveBeenLastCalledWith( expect.objectContaining({ sort_by: 'popular' }) diff --git a/src/platform/auth/unified/remintRetry.test.ts b/src/platform/auth/unified/remintRetry.test.ts index 33c76045aa1..69a232f1f38 100644 --- a/src/platform/auth/unified/remintRetry.test.ts +++ b/src/platform/auth/unified/remintRetry.test.ts @@ -3,22 +3,19 @@ import type { AxiosAdapter } from 'axios' import axios, { AxiosError } from 'axios' import { beforeEach, describe, expect, it, vi } from 'vitest' +import { useTelemetry } from '@/platform/telemetry' + import { attachUnifiedRemintInterceptor, fetchWithUnifiedRemint } from '@/platform/auth/unified/remintRetry' -const { mockRemint, mockTrackUnifiedAuthRetry, flagState } = vi.hoisted(() => ({ +const { mockRemint, flagState } = vi.hoisted(() => ({ mockRemint: vi.fn(), - mockTrackUnifiedAuthRetry: vi.fn(), flagState: { unifiedCloudAuthEnabled: true } })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackUnifiedAuthRetry: mockTrackUnifiedAuthRetry - }) -})) +vi.mock(import('@/platform/telemetry')) vi.mock(import('@/composables/useFeatureFlags'), () => ({ useFeatureFlags: () => ({ @@ -73,7 +70,9 @@ describe('fetchWithUnifiedRemint', () => { const retryHeaders = new Headers(mockFetch.mock.calls[1][1].headers) expect(retryHeaders.get('Authorization')).toBe('Bearer tokenB') expect(retryHeaders.get('Comfy-User')).toBe('u1') - expect(mockTrackUnifiedAuthRetry).toHaveBeenCalledExactlyOnceWith({ + expect( + useTelemetry()?.trackUnifiedAuthRetry + ).toHaveBeenCalledExactlyOnceWith({ transport: 'fetch', outcome: 'succeeded', final_status: 200 @@ -96,7 +95,9 @@ describe('fetchWithUnifiedRemint', () => { expect(result).toBe(secondUnauthorized) expect(mockFetch).toHaveBeenCalledTimes(2) expect(mockRemint).toHaveBeenCalledTimes(1) - expect(mockTrackUnifiedAuthRetry).toHaveBeenCalledExactlyOnceWith({ + expect( + useTelemetry()?.trackUnifiedAuthRetry + ).toHaveBeenCalledExactlyOnceWith({ transport: 'fetch', outcome: 'failed', final_status: 401, @@ -116,7 +117,7 @@ describe('fetchWithUnifiedRemint', () => { expect(result).toBe(unauthorized) expect(mockFetch).toHaveBeenCalledTimes(1) expect(mockRemint).not.toHaveBeenCalled() - expect(mockTrackUnifiedAuthRetry).not.toHaveBeenCalled() + expect(useTelemetry()?.trackUnifiedAuthRetry).not.toHaveBeenCalled() }) it('does not retry a non-401 response', async () => { @@ -147,7 +148,9 @@ describe('fetchWithUnifiedRemint', () => { expect(result).toBe(unauthorized) expect(mockFetch).toHaveBeenCalledTimes(1) expect(mockRemint).toHaveBeenCalledTimes(1) - expect(mockTrackUnifiedAuthRetry).toHaveBeenCalledExactlyOnceWith({ + expect( + useTelemetry()?.trackUnifiedAuthRetry + ).toHaveBeenCalledExactlyOnceWith({ transport: 'fetch', outcome: 'failed', final_status: 401, @@ -205,7 +208,9 @@ describe('fetchWithUnifiedRemint', () => { expect(result).toBe(unauthorized) expect(mockFetch).toHaveBeenCalledTimes(1) expect(mockRemint).not.toHaveBeenCalled() - expect(mockTrackUnifiedAuthRetry).toHaveBeenCalledExactlyOnceWith({ + expect( + useTelemetry()?.trackUnifiedAuthRetry + ).toHaveBeenCalledExactlyOnceWith({ transport: 'fetch', outcome: 'failed', final_status: 401, @@ -245,7 +250,9 @@ describe('fetchWithUnifiedRemint', () => { expect(result).toBe(unauthorized) expect(mockFetch).toHaveBeenCalledTimes(1) expect(mockRemint).not.toHaveBeenCalled() - expect(mockTrackUnifiedAuthRetry).toHaveBeenCalledExactlyOnceWith({ + expect( + useTelemetry()?.trackUnifiedAuthRetry + ).toHaveBeenCalledExactlyOnceWith({ transport: 'fetch', outcome: 'failed', final_status: 401, @@ -350,7 +357,9 @@ describe('attachUnifiedRemintInterceptor', () => { expect(String(adapter.mock.calls[1][0].headers.Authorization)).toBe( 'Bearer tokenB' ) - expect(mockTrackUnifiedAuthRetry).toHaveBeenCalledExactlyOnceWith({ + expect( + useTelemetry()?.trackUnifiedAuthRetry + ).toHaveBeenCalledExactlyOnceWith({ transport: 'axios', outcome: 'succeeded', final_status: 200 @@ -369,7 +378,9 @@ describe('attachUnifiedRemintInterceptor', () => { expect(adapter).toHaveBeenCalledTimes(2) expect(mockRemint).toHaveBeenCalledTimes(1) - expect(mockTrackUnifiedAuthRetry).toHaveBeenCalledExactlyOnceWith({ + expect( + useTelemetry()?.trackUnifiedAuthRetry + ).toHaveBeenCalledExactlyOnceWith({ transport: 'axios', outcome: 'failed', final_status: 401, @@ -389,7 +400,7 @@ describe('attachUnifiedRemintInterceptor', () => { expect(adapter).toHaveBeenCalledTimes(1) expect(mockRemint).not.toHaveBeenCalled() - expect(mockTrackUnifiedAuthRetry).not.toHaveBeenCalled() + expect(useTelemetry()?.trackUnifiedAuthRetry).not.toHaveBeenCalled() }) it('does not re-mint a request flagged __skipUnifiedRemint (acceptInvite)', async () => { diff --git a/src/platform/cloud/onboarding/CloudSignupView.test.ts b/src/platform/cloud/onboarding/CloudSignupView.test.ts index 632a31bd452..76133ffbf20 100644 --- a/src/platform/cloud/onboarding/CloudSignupView.test.ts +++ b/src/platform/cloud/onboarding/CloudSignupView.test.ts @@ -23,9 +23,7 @@ vi.mock( vi.mock(import('@comfyorg/account/webviewDetection'), () => ({ isEmbeddedWebView: () => false })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => undefined -})) +vi.mock(import('@/platform/telemetry')) const inChina = vi.hoisted(() => ({ value: false, diff --git a/src/platform/cloud/subscription/components/PricingTable.test.ts b/src/platform/cloud/subscription/components/PricingTable.test.ts index 1ab8e8052b6..9fa999aafea 100644 --- a/src/platform/cloud/subscription/components/PricingTable.test.ts +++ b/src/platform/cloud/subscription/components/PricingTable.test.ts @@ -5,6 +5,8 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' import { computed, nextTick, ref } from 'vue' import { createI18n } from 'vue-i18n' +import { useTelemetry } from '@/platform/telemetry' + import PricingTable from '@/platform/cloud/subscription/components/PricingTable.vue' import Button from '@/components/ui/button/Button.vue' import type { IngestSubscriptionTier } from '@/platform/cloud/subscription/constants/tierPricing' @@ -28,8 +30,6 @@ const mockSubscriptionTier = ref(null) const mockSubscriptionDuration = ref<'MONTHLY' | 'ANNUAL'>('MONTHLY') const mockAccessBillingPortal = vi.fn() const mockReportError = vi.fn() -const mockTrackBeginCheckout = vi.fn() -const mockTrackBillingEvent = vi.fn() const mockGetAuthHeader = vi.fn(() => Promise.resolve({ Authorization: 'Bearer test-token' as const }) @@ -114,12 +114,7 @@ vi.mock(import('@/composables/useErrorHandling'), () => ({ }) })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackBeginCheckout: mockTrackBeginCheckout, - trackBillingEvent: mockTrackBillingEvent - }) -})) +vi.mock(import('@/platform/telemetry')) vi.mock( import('@/platform/telemetry/utils/checkoutAttribution'), @@ -265,7 +260,7 @@ describe('PricingTable', () => { await userEvent.click(creatorButton!) await flushPromises() - expect(mockTrackBeginCheckout).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBeginCheckout).toHaveBeenCalledWith({ user_id: 'user-123', tier: 'creator', cycle: 'yearly', @@ -351,7 +346,7 @@ describe('PricingTable', () => { expect( window.localStorage.getItem(PENDING_SUBSCRIPTION_CHECKOUT_STORAGE_KEY) ).toBeNull() - expect(mockTrackBeginCheckout).not.toHaveBeenCalled() + expect(useTelemetry()?.trackBeginCheckout).not.toHaveBeenCalled() }) it('should use the latest userId value when it changes after mount', async () => { @@ -371,8 +366,8 @@ describe('PricingTable', () => { await userEvent.click(creatorButton!) await flushPromises() - expect(mockTrackBeginCheckout).toHaveBeenCalledTimes(1) - expect(mockTrackBeginCheckout).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBeginCheckout).toHaveBeenCalledTimes(1) + expect(useTelemetry()?.trackBeginCheckout).toHaveBeenCalledWith({ user_id: 'user-late', tier: 'creator', cycle: 'yearly', @@ -467,7 +462,7 @@ describe('PricingTable', () => { await userEvent.click(subscribeButton!) await flushPromises() - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'subscription_checkout', stage: 'failed', outcome: 'failure', @@ -496,7 +491,7 @@ describe('PricingTable', () => { await userEvent.click(subscribeButton!) await flushPromises() - expect(mockTrackBillingEvent).toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ failure_category: 'network' }) ) }) diff --git a/src/platform/cloud/subscription/composables/useSubscriptionDialog.test.ts b/src/platform/cloud/subscription/composables/useSubscriptionDialog.test.ts index dca4859dfe9..88198ea24ef 100644 --- a/src/platform/cloud/subscription/composables/useSubscriptionDialog.test.ts +++ b/src/platform/cloud/subscription/composables/useSubscriptionDialog.test.ts @@ -4,6 +4,8 @@ import { useBillingOperationStore } from '@/platform/workspace/stores/billingOpe import { useAuthStore } from '@/stores/authStore' import { beforeEach, describe, expect, it, vi } from 'vitest' +import { useTelemetry } from '@/platform/telemetry' + import type { SubscriptionInfo } from '@/composables/billing/types' import type { BillingSubscriptionStatus, @@ -20,7 +22,6 @@ import { useSubscriptionDialog } from './useSubscriptionDialog' const mockCloseDialog = vi.fn() const mockShowLayoutDialog = vi.fn() const mockShowTeamWorkspacesDialog = vi.fn() -const mockTrackSubscription = vi.hoisted(() => vi.fn()) const mockIsFreeTier = vi.hoisted(() => ({ value: false })) const mockTier = vi.hoisted(() => ({ value: 'FREE' as string | null })) @@ -105,9 +106,7 @@ vi.mock(import('@/composables/billing/useBillingContext'), () => ({ }) })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ trackSubscription: mockTrackSubscription }) -})) +vi.mock(import('@/platform/telemetry')) vi.mock( import('@/platform/workspace/composables/useWorkspaceUI'), @@ -333,7 +332,7 @@ describe('useSubscriptionDialog', () => { expect(props).not.toHaveProperty('initialCheckout') const { dialogComponentProps } = mockShowLayoutDialog.mock.calls[0][0] expectRekaPricingDialogProps(dialogComponentProps) - expect(mockTrackSubscription).toHaveBeenCalledWith( + expect(useTelemetry()?.trackSubscription).toHaveBeenCalledWith( 'modal_opened', expect.objectContaining({ reason: 'deep_link' }) ) @@ -431,10 +430,13 @@ describe('useSubscriptionDialog', () => { showPricingTable({ reason: 'upgrade_to_add_credits' }) - expect(mockTrackSubscription).toHaveBeenCalledWith('modal_opened', { - current_tier: 'standard', - reason: 'upgrade_to_add_credits' - }) + expect(useTelemetry()?.trackSubscription).toHaveBeenCalledWith( + 'modal_opened', + { + current_tier: 'standard', + reason: 'upgrade_to_add_credits' + } + ) }) it('tracks modal_opened on the workspace (unified) path too', () => { @@ -443,7 +445,7 @@ describe('useSubscriptionDialog', () => { showPricingTable({ reason: 'subscribe_to_run' }) - expect(mockTrackSubscription).toHaveBeenCalledWith( + expect(useTelemetry()?.trackSubscription).toHaveBeenCalledWith( 'modal_opened', expect.objectContaining({ reason: 'subscribe_to_run' }) ) @@ -458,7 +460,7 @@ describe('useSubscriptionDialog', () => { showPricingTable({ reason: 'subscribe_to_run' }) expect(mockShowLayoutDialog).toHaveBeenCalledTimes(1) - expect(mockTrackSubscription).not.toHaveBeenCalled() + expect(useTelemetry()?.trackSubscription).not.toHaveBeenCalled() }) it('shows the read-only member dialog for out-of-credits too, not the pricing table', () => { @@ -482,7 +484,7 @@ describe('useSubscriptionDialog', () => { showPricingTable({ reason: 'subscribe_to_run' }) - expect(mockTrackSubscription).not.toHaveBeenCalled() + expect(useTelemetry()?.trackSubscription).not.toHaveBeenCalled() }) }) @@ -511,7 +513,7 @@ describe('useSubscriptionDialog', () => { expect(mockShowLayoutDialog).toHaveBeenCalledWith( expect.objectContaining({ key: 'subscription-required' }) ) - expect(mockTrackSubscription).not.toHaveBeenCalled() + expect(useTelemetry()?.trackSubscription).not.toHaveBeenCalled() }) it('falls back to the pricing table for a non-free-tier user', () => { @@ -544,8 +546,8 @@ describe('useSubscriptionDialog', () => { show({ reason: 'out_of_credits' }) - expect(mockTrackSubscription).toHaveBeenCalledTimes(1) - expect(mockTrackSubscription).toHaveBeenCalledWith( + expect(useTelemetry()?.trackSubscription).toHaveBeenCalledTimes(1) + expect(useTelemetry()?.trackSubscription).toHaveBeenCalledWith( 'modal_opened', expect.objectContaining({ reason: 'out_of_credits' }) ) diff --git a/src/platform/cloud/subscription/composables/useTopUpUrlLoader.test.ts b/src/platform/cloud/subscription/composables/useTopUpUrlLoader.test.ts index 2fcc1f261b0..8ad94ecd112 100644 --- a/src/platform/cloud/subscription/composables/useTopUpUrlLoader.test.ts +++ b/src/platform/cloud/subscription/composables/useTopUpUrlLoader.test.ts @@ -1,6 +1,8 @@ import { fromAny } from '@total-typescript/shoehorn' import { beforeEach, describe, expect, it, vi } from 'vitest' +import { useTelemetry } from '@/platform/telemetry' + import { useTopUpUrlLoader } from './useTopUpUrlLoader' const preservedQueryMocks = vi.hoisted(() => ({ @@ -53,13 +55,7 @@ vi.mock( }) ) -const mockTrackAddApiCreditButtonClicked = vi.hoisted(() => vi.fn()) - -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackAddApiCreditButtonClicked: mockTrackAddApiCreditButtonClicked - }) -})) +vi.mock(import('@/platform/telemetry')) describe('useTopUpUrlLoader', () => { beforeEach(() => { @@ -97,9 +93,11 @@ describe('useTopUpUrlLoader', () => { const { loadTopUpFromUrl } = useTopUpUrlLoader() await loadTopUpFromUrl() - expect(mockTrackAddApiCreditButtonClicked).toHaveBeenCalledWith({ - source: 'deep_link' - }) + expect(useTelemetry()?.trackAddApiCreditButtonClicked).toHaveBeenCalledWith( + { + source: 'deep_link' + } + ) }) it('retains the deep link until capability loading settles', async () => { @@ -136,7 +134,9 @@ describe('useTopUpUrlLoader', () => { await loadTopUpFromUrl() expect(mockShowTopUpCreditsDialog).not.toHaveBeenCalled() - expect(mockTrackAddApiCreditButtonClicked).not.toHaveBeenCalled() + expect( + useTelemetry()?.trackAddApiCreditButtonClicked + ).not.toHaveBeenCalled() }) it('opens the subscription path without top-up telemetry', async () => { @@ -148,7 +148,9 @@ describe('useTopUpUrlLoader', () => { await loadTopUpFromUrl() expect(mockShowTopUpCreditsDialog).toHaveBeenCalledOnce() - expect(mockTrackAddApiCreditButtonClicked).not.toHaveBeenCalled() + expect( + useTelemetry()?.trackAddApiCreditButtonClicked + ).not.toHaveBeenCalled() }) it('denies, strips, and clears together when the user is not eligible', async () => { diff --git a/src/platform/cloud/subscription/launchCancellationFlow.test.ts b/src/platform/cloud/subscription/launchCancellationFlow.test.ts index ea3446b9374..1e864664a19 100644 --- a/src/platform/cloud/subscription/launchCancellationFlow.test.ts +++ b/src/platform/cloud/subscription/launchCancellationFlow.test.ts @@ -1,6 +1,8 @@ import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore' import { beforeEach, describe, expect, it, vi } from 'vitest' +import { useTelemetry } from '@/platform/telemetry' + import type { SubscriptionInfo } from '@/composables/billing/types' import type { ChurnkeySession, @@ -18,8 +20,7 @@ const mocks = vi.hoisted(() => ({ activeWorkspaceId: 'workspace-1' as string | null, billingRail: 'stripe' as BillingRail | null, cancelSubscription: vi.fn(), - prepare: vi.fn(), - trackCancellation: vi.fn() + prepare: vi.fn() })) vi.mock(import('@/composables/billing/useBillingContext'), () => ({ @@ -39,11 +40,7 @@ vi.mock(import('@/platform/cloud/churnkey/churnkeyClient'), () => ({ prepareChurnkey: mocks.prepare })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackSubscriptionCancellation: mocks.trackCancellation - }) -})) +vi.mock(import('@/platform/telemetry')) import { launchCancellationFlow } from './launchCancellationFlow' @@ -109,7 +106,7 @@ describe('launchCancellationFlow', () => { await launchCancellationFlow({ showFallback }) expect(showFallback).toHaveBeenCalledOnce() - expect(mocks.trackCancellation).not.toHaveBeenCalled() + expect(useTelemetry()?.trackSubscriptionCancellation).not.toHaveBeenCalled() }) it('cancels workspace billing through the existing API callback', async () => { @@ -127,13 +124,17 @@ describe('launchCancellationFlow', () => { }) expect(mocks.cancelSubscription).toHaveBeenCalledOnce() - expect(mocks.trackCancellation).toHaveBeenNthCalledWith(1, 'flow_opened', { + expect( + useTelemetry()?.trackSubscriptionCancellation + ).toHaveBeenNthCalledWith(1, 'flow_opened', { source: 'cancel_plan_menu', current_tier: 'pro', cycle: 'yearly', end_date: '2026-08-02T00:00:00Z' }) - expect(mocks.trackCancellation).toHaveBeenNthCalledWith( + expect( + useTelemetry()?.trackSubscriptionCancellation + ).toHaveBeenNthCalledWith( 2, 'confirmed', expect.objectContaining({ @@ -149,7 +150,9 @@ describe('launchCancellationFlow', () => { await launchCancellationFlow({ showFallback: vi.fn() }) - expect(mocks.trackCancellation).toHaveBeenLastCalledWith( + expect( + useTelemetry()?.trackSubscriptionCancellation + ).toHaveBeenLastCalledWith( 'abandoned', expect.objectContaining({ cycle: 'yearly', @@ -168,7 +171,7 @@ describe('launchCancellationFlow', () => { await launchCancellationFlow({ showFallback: preparationFallback }) expect(preparationFallback).toHaveBeenCalledWith() - expect(mocks.trackCancellation).not.toHaveBeenCalled() + expect(useTelemetry()?.trackSubscriptionCancellation).not.toHaveBeenCalled() expect(warn).toHaveBeenCalledWith( 'Failed to prepare Churnkey cancellation flow:', preparationError @@ -184,7 +187,9 @@ describe('launchCancellationFlow', () => { await launchCancellationFlow({ showFallback: runtimeFallback }) expect(runtimeFallback).toHaveBeenCalledWith({ flowAlreadyOpened: true }) - expect(mocks.trackCancellation).toHaveBeenLastCalledWith( + expect( + useTelemetry()?.trackSubscriptionCancellation + ).toHaveBeenLastCalledWith( 'failed', expect.objectContaining({ cycle: 'yearly', @@ -206,11 +211,11 @@ describe('launchCancellationFlow', () => { await launchCancellationFlow({ showFallback }) - expect(mocks.trackCancellation).toHaveBeenCalledWith( + expect(useTelemetry()?.trackSubscriptionCancellation).toHaveBeenCalledWith( 'confirmed', expect.anything() ) - expect(mocks.trackCancellation).toHaveBeenCalledWith( + expect(useTelemetry()?.trackSubscriptionCancellation).toHaveBeenCalledWith( 'failed', expect.objectContaining({ error_message: 'API down' }) ) diff --git a/src/platform/cloud/subscription/utils/teamSubscriptionCheckoutUtil.test.ts b/src/platform/cloud/subscription/utils/teamSubscriptionCheckoutUtil.test.ts index 572d2b1f0cf..811ebaf7dd7 100644 --- a/src/platform/cloud/subscription/utils/teamSubscriptionCheckoutUtil.test.ts +++ b/src/platform/cloud/subscription/utils/teamSubscriptionCheckoutUtil.test.ts @@ -1,16 +1,11 @@ import { useAuthStore } from '@/stores/authStore' import { beforeEach, describe, expect, it, vi } from 'vitest' -const { - mockIsCloud, - mockSubscribe, - mockTrackBeginCheckout, - mockTrackBillingEvent -} = vi.hoisted(() => ({ +import { useTelemetry } from '@/platform/telemetry' + +const { mockIsCloud, mockSubscribe } = vi.hoisted(() => ({ mockIsCloud: { value: true }, - mockSubscribe: vi.fn(), - mockTrackBeginCheckout: vi.fn(), - mockTrackBillingEvent: vi.fn() + mockSubscribe: vi.fn() })) vi.mock(import('@/platform/distribution/types'), () => ({ @@ -34,12 +29,7 @@ vi.mock(import('@/platform/workspace/api/workspaceApi'), () => ({ } } })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackBeginCheckout: mockTrackBeginCheckout, - trackBillingEvent: mockTrackBillingEvent - }) -})) +vi.mock(import('@/platform/telemetry')) import { performTeamSubscriptionCheckout } from './teamSubscriptionCheckoutUtil' @@ -82,7 +72,7 @@ describe('performTeamSubscriptionCheckout', () => { teamCreditStopId: 'team_700' }) expect(assignedHref).toBe('https://stripe.test/pay') - expect(mockTrackBeginCheckout).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBeginCheckout).toHaveBeenCalledWith({ user_id: 'user-1', tier: 'team', cycle: 'yearly', @@ -119,7 +109,7 @@ describe('performTeamSubscriptionCheckout', () => { ).rejects.toThrow(/payment URL/) expect(assignedHref).toBeUndefined() - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'subscription_checkout', stage: 'failed', outcome: 'failure', @@ -140,8 +130,8 @@ describe('performTeamSubscriptionCheckout', () => { }) ).rejects.toThrow('subscribe failed') - expect(mockTrackBeginCheckout).not.toHaveBeenCalled() - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBeginCheckout).not.toHaveBeenCalled() + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'subscription_checkout', stage: 'failed', outcome: 'failure', diff --git a/src/platform/onboarding/onboardingTourStore.registeredTour.test.ts b/src/platform/onboarding/onboardingTourStore.registeredTour.test.ts index 74abcf2eb9c..5522ed0656d 100644 --- a/src/platform/onboarding/onboardingTourStore.registeredTour.test.ts +++ b/src/platform/onboarding/onboardingTourStore.registeredTour.test.ts @@ -1,9 +1,15 @@ import { useSettingStore } from '@/platform/settings/settingStore' import { useAppModeStore } from '@/stores/appModeStore' -import { beforeEach, afterEach, describe, expect, it, vi } from 'vitest' +import { assert, beforeEach, afterEach, describe, expect, it, vi } from 'vitest' import { nextTick, ref } from 'vue' import type { Ref } from 'vue' +import { useTelemetry } from '@/platform/telemetry' +import type { + OnboardingTourStepStage, + OnboardingTourStepMetadata +} from '@/platform/telemetry/types' + import type { AppMode } from '@/utils/appMode' import { clearCoachmarks } from './coachmarkRegistry' @@ -11,10 +17,13 @@ import { TOUR_SEEN_SETTING, registerTour } from './onboardingTours' import type { SpotlightStep } from './onboardingTours' import { useOnboardingTourStore } from './onboardingTourStore' -const telemetry = vi.hoisted(() => ({ track: vi.fn() })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ trackOnboardingTour: telemetry.track }) -})) +vi.mock(import('@/platform/telemetry')) + +const dispatcher = useTelemetry() +assert.exists(dispatcher) +const trackOnboardingTour = vi.mocked< + (stage: OnboardingTourStepStage, metadata: OnboardingTourStepMetadata) => void +>(dispatcher.trackOnboardingTour) const appModeMock = vi.hoisted(() => ({ mode: null as Ref | null })) vi.mock(import('@/composables/useAppMode'), async () => { @@ -45,7 +54,7 @@ function step( } function stages(): string[] { - return telemetry.track.mock.calls.map(([stage]) => stage) + return trackOnboardingTour.mock.calls.map(([stage]) => stage) } function mountStore() { @@ -66,7 +75,7 @@ beforeEach(() => { describe('onboardingTourStore — runtime-resolved tours', () => { afterEach(() => { clearCoachmarks() - telemetry.track.mockClear() + trackOnboardingTour.mockClear() }) it('reports no start for an entry no one registered', async () => { @@ -101,7 +110,7 @@ describe('onboardingTourStore — runtime-resolved tours', () => { await expect(store.startTour('firstRun')).resolves.toBe(false) expect( - telemetry.track, + trackOnboardingTour, 'counted as a plain no-start, a repeat user reads as a tour that failed to open' ).toHaveBeenCalledWith( 'not_started', @@ -143,7 +152,7 @@ describe('onboardingTourStore — runtime-resolved tours', () => { await expect(store.startTour('firstRun')).resolves.toBe(false) expect( - telemetry.track, + trackOnboardingTour, 'sharing a reason with an empty pin set reports the tour crash rate as zero' ).toHaveBeenCalledWith( 'not_started', @@ -160,7 +169,9 @@ describe('onboardingTourStore — runtime-resolved tours', () => { await store.startTour('firstRun') expect( - telemetry.track.mock.calls.filter(([stage]) => stage === 'not_started'), + trackOnboardingTour.mock.calls.filter( + ([stage]) => stage === 'not_started' + ), 'the trigger re-fires on every mode change, so the funnel would count edges not users' ).toHaveLength(1) }) @@ -190,7 +201,7 @@ describe('onboardingTourStore — runtime-resolved tours', () => { store.activeTour, 'a tour whose targets are no longer laid out points at nothing' ).toBeNull() - expect(telemetry.track).toHaveBeenCalledWith( + expect(trackOnboardingTour).toHaveBeenCalledWith( 'skipped', expect.objectContaining({ skip_reason: 'trigger_lost' }) ) @@ -311,7 +322,7 @@ describe('onboardingTourStore — runtime-resolved tours', () => { store.postpone() expect( - telemetry.track, + trackOnboardingTour, 'a postponement counted as a plain skip reads as a user who refused the tour' ).toHaveBeenCalledWith( 'skipped', diff --git a/src/platform/onboarding/onboardingTourStore.test.ts b/src/platform/onboarding/onboardingTourStore.test.ts index 158ae9d2c5e..7ecd5d5d520 100644 --- a/src/platform/onboarding/onboardingTourStore.test.ts +++ b/src/platform/onboarding/onboardingTourStore.test.ts @@ -1,10 +1,16 @@ import { useAppModeStore } from '@/stores/appModeStore' import { useSettingStore } from '@/platform/settings/settingStore' import type { DetachedWindowAPI } from 'happy-dom' -import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { nextTick } from 'vue' import type { Ref } from 'vue' +import { useTelemetry } from '@/platform/telemetry' +import type { + OnboardingTourStepStage, + OnboardingTourStepMetadata +} from '@/platform/telemetry/types' + import { useToastStore } from '@/platform/updates/common/toastStore' import { useSidebarTabStore } from '@/stores/workspace/sidebarTabStore' import type { AppMode } from '@/utils/appMode' @@ -18,10 +24,13 @@ import { TOUR_SEEN_SETTING, tourDefinition } from './onboardingTours' import type { CoachId, CoachStep } from './onboardingTours' import { useOnboardingTourStore } from './onboardingTourStore' -const telemetry = vi.hoisted(() => ({ track: vi.fn() })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ trackOnboardingTour: telemetry.track }) -})) +vi.mock(import('@/platform/telemetry')) + +const dispatcher = useTelemetry() +assert.exists(dispatcher) +const trackOnboardingTour = vi.mocked< + (stage: OnboardingTourStepStage, metadata: OnboardingTourStepMetadata) => void +>(dispatcher.trackOnboardingTour) const appModeMock = vi.hoisted((): { mode: Ref | null } => ({ mode: null @@ -71,7 +80,7 @@ function mountStore() { } function startedCount() { - return telemetry.track.mock.calls.filter(([stage]) => stage === 'started') + return trackOnboardingTour.mock.calls.filter(([stage]) => stage === 'started') .length } @@ -80,7 +89,7 @@ function shownCoachId(step: CoachStep | null | undefined) { } function shownCount(coachId?: CoachId) { - return telemetry.track.mock.calls.filter( + return trackOnboardingTour.mock.calls.filter( ([stage, meta]) => stage === 'step_shown' && (!coachId || meta.coach_id === coachId) ).length @@ -113,7 +122,7 @@ describe('onboardingTourStore', () => { appendedTargets.length = 0 setViewport({ width: 1024, height: 768 }) if (appModeMock.mode) appModeMock.mode.value = 'graph' - telemetry.track.mockClear() + trackOnboardingTour.mockClear() }) /** Register one laid-out element for a coach id, so its step resolves at once. */ @@ -206,7 +215,7 @@ describe('onboardingTourStore', () => { await nextTick() expect(store.step).toBeNull() - const skipped = telemetry.track.mock.calls.find( + const skipped = trackOnboardingTour.mock.calls.find( ([stage]) => stage === 'skipped' ) expect(skipped?.[1]).toMatchObject({ skip_reason: 'trigger_lost' }) @@ -233,7 +242,7 @@ describe('onboardingTourStore', () => { expect(seenTours()).toContain('appMode') // A deliberate dismissal reports the user as the skip reason. - const skipped = telemetry.track.mock.calls.find( + const skipped = trackOnboardingTour.mock.calls.find( ([stage]) => stage === 'skipped' ) expect(skipped?.[1]).toMatchObject({ skip_reason: 'user' }) @@ -364,7 +373,7 @@ describe('onboardingTourStore', () => { // The skipped event reports the timed-out step, not the prior landing, // and attributes the skip to the timeout rather than the user. - const skipped = telemetry.track.mock.calls.find( + const skipped = trackOnboardingTour.mock.calls.find( ([stage]) => stage === 'skipped' ) expect(skipped?.[1]).toMatchObject({ @@ -419,7 +428,7 @@ describe('onboardingTourStore', () => { store.skip() await vi.advanceTimersByTimeAsync(8000) - const skipped = telemetry.track.mock.calls.filter( + const skipped = trackOnboardingTour.mock.calls.filter( ([stage]) => stage === 'skipped' ) expect(skipped).toHaveLength(1) @@ -439,7 +448,7 @@ describe('onboardingTourStore', () => { expect(store.step).toBeNull() expect(seenTours()).not.toContain('appMode') - const skipped = telemetry.track.mock.calls.find( + const skipped = trackOnboardingTour.mock.calls.find( ([stage]) => stage === 'skipped' ) expect(skipped?.[1]).toMatchObject({ skip_reason: 'trigger_lost' }) @@ -460,7 +469,7 @@ describe('onboardingTourStore', () => { await vi.advanceTimersByTimeAsync(8000) expect(useToastStore().messagesToAdd).toHaveLength(0) - const skipReasons = telemetry.track.mock.calls + const skipReasons = trackOnboardingTour.mock.calls .filter(([stage]) => stage === 'skipped') .map(([, meta]) => meta.skip_reason) expect(skipReasons).toEqual(['trigger_lost']) @@ -487,7 +496,7 @@ describe('onboardingTourStore', () => { } expect(seenTours()).toContain('appMode') - const completed = telemetry.track.mock.calls.find( + const completed = trackOnboardingTour.mock.calls.find( ([stage]) => stage === 'completed' ) expect(completed).toBeTruthy() @@ -605,19 +614,19 @@ describe('onboardingTourStore', () => { await nextTick() // The landing isn't numbered, so the four spotlight steps carry the count. - const started = telemetry.track.mock.calls.find( + const started = trackOnboardingTour.mock.calls.find( ([stage]) => stage === 'started' ) expect(started?.[1]).toEqual({ tour: 'appMode', step_count: 4 }) - const landingShown = telemetry.track.mock.calls.find( + const landingShown = trackOnboardingTour.mock.calls.find( ([stage]) => stage === 'step_shown' ) expect(landingShown?.[1]).toEqual({ tour: 'appMode', step_count: 4 }) store.next() await nextTick() - const shown = telemetry.track.mock.calls + const shown = trackOnboardingTour.mock.calls .filter(([stage]) => stage === 'step_shown') .at(-1) expect(shown?.[1]).toEqual({ @@ -639,7 +648,7 @@ describe('onboardingTourStore', () => { await nextTick() expect(store.step?.kind).not.toBe('landing') - const skipped = telemetry.track.mock.calls.some( + const skipped = trackOnboardingTour.mock.calls.some( ([stage]) => stage === 'skipped' ) expect(skipped).toBe(false) @@ -689,7 +698,7 @@ describe('onboardingTourStore', () => { useToastStore().messagesToAdd, 'leaving app mode is an ordinary thing to do, so it must not read as an error' ).toEqual([]) - const skipped = telemetry.track.mock.calls.findLast( + const skipped = trackOnboardingTour.mock.calls.findLast( ([stage]) => stage === 'skipped' ) expect(skipped?.[1]).toMatchObject({ skip_reason: 'trigger_lost' }) @@ -905,7 +914,7 @@ describe('onboardingTourStore', () => { ).not.toBeNull() expect(useToastStore().messagesToAdd).toHaveLength(0) expect( - telemetry.track.mock.calls.filter(([stage]) => stage === 'skipped') + trackOnboardingTour.mock.calls.filter(([stage]) => stage === 'skipped') ).toHaveLength(0) }) }) diff --git a/src/platform/settings/composables/useSettingsDialog.test.ts b/src/platform/settings/composables/useSettingsDialog.test.ts index 39016f9c5d4..8448a1464b0 100644 --- a/src/platform/settings/composables/useSettingsDialog.test.ts +++ b/src/platform/settings/composables/useSettingsDialog.test.ts @@ -20,9 +20,7 @@ vi.mock(import('@/i18n'), () => ({ t: (k: string) => k })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ trackEvent: vi.fn() }) -})) +vi.mock(import('@/platform/telemetry')) vi.mock(import('@/composables/billing/useBillingContext'), () => ({ useBillingContext: () => ({ diff --git a/src/platform/settings/settingStore.test.ts b/src/platform/settings/settingStore.test.ts index 8c637cbb2ff..f53544e2932 100644 --- a/src/platform/settings/settingStore.test.ts +++ b/src/platform/settings/settingStore.test.ts @@ -1,5 +1,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' +import { useTelemetry } from '@/platform/telemetry' + import { getSettingInfo, useSettingStore @@ -9,15 +11,7 @@ import type { Settings } from '@/schemas/apiSchema' import { api } from '@/scripts/api' import { app } from '@/scripts/app' -const { trackSettingChanged } = vi.hoisted(() => ({ - trackSettingChanged: vi.fn() -})) - -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: vi.fn(() => ({ - trackSettingChanged - })) -})) +vi.mock(import('@/platform/telemetry')) // Mock the api vi.mock(import('@/scripts/api'), () => ({ @@ -629,7 +623,7 @@ describe('useSettingStore', () => { await store.set('test.setting', 'newvalue') - expect(trackSettingChanged).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackSettingChanged).toHaveBeenCalledWith({ setting_id: 'test.setting', previous_value: 'default', new_value: 'newvalue' @@ -646,7 +640,7 @@ describe('useSettingStore', () => { await store.set('test.setting', 'newvalue') - expect(trackSettingChanged).not.toHaveBeenCalled() + expect(useTelemetry()?.trackSettingChanged).not.toHaveBeenCalled() }) it('does not track visible settings that opt out', async () => { @@ -660,7 +654,7 @@ describe('useSettingStore', () => { await store.set('test.setting', 'newvalue') - expect(trackSettingChanged).not.toHaveBeenCalled() + expect(useTelemetry()?.trackSettingChanged).not.toHaveBeenCalled() }) it('tracks visible settings without values when values opt out', async () => { @@ -674,7 +668,7 @@ describe('useSettingStore', () => { await store.set('test.setting', 'newvalue') - expect(trackSettingChanged).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackSettingChanged).toHaveBeenCalledWith({ setting_id: 'test.setting' }) }) @@ -689,13 +683,13 @@ describe('useSettingStore', () => { }) await store.set('test.setting', 'newvalue') - expect(trackSettingChanged).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackSettingChanged).toHaveBeenCalledWith({ setting_id: 'test.setting' }) // Setting the same value again is a no-op and should not re-emit await store.set('test.setting', 'newvalue') - expect(trackSettingChanged).toHaveBeenCalledTimes(1) + expect(useTelemetry()?.trackSettingChanged).toHaveBeenCalledTimes(1) }) it('ships previous/new values when the setting opts into includeValues', async () => { @@ -709,7 +703,7 @@ describe('useSettingStore', () => { await store.set('Comfy.ColorPalette', 'light') - expect(trackSettingChanged).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackSettingChanged).toHaveBeenCalledWith({ setting_id: 'Comfy.ColorPalette', previous_value: 'dark', new_value: 'light' @@ -730,7 +724,7 @@ describe('useSettingStore', () => { 'failed' ) - expect(trackSettingChanged).not.toHaveBeenCalled() + expect(useTelemetry()?.trackSettingChanged).not.toHaveBeenCalled() }) describe('object mutation prevention', () => { @@ -880,8 +874,8 @@ describe('useSettingStore', () => { 'Comfy.Release.Version': '1.0.0' }) - expect(trackSettingChanged).toHaveBeenCalledTimes(1) - expect(trackSettingChanged).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackSettingChanged).toHaveBeenCalledTimes(1) + expect(useTelemetry()?.trackSettingChanged).toHaveBeenCalledWith({ setting_id: 'Comfy.ColorPalette', previous_value: 'dark', new_value: 'light' @@ -927,7 +921,7 @@ describe('useSettingStore', () => { await store.setMany({ 'Comfy.Release.Version': 'existing' }) expect(api.storeSettings).not.toHaveBeenCalled() - expect(trackSettingChanged).not.toHaveBeenCalled() + expect(useTelemetry()?.trackSettingChanged).not.toHaveBeenCalled() }) }) }) diff --git a/src/platform/support/feedbackDialog.test.ts b/src/platform/support/feedbackDialog.test.ts index 10dbb33c4c6..e40d88082f3 100644 --- a/src/platform/support/feedbackDialog.test.ts +++ b/src/platform/support/feedbackDialog.test.ts @@ -1,8 +1,9 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' -import { openTypeformDialog } from '@/platform/surveys/openTypeformDialog' import { useTelemetry } from '@/platform/telemetry' +import { openTypeformDialog } from '@/platform/surveys/openTypeformDialog' + import { FEEDBACK_TYPEFORM_ID } from './config' import { openFeedbackDialog } from './feedbackDialog' @@ -14,10 +15,7 @@ vi.mock(import('@/platform/surveys/openTypeformDialog'), () => ({ openTypeformDialog: vi.fn() })) -const trackUiButtonClicked = vi.fn() -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: vi.fn(() => ({ trackUiButtonClicked })) -})) +vi.mock(import('@/platform/telemetry')) const userEmail = vi.hoisted((): { value: string | undefined } => ({ value: undefined @@ -63,7 +61,7 @@ describe('openFeedbackDialog', () => { it('tracks the button click tagged with the opening source', () => { openFeedbackDialog('topbar') - expect(trackUiButtonClicked).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackUiButtonClicked).toHaveBeenCalledWith({ button_id: 'feedback_button_clicked', element_group: 'topbar' }) diff --git a/src/platform/telemetry/__mocks__/index.ts b/src/platform/telemetry/__mocks__/index.ts new file mode 100644 index 00000000000..a06b5a450d1 --- /dev/null +++ b/src/platform/telemetry/__mocks__/index.ts @@ -0,0 +1,11 @@ +import { vi } from 'vitest' + +import type { + setTelemetryRegistry as realSetTelemetryRegistry, + useTelemetry as realUseTelemetry +} from '../index' +import { TelemetryRegistry } from '../TelemetryRegistry' + +const telemetryMock = vi.mockObject(new TelemetryRegistry()) +export const useTelemetry = vi.fn(() => telemetryMock) +export const setTelemetryRegistry = vi.fn() diff --git a/src/platform/telemetry/searchQuery/useSearchQueryTracking.test.ts b/src/platform/telemetry/searchQuery/useSearchQueryTracking.test.ts index 8a4cae2cafb..98e55ab31d2 100644 --- a/src/platform/telemetry/searchQuery/useSearchQueryTracking.test.ts +++ b/src/platform/telemetry/searchQuery/useSearchQueryTracking.test.ts @@ -2,13 +2,9 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import type { EffectScope, Ref } from 'vue' import { effectScope, ref } from 'vue' -const hoisted = vi.hoisted(() => ({ - trackSearchQuery: vi.fn() -})) +import { useTelemetry } from '@/platform/telemetry' -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ trackSearchQuery: hoisted.trackSearchQuery }) -})) +vi.mock(import('@/platform/telemetry')) import { useSearchQueryTracking } from './useSearchQueryTracking' @@ -42,7 +38,7 @@ describe('useSearchQueryTracking', () => { track(query, results) query.value = ' hello ' await vi.advanceTimersByTimeAsync(500) - expect(hoisted.trackSearchQuery).toHaveBeenCalledExactlyOnceWith({ + expect(useTelemetry()?.trackSearchQuery).toHaveBeenCalledExactlyOnceWith({ surface: 'node_sidebar', query: 'hello', query_length: 5, @@ -57,7 +53,7 @@ describe('useSearchQueryTracking', () => { track(query, results) query.value = 'nothingmatches' await vi.advanceTimersByTimeAsync(500) - expect(hoisted.trackSearchQuery).toHaveBeenCalledExactlyOnceWith({ + expect(useTelemetry()?.trackSearchQuery).toHaveBeenCalledExactlyOnceWith({ surface: 'node_sidebar', query: 'nothingmatches', query_length: 14, @@ -72,7 +68,7 @@ describe('useSearchQueryTracking', () => { track(query, results) query.value = ' ' await vi.advanceTimersByTimeAsync(500) - expect(hoisted.trackSearchQuery).not.toHaveBeenCalled() + expect(useTelemetry()?.trackSearchQuery).not.toHaveBeenCalled() }) it('cancels a pending debounced call when the scope is disposed', async () => { @@ -82,7 +78,7 @@ describe('useSearchQueryTracking', () => { query.value = 'hello' scope.stop() await vi.advanceTimersByTimeAsync(500) - expect(hoisted.trackSearchQuery).not.toHaveBeenCalled() + expect(useTelemetry()?.trackSearchQuery).not.toHaveBeenCalled() }) it('truncates query to 100 chars while preserving original length', async () => { @@ -92,7 +88,7 @@ describe('useSearchQueryTracking', () => { const long = 'x'.repeat(250) query.value = long await vi.advanceTimersByTimeAsync(500) - expect(hoisted.trackSearchQuery).toHaveBeenCalledExactlyOnceWith({ + expect(useTelemetry()?.trackSearchQuery).toHaveBeenCalledExactlyOnceWith({ surface: 'node_sidebar', query: 'x'.repeat(100), query_length: 250, diff --git a/src/platform/workflow/core/services/workflowService.insertWorkflow.test.ts b/src/platform/workflow/core/services/workflowService.insertWorkflow.test.ts index 4e13f9b3da7..1c3445d4cf8 100644 --- a/src/platform/workflow/core/services/workflowService.insertWorkflow.test.ts +++ b/src/platform/workflow/core/services/workflowService.insertWorkflow.test.ts @@ -51,13 +51,7 @@ vi.mock( }) ) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackDefaultViewSet: vi.fn(), - trackWorkflowSaved: vi.fn(), - trackEnterLinear: vi.fn() - }) -})) +vi.mock(import('@/platform/telemetry')) const PROBE_NODE_TYPE = 'test/insert-workflow-probe' diff --git a/src/platform/workflow/core/services/workflowService.test.ts b/src/platform/workflow/core/services/workflowService.test.ts index 2fe1d295ffa..e547cc9f13f 100644 --- a/src/platform/workflow/core/services/workflowService.test.ts +++ b/src/platform/workflow/core/services/workflowService.test.ts @@ -9,6 +9,8 @@ import { } from 'firebase/auth' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { useTelemetry } from '@/platform/telemetry' + import type { LoadedComfyWorkflow, PendingWarnings @@ -87,9 +89,8 @@ function makeWorkflowDataWithId(id: string): ComfyWorkflowJSON { return { ...makeWorkflowData(), id } } -const { mockConfirm, mockTrackWorkflowSaved } = vi.hoisted(() => ({ - mockConfirm: vi.fn(), - mockTrackWorkflowSaved: vi.fn() +const { mockConfirm } = vi.hoisted(() => ({ + mockConfirm: vi.fn() })) vi.mock(import('@/services/dialogService'), () => ({ @@ -131,13 +132,7 @@ vi.mock(import('@/platform/telemetry/reportError'), () => ({ reportError: reportErrorMock })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackDefaultViewSet: vi.fn(), - trackWorkflowSaved: mockTrackWorkflowSaved, - trackEnterLinear: vi.fn() - }) -})) +vi.mock(import('@/platform/telemetry')) function createWorkflow( warnings: PendingWarnings | null = null, @@ -2530,8 +2525,8 @@ describe('useWorkflowService', () => { 'workflows/test.app.json' ) expect(workflowStore.saveWorkflow).toHaveBeenCalledWith(copy) - expect(mockTrackWorkflowSaved).toHaveBeenCalledTimes(1) - expect(mockTrackWorkflowSaved).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackWorkflowSaved).toHaveBeenCalledTimes(1) + expect(useTelemetry()?.trackWorkflowSaved).toHaveBeenCalledWith({ is_app: true, is_new: true }) @@ -2568,8 +2563,8 @@ describe('useWorkflowService', () => { isApp: true }) - expect(mockTrackWorkflowSaved).toHaveBeenCalledTimes(1) - expect(mockTrackWorkflowSaved).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackWorkflowSaved).toHaveBeenCalledTimes(1) + expect(useTelemetry()?.trackWorkflowSaved).toHaveBeenCalledWith({ is_app: true, is_new: true }) diff --git a/src/platform/workflow/sharing/components/ShareWorkflowDialogContent.test.ts b/src/platform/workflow/sharing/components/ShareWorkflowDialogContent.test.ts index 1433b1c0bc4..516ad0824a3 100644 --- a/src/platform/workflow/sharing/components/ShareWorkflowDialogContent.test.ts +++ b/src/platform/workflow/sharing/components/ShareWorkflowDialogContent.test.ts @@ -5,15 +5,11 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' import { nextTick } from 'vue' import { createI18n } from 'vue-i18n' -import ShareWorkflowDialogContent from '@/platform/workflow/sharing/components/ShareWorkflowDialogContent.vue' +import { useTelemetry } from '@/platform/telemetry' -const mockTrackShareFlow = vi.hoisted(() => vi.fn()) +import ShareWorkflowDialogContent from '@/platform/workflow/sharing/components/ShareWorkflowDialogContent.vue' -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackShareFlow: mockTrackShareFlow - }) -})) +vi.mock(import('@/platform/telemetry')) const mockToast = vi.hoisted(() => ({ add: vi.fn() })) @@ -379,7 +375,7 @@ describe('ShareWorkflowDialogContent', () => { 'workflows/test.json', initialShareableAssets ) - expect(mockTrackShareFlow).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackShareFlow).toHaveBeenCalledWith({ step: 'link_created', source: 'graph_mode', view_mode: 'graph', @@ -401,7 +397,7 @@ describe('ShareWorkflowDialogContent', () => { await userEvent.click(screen.getByRole('button', { name: /Copy link/i })) - expect(mockTrackShareFlow).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackShareFlow).toHaveBeenCalledWith({ step: 'link_copied', source: 'graph_mode', view_mode: 'graph', diff --git a/src/platform/workflow/sharing/composables/useSharedWorkflowUrlLoader.test.ts b/src/platform/workflow/sharing/composables/useSharedWorkflowUrlLoader.test.ts index 481d04399f6..0ec03a87f51 100644 --- a/src/platform/workflow/sharing/composables/useSharedWorkflowUrlLoader.test.ts +++ b/src/platform/workflow/sharing/composables/useSharedWorkflowUrlLoader.test.ts @@ -4,6 +4,8 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import type { App } from 'vue' import { createApp, defineComponent } from 'vue' +import { useTelemetry } from '@/platform/telemetry' + import { i18n } from '@/i18n' import { useSharedWorkflowUrlLoader as createSharedWorkflowUrlLoader } from '@/platform/workflow/sharing/composables/useSharedWorkflowUrlLoader' import type { SharedWorkflowPayload } from '@/platform/workflow/sharing/types/shareTypes' @@ -34,7 +36,6 @@ vi.mock(import('vue-router'), () => ({ const mockImportPublishedAssets = vi.fn() const mockIsLoggedIn = vi.hoisted(() => ({ value: false })) -const mockTrackShareLinkOpened = vi.hoisted(() => vi.fn()) vi.mock(import('@/composables/auth/useCurrentUser'), () => ({ useCurrentUser: () => ({ @@ -49,11 +50,7 @@ vi.mock(import('@/composables/useAppMode'), () => ({ }) })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackShareLinkOpened: mockTrackShareLinkOpened - }) -})) +vi.mock(import('@/platform/telemetry')) vi.mock( import('@/platform/workflow/sharing/services/workflowShareService'), @@ -249,7 +246,7 @@ describe('useSharedWorkflowUrlLoader', () => { expect(loaded).toBe('not-present') expect(mockShowLayoutDialog).not.toHaveBeenCalled() expect(mockLoadGraphData).not.toHaveBeenCalled() - expect(mockTrackShareLinkOpened).not.toHaveBeenCalled() + expect(useTelemetry()?.trackShareLinkOpened).not.toHaveBeenCalled() }) it('opens dialog immediately with shareId and loads graph on confirm', async () => { @@ -273,7 +270,7 @@ describe('useSharedWorkflowUrlLoader', () => { 'Test Workflow', { openSource: 'shared_url', shareId: 'share-id-1' } ) - expect(mockTrackShareLinkOpened).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackShareLinkOpened).toHaveBeenCalledWith({ share_id: 'share-id-1', is_authenticated: false, view_mode: 'graph', @@ -297,7 +294,7 @@ describe('useSharedWorkflowUrlLoader', () => { const loaded = await loadSharedWorkflowFromUrl() expect(loaded).toBe('loaded') - expect(mockTrackShareLinkOpened).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackShareLinkOpened).toHaveBeenCalledWith({ share_id: 'share-id-1', is_authenticated: true, view_mode: 'graph', diff --git a/src/platform/workspace/components/CurrentUserPopoverWorkspace.test.ts b/src/platform/workspace/components/CurrentUserPopoverWorkspace.test.ts index d11ff770641..325b51d6157 100644 --- a/src/platform/workspace/components/CurrentUserPopoverWorkspace.test.ts +++ b/src/platform/workspace/components/CurrentUserPopoverWorkspace.test.ts @@ -127,9 +127,7 @@ vi.mock(import('@/services/dialogService'), () => ({ }) })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => undefined -})) +vi.mock(import('@/platform/telemetry')) vi.mock(import('@/composables/useExternalLink'), () => ({ useExternalLink: () => ({ diff --git a/src/platform/workspace/components/InviteMembersForm.test.ts b/src/platform/workspace/components/InviteMembersForm.test.ts index f33b1a8669a..e3c401b374f 100644 --- a/src/platform/workspace/components/InviteMembersForm.test.ts +++ b/src/platform/workspace/components/InviteMembersForm.test.ts @@ -4,20 +4,15 @@ import userEvent from '@testing-library/user-event' import { beforeEach, describe, expect, it, vi } from 'vitest' import { createI18n } from 'vue-i18n' +import { useTelemetry } from '@/platform/telemetry' + import InviteMembersForm from './InviteMembersForm.vue' import type { WorkspacePendingInvite } from '@/platform/workspace/stores/teamWorkspaceStore' -const { - mockFetchStatus, - mockToastAdd, - mockTrackInviteSent, - mockTrackInviteFailed -} = vi.hoisted(() => ({ +const { mockFetchStatus, mockToastAdd } = vi.hoisted(() => ({ mockFetchStatus: vi.fn(), - mockToastAdd: vi.fn(), - mockTrackInviteSent: vi.fn(), - mockTrackInviteFailed: vi.fn() + mockToastAdd: vi.fn() })) vi.mock(import('@/composables/billing/useBillingContext'), () => ({ @@ -33,12 +28,7 @@ vi.mock( }) ) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackWorkspaceInviteSent: mockTrackInviteSent, - trackWorkspaceInviteFailed: mockTrackInviteFailed - }) -})) +vi.mock(import('@/platform/telemetry')) const i18n = createI18n({ legacy: false, @@ -129,7 +119,7 @@ describe('InviteMembersForm', () => { ) expect(useTeamWorkspaceStore().createInvite).toHaveBeenCalledWith('a@b.com') expect(useTeamWorkspaceStore().createInvite).toHaveBeenCalledWith('c@d.com') - expect(mockTrackInviteSent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackWorkspaceInviteSent).toHaveBeenCalledWith({ source: 'post_upgrade_success', count: 2 }) @@ -228,7 +218,7 @@ describe('InviteMembersForm', () => { expect.objectContaining({ severity: 'error' }) ) expect(emitted().submitted).toBeUndefined() - expect(mockTrackInviteSent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackWorkspaceInviteSent).toHaveBeenCalledWith({ source: 'post_upgrade_success', count: 1 }) @@ -239,8 +229,8 @@ describe('InviteMembersForm', () => { expect(useTeamWorkspaceStore().createInvite).toHaveBeenCalledTimes(3) ) expect(emitted().submitted).toEqual([[['ok@x.com', 'fail@x.com']]]) - expect(mockTrackInviteSent).toHaveBeenCalledTimes(2) - expect(mockTrackInviteSent).toHaveBeenLastCalledWith({ + expect(useTelemetry()?.trackWorkspaceInviteSent).toHaveBeenCalledTimes(2) + expect(useTelemetry()?.trackWorkspaceInviteSent).toHaveBeenLastCalledWith({ source: 'post_upgrade_success', count: 1 }) @@ -264,7 +254,7 @@ describe('InviteMembersForm', () => { expect.objectContaining({ severity: 'error' }) ) expect(emitted().submitted).toBeUndefined() - expect(mockTrackInviteSent).not.toHaveBeenCalled() + expect(useTelemetry()?.trackWorkspaceInviteSent).not.toHaveBeenCalled() expect(mockFetchStatus).not.toHaveBeenCalled() }) diff --git a/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts b/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts index d5d2df5eab6..5b9ac064cfe 100644 --- a/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts +++ b/src/platform/workspace/components/TopUpCreditsDialogContentWorkspace.test.ts @@ -19,6 +19,8 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' import { nextTick } from 'vue' import { createI18n } from 'vue-i18n' +import { useTelemetry } from '@/platform/telemetry' + import enMessages from '@/locales/en/main.json' with { type: 'json' } import { WorkspaceApiError } from '@/platform/workspace/api/workspaceApi' @@ -42,9 +44,6 @@ const mockTopup = const mockShowSettings = vi.fn() const mockToastAdd = vi.fn() -const mockTrackTopUpPurchase = vi.fn() -const mockTrackBillingEvent = vi.fn() -const mockTrackCheckoutJourneyEvent = vi.hoisted(() => vi.fn()) const mockCanTopUp = vi.hoisted(() => ({ ref: undefined as { value: boolean } | undefined })) @@ -96,16 +95,9 @@ vi.mock( }) ) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackApiCreditTopupButtonPurchaseClicked: mockTrackTopUpPurchase, - trackBillingEvent: mockTrackBillingEvent, - trackCheckoutJourneyEvent: mockTrackCheckoutJourneyEvent - }) -})) +vi.mock(import('@/platform/telemetry')) vi.mock(import('firebase/auth'), { spy: true }) - const mockClearPendingTopup = vi.hoisted(() => vi.fn()) vi.mock(import('@/composables/billing/usePendingTopup'), () => ({ usePendingTopup: () => ({ clearPendingTopup: mockClearPendingTopup }) @@ -203,7 +195,7 @@ beforeEach(() => { vi.mocked(useDialogStore().closeDialog).mockImplementation(() => {}) Object.assign(useAuthStore(), { userId: 'user-1' }) Object.assign(useTeamWorkspaceStore(), { activeWorkspaceId: 'workspace-1' }) - mockTrackCheckoutJourneyEvent.mockClear() + vi.mocked(useTelemetry()?.trackCheckoutJourneyEvent)?.mockClear() sessionStorage.clear() clearCheckoutJourney() }) @@ -252,13 +244,13 @@ describe('TopUpCreditsDialogContentWorkspace', () => { await userEvent.click(screen.getByRole('button', { name: 'Pay $50.00' })) await waitFor(() => - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'topup', stage: 'started', outcome: 'pending' }) ) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'operation', stage: 'started', outcome: 'pending', @@ -271,7 +263,7 @@ describe('TopUpCreditsDialogContentWorkspace', () => { renderDialog() await waitFor(() => - expect(mockTrackCheckoutJourneyEvent).toHaveBeenCalledWith( + expect(useTelemetry()?.trackCheckoutJourneyEvent).toHaveBeenCalledWith( expect.objectContaining({ phase: 'entered', entry_flow: 'topup' }) ) ) @@ -280,16 +272,16 @@ describe('TopUpCreditsDialogContentWorkspace', () => { await userEvent.click(screen.getByRole('button', { name: 'Pay $50.00' })) await waitFor(() => - expect(mockTrackCheckoutJourneyEvent).toHaveBeenCalledWith( + expect(useTelemetry()?.trackCheckoutJourneyEvent).toHaveBeenCalledWith( expect.objectContaining({ phase: 'operation_linked', billing_op_id: 'op-1' }) ) ) - const phases = mockTrackCheckoutJourneyEvent.mock.calls.map( - ([event]) => event.phase - ) + const phases = ( + vi.mocked(useTelemetry()?.trackCheckoutJourneyEvent)?.mock.calls ?? [] + ).map(([event]) => event.phase) expect(phases.indexOf('submitted')).toBeLessThan( phases.indexOf('operation_linked') ) @@ -297,9 +289,9 @@ describe('TopUpCreditsDialogContentWorkspace', () => { // One denominator: every phase of a top-up must carry the same journey. const journeyIds = new Set( - mockTrackCheckoutJourneyEvent.mock.calls.map( - ([event]) => event.checkout_journey_id - ) + ( + vi.mocked(useTelemetry()?.trackCheckoutJourneyEvent)?.mock.calls ?? [] + ).map(([event]) => event.checkout_journey_id) ) expect(journeyIds.size).toBe(1) }) @@ -316,7 +308,7 @@ describe('TopUpCreditsDialogContentWorkspace', () => { await clickAddCredits() await userEvent.click(screen.getByRole('button', { name: 'Pay $50.00' })) await waitFor(() => - expect(mockTrackCheckoutJourneyEvent).toHaveBeenCalledWith( + expect(useTelemetry()?.trackCheckoutJourneyEvent).toHaveBeenCalledWith( expect.objectContaining({ phase: 'submitted' }) ) ) @@ -334,9 +326,9 @@ describe('TopUpCreditsDialogContentWorkspace', () => { resolveTopup(topupResponse('completed')) await waitFor(() => expect(mockFetchBalance).toHaveBeenCalled()) - const phases = mockTrackCheckoutJourneyEvent.mock.calls.map( - ([event]) => event.phase - ) + const phases = ( + vi.mocked(useTelemetry()?.trackCheckoutJourneyEvent)?.mock.calls ?? [] + ).map(([event]) => event.phase) expect(phases).toContain('submitted') expect(phases).not.toContain('operation_linked') expect(replacement.status).toBe('active') @@ -351,7 +343,7 @@ describe('TopUpCreditsDialogContentWorkspace', () => { await userEvent.click(screen.getByRole('button', { name: 'Pay $50.00' })) await waitFor(() => - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'topup', stage: 'failed', outcome: 'failure', @@ -704,7 +696,7 @@ describe('TopUpCreditsDialogContentWorkspace', () => { summary: 'Purchase Failed', detail: 'Failed to purchase credits: An unknown error occurred' }) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'topup', stage: 'failed', outcome: 'failure', @@ -726,14 +718,14 @@ describe('TopUpCreditsDialogContentWorkspace', () => { expect(mockFetchBalance).toHaveBeenCalledOnce() expect(mockFetchStatus).toHaveBeenCalledOnce() expect(mockShowSettings).toHaveBeenCalledWith('workspace') - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'topup', stage: 'succeeded', outcome: 'success', billing_op_id: 'op-1', duration_ms: expect.any(Number) }) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'operation', stage: 'succeeded', outcome: 'success', @@ -772,8 +764,8 @@ describe('TopUpCreditsDialogContentWorkspace', () => { await clickAddCredits() await userEvent.click(screen.getByRole('button', { name: 'Pay $50.00' })) - expect(mockTrackBillingEvent).toHaveBeenCalledTimes(4) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledTimes(4) + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'topup', stage: 'succeeded', outcome: 'success', @@ -800,7 +792,7 @@ describe('TopUpCreditsDialogContentWorkspace', () => { ) expect(mockFetchBalance).not.toHaveBeenCalled() expect(mockFetchStatus).not.toHaveBeenCalled() - expect(mockTrackBillingEvent).not.toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).not.toHaveBeenCalledWith( expect.objectContaining({ stage: 'succeeded' }) ) }) @@ -814,7 +806,7 @@ describe('TopUpCreditsDialogContentWorkspace', () => { expect(mockFetchBalance).not.toHaveBeenCalled() expect(mockFetchStatus).not.toHaveBeenCalled() - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'topup', stage: 'failed', outcome: 'failure', @@ -822,7 +814,7 @@ describe('TopUpCreditsDialogContentWorkspace', () => { failure_category: 'provider_decline', duration_ms: expect.any(Number) }) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'operation', stage: 'failed', outcome: 'failure', @@ -842,7 +834,7 @@ describe('TopUpCreditsDialogContentWorkspace', () => { await userEvent.click(screen.getByRole('button', { name: 'Pay $50.00' })) await waitFor(() => - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'topup', stage: 'failed', outcome: 'failure', @@ -861,7 +853,9 @@ describe('TopUpCreditsDialogContentWorkspace', () => { expect(screen.getByRole('button', { name: 'Pay $50.00' })).toBeDisabled() expect(mockTopup).not.toHaveBeenCalled() - expect(mockTrackTopUpPurchase).not.toHaveBeenCalled() + expect( + useTelemetry()?.trackApiCreditTopupButtonPurchaseClicked + ).not.toHaveBeenCalled() expect(mockToastAdd).not.toHaveBeenCalled() expect(useDialogStore().closeDialog).not.toHaveBeenCalled() }) diff --git a/src/platform/workspace/components/dialogs/InviteMemberDialogContent.test.ts b/src/platform/workspace/components/dialogs/InviteMemberDialogContent.test.ts index 838d4183660..8029b40d6d4 100644 --- a/src/platform/workspace/components/dialogs/InviteMemberDialogContent.test.ts +++ b/src/platform/workspace/components/dialogs/InviteMemberDialogContent.test.ts @@ -5,28 +5,22 @@ import userEvent from '@testing-library/user-event' import { beforeEach, describe, expect, it, vi } from 'vitest' import { createI18n } from 'vue-i18n' +import { useTelemetry } from '@/platform/telemetry' + import InviteMemberDialogContent from './InviteMemberDialogContent.vue' import type { WorkspacePendingInvite } from '@/platform/workspace/stores/teamWorkspaceStore' -const { - mockToastAdd, - mockTrackInviteSent, - mockTrackInviteFailed, - mockFetchStatus, - mockMaxSeats, - mockOccupiedSeats -} = vi.hoisted(() => { - const nullableNumber = (value: number | null) => ({ value }) - return { - mockToastAdd: vi.fn(), - mockTrackInviteSent: vi.fn(), - mockTrackInviteFailed: vi.fn(), - mockFetchStatus: vi.fn(), - mockMaxSeats: nullableNumber(73), - mockOccupiedSeats: nullableNumber(0) - } -}) +const { mockToastAdd, mockFetchStatus, mockMaxSeats, mockOccupiedSeats } = + vi.hoisted(() => { + const nullableNumber = (value: number | null) => ({ value }) + return { + mockToastAdd: vi.fn(), + mockFetchStatus: vi.fn(), + mockMaxSeats: nullableNumber(73), + mockOccupiedSeats: nullableNumber(0) + } + }) vi.mock(import('@/composables/billing/useBillingContext'), () => ({ useBillingContext: () => ({ @@ -36,12 +30,7 @@ vi.mock(import('@/composables/billing/useBillingContext'), () => ({ }) })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackWorkspaceInviteSent: mockTrackInviteSent, - trackWorkspaceInviteFailed: mockTrackInviteFailed - }) -})) +vi.mock(import('@/platform/telemetry')) vi.mock( import('primevue/usetoast'), // eslint-disable-line primevue-removal/no-imports @@ -205,7 +194,7 @@ describe('InviteMemberDialogContent', () => { expect(useTeamWorkspaceStore().createInvite).toHaveBeenCalledTimes(2) expect(useTeamWorkspaceStore().createInvite).toHaveBeenCalledWith('a@b.com') expect(useTeamWorkspaceStore().createInvite).toHaveBeenCalledWith('c@d.com') - expect(mockTrackInviteSent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackWorkspaceInviteSent).toHaveBeenCalledWith({ source: 'settings_members', count: 2 }) @@ -240,7 +229,7 @@ describe('InviteMemberDialogContent', () => { expect(mockToastAdd).toHaveBeenCalledWith( expect.objectContaining({ severity: 'error' }) ) - expect(mockTrackInviteSent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackWorkspaceInviteSent).toHaveBeenCalledWith({ source: 'settings_members', count: 1 }) @@ -267,7 +256,7 @@ describe('InviteMemberDialogContent', () => { expect(mockToastAdd).toHaveBeenCalledWith( expect.objectContaining({ severity: 'error' }) ) - expect(mockTrackInviteSent).not.toHaveBeenCalled() + expect(useTelemetry()?.trackWorkspaceInviteSent).not.toHaveBeenCalled() expect(inviteButton()).toBeEnabled() }) diff --git a/src/platform/workspace/composables/useDowngradeToPersonal.test.ts b/src/platform/workspace/composables/useDowngradeToPersonal.test.ts index 6036a8ffd66..85e7949e0f1 100644 --- a/src/platform/workspace/composables/useDowngradeToPersonal.test.ts +++ b/src/platform/workspace/composables/useDowngradeToPersonal.test.ts @@ -3,6 +3,8 @@ import { useBillingOperationStore } from '@/platform/workspace/stores/billingOpe import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { ref } from 'vue' +import { useTelemetry } from '@/platform/telemetry' + import { WorkspaceApiError } from '@/platform/workspace/api/workspaceApi' import type { ListMembersParams } from '@/platform/workspace/api/workspaceApi' import type { WorkspaceMember } from '@/platform/workspace/stores/teamWorkspaceStore' @@ -24,7 +26,6 @@ const mockSubscribe = vi.hoisted(() => vi.fn()) const mockPreviewSubscribe = vi.hoisted(() => vi.fn()) const mockFetchStatus = vi.hoisted(() => vi.fn()) -const mockTrackBillingEvent = vi.hoisted(() => vi.fn()) const mockPermissions = vi.hoisted(() => ({ value: { canManageSubscription: true, @@ -104,11 +105,7 @@ vi.mock(import('@/config/comfyApi'), () => ({ getComfyPlatformBaseUrl: () => 'https://platform.test' })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackBillingEvent: mockTrackBillingEvent - }) -})) +vi.mock(import('@/platform/telemetry')) function createMember( overrides: Partial = {} @@ -503,15 +500,17 @@ describe('useDowngradeToPersonal', () => { calls.push('remove') return Promise.resolve() }) - mockTrackBillingEvent.mockImplementation((event) => { - if ( - event.stage === 'started' && - (event.operation === 'subscription_checkout' || - event.operation === 'operation') - ) { - calls.push(`${event.operation}-start`) + vi.mocked(useTelemetry()?.trackBillingEvent)?.mockImplementation( + (event) => { + if ( + event.stage === 'started' && + (event.operation === 'subscription_checkout' || + event.operation === 'operation') + ) { + calls.push(`${event.operation}-start`) + } } - }) + ) mockSubscribe.mockImplementation(() => { calls.push('subscribe') return Promise.resolve({ billing_op_id: 'op-1', status: 'subscribed' }) @@ -563,7 +562,7 @@ describe('useDowngradeToPersonal', () => { const result = await downgradeToPersonal('creator-annual') expect(result).toStrictEqual({ preview, response }) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'downgrade_to_personal', stage: 'succeeded', outcome: 'success', @@ -689,7 +688,7 @@ describe('useDowngradeToPersonal', () => { attemptStartedAt: expect.any(Number) } ) - expect(mockTrackBillingEvent).not.toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).not.toHaveBeenCalledWith( expect.objectContaining({ stage: 'succeeded' }) ) }) @@ -737,7 +736,7 @@ describe('useDowngradeToPersonal', () => { await downgradeToPersonal('founder-monthly') - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'downgrade_to_personal', stage: 'started', outcome: 'pending', @@ -757,7 +756,7 @@ describe('useDowngradeToPersonal', () => { 'm2@example.com' ) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'downgrade_to_personal', stage: 'failed', outcome: 'failure', @@ -768,7 +767,7 @@ describe('useDowngradeToPersonal', () => { error_code: 'member_removal_failed', duration_ms: expect.any(Number) }) - expect(mockTrackBillingEvent).not.toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).not.toHaveBeenCalledWith( expect.objectContaining({ stage: 'succeeded' }) ) }) @@ -780,7 +779,7 @@ describe('useDowngradeToPersonal', () => { await expect(downgradeToPersonal('founder-monthly')).rejects.toBe('boom') - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'downgrade_to_personal', stage: 'failed', outcome: 'failure', @@ -803,7 +802,7 @@ describe('useDowngradeToPersonal', () => { 'offline' ) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'downgrade_to_personal', stage: 'failed', outcome: 'failure', @@ -824,7 +823,7 @@ describe('useDowngradeToPersonal', () => { 'offline' ) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'downgrade_to_personal', stage: 'failed', outcome: 'failure', @@ -845,7 +844,7 @@ describe('useDowngradeToPersonal', () => { 'm1@example.com' ) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'downgrade_to_personal', stage: 'failed', outcome: 'failure', diff --git a/src/platform/workspace/composables/useResubscribe.test.ts b/src/platform/workspace/composables/useResubscribe.test.ts index b628ac9d6b6..e092a26e264 100644 --- a/src/platform/workspace/composables/useResubscribe.test.ts +++ b/src/platform/workspace/composables/useResubscribe.test.ts @@ -3,6 +3,8 @@ import { createApp, defineComponent } from 'vue' import type { App } from 'vue' import { createI18n } from 'vue-i18n' +import { useTelemetry } from '@/platform/telemetry' + import { AuthStoreError } from '@/stores/authStore' import { useResubscribe as createResubscribe } from './useResubscribe' @@ -13,9 +15,7 @@ const state = vi.hoisted(() => ({ canReactivate: true, canReactivatePlan: true, resubscribe: vi.fn(), - toastAdd: vi.fn(), - trackResubscribeClicked: vi.fn(), - trackBillingEvent: vi.fn() + toastAdd: vi.fn() })) vi.mock(import('@/composables/billing/useBillingContext'), () => ({ @@ -67,12 +67,7 @@ vi.mock( }) ) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackResubscribeClicked: state.trackResubscribeClicked, - trackBillingEvent: state.trackBillingEvent - }) -})) +vi.mock(import('@/platform/telemetry')) vi.mock( import('primevue/usetoast'), // eslint-disable-line primevue-removal/no-imports @@ -122,7 +117,7 @@ describe('useResubscribe', () => { await handleResubscribe() expect(state.resubscribe).not.toHaveBeenCalled() - expect(state.trackResubscribeClicked).not.toHaveBeenCalled() + expect(useTelemetry()?.trackResubscribeClicked).not.toHaveBeenCalled() expect(state.toastAdd).not.toHaveBeenCalled() expect(isResubscribing.value).toBe(false) }) @@ -136,7 +131,7 @@ describe('useResubscribe', () => { await handleResubscribe() expect(state.resubscribe).not.toHaveBeenCalled() - expect(state.trackResubscribeClicked).not.toHaveBeenCalled() + expect(useTelemetry()?.trackResubscribeClicked).not.toHaveBeenCalled() expect(state.toastAdd).not.toHaveBeenCalled() expect(isResubscribing.value).toBe(false) }) @@ -171,7 +166,7 @@ describe('useResubscribe', () => { await handleResubscribe() - expect(state.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'resubscribe', stage: 'started', outcome: 'pending', @@ -190,11 +185,11 @@ describe('useResubscribe', () => { await handleResubscribe() expect(state.resubscribe).toHaveBeenCalledOnce() - expect(state.trackResubscribeClicked).toHaveBeenCalledOnce() - expect(state.trackBillingEvent).not.toHaveBeenCalledWith( + expect(useTelemetry()?.trackResubscribeClicked).toHaveBeenCalledOnce() + expect(useTelemetry()?.trackBillingEvent).not.toHaveBeenCalledWith( expect.objectContaining({ stage: 'succeeded' }) ) - expect(state.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'resubscribe', stage: 'started', outcome: 'pending', @@ -202,7 +197,7 @@ describe('useResubscribe', () => { }) // Exactly one started event on the legacy success rail: the pre-call start, // with no duplicate post-await started/pending emitted after resubscribe() resolves. - expect(state.trackBillingEvent).toHaveBeenCalledTimes(1) + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledTimes(1) expect(state.toastAdd).toHaveBeenCalledWith( expect.objectContaining({ severity: 'success' }) ) @@ -223,7 +218,7 @@ describe('useResubscribe', () => { detail: 'Resubscribe failed for person@example.com' }) ) - expect(state.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'resubscribe', stage: 'failed', outcome: 'failure', @@ -244,10 +239,10 @@ describe('useResubscribe', () => { await handleResubscribe() - expect(state.trackBillingEvent).not.toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).not.toHaveBeenCalledWith( expect.objectContaining({ stage: 'succeeded' }) ) - expect(state.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'resubscribe', stage: 'failed', outcome: 'failure', @@ -264,7 +259,7 @@ describe('useResubscribe', () => { await handleResubscribe() - expect(state.trackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'resubscribe', stage: 'failed', outcome: 'failure', @@ -278,9 +273,11 @@ describe('useResubscribe', () => { state.resubscribe.mockImplementation(async () => { callOrder.push('resubscribe') }) - state.trackBillingEvent.mockImplementation((event: { stage: string }) => { - callOrder.push(`trackBillingEvent:${event.stage}`) - }) + vi.mocked(useTelemetry()?.trackBillingEvent)?.mockImplementation( + (event: { stage: string }) => { + callOrder.push(`trackBillingEvent:${event.stage}`) + } + ) const { handleResubscribe } = useResubscribe() await handleResubscribe() diff --git a/src/platform/workspace/composables/useSubscriptionCheckout.test.ts b/src/platform/workspace/composables/useSubscriptionCheckout.test.ts index 7c7246fcc86..f59e8f067b0 100644 --- a/src/platform/workspace/composables/useSubscriptionCheckout.test.ts +++ b/src/platform/workspace/composables/useSubscriptionCheckout.test.ts @@ -1,5 +1,5 @@ import { render } from '@testing-library/vue' -import { beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, beforeEach, describe, expect, it, vi } from 'vitest' import { computed } from 'vue' import { billingOperation } from './billingOperationTestUtils' import type { BillingOperation } from './billingOperationTestUtils' @@ -12,6 +12,8 @@ import { } from 'firebase/auth' import { createI18n } from 'vue-i18n' +import { useTelemetry } from '@/platform/telemetry' + import type { PaymentIntentSource } from '@/platform/telemetry/types' import { clearCheckoutJourney, @@ -188,8 +190,6 @@ const { mockResubscribe, mockToastAdd, mockListSavedPaymentMethods, - mockTrackBeginCheckout, - mockTrackBillingEvent, mockShowDowngradeToPersonalDialog, mockIsTeamPlan, mockShouldUseWorkspaceBilling, @@ -214,8 +214,6 @@ const { mockResubscribe: vi.fn(), mockToastAdd: vi.fn(), mockListSavedPaymentMethods: vi.fn(), - mockTrackBeginCheckout: vi.fn(), - mockTrackBillingEvent: vi.fn(), mockShowDowngradeToPersonalDialog: vi.fn(), mockIsTeamPlan: { value: false }, mockShouldUseWorkspaceBilling: { value: true }, @@ -236,7 +234,11 @@ const { canDowngradeToPersonal: true } }, - mockSubscription: { value: null as { isCancelled: boolean } | null }, + mockSubscription: { + value: null as { + isCancelled: boolean + } | null + }, mockBillingStatus: { value: null as BillingStatus | null } } }) @@ -377,19 +379,7 @@ vi.mock( }) ) -const mockTrackResubscribeClicked = vi.hoisted(() => vi.fn()) -const mockTrackMonthlySubscriptionSucceeded = vi.hoisted(() => vi.fn()) -const mockTrackCheckoutJourneyEvent = vi.hoisted(() => vi.fn()) - -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackBillingEvent: mockTrackBillingEvent, - trackResubscribeClicked: mockTrackResubscribeClicked, - trackBeginCheckout: mockTrackBeginCheckout, - trackMonthlySubscriptionSucceeded: mockTrackMonthlySubscriptionSucceeded, - trackCheckoutJourneyEvent: mockTrackCheckoutJourneyEvent - }) -})) +vi.mock(import('@/platform/telemetry')) vi.mock(import('@/platform/telemetry/reportError'), () => ({ reportError: mockReportError @@ -539,16 +529,16 @@ describe('useSubscriptionCheckout', () => { } mockCanReactivatePlan.value = true mockSubscription.value = null - mockTrackCheckoutJourneyEvent.mockClear() + vi.mocked(useTelemetry()?.trackCheckoutJourneyEvent)?.mockClear() sessionStorage.clear() clearCheckoutJourney() }) describe('checkout journey instrumentation', () => { function journeyPhases() { - return mockTrackCheckoutJourneyEvent.mock.calls.map( - ([event]) => event.phase - ) + return ( + vi.mocked(useTelemetry()?.trackCheckoutJourneyEvent)?.mock.calls ?? [] + ).map(([event]) => event.phase) } it('emits entered, submitted, and operation_linked across a subscribe', async () => { @@ -575,9 +565,9 @@ describe('useSubscriptionCheckout', () => { phases.indexOf('operation_linked') ) - const events = mockTrackCheckoutJourneyEvent.mock.calls.map( - ([event]) => event - ) + const events = ( + vi.mocked(useTelemetry()?.trackCheckoutJourneyEvent)?.mock.calls ?? [] + ).map(([event]) => event) const opLinked = events.find( (event) => event.phase === 'operation_linked' ) @@ -660,9 +650,9 @@ describe('useSubscriptionCheckout', () => { }) await checkout.handleConfirmTransition() - const events = mockTrackCheckoutJourneyEvent.mock.calls.map( - ([event]) => event - ) + const events = ( + vi.mocked(useTelemetry()?.trackCheckoutJourneyEvent)?.mock.calls ?? [] + ).map(([event]) => event) expect(events.some((event) => event.phase === 'operation_linked')).toBe( false ) @@ -671,13 +661,13 @@ describe('useSubscriptionCheckout', () => { it('records a correlated preview failure with no operation id', async () => { await submitRejectedPreview('PREVIEW_FAILED') - const events = mockTrackCheckoutJourneyEvent.mock.calls.map( - ([event]) => event - ) + const events = ( + vi.mocked(useTelemetry()?.trackCheckoutJourneyEvent)?.mock.calls ?? [] + ).map(([event]) => event) const entered = events.find((event) => event.phase === 'entered') const failed = events.find((event) => event.phase === 'preview_failed') - expect(entered).toBeDefined() - expect(failed).toBeDefined() + assert.exists(entered) + assert.exists(failed) expect(events.some((event) => event.phase === 'operation_linked')).toBe( false ) @@ -1440,9 +1430,9 @@ describe('useSubscriptionCheckout', () => { expect(checkout.previewData.value).toStrictEqual(preview) expect(checkout.checkoutStep.value).toBe('success') - expect(mockTrackBillingEvent).not.toHaveBeenCalled() + expect(useTelemetry()?.trackBillingEvent).not.toHaveBeenCalled() expect(mockToastAdd).not.toHaveBeenCalled() - expect(mockTrackBeginCheckout).toHaveBeenCalledWith( + expect(useTelemetry()?.trackBeginCheckout).toHaveBeenCalledWith( expect.objectContaining({ tier: 'creator', cycle: 'monthly', @@ -1469,7 +1459,7 @@ describe('useSubscriptionCheckout', () => { }) expect(checkout.checkoutStep.value).toBe('success') - expect(mockTrackBillingEvent).not.toHaveBeenCalled() + expect(useTelemetry()?.trackBillingEvent).not.toHaveBeenCalled() }) }) @@ -2146,7 +2136,7 @@ describe('useSubscriptionCheckout', () => { await checkout.handleTeamSubscribe() - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'subscription_checkout', stage: 'started', outcome: 'pending', @@ -2155,7 +2145,7 @@ describe('useSubscriptionCheckout', () => { checkout_type: 'new', payment_intent_source: undefined }) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'operation', stage: 'started', outcome: 'pending', @@ -2195,7 +2185,7 @@ describe('useSubscriptionCheckout', () => { confirmReactivation: false }) expect(checkout.checkoutStep.value).toBe('success') - expect(mockTrackBeginCheckout).toHaveBeenCalledWith( + expect(useTelemetry()?.trackBeginCheckout).toHaveBeenCalledWith( expect.objectContaining({ tier: 'team', checkout_type: 'new', @@ -2383,7 +2373,7 @@ describe('useSubscriptionCheckout', () => { detail: 'Reactivation confirmation required' }) ) - expect(mockTrackBillingEvent).toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ operation: 'subscription_checkout', stage: 'failed', @@ -2442,7 +2432,7 @@ describe('useSubscriptionCheckout', () => { expect(mockToastAdd).toHaveBeenCalledWith( expect.objectContaining({ severity: 'error' }) ) - expect(mockTrackBillingEvent).not.toHaveBeenCalled() + expect(useTelemetry()?.trackBillingEvent).not.toHaveBeenCalled() }) it('refuses to bill a team reactivation when a fresh preview no longer matches the confirmed charge', async () => { @@ -2530,7 +2520,7 @@ describe('useSubscriptionCheckout', () => { detail: 'status unavailable' }) ) - expect(mockTrackBillingEvent).not.toHaveBeenCalled() + expect(useTelemetry()?.trackBillingEvent).not.toHaveBeenCalled() }) it('bounces to pricing when a required reactivation refresh cannot collect consent', async () => { @@ -2629,7 +2619,7 @@ describe('useSubscriptionCheckout', () => { detail: 'Reactivation confirmation required' }) ) - expect(mockTrackBillingEvent).not.toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).not.toHaveBeenCalledWith( expect.objectContaining({ stage: 'failed' }) ) @@ -2650,17 +2640,21 @@ describe('useSubscriptionCheckout', () => { ) expect(checkout.checkoutStep.value).toBe('success') expect( - mockTrackBillingEvent.mock.calls.filter( - ([event]) => - event.operation === 'subscription_checkout' && - event.stage === 'started' - ) + vi + .mocked(useTelemetry()?.trackBillingEvent) + ?.mock.calls.filter( + ([event]) => + event.operation === 'subscription_checkout' && + event.stage === 'started' + ) ).toHaveLength(1) expect( - mockTrackBillingEvent.mock.calls.filter( - ([event]) => - event.operation === 'operation' && event.stage === 'started' - ) + vi + .mocked(useTelemetry()?.trackBillingEvent) + ?.mock.calls.filter( + ([event]) => + event.operation === 'operation' && event.stage === 'started' + ) ).toHaveLength(1) }) @@ -2756,8 +2750,8 @@ describe('useSubscriptionCheckout', () => { detail: 'Team payment failed' }) ) - expect(mockTrackBeginCheckout).not.toHaveBeenCalled() - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBeginCheckout).not.toHaveBeenCalled() + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'subscription_checkout', stage: 'failed', outcome: 'failure', @@ -3118,7 +3112,7 @@ describe('useSubscriptionCheckout', () => { await checkout.handleAddCreditCard() - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'subscription_checkout', stage: 'started', outcome: 'pending', @@ -3127,7 +3121,7 @@ describe('useSubscriptionCheckout', () => { checkout_type: 'new', payment_intent_source: undefined }) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'operation', stage: 'started', outcome: 'pending', @@ -3158,7 +3152,7 @@ describe('useSubscriptionCheckout', () => { confirmReactivation: false }) expect(checkout.checkoutStep.value).toBe('success') - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'subscription_checkout', stage: 'succeeded', outcome: 'success', @@ -3169,7 +3163,9 @@ describe('useSubscriptionCheckout', () => { billing_op_id: 'op-1', duration_ms: expect.any(Number) }) - expect(mockTrackMonthlySubscriptionSucceeded).not.toHaveBeenCalled() + expect( + useTelemetry()?.trackMonthlySubscriptionSucceeded + ).not.toHaveBeenCalled() expect(mockFetchStatus).toHaveBeenCalledTimes(1) expect(mockFetchBalance).not.toHaveBeenCalled() }) @@ -3188,7 +3184,7 @@ describe('useSubscriptionCheckout', () => { await checkout.handleAddCreditCard() - expect(mockTrackBeginCheckout).not.toHaveBeenCalled() + expect(useTelemetry()?.trackBeginCheckout).not.toHaveBeenCalled() Object.assign(useAuthStore(), { userId: 'user-1' }) }) @@ -3205,7 +3201,7 @@ describe('useSubscriptionCheckout', () => { await checkout.handleAddCreditCard() - expect(mockTrackBeginCheckout).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBeginCheckout).toHaveBeenCalledWith({ user_id: 'user-1', tier: 'standard', cycle: 'yearly', @@ -3680,8 +3676,8 @@ describe('useSubscriptionCheckout', () => { detail: 'Payment failed' }) ) - expect(mockTrackBeginCheckout).not.toHaveBeenCalled() - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBeginCheckout).not.toHaveBeenCalled() + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'subscription_checkout', stage: 'failed', outcome: 'failure', @@ -3702,7 +3698,7 @@ describe('useSubscriptionCheckout', () => { await checkout.handleAddCreditCard() - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'subscription_checkout', stage: 'failed', outcome: 'failure', @@ -3725,7 +3721,7 @@ describe('useSubscriptionCheckout', () => { await checkout.handleAddCreditCard() - expect(mockTrackBillingEvent).not.toHaveBeenCalled() + expect(useTelemetry()?.trackBillingEvent).not.toHaveBeenCalled() }) it('does not submit when workspace ownership is revoked', async () => { @@ -3757,7 +3753,9 @@ describe('useSubscriptionCheckout', () => { await checkout.handleConfirmTransition() expect(checkout.checkoutStep.value).toBe('success') - expect(mockTrackMonthlySubscriptionSucceeded).not.toHaveBeenCalled() + expect( + useTelemetry()?.trackMonthlySubscriptionSucceeded + ).not.toHaveBeenCalled() }) it('shows error toast on failure', async () => { @@ -3885,7 +3883,7 @@ describe('useSubscriptionCheckout', () => { detail: 'Reactivation confirmation required' }) ) - expect(mockTrackBillingEvent).not.toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).not.toHaveBeenCalledWith( expect.objectContaining({ stage: 'failed' }) ) }) @@ -4002,7 +4000,7 @@ describe('useSubscriptionCheckout', () => { detail: 'Reactivation amount changed' }) ) - expect(mockTrackBillingEvent).toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ operation: 'subscription_checkout', stage: 'failed', @@ -4087,7 +4085,7 @@ describe('useSubscriptionCheckout', () => { expect(mockToastAdd).toHaveBeenCalledWith( expect.objectContaining({ severity: 'error' }) ) - expect(mockTrackBillingEvent).not.toHaveBeenCalled() + expect(useTelemetry()?.trackBillingEvent).not.toHaveBeenCalled() }) it('refuses to bill when a fresh preview no longer matches the confirmed charge', async () => { @@ -4190,7 +4188,7 @@ describe('useSubscriptionCheckout', () => { await checkout.handleConfirmTransition() expect(mockSubscribe).not.toHaveBeenCalled() - expect(mockTrackBeginCheckout).not.toHaveBeenCalled() + expect(useTelemetry()?.trackBeginCheckout).not.toHaveBeenCalled() expect(emit).not.toHaveBeenCalled() expect(mockToastAdd).not.toHaveBeenCalled() }) @@ -4263,7 +4261,7 @@ describe('useSubscriptionCheckout', () => { await checkout.handleResubscribe() - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'resubscribe', stage: 'started', outcome: 'pending', @@ -4285,11 +4283,11 @@ describe('useSubscriptionCheckout', () => { expect(mockResubscribe).toHaveBeenCalled() expect(emit).toHaveBeenCalledWith('close', true) - expect(mockTrackResubscribeClicked).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackResubscribeClicked).toHaveBeenCalledWith({ source: 'pricing_dialog', payment_intent_source: 'subscribe_to_run' }) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'resubscribe', stage: 'succeeded', outcome: 'success', @@ -4312,7 +4310,7 @@ describe('useSubscriptionCheckout', () => { detail: 'Resubscribe failed for person@example.com' }) ) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'resubscribe', stage: 'failed', outcome: 'failure', @@ -4330,18 +4328,18 @@ describe('useSubscriptionCheckout', () => { await checkout.handleResubscribe() expect(mockResubscribe).toHaveBeenCalledOnce() - expect(mockTrackResubscribeClicked).toHaveBeenCalledOnce() - expect(mockTrackBillingEvent).not.toHaveBeenCalledWith( + expect(useTelemetry()?.trackResubscribeClicked).toHaveBeenCalledOnce() + expect(useTelemetry()?.trackBillingEvent).not.toHaveBeenCalledWith( expect.objectContaining({ stage: 'succeeded' }) ) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'resubscribe', stage: 'started', outcome: 'pending', source: 'pricing_dialog', payment_intent_source: 'subscribe_to_run' }) - expect(mockTrackBillingEvent).toHaveBeenCalledTimes(1) + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledTimes(1) }) it('fires resubscribe failure telemetry on the legacy rail too', async () => { @@ -4352,7 +4350,7 @@ describe('useSubscriptionCheckout', () => { await checkout.handleResubscribe() - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'resubscribe', stage: 'failed', outcome: 'failure', @@ -4388,7 +4386,7 @@ describe('useSubscriptionCheckout', () => { await checkout.handleResubscribe() expect(mockResubscribe).not.toHaveBeenCalled() - expect(mockTrackResubscribeClicked).not.toHaveBeenCalled() + expect(useTelemetry()?.trackResubscribeClicked).not.toHaveBeenCalled() }) it('does not resubscribe when the server denies reactivation to a client-side owner', async () => { @@ -4399,7 +4397,7 @@ describe('useSubscriptionCheckout', () => { await checkout.handleResubscribe() expect(mockResubscribe).not.toHaveBeenCalled() - expect(mockTrackResubscribeClicked).not.toHaveBeenCalled() + expect(useTelemetry()?.trackResubscribeClicked).not.toHaveBeenCalled() }) it('emits started before the awaited resubscribe call resolves', async () => { @@ -4408,7 +4406,7 @@ describe('useSubscriptionCheckout', () => { callOrder.push('resubscribe') return { billing_op_id: 'op-4', status: 'active' } }) - mockTrackBillingEvent.mockImplementationOnce( + vi.mocked(useTelemetry()?.trackBillingEvent)?.mockImplementationOnce( (event: { stage: string }) => { callOrder.push(`trackBillingEvent:${event.stage}`) } diff --git a/src/platform/workspace/composables/useWorkspaceBilling.test.ts b/src/platform/workspace/composables/useWorkspaceBilling.test.ts index a0789802746..64abb06bb4e 100644 --- a/src/platform/workspace/composables/useWorkspaceBilling.test.ts +++ b/src/platform/workspace/composables/useWorkspaceBilling.test.ts @@ -4,6 +4,8 @@ import { useBillingOperationStore } from '@/platform/workspace/stores/billingOpe import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { effectScope } from 'vue' +import { useTelemetry } from '@/platform/telemetry' + import type { BillingStatusResponse, SubscribeResponse @@ -83,13 +85,7 @@ vi.mock(import('@/platform/telemetry/reportError'), () => ({ reportError: mockReportError })) -const mockTrackBillingEvent = vi.hoisted(() => vi.fn()) - -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackBillingEvent: mockTrackBillingEvent - }) -})) +vi.mock(import('@/platform/telemetry')) let scope: ReturnType | undefined @@ -1176,7 +1172,7 @@ describe('useWorkspaceBilling', () => { const billing = setupBilling() await billing.cancelSubscription() - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'operation', stage: 'started', outcome: 'pending', @@ -1194,7 +1190,7 @@ describe('useWorkspaceBilling', () => { await expect(billing.cancelSubscription()).rejects.toThrow( 'Upstream failure' ) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'operation', stage: 'failed', outcome: 'failure', @@ -1212,7 +1208,7 @@ describe('useWorkspaceBilling', () => { const billing = setupBilling() await expect(billing.cancelSubscription()).rejects.toThrow() - expect(mockTrackBillingEvent).toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ failure_category: 'network' }) ) }) @@ -1234,7 +1230,7 @@ describe('useWorkspaceBilling', () => { await expect(billing.cancelSubscription()).rejects.toThrow( 'processor rejected' ) - expect(mockTrackBillingEvent).not.toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).not.toHaveBeenCalledWith( expect.objectContaining({ stage: 'failed' }) ) }) @@ -1272,16 +1268,16 @@ describe('useWorkspaceBilling', () => { expect(billing.subscription.value?.tier).toBe('CREATOR') expect(useBillingOperationStore().startOperation).not.toHaveBeenCalled() expect(billing.isLoading.value).toBe(false) - expect(mockTrackBillingEvent).not.toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).not.toHaveBeenCalledWith( expect.objectContaining({ stage: 'failed' }) ) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'operation', stage: 'started', outcome: 'pending', operation_type: 'cancel' }) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'operation', stage: 'succeeded', outcome: 'success', diff --git a/src/platform/workspace/stores/billingOperationStore.test.ts b/src/platform/workspace/stores/billingOperationStore.test.ts index 5c35d18cd80..156378e70c2 100644 --- a/src/platform/workspace/stores/billingOperationStore.test.ts +++ b/src/platform/workspace/stores/billingOperationStore.test.ts @@ -9,6 +9,8 @@ import { useToastStore } from '@/platform/updates/common/toastStore' import { useDialogStore } from '@/stores/dialogStore' import { beforeEach, describe, expect, it, vi } from 'vitest' +import { useTelemetry } from '@/platform/telemetry' + import type { BillingOpStatusResponse } from '@/platform/workspace/api/workspaceApi' const { mockHandleNextAction, mockLoadStripe, mockFeatureFlags } = vi.hoisted( @@ -80,15 +82,7 @@ vi.mock(import('@/platform/settings/composables/useSettingsDialog'), () => ({ }) })) -const mockTrackBillingEvent = vi.fn() -const mockTrackMonthlySubscriptionSucceeded = vi.fn() - -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackBillingEvent: mockTrackBillingEvent, - trackMonthlySubscriptionSucceeded: mockTrackMonthlySubscriptionSucceeded - }) -})) +vi.mock(import('@/platform/telemetry')) import { workspaceApi } from '@/platform/workspace/api/workspaceApi' @@ -390,7 +384,7 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) - expect(mockTrackBillingEvent.mock.calls).toEqual([ + expect(vi.mocked(useTelemetry()?.trackBillingEvent)?.mock.calls).toEqual([ [ { operation: 'operation', @@ -433,7 +427,7 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) - expect(mockTrackBillingEvent.mock.calls).toEqual([ + expect(vi.mocked(useTelemetry()?.trackBillingEvent)?.mock.calls).toEqual([ [ { operation: 'operation', @@ -560,7 +554,7 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'subscription_checkout', stage: 'succeeded', outcome: 'success', @@ -591,7 +585,9 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) - expect(mockTrackMonthlySubscriptionSucceeded).toHaveBeenCalledWith({ + expect( + useTelemetry()?.trackMonthlySubscriptionSucceeded + ).toHaveBeenCalledWith({ tier: 'creator', cycle: 'yearly', checkout_type: 'new', @@ -612,7 +608,9 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) - expect(mockTrackMonthlySubscriptionSucceeded).not.toHaveBeenCalled() + expect( + useTelemetry()?.trackMonthlySubscriptionSucceeded + ).not.toHaveBeenCalled() }) it('does not fire the generic subscription-success event for a downgrade-to-personal success', async () => { @@ -640,8 +638,10 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) - expect(mockTrackMonthlySubscriptionSucceeded).not.toHaveBeenCalled() - expect(mockTrackBillingEvent).toHaveBeenCalledWith( + expect( + useTelemetry()?.trackMonthlySubscriptionSucceeded + ).not.toHaveBeenCalled() + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ operation: 'downgrade_to_personal' }) ) }) @@ -667,10 +667,10 @@ describe('billingOperationStore', () => { } }) - expect(mockTrackBillingEvent).not.toHaveBeenCalled() + expect(useTelemetry()?.trackBillingEvent).not.toHaveBeenCalled() await vi.advanceTimersByTimeAsync(0) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'downgrade_to_personal', stage: 'succeeded', outcome: 'success', @@ -695,7 +695,7 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'topup', stage: 'succeeded', outcome: 'success', @@ -726,7 +726,7 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'operation', stage: 'succeeded', outcome: 'success', @@ -779,11 +779,14 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) await vi.advanceTimersByTimeAsync(1500) - const successCall = mockTrackBillingEvent.mock.calls.find( - ([event]) => - event.operation === 'operation' && event.stage === 'succeeded' - ) - expect(successCall?.[0].duration_ms).toBeGreaterThanOrEqual(1500) + const successEvent = vi + .mocked(useTelemetry()?.trackBillingEvent) + ?.mock.calls.map(([event]) => event) + .find( + (event) => + event.operation === 'operation' && event.stage === 'succeeded' + ) + expect(successEvent?.duration_ms).toBeGreaterThanOrEqual(1500) }) it('computes duration_ms from the caller-supplied attemptStartedAt, not from when startOperation() itself ran', async () => { @@ -808,12 +811,15 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) await vi.advanceTimersByTimeAsync(1500) - const successCall = mockTrackBillingEvent.mock.calls.find( - ([event]) => event.operation === 'topup' && event.stage === 'succeeded' - ) + const successEvent = vi + .mocked(useTelemetry()?.trackBillingEvent) + ?.mock.calls.map(([event]) => event) + .find( + (event) => event.operation === 'topup' && event.stage === 'succeeded' + ) // Poll-observed time alone is ~1500ms; duration_ms must also include the // 300ms initiation latency that preceded startOperation() running. - expect(successCall?.[0].duration_ms).toBeGreaterThanOrEqual(1800) + expect(successEvent?.duration_ms).toBeGreaterThanOrEqual(1800) }) it('removes the received toast when operation succeeds', async () => { @@ -925,7 +931,7 @@ describe('billingOperationStore', () => { detail: 'billingOperation.subscriptionFailedDetail', life: 7000 }) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'operation', stage: 'failed', outcome: 'failure', @@ -952,7 +958,7 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) - expect(mockTrackBillingEvent).toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ operation_type: 'topup', failure_category: 'provider_decline' @@ -977,7 +983,7 @@ describe('billingOperationStore', () => { expect(useToastStore().add).not.toHaveBeenCalledWith( expect.objectContaining({ severity: 'error' }) ) - expect(mockTrackBillingEvent).toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ stage: 'failed', billing_op_id: 'op-1', @@ -998,7 +1004,7 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) - expect(mockTrackBillingEvent).toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ operation_type: 'cancel', failure_category: 'api_rejected' @@ -1028,21 +1034,21 @@ describe('billingOperationStore', () => { // Both emissions must agree: a downgrade that was merely replaced is not // an unexplained billing failure in either event stream. - expect(mockTrackBillingEvent).toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ operation: 'operation', stage: 'failed', failure_category: 'stale_operation' }) ) - expect(mockTrackBillingEvent).toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ operation: 'downgrade_to_personal', stage: 'failed', failure_category: 'stale_operation' }) ) - expect(mockTrackBillingEvent).not.toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).not.toHaveBeenCalledWith( expect.objectContaining({ failure_category: 'unknown' }) ) }) @@ -1066,17 +1072,20 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) await vi.advanceTimersByTimeAsync(1500) - expect(mockTrackBillingEvent).toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ operation: 'operation', stage: 'failed', duration_ms: expect.any(Number) }) ) - const failureCall = mockTrackBillingEvent.mock.calls.find( - ([event]) => event.operation === 'operation' && event.stage === 'failed' - ) - expect(failureCall?.[0].duration_ms).toBeGreaterThanOrEqual(1500) + const failureEvent = vi + .mocked(useTelemetry()?.trackBillingEvent) + ?.mock.calls.map(([event]) => event) + .find( + (event) => event.operation === 'operation' && event.stage === 'failed' + ) + expect(failureEvent?.duration_ms).toBeGreaterThanOrEqual(1500) }) it('uses default message when no error_message in response', async () => { @@ -1120,20 +1129,20 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) - expect(mockTrackBillingEvent).toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ operation: 'operation', operation_type: 'subscription', failure_category: 'api_rejected' }) ) - expect(mockTrackBillingEvent).toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ operation: 'downgrade_to_personal', failure_category: 'api_rejected' }) ) - expect(mockTrackBillingEvent).not.toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).not.toHaveBeenCalledWith( expect.objectContaining({ failure_category: 'provider_decline' }) ) }) @@ -1151,7 +1160,7 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(0) - expect(mockTrackBillingEvent).toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ operation_type: 'subscription', failure_category: 'network' @@ -1899,7 +1908,7 @@ describe('billingOperationStore', () => { }) await vi.advanceTimersByTimeAsync(60_000) expect(workspaceApi.getBillingOpStatus).toHaveBeenCalledOnce() - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'operation', stage: 'failed', outcome: 'failure', @@ -1912,7 +1921,7 @@ describe('billingOperationStore', () => { failure_category: 'reconciliation_needed', duration_ms: 0 }) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'subscription_checkout', stage: 'failed', outcome: 'failure', @@ -2056,18 +2065,21 @@ describe('billingOperationStore', () => { await vi.advanceTimersByTimeAsync(121_000) await vi.runAllTimersAsync() - expect(mockTrackBillingEvent).toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ operation: 'operation', stage: 'timeout', duration_ms: expect.any(Number) }) ) - const timeoutCall = mockTrackBillingEvent.mock.calls.find( - ([event]) => - event.operation === 'operation' && event.stage === 'timeout' - ) - expect(timeoutCall?.[0].duration_ms).toBeGreaterThanOrEqual(120_000) + const timeoutEvent = vi + .mocked(useTelemetry()?.trackBillingEvent) + ?.mock.calls.map(([event]) => event) + .find( + (event) => + event.operation === 'operation' && event.stage === 'timeout' + ) + expect(timeoutEvent?.duration_ms).toBeGreaterThanOrEqual(120_000) }) it('keeps a valid action URL pending past discovery and clears it on success', async () => { @@ -2111,9 +2123,9 @@ describe('billingOperationStore', () => { expect( JSON.stringify(vi.mocked(useToastStore().add).mock.calls) ).not.toContain(actionUrl) - expect(JSON.stringify(mockTrackBillingEvent.mock.calls)).not.toContain( - actionUrl - ) + expect( + JSON.stringify(vi.mocked(useTelemetry()?.trackBillingEvent)?.mock.calls) + ).not.toContain(actionUrl) }) it('replaces the processing toast when the operation parks on a bank challenge', async () => { @@ -2467,7 +2479,7 @@ describe('billingOperationStore', () => { ).toHaveBeenCalledWith({ isSubscribed: false }) - expect(mockTrackBillingEvent).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith({ operation: 'operation', stage: 'succeeded', outcome: 'success', @@ -2530,7 +2542,7 @@ describe('billingOperationStore', () => { useTeamWorkspaceStore().updateActiveWorkspace ).not.toHaveBeenCalled() expect(useToastStore().add).not.toHaveBeenCalled() - expect(mockTrackBillingEvent).toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ operation: 'operation', stage: 'failed', @@ -2566,7 +2578,7 @@ describe('billingOperationStore', () => { useTeamWorkspaceStore().updateActiveWorkspace ).not.toHaveBeenCalled() expect(useToastStore().add).not.toHaveBeenCalled() - expect(mockTrackBillingEvent).toHaveBeenCalledWith( + expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith( expect.objectContaining({ operation: 'operation', stage: 'timeout', diff --git a/src/platform/workspace/stores/useWorkspaceAuth.test.ts b/src/platform/workspace/stores/useWorkspaceAuth.test.ts index d64cb82244a..07c51baac66 100644 --- a/src/platform/workspace/stores/useWorkspaceAuth.test.ts +++ b/src/platform/workspace/stores/useWorkspaceAuth.test.ts @@ -11,6 +11,8 @@ import { storeToRefs } from 'pinia' import { nextTick } from 'vue' import { beforeEach, describe, expect, it, vi } from 'vitest' +import { useTelemetry } from '@/platform/telemetry' + import { useWorkspaceAuthStore, WorkspaceAuthError @@ -24,8 +26,6 @@ import { WORKSPACE_STORAGE_KEYS } from '@/platform/workspace/workspaceConstants' vi.mock(import('firebase/auth'), { spy: true }) -const mockTrackUnifiedAuthRefresh = vi.fn() - /** * Stands in for Firebase behind the store's identity entry: assigning * `value` moves the store's user AND fires the port, the way a real @@ -70,11 +70,7 @@ vi.mock(import('@/platform/auth/session/useSessionCookie'), () => ({ }) })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackUnifiedAuthRefresh: mockTrackUnifiedAuthRefresh - }) -})) +vi.mock(import('@/platform/telemetry')) vi.mock(import('@/platform/workspace/api/workspaceApiUrl'), () => ({ workspaceApiUrl: (route: string) => `https://api.example.com/api${route}` @@ -3061,7 +3057,9 @@ describe('useWorkspaceAuthStore', () => { expect(useToastStore().add).toHaveBeenCalledWith( expect.objectContaining({ severity: 'error', detail: detailKey }) ) - expect(mockTrackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ + expect( + useTelemetry()?.trackUnifiedAuthRefresh + ).toHaveBeenLastCalledWith({ outcome: 'permanent_failure', retry_count: 0 }) @@ -3198,7 +3196,7 @@ describe('useWorkspaceAuthStore', () => { await vi.advanceTimersByTimeAsync(refreshDelay) expect(mockFetch).toHaveBeenCalledTimes(2) expect(useAuthStore().notifyTokenRefreshed).not.toHaveBeenCalled() - expect(mockTrackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ + expect(useTelemetry()?.trackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ outcome: 'retry_scheduled', retry_count: 1 }) @@ -3207,7 +3205,7 @@ describe('useWorkspaceAuthStore', () => { expect(mockFetch).toHaveBeenCalledTimes(3) expect(useAuthStore().notifyTokenRefreshed).toHaveBeenCalledTimes(1) - expect(mockTrackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ + expect(useTelemetry()?.trackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ outcome: 'succeeded' }) expect(unifiedToken.value).toBe('unified-token-1') @@ -3251,7 +3249,7 @@ describe('useWorkspaceAuthStore', () => { const store = useWorkspaceAuthStore() await store.mintAtLogin() await vi.advanceTimersByTimeAsync(expiresInMs - 5 * 60 * 1000) - expect(mockTrackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ + expect(useTelemetry()?.trackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ outcome: 'retry_scheduled', retry_count: 1 }) @@ -3262,7 +3260,7 @@ describe('useWorkspaceAuthStore', () => { await vi.advanceTimersByTimeAsync(expiresInMs - 5 * 60 * 1000) expect( - mockTrackUnifiedAuthRefresh, + useTelemetry()?.trackUnifiedAuthRefresh, 'a successful mint starts a fresh retry chain; a stale count here poisons the exhaustion signal' ).toHaveBeenLastCalledWith({ outcome: 'retry_scheduled', @@ -3305,7 +3303,7 @@ describe('useWorkspaceAuthStore', () => { await vi.advanceTimersByTimeAsync(20000) expect(mockFetch).toHaveBeenCalledTimes(5) - expect(mockTrackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ + expect(useTelemetry()?.trackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ outcome: 'retries_exhausted', retry_count: 3 }) @@ -3318,7 +3316,7 @@ describe('useWorkspaceAuthStore', () => { expect(mockFetch).toHaveBeenCalledTimes(5) expect(useToastStore().add).not.toHaveBeenCalled() - expect(mockTrackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ + expect(useTelemetry()?.trackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ outcome: 'expired', retry_count: 3 }) @@ -3378,7 +3376,7 @@ describe('useWorkspaceAuthStore', () => { await vi.advanceTimersByTimeAsync(expiresInMs - 5 * 60 * 1000) await vi.advanceTimersByTimeAsync(5000 + 10_000 + 20_000) - expect(mockTrackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ + expect(useTelemetry()?.trackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ outcome: 'retries_exhausted', retry_count: 3 }) @@ -3391,7 +3389,7 @@ describe('useWorkspaceAuthStore', () => { await vi.advanceTimersByTimeAsync(5 * 60 * 1000) - expect(mockTrackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ + expect(useTelemetry()?.trackUnifiedAuthRefresh).toHaveBeenLastCalledWith({ outcome: 'expired', retry_count: 3 }) diff --git a/src/renderer/extensions/firstRunTour/nudge/FirstRunTourNudge.test.ts b/src/renderer/extensions/firstRunTour/nudge/FirstRunTourNudge.test.ts index b4808391abb..d138d5f3df3 100644 --- a/src/renderer/extensions/firstRunTour/nudge/FirstRunTourNudge.test.ts +++ b/src/renderer/extensions/firstRunTour/nudge/FirstRunTourNudge.test.ts @@ -5,6 +5,8 @@ import { render, screen } from '@testing-library/vue' import { beforeEach, describe, expect, it, vi } from 'vitest' import { createI18n } from 'vue-i18n' +import { useTelemetry } from '@/platform/telemetry' + import enMessages from '@/locales/en/main.json' with { type: 'json' } import FirstRunTourNudge from './FirstRunTourNudge.vue' @@ -16,12 +18,10 @@ const mocks = await vi.hoisted(async () => { return { nudgeArmed: ref(false), tourWasCompleted: ref(true), - dismissNudge: vi.fn(() => { mocks.nudgeArmed.value = false }), - showTemplates: vi.fn(), - trackOnboardingTour: vi.fn() + showTemplates: vi.fn() } }) @@ -40,9 +40,7 @@ vi.mock( }) ) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ trackOnboardingTour: mocks.trackOnboardingTour }) -})) +vi.mock(import('@/platform/telemetry')) const i18n = createI18n({ legacy: false, @@ -83,10 +81,13 @@ describe('FirstRunTourNudge', () => { nudge(), 'a nudge armed before this mounted still has to appear' ).not.toBeNull() - expect(mocks.trackOnboardingTour).toHaveBeenCalledWith('nudge_shown', { - tour: 'firstRun', - tour_completed: true - }) + expect(useTelemetry()?.trackOnboardingTour).toHaveBeenCalledWith( + 'nudge_shown', + { + tour: 'firstRun', + tour_completed: true + } + ) }) it('waits out a dialog that is already open', async () => { @@ -122,7 +123,7 @@ describe('FirstRunTourNudge', () => { 'a nudge that came due behind a dialog would land on top of the modal' ).toBeNull() expect( - mocks.trackOnboardingTour, + useTelemetry()?.trackOnboardingTour, 'a nudge nobody can see has not been shown' ).not.toHaveBeenCalledWith('nudge_shown', expect.anything()) }) @@ -137,9 +138,9 @@ describe('FirstRunTourNudge', () => { useDialogStore().dialogStack = [] await vi.advanceTimersByTimeAsync(APPEAR_DELAY_MS) - const shown = mocks.trackOnboardingTour.mock.calls.filter( - ([stage]) => stage === 'nudge_shown' - ) + const shown = vi + .mocked(useTelemetry()?.trackOnboardingTour) + ?.mock.calls.filter(([stage]) => stage === 'nudge_shown') expect( shown, 'the funnel counts nudges, so a reappearance is not a second one' @@ -219,7 +220,7 @@ describe('FirstRunTourNudge', () => { 'the source is what separates a nudge conversion from a command-palette one, and it defaults to command' ).toHaveBeenCalledWith('first_run_nudge') expect(mocks.dismissNudge).toHaveBeenCalled() - expect(mocks.trackOnboardingTour).toHaveBeenCalledWith( + expect(useTelemetry()?.trackOnboardingTour).toHaveBeenCalledWith( 'explore_templates_clicked', { tour: 'firstRun', tour_completed: true } ) @@ -237,11 +238,14 @@ describe('FirstRunTourNudge', () => { // Both events carry it, so the funnel can be read end to end: without it // a conversion from a finished tour and one from a tour that never // started are indistinguishable. - expect(mocks.trackOnboardingTour).toHaveBeenCalledWith('nudge_shown', { - tour: 'firstRun', - tour_completed: false - }) - expect(mocks.trackOnboardingTour).toHaveBeenCalledWith( + expect(useTelemetry()?.trackOnboardingTour).toHaveBeenCalledWith( + 'nudge_shown', + { + tour: 'firstRun', + tour_completed: false + } + ) + expect(useTelemetry()?.trackOnboardingTour).toHaveBeenCalledWith( 'explore_templates_clicked', { tour: 'firstRun', tour_completed: false } ) diff --git a/src/renderer/extensions/vueNodes/components/ImagePreview.test.ts b/src/renderer/extensions/vueNodes/components/ImagePreview.test.ts index c9a657a5d5c..6e40c8c63fb 100644 --- a/src/renderer/extensions/vueNodes/components/ImagePreview.test.ts +++ b/src/renderer/extensions/vueNodes/components/ImagePreview.test.ts @@ -7,6 +7,8 @@ import { describe, expect, it, vi } from 'vitest' import { nextTick } from 'vue' import { createI18n } from 'vue-i18n' +import { useTelemetry } from '@/platform/telemetry' + import { downloadFile } from '@/base/common/downloadUtil' import ImagePreview from '@/renderer/extensions/vueNodes/components/ImagePreview.vue' @@ -19,12 +21,7 @@ vi.mock(import('@/services/hdrViewerService'), () => ({ openHdrViewer: vi.fn() })) -const mockTrackImageLoadFailed = vi.fn() -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackImageLoadFailed: mockTrackImageLoadFailed - }) -})) +vi.mock(import('@/platform/telemetry')) const i18n = createI18n({ legacy: false, @@ -170,7 +167,9 @@ describe('ImagePreview', () => { expect( screen.queryByRole('button', { name: 'Download image' }) ).not.toBeInTheDocument() - expect(mockTrackImageLoadFailed).toHaveBeenCalledExactlyOnceWith({ + expect( + useTelemetry()?.trackImageLoadFailed + ).toHaveBeenCalledExactlyOnceWith({ source: 'node_image_preview' }) }) diff --git a/src/services/dialogService.downgrade.test.ts b/src/services/dialogService.downgrade.test.ts index bbc2db3b5f6..512c33fa441 100644 --- a/src/services/dialogService.downgrade.test.ts +++ b/src/services/dialogService.downgrade.test.ts @@ -38,9 +38,7 @@ vi.mock(import('@/i18n'), () => ({ t: (key: string) => key })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ trackEvent: vi.fn() }) -})) +vi.mock(import('@/platform/telemetry')) vi.mock(import('@/platform/distribution/types'), () => ({ isCloud: false diff --git a/src/services/dialogService.renderer.test.ts b/src/services/dialogService.renderer.test.ts index 73c126fbdab..d0b7d7f9f55 100644 --- a/src/services/dialogService.renderer.test.ts +++ b/src/services/dialogService.renderer.test.ts @@ -9,9 +9,7 @@ vi.mock(import('@/i18n'), () => ({ t: (key: string) => key })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ trackEvent: vi.fn() }) -})) +vi.mock(import('@/platform/telemetry')) vi.mock(import('@/platform/distribution/types'), () => ({ isCloud: false diff --git a/src/services/dialogService.topUpCredits.test.ts b/src/services/dialogService.topUpCredits.test.ts index a09cf064f5a..b796c09665a 100644 --- a/src/services/dialogService.topUpCredits.test.ts +++ b/src/services/dialogService.topUpCredits.test.ts @@ -17,9 +17,7 @@ vi.mock(import('@/i18n'), () => ({ t: (key: string) => key })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ trackEvent: vi.fn() }) -})) +vi.mock(import('@/platform/telemetry')) const mockIsCloud = vi.hoisted(() => ({ value: true })) vi.mock(import('@/platform/distribution/types'), () => ({ diff --git a/src/stores/__tests__/authTokenPriority.test.ts b/src/stores/__tests__/authTokenPriority.test.ts index 831e54b087e..3cd21bb2226 100644 --- a/src/stores/__tests__/authTokenPriority.test.ts +++ b/src/stores/__tests__/authTokenPriority.test.ts @@ -33,9 +33,7 @@ vi.mock(import('vuefire'), () => ({ vi.mock(import('firebase/auth')) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ trackAuth: vi.fn() }) -})) +vi.mock(import('@/platform/telemetry')) vi.mock(import('@/services/dialogService')) vi.mock(import('@/platform/distribution/types'), () => mockDistributionTypes) diff --git a/src/stores/apiKeyAuthStore.integration.test.ts b/src/stores/apiKeyAuthStore.integration.test.ts index 25c0b44f011..23af20e45c1 100644 --- a/src/stores/apiKeyAuthStore.integration.test.ts +++ b/src/stores/apiKeyAuthStore.integration.test.ts @@ -30,9 +30,7 @@ vi.mock(import('@/composables/useFeatureFlags'), () => ({ }) })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ trackAuth: vi.fn() }) -})) +vi.mock(import('@/platform/telemetry')) vi.mock(import('@/services/dialogService'), () => ({ useDialogService: () => ({ showErrorDialog: vi.fn() }) diff --git a/src/stores/authStore.test.ts b/src/stores/authStore.test.ts index 1429154b17c..d372b8d94bb 100644 --- a/src/stores/authStore.test.ts +++ b/src/stores/authStore.test.ts @@ -7,6 +7,8 @@ import type { Mock } from 'vitest' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import * as vuefire from 'vuefire' +import { useTelemetry } from '@/platform/telemetry' + import { i18n } from '@/i18n' import { capturePreservedQuery, @@ -94,12 +96,7 @@ vi.mock(import('vuefire'), () => ({ vi.mock(import('firebase/auth')) -const mockTrackAuth = vi.fn() -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackAuth: mockTrackAuth - }) -})) +vi.mock(import('@/platform/telemetry')) let mockResetSocket: Mock @@ -1535,7 +1532,7 @@ describe('useAuthStore', () => { await store[method]() - expect(mockTrackAuth).toHaveBeenCalledWith( + expect(useTelemetry()?.trackAuth).toHaveBeenCalledWith( expect.objectContaining({ is_new_user: true }) ) } @@ -1552,7 +1549,7 @@ describe('useAuthStore', () => { await store[method]({ isNewUser: true }) - expect(mockTrackAuth).toHaveBeenCalledWith( + expect(useTelemetry()?.trackAuth).toHaveBeenCalledWith( expect.objectContaining({ is_new_user: true }) ) } @@ -1569,7 +1566,7 @@ describe('useAuthStore', () => { await store[method]() - expect(mockTrackAuth).toHaveBeenCalledWith( + expect(useTelemetry()?.trackAuth).toHaveBeenCalledWith( expect.objectContaining({ is_new_user: false }) ) } @@ -1582,7 +1579,7 @@ describe('useAuthStore', () => { await store[method]() - expect(mockTrackAuth).toHaveBeenCalledWith( + expect(useTelemetry()?.trackAuth).toHaveBeenCalledWith( expect.objectContaining({ is_new_user: false }) ) } @@ -1633,7 +1630,7 @@ describe('useAuthStore', () => { await store.register('new@example.com', 'password') - expect(mockTrackAuth).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackAuth).toHaveBeenCalledWith({ method: 'email', is_new_user: true, user_id: 'test-user-id', @@ -1648,7 +1645,7 @@ describe('useAuthStore', () => { await store.login('test@example.com', 'password') - expect(mockTrackAuth).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackAuth).toHaveBeenCalledWith({ method: 'email', is_new_user: false, user_id: 'test-user-id', @@ -1663,7 +1660,7 @@ describe('useAuthStore', () => { await store.loginWithGoogle() - expect(mockTrackAuth).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackAuth).toHaveBeenCalledWith({ method: 'google', is_new_user: true, user_id: 'test-user-id', @@ -1678,7 +1675,7 @@ describe('useAuthStore', () => { await store.loginWithGithub() - expect(mockTrackAuth).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackAuth).toHaveBeenCalledWith({ method: 'github', is_new_user: true, user_id: 'test-user-id', diff --git a/src/stores/executionStore.test.ts b/src/stores/executionStore.test.ts index ad8c0bb6f10..a4935fdf5c2 100644 --- a/src/stores/executionStore.test.ts +++ b/src/stores/executionStore.test.ts @@ -4,6 +4,8 @@ import { fromPartial } from '@total-typescript/shoehorn' import { beforeEach, describe, expect, it, vi } from 'vitest' import { nextTick } from 'vue' +import { useTelemetry } from '@/platform/telemetry' + import { app } from '@/scripts/app' import { api } from '@/scripts/api' import { MAX_PROGRESS_JOBS, useExecutionStore } from '@/stores/executionStore' @@ -17,19 +19,9 @@ import { executionIdToNodeLocatorId } from '@/utils/graphTraversalUtil' import type { LGraphCanvas } from '@/lib/litegraph/src/LGraphCanvas' import type { NodeProgressState } from '@/schemas/apiSchema' -const { - mockShowTextPreview, - mockTrackExecutionError, - mockTrackExecutionOutcome, - mockTrackExecutionSuccess, - mockTrackSharedWorkflowRun -} = await vi.hoisted(async () => { +const { mockShowTextPreview } = await vi.hoisted(async () => { return { - mockShowTextPreview: vi.fn(), - mockTrackExecutionError: vi.fn(), - mockTrackExecutionOutcome: vi.fn(), - mockTrackExecutionSuccess: vi.fn(), - mockTrackSharedWorkflowRun: vi.fn() + mockShowTextPreview: vi.fn() } }) @@ -57,14 +49,7 @@ vi.mock(import('@/platform/distribution/types'), () => ({ isCloud: true })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => ({ - trackExecutionError: mockTrackExecutionError, - trackExecutionOutcome: mockTrackExecutionOutcome, - trackExecutionSuccess: mockTrackExecutionSuccess, - trackSharedWorkflowRun: mockTrackSharedWorkflowRun - }) -})) +vi.mock(import('@/platform/telemetry')) // Remove any previous global types declare global { @@ -607,7 +592,7 @@ describe('useExecutionStore - workflowStatus', () => { callStoreJob('job-1', workflowA) fireExecutionStart('job-1') - expect(mockTrackExecutionOutcome).not.toHaveBeenCalled() + expect(useTelemetry()?.trackExecutionOutcome).not.toHaveBeenCalled() expect(store.getWorkflowStatus(workflowA)).toBe('running') }) @@ -628,7 +613,9 @@ describe('useExecutionStore - workflowStatus', () => { fireExecutionSuccess('job-1') callStoreJob('job-1', workflowA) - expect(mockTrackExecutionOutcome).toHaveBeenCalledExactlyOnceWith({ + expect( + useTelemetry()?.trackExecutionOutcome + ).toHaveBeenCalledExactlyOnceWith({ startTime: 42, ...defaultWorkflowExecutionIntent, submissionAcceptedAt: 62, @@ -651,7 +638,9 @@ describe('useExecutionStore - workflowStatus', () => { fireExecutionError('job-1') callStoreJob('job-1', workflowA) - expect(mockTrackExecutionOutcome).toHaveBeenCalledExactlyOnceWith({ + expect( + useTelemetry()?.trackExecutionOutcome + ).toHaveBeenCalledExactlyOnceWith({ startTime: 42, ...defaultWorkflowExecutionIntent, submissionAcceptedAt: 62, @@ -682,7 +671,9 @@ describe('useExecutionStore - workflowStatus', () => { now.mockReturnValue(142) fireExecutionSuccess('job-1') - expect(mockTrackExecutionOutcome).toHaveBeenCalledExactlyOnceWith({ + expect( + useTelemetry()?.trackExecutionOutcome + ).toHaveBeenCalledExactlyOnceWith({ startTime: 42, ...defaultWorkflowExecutionIntent, submissionAcceptedAt: 62, @@ -707,7 +698,7 @@ describe('useExecutionStore - workflowStatus', () => { fireExecutionSuccess('job-1') fireExecutionSuccess('job-1') - expect(mockTrackExecutionOutcome).toHaveBeenCalledOnce() + expect(useTelemetry()?.trackExecutionOutcome).toHaveBeenCalledOnce() } finally { now.mockRestore() } @@ -725,7 +716,9 @@ describe('useExecutionStore - workflowStatus', () => { now.mockReturnValue(142) fireExecutionSuccess('job-1') - expect(mockTrackExecutionOutcome).toHaveBeenCalledExactlyOnceWith({ + expect( + useTelemetry()?.trackExecutionOutcome + ).toHaveBeenCalledExactlyOnceWith({ startTime: 42, ...defaultWorkflowExecutionIntent, submissionAcceptedAt: 62, @@ -765,7 +758,7 @@ describe('useExecutionStore - workflowStatus', () => { }) fireExecutionSuccess('job-1') - expect(mockTrackExecutionOutcome).toHaveBeenCalledWith( + expect(useTelemetry()?.trackExecutionOutcome).toHaveBeenCalledWith( expect.objectContaining({ startTime: 42, success: true, @@ -785,7 +778,9 @@ describe('useExecutionStore - workflowStatus', () => { now.mockReturnValue(142) fireExecutionError('job-1') - expect(mockTrackExecutionOutcome).toHaveBeenCalledExactlyOnceWith({ + expect( + useTelemetry()?.trackExecutionOutcome + ).toHaveBeenCalledExactlyOnceWith({ startTime: 42, ...defaultWorkflowExecutionIntent, submissionAcceptedAt: 62, @@ -809,7 +804,9 @@ describe('useExecutionStore - workflowStatus', () => { now.mockReturnValue(142) fireExecutionInterrupted('job-1') - expect(mockTrackExecutionOutcome).toHaveBeenCalledExactlyOnceWith({ + expect( + useTelemetry()?.trackExecutionOutcome + ).toHaveBeenCalledExactlyOnceWith({ startTime: 42, ...defaultWorkflowExecutionIntent, submissionAcceptedAt: 62, @@ -905,7 +902,9 @@ describe('useExecutionStore - workflowStatus', () => { }) ) - expect(mockTrackExecutionOutcome).toHaveBeenCalledExactlyOnceWith({ + expect( + useTelemetry()?.trackExecutionOutcome + ).toHaveBeenCalledExactlyOnceWith({ startTime: 42, ...defaultWorkflowExecutionIntent, submissionAcceptedAt: 62, @@ -2484,8 +2483,8 @@ describe('useExecutionStore - WebSocket event handlers', () => { it('does not track success for jobs this client did not queue', () => { fire('execution_success', { prompt_id: 'foreign-job', timestamp: 0 }) - expect(mockTrackExecutionSuccess).not.toHaveBeenCalled() - expect(mockTrackSharedWorkflowRun).not.toHaveBeenCalled() + expect(useTelemetry()?.trackExecutionSuccess).not.toHaveBeenCalled() + expect(useTelemetry()?.trackSharedWorkflowRun).not.toHaveBeenCalled() }) it('tracks shared workflow run when the queued workflow has share attribution', () => { @@ -2504,10 +2503,10 @@ describe('useExecutionStore - WebSocket event handlers', () => { fire('execution_success', { prompt_id: 'job-1', timestamp: 0 }) - expect(mockTrackExecutionSuccess).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackExecutionSuccess).toHaveBeenCalledWith({ jobId: 'job-1' }) - expect(mockTrackSharedWorkflowRun).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackSharedWorkflowRun).toHaveBeenCalledWith({ job_id: 'job-1', share_id: 'share-1', view_mode: 'graph', @@ -2530,7 +2529,7 @@ describe('useExecutionStore - WebSocket event handlers', () => { fire('execution_success', { prompt_id: 'job-1', timestamp: 0 }) - expect(mockTrackSharedWorkflowRun).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackSharedWorkflowRun).toHaveBeenCalledWith({ job_id: 'job-1', share_id: 'share-1', view_mode: 'graph', @@ -2555,7 +2554,7 @@ describe('useExecutionStore - WebSocket event handlers', () => { mockAppModeState.isAppMode.value = true fire('execution_success', { prompt_id: 'job-1', timestamp: 0 }) - expect(mockTrackSharedWorkflowRun).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackSharedWorkflowRun).toHaveBeenCalledWith({ job_id: 'job-1', share_id: 'share-1', view_mode: 'graph', @@ -2579,7 +2578,7 @@ describe('useExecutionStore - WebSocket event handlers', () => { fire('execution_success', { prompt_id: 'job-1', timestamp: 0 }) - expect(mockTrackSharedWorkflowRun).toHaveBeenCalledWith({ + expect(useTelemetry()?.trackSharedWorkflowRun).toHaveBeenCalledWith({ job_id: 'job-1', share_id: 'share-1', view_mode: 'app', diff --git a/src/views/GraphView.test.ts b/src/views/GraphView.test.ts index 79fe5d3dec8..ccfc459c1e5 100644 --- a/src/views/GraphView.test.ts +++ b/src/views/GraphView.test.ts @@ -115,9 +115,7 @@ vi.mock(import('@/composables/useProgressFavicon'), () => ({ })) vi.mock(import('@/platform/distribution/types'), () => distribution) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => undefined -})) +vi.mock(import('@/platform/telemetry')) vi.mock( import('@/platform/updates/common/useFrontendVersionMismatchWarning'), () => ({ diff --git a/src/workbench/extensions/agent/components/agent/DockedAgentPanel.test.ts b/src/workbench/extensions/agent/components/agent/DockedAgentPanel.test.ts index 3dd31606946..05386196729 100644 --- a/src/workbench/extensions/agent/components/agent/DockedAgentPanel.test.ts +++ b/src/workbench/extensions/agent/components/agent/DockedAgentPanel.test.ts @@ -13,9 +13,7 @@ import { useAgentRunModeStore } from '@/workbench/extensions/agent/stores/agent/ import DockedAgentPanel from './DockedAgentPanel.vue' -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => undefined -})) +vi.mock(import('@/platform/telemetry')) vi.mock(import('@/platform/telemetry/reportError'), () => ({ reportError: vi.fn() })) diff --git a/src/workbench/extensions/agent/components/agent/dockedAgentPanelLoadFailure.test.ts b/src/workbench/extensions/agent/components/agent/dockedAgentPanelLoadFailure.test.ts index de1075f830a..bd0d9485dea 100644 --- a/src/workbench/extensions/agent/components/agent/dockedAgentPanelLoadFailure.test.ts +++ b/src/workbench/extensions/agent/components/agent/dockedAgentPanelLoadFailure.test.ts @@ -11,9 +11,7 @@ import DockedAgentPanel from './DockedAgentPanel.vue' vi.mock(import('@/platform/telemetry/reportError'), () => ({ reportError: vi.fn() })) -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => undefined -})) +vi.mock(import('@/platform/telemetry')) // The mocked module factory throws, so the dynamic import itself rejects - // the chunk-load failure path, distinct from a runtime error inside a diff --git a/src/workbench/extensions/agent/composables/useAgentDockMount.test.ts b/src/workbench/extensions/agent/composables/useAgentDockMount.test.ts index 25dde8c79d5..bfd477ac796 100644 --- a/src/workbench/extensions/agent/composables/useAgentDockMount.test.ts +++ b/src/workbench/extensions/agent/composables/useAgentDockMount.test.ts @@ -4,9 +4,7 @@ import { useAgentPanelStore } from '@/workbench/extensions/agent/stores/agent/ag import { useAgentDockMount } from './useAgentDockMount' -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => undefined -})) +vi.mock(import('@/platform/telemetry')) const { loadDockedAgentPanel } = vi.hoisted(() => ({ loadDockedAgentPanel: vi.fn(() => ({ name: 'DockedAgentPanel' })) })) diff --git a/src/workbench/extensions/agent/stores/agent/agentPanelStoreId.test.ts b/src/workbench/extensions/agent/stores/agent/agentPanelStoreId.test.ts index b74e01f2429..d5470574987 100644 --- a/src/workbench/extensions/agent/stores/agent/agentPanelStoreId.test.ts +++ b/src/workbench/extensions/agent/stores/agent/agentPanelStoreId.test.ts @@ -8,9 +8,7 @@ import { useAgentDockMount } from '@/workbench/extensions/agent/composables/useA import { useAgentPanelStore } from './agentPanelStore' -vi.mock(import('@/platform/telemetry'), () => ({ - useTelemetry: () => undefined -})) +vi.mock(import('@/platform/telemetry')) /** * Regression pin for the duplicate Pinia id `agentPanel`.