test(update-auth-client): cover HTTP 422 response

This commit is contained in:
Ali BARIN
2024-08-28 08:46:13 +00:00
parent 09bc0bba1e
commit 61ff6986d3
2 changed files with 25 additions and 3 deletions

View File

@@ -2,10 +2,8 @@ import { renderObject } from '../../../../../helpers/renderer.js';
import AppAuthClient from '../../../../../models/app-auth-client.js';
export default async (request, response) => {
const id = request.params.appAuthClientId;
const appAuthClient = await AppAuthClient.query()
.findById(id)
.findById(request.params.appAuthClientId)
.throwIfNotFound();
await appAuthClient.$query().patchAndFetch(appAuthClientParams(request));

View File

@@ -77,4 +77,28 @@ describe('PATCH /api/v1/admin/apps/:appKey/auth-clients', () => {
.set('Authorization', token)
.expect(400);
});
it('should return HTTP 422 for invalid payload', async () => {
const appAuthClient = {
formattedAuthDefaults: 'invalid input',
};
const existingAppAuthClient = await createAppAuthClient({
appKey: 'gitlab',
name: 'First auth client',
});
const response = await request(app)
.patch(
`/api/v1/admin/apps/gitlab/auth-clients/${existingAppAuthClient.id}`
)
.set('Authorization', token)
.send(appAuthClient)
.expect(422);
expect(response.body.meta.type).toBe('ModelValidation');
expect(response.body.errors).toMatchObject({
formattedAuthDefaults: ['must be object'],
});
});
});