mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-14 16:44:07 -08:00
wip: parameters validation, more tests
This commit is contained in:
parent
9849739d39
commit
2482903c7c
|
@ -59,4 +59,7 @@ export class TestDefinition extends WithTimestamps {
|
|||
*/
|
||||
@ManyToOne('AnnotationTagEntity', 'test')
|
||||
annotationTag: AnnotationTagEntity;
|
||||
|
||||
@RelationId((test: TestDefinition) => test.annotationTag)
|
||||
annotationTagId: string;
|
||||
}
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
import { Service } from 'typedi';
|
||||
|
||||
import type { TestDefinition } from '@/databases/entities/test-definition.ee';
|
||||
import { AnnotationTagRepository } from '@/databases/repositories/annotation-tag.repository.ee';
|
||||
import { TestDefinitionRepository } from '@/databases/repositories/test-definition.repository.ee';
|
||||
import { NotFoundError } from '@/errors/response-errors/not-found.error';
|
||||
import { validateEntity } from '@/generic-helpers';
|
||||
import type { ListQuery } from '@/requests';
|
||||
import { BadRequestError } from '@/errors/response-errors/bad-request.error';
|
||||
|
||||
type TestDefinitionLike = Omit<
|
||||
Partial<TestDefinition>,
|
||||
|
@ -17,7 +19,10 @@ type TestDefinitionLike = Omit<
|
|||
|
||||
@Service()
|
||||
export class TestDefinitionsService {
|
||||
constructor(private testRepository: TestDefinitionRepository) {}
|
||||
constructor(
|
||||
private testRepository: TestDefinitionRepository,
|
||||
private annotationTagRepository: AnnotationTagRepository,
|
||||
) {}
|
||||
|
||||
private toEntityLike(attrs: {
|
||||
name?: string;
|
||||
|
@ -89,6 +94,20 @@ export class TestDefinitionsService {
|
|||
delete attrs.workflowId;
|
||||
}
|
||||
|
||||
// Check if the annotation tag exists
|
||||
if (attrs.annotationTagId) {
|
||||
const annotationTagExists = await this.annotationTagRepository.exists({
|
||||
where: {
|
||||
id: attrs.annotationTagId,
|
||||
},
|
||||
});
|
||||
|
||||
if (!annotationTagExists) {
|
||||
throw new BadRequestError('Annotation tag not found');
|
||||
}
|
||||
}
|
||||
|
||||
// Update the test definition
|
||||
const queryResult = await this.testRepository.update(id, this.toEntityLike(attrs));
|
||||
|
||||
if (queryResult.affected === 0) {
|
||||
|
|
|
@ -9,12 +9,15 @@ import { createWorkflow } from './../shared/db/workflows';
|
|||
import * as testDb from './../shared/test-db';
|
||||
import type { SuperAgentTest } from './../shared/types';
|
||||
import * as utils from './../shared/utils/';
|
||||
import { AnnotationTagEntity } from '@/databases/entities/annotation-tag-entity.ee';
|
||||
import { createAnnotationTags } from '@test-integration/db/executions';
|
||||
|
||||
let authOwnerAgent: SuperAgentTest;
|
||||
let workflowUnderTest: WorkflowEntity;
|
||||
let evaluationWorkflow: WorkflowEntity;
|
||||
let otherWorkflow: WorkflowEntity;
|
||||
let ownerShell: User;
|
||||
let annotationTag: AnnotationTagEntity;
|
||||
const testServer = utils.setupTestServer({ endpointGroups: ['evaluation'] });
|
||||
|
||||
beforeAll(async () => {
|
||||
|
@ -23,11 +26,12 @@ beforeAll(async () => {
|
|||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
await testDb.truncate(['TestDefinition', 'Workflow']);
|
||||
await testDb.truncate(['TestDefinition', 'Workflow', 'AnnotationTag']);
|
||||
|
||||
workflowUnderTest = await createWorkflow({ name: 'workflow-under-test' }, ownerShell);
|
||||
evaluationWorkflow = await createWorkflow({ name: 'evaluation-workflow' }, ownerShell);
|
||||
otherWorkflow = await createWorkflow({ name: 'other-workflow' });
|
||||
annotationTag = (await createAnnotationTags(['test-tag']))[0];
|
||||
});
|
||||
|
||||
describe('GET /evaluation/test-definitions', () => {
|
||||
|
@ -244,4 +248,34 @@ describe('PATCH /evaluation/test-definitions/:id', () => {
|
|||
expect(resp.body.data.name).toBe('updated-test');
|
||||
expect(resp.body.data.workflowId).toBe(workflowUnderTest.id);
|
||||
});
|
||||
|
||||
test('should update annotationTagId', async () => {
|
||||
const newTest = Container.get(TestDefinitionRepository).create({
|
||||
name: 'test',
|
||||
workflow: { id: workflowUnderTest.id },
|
||||
});
|
||||
await Container.get(TestDefinitionRepository).save(newTest);
|
||||
|
||||
const resp = await authOwnerAgent.patch(`/evaluation/test-definitions/${newTest.id}`).send({
|
||||
annotationTagId: annotationTag.id,
|
||||
});
|
||||
|
||||
expect(resp.statusCode).toBe(200);
|
||||
expect(resp.body.data.annotationTag.id).toBe(annotationTag.id);
|
||||
});
|
||||
|
||||
test('should return error if annotationTagId is invalid', async () => {
|
||||
const newTest = Container.get(TestDefinitionRepository).create({
|
||||
name: 'test',
|
||||
workflow: { id: workflowUnderTest.id },
|
||||
});
|
||||
await Container.get(TestDefinitionRepository).save(newTest);
|
||||
|
||||
const resp = await authOwnerAgent.patch(`/evaluation/test-definitions/${newTest.id}`).send({
|
||||
annotationTagId: 123,
|
||||
});
|
||||
|
||||
expect(resp.statusCode).toBe(400);
|
||||
expect(resp.body.message).toBe('Annotation tag not found');
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue