Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge dev #456

Merged
merged 11 commits into from
May 2, 2024
Binary file modified docs/images/sonarcloud.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions users/userservice/user-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.`);
}
}
}
Expand All @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions users/userservice/user-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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.');
});
});

Expand Down