n8n/packages/cli/test/integration/workflow-hook-context.service.test.ts
Konstantin Tieber 19fef9be1b
Some checks are pending
CI: Master (Build, Test, Lint) / Build for Github Cache (push) Waiting to run
CI: Master (Build, Test, Lint) / Unit tests (22.x) (push) Waiting to run
CI: Master (Build, Test, Lint) / Unit tests (24.15.0) (push) Waiting to run
CI: Master (Build, Test, Lint) / Lint (push) Waiting to run
CI: Master (Build, Test, Lint) / Performance (push) Waiting to run
CI: Master (Build, Test, Lint) / Notify Slack on failure (push) Blocked by required conditions
feat(core): Support checking for workflow tags existing in preExecute hook (#30440)
2026-05-19 18:23:18 +00:00

46 lines
1.3 KiB
TypeScript

import { createWorkflow, testDb } from '@n8n/backend-test-utils';
import { Container } from '@n8n/di';
import { WorkflowHookContextService } from '@/workflow-hook-context.service';
import { createTag } from './shared/db/tags';
describe('WorkflowHookContextService', () => {
let service: WorkflowHookContextService;
beforeAll(async () => {
await testDb.init();
service = Container.get(WorkflowHookContextService);
});
beforeEach(async () => {
await testDb.truncate(['WorkflowEntity', 'TagEntity']);
});
afterAll(async () => {
await testDb.terminate();
});
describe('getWorkflowTags', () => {
it('returns the tag names of the workflow', async () => {
const workflow = await createWorkflow();
await createTag({ name: 'tagOne' }, workflow);
await createTag({ name: 'tagTwo' }, workflow);
await expect(service.getWorkflowTags(workflow.id)).resolves.toEqual(
expect.arrayContaining(['tagOne', 'tagTwo']),
);
});
it('returns an empty array when the workflow has no tags', async () => {
const workflow = await createWorkflow();
await expect(service.getWorkflowTags(workflow.id)).resolves.toEqual([]);
});
it('returns an empty array when the workflow does not exist', async () => {
await expect(service.getWorkflowTags('non-existent-id')).resolves.toEqual([]);
});
});
});