refactor(create-config): move unique violation error handling to error-handler

This commit is contained in:
Ali BARIN
2024-08-27 16:30:05 +00:00
parent 48b2b006c0
commit 0800642a2a
5 changed files with 55 additions and 30 deletions

View File

@@ -23,7 +23,6 @@ describe('POST /api/v1/admin/apps/:appKey/config', () => {
it('should return created app config', async () => {
const appConfig = {
key: 'gitlab',
allowCustomConnection: true,
shared: true,
disabled: false,
@@ -35,11 +34,14 @@ describe('POST /api/v1/admin/apps/:appKey/config', () => {
.send(appConfig)
.expect(201);
const expectedPayload = createAppConfigMock(appConfig);
const expectedPayload = createAppConfigMock({
...appConfig,
key: 'gitlab',
});
expect(response.body).toMatchObject(expectedPayload);
});
it('should return HTTP 409 for already existing app config', async () => {
it('should return HTTP 422 for already existing app config', async () => {
const appConfig = {
key: 'gitlab',
allowCustomConnection: true,
@@ -49,10 +51,17 @@ describe('POST /api/v1/admin/apps/:appKey/config', () => {
await createAppConfig(appConfig);
await request(app)
const response = await request(app)
.post('/api/v1/admin/apps/gitlab/config')
.set('Authorization', token)
.send(appConfig)
.expect(409);
.send({
disabled: false,
})
.expect(422);
expect(response.body.meta.type).toEqual('UniqueViolationError');
expect(response.body.errors).toMatchObject({
key: ["'key' must be unique."],
});
});
});