n8n/packages/cli/test/integration/shared/utils/communityNodes.ts
कारतोफ्फेलस्क्रिप्ट™ 000e76e3b4
ci(core): Reduce memory usage in tests (part-2) (no-changelog) (#7671)
This also gets rid of `Db.collection`, which was another source of
circular dependencies.
2023-11-10 15:04:26 +01:00

48 lines
1.5 KiB
TypeScript

import { NODE_PACKAGE_PREFIX } from '@/constants';
import { InstalledPackages } from '@db/entities/InstalledPackages';
import { randomName } from '../random';
import { COMMUNITY_NODE_VERSION, COMMUNITY_PACKAGE_VERSION } from '../constants';
import { InstalledNodesRepository } from '@db/repositories/installedNodes.repository';
import { InstalledPackagesRepository } from '@db/repositories/installedPackages.repository';
import Container from 'typedi';
export const mockPackageName = () => NODE_PACKAGE_PREFIX + randomName();
export const mockPackage = () =>
Container.get(InstalledPackagesRepository).create({
packageName: mockPackageName(),
installedVersion: COMMUNITY_PACKAGE_VERSION.CURRENT,
installedNodes: [],
});
export const mockNode = (packageName: string) => {
const nodeName = randomName();
return Container.get(InstalledNodesRepository).create({
name: nodeName,
type: nodeName,
latestVersion: COMMUNITY_NODE_VERSION.CURRENT.toString(),
package: { packageName },
});
};
export const emptyPackage = async () => {
const installedPackage = new InstalledPackages();
installedPackage.installedNodes = [];
return installedPackage;
};
export function mockPackagePair(): InstalledPackages[] {
const pkgA = mockPackage();
const nodeA = mockNode(pkgA.packageName);
pkgA.installedNodes = [nodeA];
const pkgB = mockPackage();
const nodeB1 = mockNode(pkgB.packageName);
const nodeB2 = mockNode(pkgB.packageName);
pkgB.installedNodes = [nodeB1, nodeB2];
return [pkgA, pkgB];
}