mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 17:46:45 +00:00
refactor(core): Prepare insights for move to standalone module (#16426)
This commit is contained in:
@@ -21,6 +21,8 @@
|
||||
"dist/**/*"
|
||||
],
|
||||
"dependencies": {
|
||||
"@n8n/backend-common": "workspace:^",
|
||||
"jest-mock-extended": "^3.0.4",
|
||||
"reflect-metadata": "catalog:"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -1 +1,5 @@
|
||||
export {};
|
||||
import type { Logger } from '@n8n/backend-common';
|
||||
import { mock } from 'jest-mock-extended';
|
||||
|
||||
export const mockLogger = (): Logger =>
|
||||
mock<Logger>({ scoped: jest.fn().mockReturnValue(mock<Logger>()) });
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { WorkflowEntity } from '@n8n/db';
|
||||
import type { WorkflowRepository } from '@n8n/db';
|
||||
import { mockLogger } from '@n8n/integration-test-utils';
|
||||
import { mock } from 'jest-mock-extended';
|
||||
import type { InstanceSettings } from 'n8n-core';
|
||||
import type {
|
||||
@@ -13,7 +14,6 @@ import { Workflow } from 'n8n-workflow';
|
||||
|
||||
import { ActiveWorkflowManager } from '@/active-workflow-manager';
|
||||
import type { NodeTypes } from '@/node-types';
|
||||
import { mockLogger } from '@test/mocking';
|
||||
|
||||
describe('ActiveWorkflowManager', () => {
|
||||
let activeWorkflowManager: ActiveWorkflowManager;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import type { GlobalConfig } from '@n8n/config';
|
||||
import { mockLogger } from '@n8n/integration-test-utils';
|
||||
import { LicenseManager } from '@n8n_io/license-sdk';
|
||||
import { mock } from 'jest-mock-extended';
|
||||
import type { InstanceSettings } from 'n8n-core';
|
||||
|
||||
import { N8N_VERSION } from '@/constants';
|
||||
import { License } from '@/license';
|
||||
import { mockLogger } from '@test/mocking';
|
||||
|
||||
jest.mock('@n8n_io/license-sdk');
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { Project } from '@n8n/db';
|
||||
import type { IExecutionResponse } from '@n8n/db';
|
||||
import type { ExecutionRepository } from '@n8n/db';
|
||||
import { mockLogger } from '@n8n/integration-test-utils';
|
||||
import { mock } from 'jest-mock-extended';
|
||||
import type { InstanceSettings } from 'n8n-core';
|
||||
import type { IRun, IWorkflowBase } from 'n8n-workflow';
|
||||
@@ -11,7 +12,6 @@ import type { MultiMainSetup } from '@/scaling/multi-main-setup.ee';
|
||||
import type { OwnershipService } from '@/services/ownership.service';
|
||||
import { WaitTracker } from '@/wait-tracker';
|
||||
import type { WorkflowRunner } from '@/workflow-runner';
|
||||
import { mockLogger } from '@test/mocking';
|
||||
|
||||
jest.useFakeTimers({ advanceTimers: true });
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { GlobalConfig } from '@n8n/config';
|
||||
import type { ExecutionRepository } from '@n8n/db';
|
||||
import { mockLogger } from '@n8n/integration-test-utils';
|
||||
import { mock } from 'jest-mock-extended';
|
||||
import type { WorkflowExecuteMode as ExecutionMode } from 'n8n-workflow';
|
||||
|
||||
@@ -13,7 +14,6 @@ import config from '@/config';
|
||||
import { InvalidConcurrencyLimitError } from '@/errors/invalid-concurrency-limit.error';
|
||||
import type { EventService } from '@/events/event.service';
|
||||
import type { Telemetry } from '@/telemetry';
|
||||
import { mockLogger } from '@test/mocking';
|
||||
|
||||
import { ConcurrencyQueue } from '../concurrency-queue';
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import type { TestRun } from '@n8n/db';
|
||||
import type { TestCaseExecutionRepository } from '@n8n/db';
|
||||
import type { TestRunRepository } from '@n8n/db';
|
||||
import type { WorkflowRepository } from '@n8n/db';
|
||||
import { mockLogger } from '@n8n/integration-test-utils';
|
||||
import { readFileSync } from 'fs';
|
||||
import type { Mock } from 'jest-mock';
|
||||
import { mock } from 'jest-mock-extended';
|
||||
@@ -17,7 +18,7 @@ import { TestRunError } from '@/evaluation.ee/test-runner/errors.ee';
|
||||
import { LoadNodesAndCredentials } from '@/load-nodes-and-credentials';
|
||||
import type { Telemetry } from '@/telemetry';
|
||||
import type { WorkflowRunner } from '@/workflow-runner';
|
||||
import { mockInstance, mockLogger } from '@test/mocking';
|
||||
import { mockInstance } from '@test/mocking';
|
||||
import { mockNodeTypesData } from '@test-integration/utils/node-types-data';
|
||||
|
||||
import { TestRunnerService } from '../test-runner.service.ee';
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { LDAP_FEATURE_NAME, type LdapConfig } from '@n8n/constants';
|
||||
import type { Settings } from '@n8n/db';
|
||||
import { AuthIdentityRepository, SettingsRepository } from '@n8n/db';
|
||||
import { mockLogger } from '@n8n/integration-test-utils';
|
||||
import { QueryFailedError } from '@n8n/typeorm';
|
||||
import { mock } from 'jest-mock-extended';
|
||||
import { Client } from 'ldapts';
|
||||
@@ -9,7 +10,7 @@ import { randomString } from 'n8n-workflow';
|
||||
|
||||
import config from '@/config';
|
||||
import type { EventService } from '@/events/event.service';
|
||||
import { mockInstance, mockLogger } from '@test/mocking';
|
||||
import { mockInstance } from '@test/mocking';
|
||||
|
||||
import { BINARY_AD_ATTRIBUTES, LDAP_LOGIN_ENABLED, LDAP_LOGIN_LABEL } from '../constants';
|
||||
import {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { Settings, SettingsRepository } from '@n8n/db';
|
||||
import { mockLogger } from '@n8n/integration-test-utils';
|
||||
import { captor, mock } from 'jest-mock-extended';
|
||||
|
||||
import type { License } from '@/license';
|
||||
@@ -9,7 +10,7 @@ import {
|
||||
FailedProvider,
|
||||
MockProviders,
|
||||
} from '@test/external-secrets/utils';
|
||||
import { mockCipher, mockLogger } from '@test/mocking';
|
||||
import { mockCipher } from '@test/mocking';
|
||||
|
||||
import { EXTERNAL_SECRETS_DB_KEY } from '../constants';
|
||||
import { ExternalSecretsManager } from '../external-secrets-manager.ee';
|
||||
|
||||
@@ -4,6 +4,7 @@ import type { IWorkflowDb } from '@n8n/db';
|
||||
import type { SharedWorkflowRepository } from '@n8n/db';
|
||||
import type { WorkflowExecuteAfterContext } from '@n8n/decorators';
|
||||
import { Container } from '@n8n/di';
|
||||
import { mockLogger } from '@n8n/integration-test-utils';
|
||||
import { In } from '@n8n/typeorm';
|
||||
import { mock } from 'jest-mock-extended';
|
||||
import { DateTime } from 'luxon';
|
||||
@@ -17,7 +18,6 @@ import {
|
||||
import type { TypeUnit } from '@/modules/insights/database/entities/insights-shared';
|
||||
import { InsightsMetadataRepository } from '@/modules/insights/database/repositories/insights-metadata.repository';
|
||||
import { InsightsRawRepository } from '@/modules/insights/database/repositories/insights-raw.repository';
|
||||
import { mockLogger } from '@test/mocking';
|
||||
import { createTeamProject } from '@test-integration/db/projects';
|
||||
import { createWorkflow } from '@test-integration/db/workflows';
|
||||
import * as testDb from '@test-integration/test-db';
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { Container } from '@n8n/di';
|
||||
import { mockLogger } from '@n8n/integration-test-utils';
|
||||
import { mock } from 'jest-mock-extended';
|
||||
import { DateTime } from 'luxon';
|
||||
|
||||
import { InsightsRawRepository } from '@/modules/insights/database/repositories/insights-raw.repository';
|
||||
import { mockLogger } from '@test/mocking';
|
||||
import { createTeamProject } from '@test-integration/db/projects';
|
||||
import { createWorkflow } from '@test-integration/db/workflows';
|
||||
import * as testDb from '@test-integration/test-db';
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import type { LicenseState } from '@n8n/backend-common';
|
||||
import { Container } from '@n8n/di';
|
||||
import { mockLogger } from '@n8n/integration-test-utils';
|
||||
import { mock } from 'jest-mock-extended';
|
||||
import { DateTime } from 'luxon';
|
||||
|
||||
import { Time } from '@/constants';
|
||||
import { mockLogger } from '@test/mocking';
|
||||
import { createTeamProject } from '@test-integration/db/projects';
|
||||
import { createWorkflow } from '@test-integration/db/workflows';
|
||||
import * as testDb from '@test-integration/test-db';
|
||||
|
||||
@@ -5,13 +5,13 @@ import type { WorkflowEntity } from '@n8n/db';
|
||||
import type { IWorkflowDb } from '@n8n/db';
|
||||
import type { WorkflowExecuteAfterContext } from '@n8n/decorators';
|
||||
import { Container } from '@n8n/di';
|
||||
import { mockLogger } from '@n8n/integration-test-utils';
|
||||
import type { MockProxy } from 'jest-mock-extended';
|
||||
import { mock } from 'jest-mock-extended';
|
||||
import { DateTime } from 'luxon';
|
||||
import type { InstanceSettings } from 'n8n-core';
|
||||
import type { IRun } from 'n8n-workflow';
|
||||
|
||||
import { mockLogger } from '@test/mocking';
|
||||
import { createTeamProject } from '@test-integration/db/projects';
|
||||
import { createWorkflow } from '@test-integration/db/workflows';
|
||||
import * as testDb from '@test-integration/test-db';
|
||||
|
||||
@@ -3,11 +3,18 @@ import type { InsightsSummary, InsightsByTime, InsightsByWorkflow } from '@n8n/a
|
||||
import { Get, GlobalScope, Licensed, Query, RestController } from '@n8n/decorators';
|
||||
import type { UserError } from 'n8n-workflow';
|
||||
|
||||
import { ForbiddenError } from '@/errors/response-errors/forbidden.error';
|
||||
import { AuthenticatedRequest } from '@/requests';
|
||||
|
||||
import { InsightsService } from './insights.service';
|
||||
|
||||
export class ForbiddenError extends Error {
|
||||
readonly httpStatusCode = 403;
|
||||
|
||||
readonly errorCode = 403;
|
||||
|
||||
readonly shouldReport = false;
|
||||
}
|
||||
|
||||
@RestController('/insights')
|
||||
export class InsightsController {
|
||||
constructor(private readonly insightsService: InsightsService) {}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { GlobalConfig } from '@n8n/config';
|
||||
import { Container } from '@n8n/di';
|
||||
import { mockLogger } from '@n8n/integration-test-utils';
|
||||
import * as BullModule from 'bull';
|
||||
import { mock } from 'jest-mock-extended';
|
||||
import { InstanceSettings } from 'n8n-core';
|
||||
import { ApplicationError, ExecutionCancelledError } from 'n8n-workflow';
|
||||
|
||||
import { mockInstance, mockLogger } from '@test/mocking';
|
||||
import { mockInstance } from '@test/mocking';
|
||||
|
||||
import { JOB_TYPE_NAME, QUEUE_NAME } from '../constants';
|
||||
import type { JobProcessor } from '../job-processor';
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { GlobalConfig } from '@n8n/config';
|
||||
import { mockLogger } from '@n8n/integration-test-utils';
|
||||
import type express from 'express';
|
||||
import { mock } from 'jest-mock-extended';
|
||||
import type { InstanceSettings } from 'n8n-core';
|
||||
@@ -9,7 +10,6 @@ import type { DbConnection } from '@/databases/db-connection';
|
||||
import type { ExternalHooks } from '@/external-hooks';
|
||||
import type { PrometheusMetricsService } from '@/metrics/prometheus-metrics.service';
|
||||
import { bodyParser, rawBodyReader } from '@/middlewares';
|
||||
import { mockLogger } from '@test/mocking';
|
||||
|
||||
import { WorkerServer } from '../worker-server';
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { mockLogger } from '@n8n/integration-test-utils';
|
||||
import type { Redis as SingleNodeClient } from 'ioredis';
|
||||
import { mock } from 'jest-mock-extended';
|
||||
import type { InstanceSettings } from 'n8n-core';
|
||||
|
||||
import config from '@/config';
|
||||
import type { RedisClientService } from '@/services/redis-client.service';
|
||||
import { mockLogger } from '@test/mocking';
|
||||
|
||||
import { Publisher } from '../publisher.service';
|
||||
import type { PubSub } from '../pubsub.types';
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import { OnPubSubEvent, PubSubMetadata } from '@n8n/decorators';
|
||||
import { Container, Service } from '@n8n/di';
|
||||
import { mockLogger } from '@n8n/integration-test-utils';
|
||||
import { mock } from 'jest-mock-extended';
|
||||
import type { InstanceSettings } from 'n8n-core';
|
||||
|
||||
import { mockLogger } from '@test/mocking';
|
||||
|
||||
import { PubSubEventBus } from '../pubsub.eventbus';
|
||||
import { PubSubRegistry } from '../pubsub.registry';
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { ExecutionsConfig } from '@n8n/config';
|
||||
import { mockLogger } from '@n8n/integration-test-utils';
|
||||
import { mock } from 'jest-mock-extended';
|
||||
import type { InstanceSettings } from 'n8n-core';
|
||||
|
||||
import type { DbConnection } from '@/databases/db-connection';
|
||||
import { mockLogger } from '@test/mocking';
|
||||
|
||||
import { ExecutionsPruningService } from '../executions-pruning.service';
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { User } from '@n8n/db';
|
||||
import { WorkflowHistoryRepository } from '@n8n/db';
|
||||
import { mockLogger } from '@n8n/integration-test-utils';
|
||||
import { mockClear } from 'jest-mock-extended';
|
||||
|
||||
import { WorkflowFinderService } from '@/workflows/workflow-finder.service';
|
||||
import { WorkflowHistoryService } from '@/workflows/workflow-history.ee/workflow-history.service.ee';
|
||||
import { mockInstance, mockLogger } from '@test/mocking';
|
||||
import { mockInstance } from '@test/mocking';
|
||||
import { getWorkflow } from '@test-integration/workflow';
|
||||
|
||||
const workflowHistoryRepository = mockInstance(WorkflowHistoryRepository);
|
||||
|
||||
@@ -2,6 +2,7 @@ import { ExecutionsConfig } from '@n8n/config';
|
||||
import type { ExecutionEntity } from '@n8n/db';
|
||||
import { ExecutionRepository } from '@n8n/db';
|
||||
import { Container } from '@n8n/di';
|
||||
import { mockLogger } from '@n8n/integration-test-utils';
|
||||
import { BinaryDataService, InstanceSettings } from 'n8n-core';
|
||||
import type { ExecutionStatus, IWorkflowBase } from 'n8n-workflow';
|
||||
|
||||
@@ -16,7 +17,7 @@ import {
|
||||
} from './shared/db/executions';
|
||||
import { createWorkflow } from './shared/db/workflows';
|
||||
import * as testDb from './shared/test-db';
|
||||
import { mockInstance, mockLogger } from '../shared/mocking';
|
||||
import { mockInstance } from '../shared/mocking';
|
||||
|
||||
describe('softDeleteOnPruningCycle()', () => {
|
||||
let pruningService: ExecutionsPruningService;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { LicenseState } from '@n8n/backend-common';
|
||||
import { SettingsRepository } from '@n8n/db';
|
||||
import { Container } from '@n8n/di';
|
||||
import { mockLogger } from '@n8n/integration-test-utils';
|
||||
import { mock } from 'jest-mock-extended';
|
||||
import { Cipher } from 'n8n-core';
|
||||
import type { IDataObject } from 'n8n-workflow';
|
||||
@@ -22,7 +23,7 @@ import {
|
||||
MockProviders,
|
||||
TestFailProvider,
|
||||
} from '../../shared/external-secrets/utils';
|
||||
import { mockInstance, mockLogger } from '../../shared/mocking';
|
||||
import { mockInstance } from '../../shared/mocking';
|
||||
import { createOwner, createUser } from '../shared/db/users';
|
||||
import type { SuperAgentTest } from '../shared/types';
|
||||
import { setupTestServer } from '../shared/utils';
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { LicenseState } from '@n8n/backend-common';
|
||||
import type { User } from '@n8n/db';
|
||||
import { Container } from '@n8n/di';
|
||||
import { mockLogger } from '@n8n/integration-test-utils';
|
||||
import cookieParser from 'cookie-parser';
|
||||
import express from 'express';
|
||||
import type superagent from 'superagent';
|
||||
@@ -19,7 +20,7 @@ import type { APIRequest } from '@/requests';
|
||||
import { Telemetry } from '@/telemetry';
|
||||
import * as testModules from '@test-integration/test-modules';
|
||||
|
||||
import { mockInstance, mockLogger } from '../../../shared/mocking';
|
||||
import { mockInstance } from '../../../shared/mocking';
|
||||
import { PUBLIC_API_REST_PATH_SEGMENT, REST_PATH_SEGMENT } from '../constants';
|
||||
import { LicenseMocker } from '../license';
|
||||
import * as testDb from '../test-db';
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import type { Logger } from '@n8n/backend-common';
|
||||
import { Container } from '@n8n/di';
|
||||
import { DataSource, EntityManager, type EntityMetadata } from '@n8n/typeorm';
|
||||
import { mock } from 'jest-mock-extended';
|
||||
@@ -24,8 +23,6 @@ export const mockEntityManager = (entityClass: Class) => {
|
||||
return entityManager;
|
||||
};
|
||||
|
||||
export const mockLogger = () => mock<Logger>({ scoped: jest.fn().mockReturnValue(mock<Logger>()) });
|
||||
|
||||
export const mockCipher = () =>
|
||||
mock<Cipher>({
|
||||
encrypt: (data) => (typeof data === 'string' ? data : JSON.stringify(data)),
|
||||
|
||||
6
pnpm-lock.yaml
generated
6
pnpm-lock.yaml
generated
@@ -740,6 +740,12 @@ importers:
|
||||
|
||||
packages/@n8n/integration-test-utils:
|
||||
dependencies:
|
||||
'@n8n/backend-common':
|
||||
specifier: workspace:^
|
||||
version: link:../backend-common
|
||||
jest-mock-extended:
|
||||
specifier: ^3.0.4
|
||||
version: 3.0.4(jest@29.6.2(@types/node@20.17.57)(ts-node@10.9.2(@types/node@20.17.57)(typescript@5.8.2)))(typescript@5.8.2)
|
||||
reflect-metadata:
|
||||
specifier: 'catalog:'
|
||||
version: 0.2.2
|
||||
|
||||
Reference in New Issue
Block a user