Skip to content

Commit

Permalink
Some errors solved in add user and i18n messages
Browse files Browse the repository at this point in the history
  • Loading branch information
UO287687 committed Apr 28, 2024
1 parent 10c2237 commit 19e1d74
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 26 deletions.
5 changes: 5 additions & 0 deletions users/userservice/user-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ app.post('/adduser', async (req, res) => {
res.status(400).json({ error: "User already exist" });
return;
}
// Check if the password has at least 4 characters
if (req.body.password.length < 4) {
res.status(400).json({ error: "Password must be at least 4 characters long" });
return;
}
// Encrypt the password before saving it
const hashedPassword = await bcrypt.hash(req.body.password, 10);

Expand Down
6 changes: 3 additions & 3 deletions webapp/e2e/steps/close-session-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ defineFeature(feature, test => {
await expect(page).toFill('input[name="password"]', password);
await expect(page).toFill('input[name="confirmPassword"]', password);

await expect(page).toClick('button.btn', { text: '' });
await expect(page).toClick('button.btn', {text: "Sign Up"});

await expect(page).toClick('button.perfilButton', { text: '' });
await expect(page).toClick('button.perfilButton');

await expect(page).toClick('li', { text: 'Logout' });
});

then('A title message should be shown in the screen', async () => {
await expect(page).toMatchElement("h1.titleLoginRegister", { text: "" });
await expect(page).toMatchElement("h1.titleLoginRegister");
});
})

Expand Down
10 changes: 5 additions & 5 deletions webapp/e2e/steps/friends.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const puppeteer = require('puppeteer');
const { defineFeature, loadFeature }=require('jest-cucumber');
const { text } = require('stream/consumers');
const setDefaultOptions = require('expect-puppeteer').setDefaultOptions
const feature = loadFeature('./features/friends.feature');

Expand All @@ -22,7 +23,6 @@ defineFeature(feature, test => {
waitUntil: "networkidle0",
})
.catch(() => {});

});

