mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
refactor(core): Update tag endpoints to use DTOs and injectable config (#12380)
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { GlobalConfig } from '@n8n/config';
|
||||
import { Container } from '@n8n/di';
|
||||
import type { INode } from 'n8n-workflow';
|
||||
|
||||
import { ActiveWorkflowManager } from '@/active-workflow-manager';
|
||||
import config from '@/config';
|
||||
import { STARTING_NODES } from '@/constants';
|
||||
import type { Project } from '@/databases/entities/project';
|
||||
import type { TagEntity } from '@/databases/entities/tag-entity';
|
||||
@@ -36,6 +36,8 @@ let activeWorkflowManager: ActiveWorkflowManager;
|
||||
const testServer = utils.setupTestServer({ endpointGroups: ['publicApi'] });
|
||||
const license = testServer.license;
|
||||
|
||||
const globalConfig = Container.get(GlobalConfig);
|
||||
|
||||
mockInstance(ExecutionService);
|
||||
|
||||
beforeAll(async () => {
|
||||
@@ -69,6 +71,8 @@ beforeEach(async () => {
|
||||
|
||||
authOwnerAgent = testServer.publicApiAgentFor(owner);
|
||||
authMemberAgent = testServer.publicApiAgentFor(member);
|
||||
|
||||
globalConfig.tags.disabled = false;
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
@@ -1287,8 +1291,8 @@ describe('GET /workflows/:id/tags', () => {
|
||||
|
||||
test('should fail due to invalid API Key', testWithAPIKey('get', '/workflows/2/tags', 'abcXYZ'));
|
||||
|
||||
test('should fail if workflowTagsDisabled', async () => {
|
||||
config.set('workflowTagsDisabled', true);
|
||||
test('should fail if N8N_WORKFLOW_TAGS_DISABLED', async () => {
|
||||
globalConfig.tags.disabled = true;
|
||||
|
||||
const response = await authOwnerAgent.get('/workflows/2/tags');
|
||||
|
||||
@@ -1297,16 +1301,12 @@ describe('GET /workflows/:id/tags', () => {
|
||||
});
|
||||
|
||||
test('should fail due to non-existing workflow', async () => {
|
||||
config.set('workflowTagsDisabled', false);
|
||||
|
||||
const response = await authOwnerAgent.get('/workflows/2/tags');
|
||||
|
||||
expect(response.statusCode).toBe(404);
|
||||
});
|
||||
|
||||
test('should return all tags of owned workflow', async () => {
|
||||
config.set('workflowTagsDisabled', false);
|
||||
|
||||
const tags = await Promise.all([await createTag({}), await createTag({})]);
|
||||
|
||||
const workflow = await createWorkflow({ tags }, member);
|
||||
@@ -1331,8 +1331,6 @@ describe('GET /workflows/:id/tags', () => {
|
||||
});
|
||||
|
||||
test('should return empty array if workflow does not have tags', async () => {
|
||||
config.set('workflowTagsDisabled', false);
|
||||
|
||||
const workflow = await createWorkflow({}, member);
|
||||
|
||||
const response = await authMemberAgent.get(`/workflows/${workflow.id}/tags`);
|
||||
@@ -1347,8 +1345,8 @@ describe('PUT /workflows/:id/tags', () => {
|
||||
|
||||
test('should fail due to invalid API Key', testWithAPIKey('put', '/workflows/2/tags', 'abcXYZ'));
|
||||
|
||||
test('should fail if workflowTagsDisabled', async () => {
|
||||
config.set('workflowTagsDisabled', true);
|
||||
test('should fail if N8N_WORKFLOW_TAGS_DISABLED', async () => {
|
||||
globalConfig.tags.disabled = true;
|
||||
|
||||
const response = await authOwnerAgent.put('/workflows/2/tags').send([]);
|
||||
|
||||
@@ -1357,16 +1355,12 @@ describe('PUT /workflows/:id/tags', () => {
|
||||
});
|
||||
|
||||
test('should fail due to non-existing workflow', async () => {
|
||||
config.set('workflowTagsDisabled', false);
|
||||
|
||||
const response = await authOwnerAgent.put('/workflows/2/tags').send([]);
|
||||
|
||||
expect(response.statusCode).toBe(404);
|
||||
});
|
||||
|
||||
test('should add the tags, workflow have not got tags previously', async () => {
|
||||
config.set('workflowTagsDisabled', false);
|
||||
|
||||
const workflow = await createWorkflow({}, member);
|
||||
const tags = await Promise.all([await createTag({}), await createTag({})]);
|
||||
|
||||
@@ -1425,8 +1419,6 @@ describe('PUT /workflows/:id/tags', () => {
|
||||
});
|
||||
|
||||
test('should add the tags, workflow have some tags previously', async () => {
|
||||
config.set('workflowTagsDisabled', false);
|
||||
|
||||
const tags = await Promise.all([await createTag({}), await createTag({}), await createTag({})]);
|
||||
const oldTags = [tags[0], tags[1]];
|
||||
const newTags = [tags[0], tags[2]];
|
||||
@@ -1513,8 +1505,6 @@ describe('PUT /workflows/:id/tags', () => {
|
||||
});
|
||||
|
||||
test('should fail to add the tags as one does not exist, workflow should maintain previous tags', async () => {
|
||||
config.set('workflowTagsDisabled', false);
|
||||
|
||||
const tags = await Promise.all([await createTag({}), await createTag({})]);
|
||||
const oldTags = [tags[0], tags[1]];
|
||||
const workflow = await createWorkflow({ tags: oldTags }, member);
|
||||
|
||||
Reference in New Issue
Block a user