diff --git a/packages/cli/src/services/__tests__/workflow-statistics.service.test.ts b/packages/cli/src/services/__tests__/workflow-statistics.service.test.ts index a8d73cbfff..fdecb7ae5a 100644 --- a/packages/cli/src/services/__tests__/workflow-statistics.service.test.ts +++ b/packages/cli/src/services/__tests__/workflow-statistics.service.test.ts @@ -7,7 +7,7 @@ import { } from '@n8n/typeorm'; import { mocked } from 'jest-mock'; import { mock } from 'jest-mock-extended'; -import type { IRun, WorkflowExecuteMode } from 'n8n-workflow'; +import type { INode, IRun, WorkflowExecuteMode } from 'n8n-workflow'; import { Container } from 'typedi'; import config from '@/config'; @@ -167,6 +167,22 @@ describe('WorkflowStatisticsService', () => { }); }); + test('should emit event with no `userId` if workflow is owned by team project', async () => { + const workflowId = '123'; + ownershipService.getPersonalProjectOwnerCached.mockResolvedValueOnce(null); + const node = mock({ id: '123', type: 'n8n-nodes-base.noOp', credentials: {} }); + + await workflowStatisticsService.nodeFetchedData(workflowId, node); + + expect(eventService.emit).toHaveBeenCalledWith('first-workflow-data-loaded', { + userId: '', + project: fakeProject.id, + workflowId, + nodeType: node.type, + nodeId: node.id, + }); + }); + test('should create metrics with credentials when the db is updated', async () => { // Call the function with a production success result, ensure metrics hook gets called const workflowId = '1'; diff --git a/packages/cli/src/services/workflow-statistics.service.ts b/packages/cli/src/services/workflow-statistics.service.ts index 1beead137c..53cbac5094 100644 --- a/packages/cli/src/services/workflow-statistics.service.ts +++ b/packages/cli/src/services/workflow-statistics.service.ts @@ -110,7 +110,7 @@ export class WorkflowStatisticsService extends TypedEmitter