Skip to content

Commit

Permalink
Merge pull request #456 from Arquisoft/master
Browse files Browse the repository at this point in the history
merge dev
  • Loading branch information
uo283055 authored May 2, 2024
2 parents 268b8af + 2bd7a0a commit 87a026e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
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

0 comments on commit 87a026e

Please sign in to comment.