mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-23 11:44:06 -08:00
fix(core): Fix ownerless project case in statistics service (#11051)
This commit is contained in:
parent
113a2e7401
commit
bdaadf10e0
|
@ -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<INode>({ 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';
|
||||
|
|
|
@ -110,7 +110,7 @@ export class WorkflowStatisticsService extends TypedEmitter<WorkflowStatisticsEv
|
|||
const owner = await this.ownershipService.getPersonalProjectOwnerCached(project.id);
|
||||
|
||||
let metrics = {
|
||||
userId: owner!.id,
|
||||
userId: owner?.id ?? '', // team projects have no owner
|
||||
project: project.id,
|
||||
workflowId,
|
||||
nodeType: node.type,
|
||||
|
|
Loading…
Reference in a new issue