From 0a416eebea201ec461d888ce6593826ba32a81e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=BE=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB?= =?UTF-8?q?=E0=A5=8D=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95?= =?UTF-8?q?=E0=A5=8D=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Thu, 22 Dec 2022 10:14:15 +0100 Subject: [PATCH] fix: Remove circular dependencies from cli tests (no-changelog) (#5000) * fix typescript errors in cli * remove circular dependencies from cli tests --- packages/cli/test/integration/shared/testDb.ts | 1 + packages/cli/test/unit/Events.test.ts | 10 +++++----- packages/cli/test/unit/License.test.ts | 4 ++-- packages/cli/test/unit/PermissionChecker.test.ts | 6 +++--- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/packages/cli/test/integration/shared/testDb.ts b/packages/cli/test/integration/shared/testDb.ts index 3360096fcf..28bb302838 100644 --- a/packages/cli/test/integration/shared/testDb.ts +++ b/packages/cli/test/integration/shared/testDb.ts @@ -249,6 +249,7 @@ function toTableName(sourceName: CollectionName | MappingName) { Settings: 'settings', InstalledPackages: 'installed_packages', InstalledNodes: 'installed_nodes', + WorkflowStatistics: 'workflow_statistics', }[sourceName]; } diff --git a/packages/cli/test/unit/Events.test.ts b/packages/cli/test/unit/Events.test.ts index 680ff32db1..0e2f09a57f 100644 --- a/packages/cli/test/unit/Events.test.ts +++ b/packages/cli/test/unit/Events.test.ts @@ -1,6 +1,6 @@ import config from '@/config'; -import { InternalHooksManager } from '../../src'; -import { nodeFetchedData, workflowExecutionCompleted } from '../../src/events/WorkflowStatistics'; +import { InternalHooksManager } from '@/InternalHooksManager'; +import { nodeFetchedData, workflowExecutionCompleted } from '@/events/WorkflowStatistics'; import { LoggerProxy, WorkflowExecuteMode } from 'n8n-workflow'; import { getLogger } from '@/Logger'; @@ -10,14 +10,14 @@ const mockedFirstProductionWorkflowSuccess = jest.fn((...args) => {}); const mockedFirstWorkflowDataLoad = jest.fn((...args) => {}); jest.spyOn(InternalHooksManager, 'getInstance').mockImplementation((...args) => { - const actual = jest.requireActual('../../src/InternalHooks'); + const actual = jest.requireActual('@/InternalHooks'); return { ...actual, onFirstProductionWorkflowSuccess: mockedFirstProductionWorkflowSuccess, onFirstWorkflowDataLoad: mockedFirstWorkflowDataLoad, }; }); -jest.mock('../../src/Db', () => { +jest.mock('@/Db', () => { return { collections: { Workflow: { @@ -36,7 +36,7 @@ jest.mock('../../src/Db', () => { }, }; }); -jest.mock('../../src/UserManagement/UserManagementHelper', () => { +jest.mock('@/UserManagement/UserManagementHelper', () => { return { getWorkflowOwner: jest.fn((workflowId) => { return { id: FAKE_USER_ID }; diff --git a/packages/cli/test/unit/License.test.ts b/packages/cli/test/unit/License.test.ts index 1d28a57a2c..c9b872f6b0 100644 --- a/packages/cli/test/unit/License.test.ts +++ b/packages/cli/test/unit/License.test.ts @@ -19,7 +19,7 @@ describe('License', () => { config.set('license.autoRenewOffset', MOCK_RENEW_OFFSET); }); - let license; + let license: License; beforeEach(async () => { license = new License(); @@ -102,6 +102,6 @@ describe('License', () => { jest.fn(license.getMainPlan).mockReset(); const mainPlan = license.getMainPlan(); - expect(mainPlan.id).toBe(MOCK_MAIN_PLAN_ID); + expect(mainPlan?.id).toBe(MOCK_MAIN_PLAN_ID); }); }); diff --git a/packages/cli/test/unit/PermissionChecker.test.ts b/packages/cli/test/unit/PermissionChecker.test.ts index 10b4fbe355..68b5ac2aae 100644 --- a/packages/cli/test/unit/PermissionChecker.test.ts +++ b/packages/cli/test/unit/PermissionChecker.test.ts @@ -1,16 +1,16 @@ import { v4 as uuid } from 'uuid'; import { INodeTypeData, INodeTypes, Workflow } from 'n8n-workflow'; -import { Db } from '../../src'; +import * as Db from '@/Db'; import * as testDb from '../integration/shared/testDb'; import { NodeTypes as MockNodeTypes } from './Helpers'; -import { PermissionChecker } from '../../src/UserManagement/PermissionChecker'; +import { PermissionChecker } from '@/UserManagement/PermissionChecker'; import { randomCredentialPayload as randomCred, randomPositiveDigit, } from '../integration/shared/random'; -import type { Role } from '../../src/databases/entities/Role'; +import type { Role } from '@/databases/entities/Role'; import type { SaveCredentialFunction } from '../integration/shared/types'; let testDbName = '';