mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-20 03:12:15 +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,5 +1,4 @@
|
||||
import type { SuperAgentTest } from 'supertest';
|
||||
import * as Db from '@/Db';
|
||||
import type { Role } from '@db/entities/Role';
|
||||
import type { User } from '@db/entities/User';
|
||||
|
||||
@@ -10,6 +9,9 @@ import * as testDb from '../shared/testDb';
|
||||
import { affixRoleToSaveCredential } from '../shared/db/credentials';
|
||||
import { getAllRoles } from '../shared/db/roles';
|
||||
import { addApiKey, createUser, createUserShell } from '../shared/db/users';
|
||||
import { CredentialsRepository } from '@db/repositories/credentials.repository';
|
||||
import Container from 'typedi';
|
||||
import { SharedCredentialsRepository } from '@db/repositories/sharedCredentials.repository';
|
||||
|
||||
let globalMemberRole: Role;
|
||||
let credentialOwnerRole: Role;
|
||||
@@ -64,13 +66,13 @@ describe('POST /credentials', () => {
|
||||
expect(name).toBe(payload.name);
|
||||
expect(type).toBe(payload.type);
|
||||
|
||||
const credential = await Db.collections.Credentials.findOneByOrFail({ id });
|
||||
const credential = await Container.get(CredentialsRepository).findOneByOrFail({ id });
|
||||
|
||||
expect(credential.name).toBe(payload.name);
|
||||
expect(credential.type).toBe(payload.type);
|
||||
expect(credential.data).not.toBe(payload.data);
|
||||
|
||||
const sharedCredential = await Db.collections.SharedCredentials.findOneOrFail({
|
||||
const sharedCredential = await Container.get(SharedCredentialsRepository).findOneOrFail({
|
||||
relations: ['user', 'credentials', 'role'],
|
||||
where: { credentialsId: credential.id, userId: owner.id },
|
||||
});
|
||||
@@ -100,13 +102,13 @@ describe('DELETE /credentials/:id', () => {
|
||||
expect(name).toBe(savedCredential.name);
|
||||
expect(type).toBe(savedCredential.type);
|
||||
|
||||
const deletedCredential = await Db.collections.Credentials.findOneBy({
|
||||
const deletedCredential = await Container.get(CredentialsRepository).findOneBy({
|
||||
id: savedCredential.id,
|
||||
});
|
||||
|
||||
expect(deletedCredential).toBeNull(); // deleted
|
||||
|
||||
const deletedSharedCredential = await Db.collections.SharedCredentials.findOneBy({});
|
||||
const deletedSharedCredential = await Container.get(SharedCredentialsRepository).findOneBy({});
|
||||
|
||||
expect(deletedSharedCredential).toBeNull(); // deleted
|
||||
});
|
||||
@@ -118,13 +120,13 @@ describe('DELETE /credentials/:id', () => {
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
|
||||
const deletedCredential = await Db.collections.Credentials.findOneBy({
|
||||
const deletedCredential = await Container.get(CredentialsRepository).findOneBy({
|
||||
id: savedCredential.id,
|
||||
});
|
||||
|
||||
expect(deletedCredential).toBeNull(); // deleted
|
||||
|
||||
const deletedSharedCredential = await Db.collections.SharedCredentials.findOneBy({});
|
||||
const deletedSharedCredential = await Container.get(SharedCredentialsRepository).findOneBy({});
|
||||
|
||||
expect(deletedSharedCredential).toBeNull(); // deleted
|
||||
});
|
||||
@@ -141,13 +143,13 @@ describe('DELETE /credentials/:id', () => {
|
||||
expect(name).toBe(savedCredential.name);
|
||||
expect(type).toBe(savedCredential.type);
|
||||
|
||||
const deletedCredential = await Db.collections.Credentials.findOneBy({
|
||||
const deletedCredential = await Container.get(CredentialsRepository).findOneBy({
|
||||
id: savedCredential.id,
|
||||
});
|
||||
|
||||
expect(deletedCredential).toBeNull(); // deleted
|
||||
|
||||
const deletedSharedCredential = await Db.collections.SharedCredentials.findOneBy({});
|
||||
const deletedSharedCredential = await Container.get(SharedCredentialsRepository).findOneBy({});
|
||||
|
||||
expect(deletedSharedCredential).toBeNull(); // deleted
|
||||
});
|
||||
@@ -173,13 +175,13 @@ describe('DELETE /credentials/:id', () => {
|
||||
expect(name).toBe(savedCredential.name);
|
||||
expect(type).toBe(savedCredential.type);
|
||||
|
||||
const deletedCredential = await Db.collections.Credentials.findOneBy({
|
||||
const deletedCredential = await Container.get(CredentialsRepository).findOneBy({
|
||||
id: savedCredential.id,
|
||||
});
|
||||
|
||||
expect(deletedCredential).toBeNull(); // deleted
|
||||
|
||||
const deletedSharedCredential = await Db.collections.SharedCredentials.findOne({
|
||||
const deletedSharedCredential = await Container.get(SharedCredentialsRepository).findOne({
|
||||
where: {
|
||||
credentialsId: savedCredential.id,
|
||||
},
|
||||
@@ -189,13 +191,13 @@ describe('DELETE /credentials/:id', () => {
|
||||
|
||||
await Promise.all(
|
||||
[notToBeChangedCredential, notToBeChangedCredential2].map(async (credential) => {
|
||||
const untouchedCredential = await Db.collections.Credentials.findOneBy({
|
||||
const untouchedCredential = await Container.get(CredentialsRepository).findOneBy({
|
||||
id: credential.id,
|
||||
});
|
||||
|
||||
expect(untouchedCredential).toEqual(credential); // not deleted
|
||||
|
||||
const untouchedSharedCredential = await Db.collections.SharedCredentials.findOne({
|
||||
const untouchedSharedCredential = await Container.get(SharedCredentialsRepository).findOne({
|
||||
where: {
|
||||
credentialsId: credential.id,
|
||||
},
|
||||
@@ -213,13 +215,13 @@ describe('DELETE /credentials/:id', () => {
|
||||
|
||||
expect(response.statusCode).toBe(404);
|
||||
|
||||
const shellCredential = await Db.collections.Credentials.findOneBy({
|
||||
const shellCredential = await Container.get(CredentialsRepository).findOneBy({
|
||||
id: savedCredential.id,
|
||||
});
|
||||
|
||||
expect(shellCredential).toBeDefined(); // not deleted
|
||||
|
||||
const deletedSharedCredential = await Db.collections.SharedCredentials.findOneBy({});
|
||||
const deletedSharedCredential = await Container.get(SharedCredentialsRepository).findOneBy({});
|
||||
|
||||
expect(deletedSharedCredential).toBeDefined(); // not deleted
|
||||
});
|
||||
|
||||
@@ -5,13 +5,14 @@ import { v4 as uuid } from 'uuid';
|
||||
import type { Role } from '@db/entities/Role';
|
||||
import { License } from '@/License';
|
||||
|
||||
import { mockInstance } from '../../shared/mocking';
|
||||
import { randomApiKey } from '../shared/random';
|
||||
import * as utils from '../shared/utils/';
|
||||
import * as testDb from '../shared/testDb';
|
||||
import { getGlobalMemberRole, getGlobalOwnerRole } from '../shared/db/roles';
|
||||
import { createUser, createUserShell } from '../shared/db/users';
|
||||
|
||||
utils.mockInstance(License, {
|
||||
mockInstance(License, {
|
||||
getUsersLimit: jest.fn().mockReturnValue(-1),
|
||||
});
|
||||
|
||||
@@ -216,7 +217,7 @@ describe('With license without quota:users', () => {
|
||||
let authOwnerAgent: SuperAgentTest;
|
||||
|
||||
beforeEach(async () => {
|
||||
utils.mockInstance(License, { getUsersLimit: jest.fn().mockReturnValue(null) });
|
||||
mockInstance(License, { getUsersLimit: jest.fn().mockReturnValue(null) });
|
||||
|
||||
const owner = await createUser({
|
||||
globalRole: globalOwnerRole,
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
import type { SuperAgentTest } from 'supertest';
|
||||
import * as Db from '@/Db';
|
||||
import type { Role } from '@db/entities/Role';
|
||||
import type { TagEntity } from '@db/entities/TagEntity';
|
||||
import type { User } from '@db/entities/User';
|
||||
import type { ActiveWorkflowRunner } from '@/ActiveWorkflowRunner';
|
||||
|
||||
import { randomApiKey } from '../shared/random';
|
||||
import * as utils from '../shared/utils/';
|
||||
import * as testDb from '../shared/testDb';
|
||||
import Container from 'typedi';
|
||||
import type { INode } from 'n8n-workflow';
|
||||
import { STARTING_NODES } from '@/constants';
|
||||
import { License } from '@/License';
|
||||
import { WorkflowHistoryRepository } from '@/databases/repositories';
|
||||
import Container from 'typedi';
|
||||
import type { Role } from '@db/entities/Role';
|
||||
import type { TagEntity } from '@db/entities/TagEntity';
|
||||
import type { User } from '@db/entities/User';
|
||||
import { SharedWorkflowRepository } from '@db/repositories/sharedWorkflow.repository';
|
||||
import { WorkflowHistoryRepository } from '@db/repositories/workflowHistory.repository';
|
||||
import type { ActiveWorkflowRunner } from '@/ActiveWorkflowRunner';
|
||||
|
||||
import { mockInstance } from '../../shared/mocking';
|
||||
import { randomApiKey } from '../shared/random';
|
||||
import * as utils from '../shared/utils/';
|
||||
import * as testDb from '../shared/testDb';
|
||||
import { getAllRoles } from '../shared/db/roles';
|
||||
import { createUser } from '../shared/db/users';
|
||||
import { createWorkflow, createWorkflowWithTrigger } from '../shared/db/workflows';
|
||||
@@ -27,7 +28,7 @@ let workflowRunner: ActiveWorkflowRunner;
|
||||
|
||||
const testServer = utils.setupTestServer({ endpointGroups: ['publicApi'] });
|
||||
|
||||
const licenseLike = utils.mockInstance(License, {
|
||||
const licenseLike = mockInstance(License, {
|
||||
isWorkflowHistoryLicensed: jest.fn().mockReturnValue(false),
|
||||
isWithinUsersLimit: jest.fn().mockReturnValue(true),
|
||||
});
|
||||
@@ -58,7 +59,7 @@ beforeEach(async () => {
|
||||
'Tag',
|
||||
'Workflow',
|
||||
'Credentials',
|
||||
WorkflowHistoryRepository,
|
||||
'WorkflowHistory',
|
||||
]);
|
||||
|
||||
authOwnerAgent = testServer.publicApiAgentFor(owner);
|
||||
@@ -397,7 +398,7 @@ describe('DELETE /workflows/:id', () => {
|
||||
expect(updatedAt).toEqual(workflow.updatedAt.toISOString());
|
||||
|
||||
// make sure the workflow actually deleted from the db
|
||||
const sharedWorkflow = await Db.collections.SharedWorkflow.findOneBy({
|
||||
const sharedWorkflow = await Container.get(SharedWorkflowRepository).findOneBy({
|
||||
workflowId: workflow.id,
|
||||
});
|
||||
|
||||
@@ -426,7 +427,7 @@ describe('DELETE /workflows/:id', () => {
|
||||
expect(updatedAt).toEqual(workflow.updatedAt.toISOString());
|
||||
|
||||
// make sure the workflow actually deleted from the db
|
||||
const sharedWorkflow = await Db.collections.SharedWorkflow.findOneBy({
|
||||
const sharedWorkflow = await Container.get(SharedWorkflowRepository).findOneBy({
|
||||
workflowId: workflow.id,
|
||||
});
|
||||
|
||||
@@ -474,7 +475,7 @@ describe('POST /workflows/:id/activate', () => {
|
||||
expect(updatedAt).toEqual(workflow.updatedAt.toISOString());
|
||||
|
||||
// check whether the workflow is on the database
|
||||
const sharedWorkflow = await Db.collections.SharedWorkflow.findOne({
|
||||
const sharedWorkflow = await Container.get(SharedWorkflowRepository).findOne({
|
||||
where: {
|
||||
userId: member.id,
|
||||
workflowId: workflow.id,
|
||||
@@ -509,7 +510,7 @@ describe('POST /workflows/:id/activate', () => {
|
||||
expect(updatedAt).toEqual(workflow.updatedAt.toISOString());
|
||||
|
||||
// check whether the workflow is on the database
|
||||
const sharedOwnerWorkflow = await Db.collections.SharedWorkflow.findOne({
|
||||
const sharedOwnerWorkflow = await Container.get(SharedWorkflowRepository).findOne({
|
||||
where: {
|
||||
userId: owner.id,
|
||||
workflowId: workflow.id,
|
||||
@@ -518,7 +519,7 @@ describe('POST /workflows/:id/activate', () => {
|
||||
|
||||
expect(sharedOwnerWorkflow).toBeNull();
|
||||
|
||||
const sharedWorkflow = await Db.collections.SharedWorkflow.findOne({
|
||||
const sharedWorkflow = await Container.get(SharedWorkflowRepository).findOne({
|
||||
where: {
|
||||
userId: member.id,
|
||||
workflowId: workflow.id,
|
||||
@@ -572,7 +573,7 @@ describe('POST /workflows/:id/deactivate', () => {
|
||||
expect(updatedAt).toBeDefined();
|
||||
|
||||
// get the workflow after it was deactivated
|
||||
const sharedWorkflow = await Db.collections.SharedWorkflow.findOne({
|
||||
const sharedWorkflow = await Container.get(SharedWorkflowRepository).findOne({
|
||||
where: {
|
||||
userId: member.id,
|
||||
workflowId: workflow.id,
|
||||
@@ -609,7 +610,7 @@ describe('POST /workflows/:id/deactivate', () => {
|
||||
expect(updatedAt).toBeDefined();
|
||||
|
||||
// check whether the workflow is deactivated in the database
|
||||
const sharedOwnerWorkflow = await Db.collections.SharedWorkflow.findOne({
|
||||
const sharedOwnerWorkflow = await Container.get(SharedWorkflowRepository).findOne({
|
||||
where: {
|
||||
userId: owner.id,
|
||||
workflowId: workflow.id,
|
||||
@@ -618,7 +619,7 @@ describe('POST /workflows/:id/deactivate', () => {
|
||||
|
||||
expect(sharedOwnerWorkflow).toBeNull();
|
||||
|
||||
const sharedWorkflow = await Db.collections.SharedWorkflow.findOne({
|
||||
const sharedWorkflow = await Container.get(SharedWorkflowRepository).findOne({
|
||||
where: {
|
||||
userId: member.id,
|
||||
workflowId: workflow.id,
|
||||
@@ -685,7 +686,7 @@ describe('POST /workflows', () => {
|
||||
expect(updatedAt).toEqual(createdAt);
|
||||
|
||||
// check if created workflow in DB
|
||||
const sharedWorkflow = await Db.collections.SharedWorkflow.findOne({
|
||||
const sharedWorkflow = await Container.get(SharedWorkflowRepository).findOne({
|
||||
where: {
|
||||
userId: member.id,
|
||||
workflowId: response.body.id,
|
||||
@@ -924,7 +925,7 @@ describe('PUT /workflows/:id', () => {
|
||||
expect(updatedAt).not.toBe(workflow.updatedAt.toISOString());
|
||||
|
||||
// check updated workflow in DB
|
||||
const sharedWorkflow = await Db.collections.SharedWorkflow.findOne({
|
||||
const sharedWorkflow = await Container.get(SharedWorkflowRepository).findOne({
|
||||
where: {
|
||||
userId: member.id,
|
||||
workflowId: response.body.id,
|
||||
@@ -1093,7 +1094,7 @@ describe('PUT /workflows/:id', () => {
|
||||
expect(updatedAt).not.toBe(workflow.updatedAt.toISOString());
|
||||
|
||||
// check updated workflow in DB
|
||||
const sharedOwnerWorkflow = await Db.collections.SharedWorkflow.findOne({
|
||||
const sharedOwnerWorkflow = await Container.get(SharedWorkflowRepository).findOne({
|
||||
where: {
|
||||
userId: owner.id,
|
||||
workflowId: response.body.id,
|
||||
@@ -1102,7 +1103,7 @@ describe('PUT /workflows/:id', () => {
|
||||
|
||||
expect(sharedOwnerWorkflow).toBeNull();
|
||||
|
||||
const sharedWorkflow = await Db.collections.SharedWorkflow.findOne({
|
||||
const sharedWorkflow = await Container.get(SharedWorkflowRepository).findOne({
|
||||
where: {
|
||||
userId: member.id,
|
||||
workflowId: response.body.id,
|
||||
|
||||
Reference in New Issue
Block a user