From e6cd9f48b54b02a4f3eb3db7a5e0a9b4cc197e19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20D=C3=ADaz=20Cancillo?= Date: Thu, 2 May 2024 18:34:14 +0200 Subject: [PATCH] Cambio idioma mensajes de error microservicio usuarios --- users/userservice/user-service.js | 6 +++--- users/userservice/user-service.test.js | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/users/userservice/user-service.js b/users/userservice/user-service.js index 12de3933..3b7b37cd 100644 --- a/users/userservice/user-service.js +++ b/users/userservice/user-service.js @@ -27,10 +27,10 @@ mongoose.connect(mongoUri); function validateRequiredFields(req, requiredFields) { for (const field of requiredFields) { if (!(field in req.body)) { - throw new Error(`Missing required field: ${field}`); + throw new Error(`Falta el campo obligatorio: ${field}`); } if (req.body[field].trim() == '' || req.body[field] == null || req.body[field] === undefined) { - throw new Error(`Field ${field} must not be empty`); + throw new Error(`El campo ${field} no debe estar vacío.`); } } } @@ -44,7 +44,7 @@ app.post('/adduser', async (req, res) => { const username = req.body.username.toString(); const existingUser = await User.findOne({ username }); if(existingUser!=null){ - throw new Error(`The username "${req.body.username}" is already in use.`); + throw new Error(`El usuario "${req.body.username}" ya está ocupado.`); } // Encrypt the password before saving it const hashedPassword = await bcrypt.hash(req.body.password, 10); diff --git a/users/userservice/user-service.test.js b/users/userservice/user-service.test.js index 32bdbc88..a8ac390b 100644 --- a/users/userservice/user-service.test.js +++ b/users/userservice/user-service.test.js @@ -60,7 +60,7 @@ describe('User Service', () => { .send({ username: 'testuser' }); // password field is missing expect(response.status).toBe(400); - expect(response.body.error).toBe('Missing required field: password'); + expect(response.body.error).toBe('Falta el campo obligatorio: password'); }); describe('should throw an error when a required field is present but empty', () => { @@ -70,7 +70,7 @@ describe('User Service', () => { .send({ username: process.env.TEST_USER3, password: ''}); // password field is empty expect(response.status).toBe(400); - expect(response.body.error).toBe('Field password must not be empty'); + expect(response.body.error).toBe('El campo password no debe estar vacío.'); }); test('password is empty and it throws an error', async () => { @@ -79,7 +79,7 @@ describe('User Service', () => { .send({ username: process.env.TEST_USER3, password: process.env.EMPTY_PASSWORD}); // password field is empty expect(response.status).toBe(400); - expect(response.body.error).toBe('Field password must not be empty'); + expect(response.body.error).toBe('El campo password no debe estar vacío.'); }); test('username is empty and it throws an error', async () => { @@ -88,7 +88,7 @@ describe('User Service', () => { .send({ username: '', password: process.env.TEST_PASSWORD}); // username field is empty expect(response.status).toBe(400); - expect(response.body.error).toBe('Field username must not be empty'); + expect(response.body.error).toBe('El campo username no debe estar vacío.'); }); test('username is empty and it throws an error', async () => { @@ -97,7 +97,7 @@ describe('User Service', () => { .send({ username: ' ', password: process.env.TEST_PASSWORD}); // username field is empty expect(response.status).toBe(400); - expect(response.body.error).toBe('Field username must not be empty'); + expect(response.body.error).toBe('El campo username no debe estar vacío.'); }); });