From 36c5c6f29739dc53fa654db5be0d468ddde59081 Mon Sep 17 00:00:00 2001 From: Tal Jacob Date: Mon, 2 Jun 2025 08:58:13 +0300 Subject: [PATCH 1/2] Hotfix Remove Response Of `value` When Validation Fails Signed-off-by: Tal Jacob --- nextstep-backend/src/types/validation_errors.ts | 1 - nextstep-backend/src/utils/handle_error.ts | 6 ++---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/nextstep-backend/src/types/validation_errors.ts b/nextstep-backend/src/types/validation_errors.ts index 4e60673..7b0b50f 100644 --- a/nextstep-backend/src/types/validation_errors.ts +++ b/nextstep-backend/src/types/validation_errors.ts @@ -1,5 +1,4 @@ export interface ValidationError { field: string; message: string; - value: any; } \ No newline at end of file diff --git a/nextstep-backend/src/utils/handle_error.ts b/nextstep-backend/src/utils/handle_error.ts index b32f9a1..abe3240 100644 --- a/nextstep-backend/src/utils/handle_error.ts +++ b/nextstep-backend/src/utils/handle_error.ts @@ -21,15 +21,13 @@ export const handleError = (err: any, res: Response) => { if (isMongoValidationErrors(err)) { const errors: ValidationError[] = Object.keys(err.errors).map(field => ({ field, - message: err.errors[field].message, - value: err.errors[field].value + message: err.errors[field].message })); res.status(400).json({ message: err.message, errors }); } else if (isReqValidationErrors(err)) { const errors: ValidationError[] = err.errors.map((error: any) => ({ field: error.parm ?? error.path , - message: error.msg, - value: error.value + message: error.msg })); res.status(400).json({ message: err.message, errors }); } else { From d95bd2212891b71960f4d51f050cab0365efcf66 Mon Sep 17 00:00:00 2001 From: Tal Jacob Date: Mon, 2 Jun 2025 09:27:18 +0300 Subject: [PATCH 2/2] Update Rooms Controller Tests With Validation Error New Schema - Remove `value` Field Signed-off-by: Tal Jacob --- nextstep-backend/src/tests/rooms_controller.test.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/nextstep-backend/src/tests/rooms_controller.test.ts b/nextstep-backend/src/tests/rooms_controller.test.ts index d8cc93c..d8874d2 100644 --- a/nextstep-backend/src/tests/rooms_controller.test.ts +++ b/nextstep-backend/src/tests/rooms_controller.test.ts @@ -77,13 +77,12 @@ describe('Rooms Controller', () => { }); it('should return 400 for invalid user IDs', async () => { - const invalidUserId = "invalidUserId" const response = await request(app) .get(`/room/user/invalidUserId`) .set('Authorization', `Bearer ${initiatorUser.accessToken}`) .query({ userId: 'invalidUserId' }); expect(response.status).toBe(400); - expect(response.text).toBe(`{"message":"Validation failed","errors":[{"field":"receiverUserId","message":"Invalid user ID","value":"${invalidUserId}"}]}`); + expect(response.text).toBe(`{"message":"Validation failed","errors":[{"field":"receiverUserId","message":"Invalid user ID"}]}`); }); }); \ No newline at end of file