test('The user is going to add a friend', ({given,when,then}) => {
Expand All @@ -47,16 +47,16 @@ defineFeature(feature, test => {
await expect(page).toFill('input[name="confirmPassword"]', password);

await page.waitForSelector('button.btn');
await expect(page).toClick('button.btn', { text: '' });
await expect(page).toClick('button.btn', {text: "Sign Up"});

await page.waitForSelector('div a');
await expect(page).toClick('div a', { text: 'Friends' });

await page.waitForSelector('.searchForm input');
await expect(page).toFill('.searchForm input', 'defaultuser');

await page.waitForSelector('button.btn');
await expect(page).toClick('button.btn', { text: '' });
await page.waitForSelector('button.btn',{text: "Add friend"});
await expect(page).toClick('button.btn',{text: "Add friend"});

});

Expand All @@ -70,7 +70,7 @@ defineFeature(feature, test => {
});

when('I am in Friends page and select the friend to remove', async () => {
await page.waitForSelector('.tableFriends button.btn');
await page.waitForSelector('.tableFriends button.btn', { text: 'Delete friend' });
await expect(page).toClick('.tableFriends button.btn', { text: 'Delete friend' });

});
Expand Down
12 changes: 6 additions & 6 deletions webapp/e2e/steps/i18n-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ defineFeature(feature, test => {
await expect(page).toFill('input[name="username"]', username);
await expect(page).toFill('input[name="password"]', password);
await expect(page).toFill('input[name="confirmPassword"]', password);
await page.waitForSelector('button.btn', { text: '' });
await expect(page).toClick('button.btn', { text: '' });
await page.waitForSelector('button.btn');
await expect(page).toClick('button.btn', {text: "Sign Up"});
await page.waitForSelector('span', { text: "Classic Game" });
await expect(page).toMatchElement("span", { text: "Classic Game" });

await page.waitForSelector('button.menuLeft', { text: '' });
await expect(page).toClick('button.menuLeft', { text: '' });
await page.waitForSelector('button.menuLeft');
await expect(page).toClick('button.menuLeft');

await page.waitForSelector('div.languageButton', { text: '' });
await expect(page).toClick('div.languageButton', { text: '' });
await page.waitForSelector('div.languageButton');
await expect(page).toClick('div.languageButton');

await page.waitForSelector('li', { text: 'Spanish' });
await expect(page).toClick('li', { text: 'Spanish' });
Expand Down
6 changes: 3 additions & 3 deletions webapp/e2e/steps/infinite-mode-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ defineFeature(feature, test => {
await expect(page).toFill('input[name="password"]', password);
await expect(page).toFill('input[name="confirmPassword"]', password);

await expect(page).toClick('button.btn', { text: '' });
await expect(page).toClick('button.btn', {text: "Sign Up"});

await page.waitForSelector('button.btn', { text: 'Infinite Mode' });
await expect(page).toClick('button.btn', { text: 'Infinite Mode' });

await page.waitForSelector('div.endGameButton', { text: '' });
await expect(page).toClick('div.endGameButton', { text: '' });
await page.waitForSelector('div.endGameButton');
await expect(page).toClick('div.endGameButton');
});

then('A Game Over message should be shown in the screen', async () => {
Expand Down
2 changes: 1 addition & 1 deletion webapp/e2e/steps/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ defineFeature(feature, test => {
when('I fill the data in the form, press submit', async () => {
await expect(page).toFill('input[name="username"]', username);
await expect(page).toFill('input[name="password"]', password);
expect(page).toClick('button.btn', { text: '' })
expect(page).toClick('button.btn')



Expand Down
2 changes: 1 addition & 1 deletion webapp/e2e/steps/play-classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ defineFeature(feature, test => {
await expect(page).toFill('input[name="password"]', password);
await expect(page).toFill('input[name="confirmPassword"]', password);

await expect(page).toClick('button.btn', { text: '' });
await expect(page).toClick('button.btn', {text: "Sign Up"});


await expect(page).toClick('button.btn', { text: 'Classic Game' });
Expand Down
2 changes: 1 addition & 1 deletion webapp/e2e/steps/register-form.steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ defineFeature(feature, test => {
await expect(page).toFill('input[name="password"]', password);
await expect(page).toFill('input[name="confirmPassword"]', password);

await expect(page).toClick('button.btn', { text: '' })
await expect(page).toClick('button.btn', {text: "Sign Up"});
});

then('A confirmation message should be shown in the screen', async () => {
Expand Down
7 changes: 6 additions & 1 deletion webapp/src/components/AddUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ const AddUser = ({goTo, changeLanguage, locale, handleToggleView}) => {

const addUser = async () => {
try {
if (password.length < 4) {
setError('Password must be at least 4 characters long');
return;
}

if (password !== confirmPassword) {
setError('Passwords do not match');
return;
Expand Down Expand Up @@ -153,7 +158,7 @@ const AddUser = ({goTo, changeLanguage, locale, handleToggleView}) => {
</div>
<Snackbar open={openSnackbar} autoHideDuration={6000} onClose={handleCloseSnackbar} message={<FormattedMessage id="userAdd" />} />
{error && (
<Snackbar open={!!error} autoHideDuration={6000} onClose={() => setError('')} message={`Error: ${error}`} />
<Snackbar open={!!error} autoHideDuration={6000} onClose={() => setError('')} message={<FormattedMessage id={error} />} />
)}
</Container>
);
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/components/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const Login = ({ goTo, changeLanguage, locale, handleToggleView }) => {
</div>
<Snackbar open={openSnackbar} autoHideDuration={6000} onClose={handleCloseSnackbar} message={<FormattedMessage id="loginSuccessfull" />} />
{error && (
<Snackbar open={!!error} autoHideDuration={6000} onClose={() => setError('')} message={`Error: ${error}`} />
<Snackbar open={!!error} autoHideDuration={6000} onClose={() => setError('')} message={<FormattedMessage id={error} />} />
)}
</div>
</Container>
Expand Down
5 changes: 4 additions & 1 deletion webapp/src/messages/messages_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
"signIn": "Sign In",
"loginSuccessfull": "Login successful",
"invalidCredentials": "Invalid credentials",
"Invalid credentials":"Invalid credentials",

"register": "Register a user",
"confirmPassword": "Confirm Password",
"selectProfileImg": "Select a profile picture",
"signUp": "Sign Up",
"alreadyAccount": "Already have an account? Login here.",
"userAdd": "User added successfully",
"passwordNotMatch": "Passwords do not match",
"Passwords do not match": "Passwords do not match",
"Password must be at least 4 characters long": "Password must be at least 4 characters long",
"User already exist": "User already exist",

"menu": "Menu",
"langen": "English",
Expand Down
5 changes: 4 additions & 1 deletion webapp/src/messages/messages_es.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
"signIn": "Iniciar sesión",
"loginSuccessfull": "Inicio de sesión exitoso",
"invalidCredentials": "Credenciales inválidas",
"Invalid credentials":"Credenciales inválidas",

"register": "Registrar usuario",
"confirmPassword": "Confirmar contraseña",
"selectProfileImg": "Seleccionar una imagen de perfil",
"signUp": "Registrarse",
"alreadyAccount": "¿Ya tienes una cuenta? Inicia sesión aquí.",
"userAdd": "Usuario agregado exitosamente",
"passwordNotMatch": "Las contraseñas no coinciden",
"Passwords do not match": "Las contraseñas no coinciden",
"Password must be at least 4 characters long": "La contraseña debe tener al menos 4 caracteres",
"User already exist": "El usuario ya existe",

"menu": "Menú",
"langen": "Inglés",
Expand Down
5 changes: 4 additions & 1 deletion webapp/src/messages/messages_fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
"signIn": "Se connecter",
"loginSuccessfull": "Connexion réussie",
"invalidCredentials": "Identifiants invalides",
"Invalid credentials":"Identifiants invalides",

"register": "Inscrire",
"confirmPassword": "Confirmer le mot de passe",
"selectProfileImg": "Sélectionner une image de profil",
"signUp": "S'inscrire",
"alreadyAccount": "Vous avez déjà un compte ? Connectez-vous ici.",
"userAdd": "Utilisateur ajouté avec succès",
"passwordNotMatch": "Les mots de passe ne correspondent pas",
"Passwords do not match": "Les mots de passe ne correspondent pas",
"Password must be at least 4 characters long": "Le mot de passe doit comporter au moins 4 caractères",
"User already exist": "L'utilisateur existe déjà",

"menu": "Menu",
"langen": "Anglais",
Expand Down
6 changes: 5 additions & 1 deletion webapp/src/messages/messages_it.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@
"signIn": "Accedi",
"loginSuccessfull": "Accesso riuscito",
"invalidCredentials": "Credenziali non valide",
"Invalid credentials":"Credenziali non valide",


"register": "Registrati",
"confirmPassword": "Conferma Password",
"selectProfileImg": "Seleziona un'immagine del profilo",
"signUp": "Registrati",
"alreadyAccount": "Hai già un account? Accedi qui.",
"userAdd": "Utente aggiunto con successo",
"passwordNotMatch": "Le password non corrispondono",
"Passwords do not match": "Le password non corrispondono",
"Password must be at least 4 characters long": "La password deve essere lunga almeno 4 caratteri",
"User already exist": "L'utente esiste già",

"menu": "Menu",
"langen": "Inglese",
Expand Down

0 comments on commit 19e1d74

Please sign in to comment.