mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
ci: Delete some duplicate code in cli tests (no-changelog) (#9049)
This commit is contained in:
committed by
GitHub
parent
b8ab049932
commit
ff77ef4b62
@@ -1,6 +1,7 @@
|
||||
import { Container } from 'typedi';
|
||||
import { mock } from 'jest-mock-extended';
|
||||
import type { DeepPartial } from 'ts-essentials';
|
||||
import { DataSource, EntityManager, type EntityMetadata } from '@n8n/typeorm';
|
||||
import type { Class } from 'n8n-core';
|
||||
|
||||
export const mockInstance = <T>(
|
||||
@@ -11,3 +12,13 @@ export const mockInstance = <T>(
|
||||
Container.set(serviceClass, instance);
|
||||
return instance;
|
||||
};
|
||||
|
||||
export const mockEntityManager = (entityClass: Class) => {
|
||||
const entityManager = mockInstance(EntityManager);
|
||||
const dataSource = mockInstance(DataSource, {
|
||||
manager: entityManager,
|
||||
getMetadata: () => mock<EntityMetadata>({ target: entityClass }),
|
||||
});
|
||||
Object.assign(entityManager, { connection: dataSource });
|
||||
return entityManager;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user