wip: add description to test-definitions API

This commit is contained in:
Eugene Molodkin 2024-11-12 12:08:02 +01:00
parent 75970bffdd
commit d2798f07cc
No known key found for this signature in database
4 changed files with 41 additions and 3 deletions

View file

@ -35,6 +35,9 @@ export class TestDefinition extends WithTimestamps {
})
name: string;
@Column('text')
description: string;
/**
* Relation to the workflow under test
*/

View file

@ -4,13 +4,16 @@ export const testDefinitionCreateRequestBodySchema = z
.object({
name: z.string().min(1).max(255),
workflowId: z.string().min(1),
description: z.string().optional(),
evaluationWorkflowId: z.string().min(1).optional(),
annotationTagId: z.string().min(1).optional(),
})
.strict();
export const testDefinitionPatchRequestBodySchema = z
.object({
name: z.string().min(1).max(255).optional(),
description: z.string().optional(),
evaluationWorkflowId: z.string().min(1).optional(),
annotationTagId: z.string().min(1).optional(),
})

View file

@ -26,6 +26,7 @@ export class TestDefinitionService {
private toEntityLike(attrs: {
name?: string;
description?: string;
workflowId?: string;
evaluationWorkflowId?: string;
annotationTagId?: string;
@ -41,6 +42,10 @@ export class TestDefinitionService {
entity.name = attrs.name?.trim();
}
if (attrs.description) {
entity.description = attrs.description.trim();
}
if (attrs.workflowId) {
entity.workflow = {
id: attrs.workflowId,

View file

@ -163,9 +163,36 @@ describe('POST /evaluation/test-definitions', () => {
});
expect(resp.statusCode).toBe(200);
expect(resp.body.data.name).toBe('test');
expect(resp.body.data.workflowId).toBe(workflowUnderTest.id);
expect(resp.body.data.evaluationWorkflowId).toBe(evaluationWorkflow.id);
expect(resp.body.data).toEqual(
expect.objectContaining({
name: 'test',
workflowId: workflowUnderTest.id,
evaluationWorkflowId: evaluationWorkflow.id,
}),
);
});
test('should create test definition with all fields', async () => {
const resp = await authOwnerAgent.post('/evaluation/test-definitions').send({
name: 'test',
description: 'test description',
workflowId: workflowUnderTest.id,
evaluationWorkflowId: evaluationWorkflow.id,
annotationTagId: annotationTag.id,
});
expect(resp.statusCode).toBe(200);
expect(resp.body.data).toEqual(
expect.objectContaining({
name: 'test',
description: 'test description',
workflowId: workflowUnderTest.id,
evaluationWorkflowId: evaluationWorkflow.id,
annotationTag: expect.objectContaining({
id: annotationTag.id,
}),
}),
);
});
test('should return error if name is empty', async () => {