1
1
mirror of https://github.com/n8n-io/n8n.git synced 2024-10-06 01:27:49 +03:00

fix(core): Fix ownerless project case in statistics service (#11051)

This commit is contained in:
Iván Ovejero 2024-10-02 10:31:17 +02:00 committed by GitHub
parent 113a2e7401
commit bdaadf10e0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 2 deletions

View File

@ -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';

View File

@ -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,