fix(core): Fix ownerless project case in statistics service (#11051)
This commit is contained in:
@@ -7,7 +7,7 @@ import {
|
|||||||
} from '@n8n/typeorm';
|
} from '@n8n/typeorm';
|
||||||
import { mocked } from 'jest-mock';
|
import { mocked } from 'jest-mock';
|
||||||
import { mock } from 'jest-mock-extended';
|
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 { Container } from 'typedi';
|
||||||
|
|
||||||
import config from '@/config';
|
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 () => {
|
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
|
// Call the function with a production success result, ensure metrics hook gets called
|
||||||
const workflowId = '1';
|
const workflowId = '1';
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ export class WorkflowStatisticsService extends TypedEmitter<WorkflowStatisticsEv
|
|||||||
const owner = await this.ownershipService.getPersonalProjectOwnerCached(project.id);
|
const owner = await this.ownershipService.getPersonalProjectOwnerCached(project.id);
|
||||||
|
|
||||||
let metrics = {
|
let metrics = {
|
||||||
userId: owner!.id,
|
userId: owner?.id ?? '', // team projects have no owner
|
||||||
project: project.id,
|
project: project.id,
|
||||||
workflowId,
|
workflowId,
|
||||||
nodeType: node.type,
|
nodeType: node.type,
|
||||||
|
|||||||
Reference in New Issue
Block a user