mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
refactor(core): Reduce boilterplate code in between tests 🧹, and fix the tests in node.js 20 (no-changelog) (#6654)
refactor(core): Reduce boilterplate code in between tests also cleaned up some imports, and fixed the tests in node.js 20
This commit is contained in:
committed by
GitHub
parent
3e07ffa73e
commit
b895ba438a
@@ -1,18 +1,14 @@
|
||||
import type { Application } from 'express';
|
||||
import type { SuperAgentTest } from 'supertest';
|
||||
import * as Db from '@/Db';
|
||||
import config from '@/config';
|
||||
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 utils from '../shared/utils/';
|
||||
import * as testDb from '../shared/testDb';
|
||||
// import { generateNanoId } from '@/databases/utils/generators';
|
||||
|
||||
let app: Application;
|
||||
let workflowOwnerRole: Role;
|
||||
let owner: User;
|
||||
let member: User;
|
||||
@@ -20,13 +16,9 @@ let authOwnerAgent: SuperAgentTest;
|
||||
let authMemberAgent: SuperAgentTest;
|
||||
let workflowRunner: ActiveWorkflowRunner;
|
||||
|
||||
beforeAll(async () => {
|
||||
app = await utils.initTestServer({
|
||||
endpointGroups: ['publicApi'],
|
||||
applyAuth: false,
|
||||
enablePublicAPI: true,
|
||||
});
|
||||
const testServer = utils.setupTestServer({ endpointGroups: ['publicApi'] });
|
||||
|
||||
beforeAll(async () => {
|
||||
const [globalOwnerRole, globalMemberRole, fetchedWorkflowOwnerRole] = await testDb.getAllRoles();
|
||||
|
||||
workflowOwnerRole = fetchedWorkflowOwnerRole;
|
||||
@@ -41,7 +33,7 @@ beforeAll(async () => {
|
||||
apiKey: randomApiKey(),
|
||||
});
|
||||
|
||||
await utils.initConfigFile();
|
||||
await utils.initEncryptionKey();
|
||||
await utils.initNodeTypes();
|
||||
workflowRunner = await utils.initActiveWorkflowRunner();
|
||||
});
|
||||
@@ -49,31 +41,14 @@ beforeAll(async () => {
|
||||
beforeEach(async () => {
|
||||
await testDb.truncate(['SharedCredentials', 'SharedWorkflow', 'Tag', 'Workflow', 'Credentials']);
|
||||
|
||||
authOwnerAgent = utils.createAgent(app, {
|
||||
apiPath: 'public',
|
||||
auth: true,
|
||||
user: owner,
|
||||
version: 1,
|
||||
});
|
||||
|
||||
authMemberAgent = utils.createAgent(app, {
|
||||
apiPath: 'public',
|
||||
auth: true,
|
||||
user: member,
|
||||
version: 1,
|
||||
});
|
||||
|
||||
config.set('userManagement.isInstanceOwnerSetUp', true);
|
||||
authOwnerAgent = testServer.publicApiAgentFor(owner);
|
||||
authMemberAgent = testServer.publicApiAgentFor(member);
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await workflowRunner?.removeAll();
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await testDb.terminate();
|
||||
});
|
||||
|
||||
const testWithAPIKey =
|
||||
(method: 'get' | 'post' | 'put' | 'delete', url: string, apiKey: string | null) => async () => {
|
||||
void authOwnerAgent.set({ 'X-N8N-API-KEY': apiKey });
|
||||
|
||||
Reference in New Issue
Block a user