mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-19 02:51:14 +00:00
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.
This commit is contained in:
committed by
GitHub
parent
37dd658dc5
commit
000e76e3b4
@@ -1,11 +1,15 @@
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import * as Db from '@/Db';
|
||||
import config from '@/config';
|
||||
import { audit } from '@/audit';
|
||||
import { CREDENTIALS_REPORT } from '@/audit/constants';
|
||||
import { getRiskSection } from './utils';
|
||||
import * as testDb from '../shared/testDb';
|
||||
import { generateNanoId } from '@db/utils/generators';
|
||||
import { WorkflowRepository } from '@db/repositories/workflow.repository';
|
||||
import Container from 'typedi';
|
||||
import { CredentialsRepository } from '@db/repositories/credentials.repository';
|
||||
import { ExecutionRepository } from '@db/repositories/execution.repository';
|
||||
import { ExecutionDataRepository } from '@db/repositories/executionData.repository';
|
||||
|
||||
beforeAll(async () => {
|
||||
await testDb.init();
|
||||
@@ -46,8 +50,8 @@ test('should report credentials not in any use', async () => {
|
||||
};
|
||||
|
||||
await Promise.all([
|
||||
Db.collections.Credentials.save(credentialDetails),
|
||||
Db.collections.Workflow.save(workflowDetails),
|
||||
Container.get(CredentialsRepository).save(credentialDetails),
|
||||
Container.get(WorkflowRepository).save(workflowDetails),
|
||||
]);
|
||||
|
||||
const testAudit = await audit(['credentials']);
|
||||
@@ -74,7 +78,7 @@ test('should report credentials not in active use', async () => {
|
||||
nodesAccess: [{ nodeType: 'n8n-nodes-base.slack', date: '2022-12-21T11:23:00.561Z' }],
|
||||
};
|
||||
|
||||
const credential = await Db.collections.Credentials.save(credentialDetails);
|
||||
const credential = await Container.get(CredentialsRepository).save(credentialDetails);
|
||||
|
||||
const workflowDetails = {
|
||||
id: generateNanoId(),
|
||||
@@ -93,7 +97,7 @@ test('should report credentials not in active use', async () => {
|
||||
],
|
||||
};
|
||||
|
||||
await Db.collections.Workflow.save(workflowDetails);
|
||||
await Container.get(WorkflowRepository).save(workflowDetails);
|
||||
|
||||
const testAudit = await audit(['credentials']);
|
||||
|
||||
@@ -119,7 +123,7 @@ test('should report credential in not recently executed workflow', async () => {
|
||||
nodesAccess: [{ nodeType: 'n8n-nodes-base.slack', date: '2022-12-21T11:23:00.561Z' }],
|
||||
};
|
||||
|
||||
const credential = await Db.collections.Credentials.save(credentialDetails);
|
||||
const credential = await Container.get(CredentialsRepository).save(credentialDetails);
|
||||
|
||||
const workflowDetails = {
|
||||
id: generateNanoId(),
|
||||
@@ -144,12 +148,12 @@ test('should report credential in not recently executed workflow', async () => {
|
||||
],
|
||||
};
|
||||
|
||||
const workflow = await Db.collections.Workflow.save(workflowDetails);
|
||||
const workflow = await Container.get(WorkflowRepository).save(workflowDetails);
|
||||
|
||||
const date = new Date();
|
||||
date.setDate(date.getDate() - config.getEnv('security.audit.daysAbandonedWorkflow') - 1);
|
||||
|
||||
const savedExecution = await Db.collections.Execution.save({
|
||||
const savedExecution = await Container.get(ExecutionRepository).save({
|
||||
finished: true,
|
||||
mode: 'manual',
|
||||
startedAt: date,
|
||||
@@ -157,7 +161,7 @@ test('should report credential in not recently executed workflow', async () => {
|
||||
workflowId: workflow.id,
|
||||
waitTill: null,
|
||||
});
|
||||
await Db.collections.ExecutionData.save({
|
||||
await Container.get(ExecutionDataRepository).save({
|
||||
execution: savedExecution,
|
||||
data: '[]',
|
||||
workflowData: workflow,
|
||||
@@ -187,7 +191,7 @@ test('should not report credentials in recently executed workflow', async () =>
|
||||
nodesAccess: [{ nodeType: 'n8n-nodes-base.slack', date: '2022-12-21T11:23:00.561Z' }],
|
||||
};
|
||||
|
||||
const credential = await Db.collections.Credentials.save(credentialDetails);
|
||||
const credential = await Container.get(CredentialsRepository).save(credentialDetails);
|
||||
|
||||
const workflowDetails = {
|
||||
id: generateNanoId(),
|
||||
@@ -212,12 +216,12 @@ test('should not report credentials in recently executed workflow', async () =>
|
||||
],
|
||||
};
|
||||
|
||||
const workflow = await Db.collections.Workflow.save(workflowDetails);
|
||||
const workflow = await Container.get(WorkflowRepository).save(workflowDetails);
|
||||
|
||||
const date = new Date();
|
||||
date.setDate(date.getDate() - config.getEnv('security.audit.daysAbandonedWorkflow') + 1);
|
||||
|
||||
const savedExecution = await Db.collections.Execution.save({
|
||||
const savedExecution = await Container.get(ExecutionRepository).save({
|
||||
finished: true,
|
||||
mode: 'manual',
|
||||
startedAt: date,
|
||||
@@ -226,7 +230,7 @@ test('should not report credentials in recently executed workflow', async () =>
|
||||
waitTill: null,
|
||||
});
|
||||
|
||||
await Db.collections.ExecutionData.save({
|
||||
await Container.get(ExecutionDataRepository).save({
|
||||
execution: savedExecution,
|
||||
data: '[]',
|
||||
workflowData: workflow,
|
||||
|
||||
Reference in New Issue
Block a user