mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
feat(core): Add workflowId filter to the test-definitions endpoint (no-changelog) (#11831)
This commit is contained in:
@@ -14,6 +14,7 @@ import * as utils from './../shared/utils/';
|
||||
|
||||
let authOwnerAgent: SuperAgentTest;
|
||||
let workflowUnderTest: WorkflowEntity;
|
||||
let workflowUnderTest2: WorkflowEntity;
|
||||
let evaluationWorkflow: WorkflowEntity;
|
||||
let otherWorkflow: WorkflowEntity;
|
||||
let ownerShell: User;
|
||||
@@ -29,6 +30,7 @@ beforeEach(async () => {
|
||||
await testDb.truncate(['TestDefinition', 'Workflow', 'AnnotationTag']);
|
||||
|
||||
workflowUnderTest = await createWorkflow({ name: 'workflow-under-test' }, ownerShell);
|
||||
workflowUnderTest2 = await createWorkflow({ name: 'workflow-under-test-2' }, ownerShell);
|
||||
evaluationWorkflow = await createWorkflow({ name: 'evaluation-workflow' }, ownerShell);
|
||||
otherWorkflow = await createWorkflow({ name: 'other-workflow' });
|
||||
annotationTag = (await createAnnotationTags(['test-tag']))[0];
|
||||
@@ -90,6 +92,44 @@ describe('GET /evaluation/test-definitions', () => {
|
||||
expect(resp.body.data.count).toBe(15);
|
||||
expect(resp.body.data.testDefinitions).toHaveLength(5);
|
||||
});
|
||||
|
||||
test('should retrieve test definitions list for a workflow', async () => {
|
||||
// Add a bunch of test definitions for two different workflows
|
||||
const testDefinitions = [];
|
||||
|
||||
for (let i = 0; i < 15; i++) {
|
||||
const newTest = Container.get(TestDefinitionRepository).create({
|
||||
name: `test-${i}`,
|
||||
workflow: { id: workflowUnderTest.id },
|
||||
});
|
||||
|
||||
const newTest2 = Container.get(TestDefinitionRepository).create({
|
||||
name: `test-${i * 2}`,
|
||||
workflow: { id: workflowUnderTest2.id },
|
||||
});
|
||||
|
||||
testDefinitions.push(newTest, newTest2);
|
||||
}
|
||||
|
||||
await Container.get(TestDefinitionRepository).save(testDefinitions);
|
||||
|
||||
// Fetch test definitions of a second workflow
|
||||
let resp = await authOwnerAgent.get(
|
||||
`/evaluation/test-definitions?filter=${JSON.stringify({ workflowId: workflowUnderTest2.id })}`,
|
||||
);
|
||||
|
||||
expect(resp.statusCode).toBe(200);
|
||||
expect(resp.body.data.count).toBe(15);
|
||||
});
|
||||
|
||||
test('should return error if user has no access to the workflowId specified in filter', async () => {
|
||||
let resp = await authOwnerAgent.get(
|
||||
`/evaluation/test-definitions?filter=${JSON.stringify({ workflowId: otherWorkflow.id })}`,
|
||||
);
|
||||
|
||||
expect(resp.statusCode).toBe(403);
|
||||
expect(resp.body.message).toBe('User does not have access to the workflow');
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /evaluation/test-definitions/:id', () => {
|
||||
|
||||
Reference in New Issue
Block a user