Cast typeorm QueryFailedError to BadRequestException for the rest api (#12217)

This commit is contained in:
martmull
2025-05-23 17:00:45 +02:00
committed by GitHub
parent 362d540aac
commit 88b967dfb8
3 changed files with 37 additions and 8 deletions

View File

@ -193,4 +193,23 @@ describe('Core REST API Create One endpoint', () => {
expect(res.body.error).toBe('BadRequestException');
});
});
it('should return a BadRequestException when trying to create an opportunity with an invalid enum', async () => {
const requestBody = {
stage: 'INVALID_ENUM_VALUE',
};
await makeRestAPIRequest({
method: 'post',
path: `/opportunities`,
body: requestBody,
})
.expect(400)
.expect((res) => {
expect(res.body.messages[0]).toMatch(
/invalid input value for enum workspace_[a-z0-9]+\.opportunity_stage_enum: "INVALID_ENUM_VALUE"/,
);
expect(res.body.error).toBe('BadRequestException');
});
});
});