From 19e1d74718b369d458b9640f04543eff02e25a34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20M=C3=A9ndez=20Murias?= Date: Sun, 28 Apr 2024 15:11:04 +0200 Subject: [PATCH] Some errors solved in add user and i18n messages --- users/userservice/user-service.js | 5 +++++ webapp/e2e/steps/close-session-steps.js | 6 +++--- webapp/e2e/steps/friends.js | 10 +++++----- webapp/e2e/steps/i18n-steps.js | 12 ++++++------ webapp/e2e/steps/infinite-mode-steps.js | 6 +++--- webapp/e2e/steps/login.js | 2 +- webapp/e2e/steps/play-classic.js | 2 +- webapp/e2e/steps/register-form.steps.js | 2 +- webapp/src/components/AddUser.js | 7 ++++++- webapp/src/components/Login.js | 2 +- webapp/src/messages/messages_en.json | 5 ++++- webapp/src/messages/messages_es.json | 5 ++++- webapp/src/messages/messages_fr.json | 5 ++++- webapp/src/messages/messages_it.json | 6 +++++- 14 files changed, 49 insertions(+), 26 deletions(-) diff --git a/users/userservice/user-service.js b/users/userservice/user-service.js index b6bb830d..6fc5fa35 100644 --- a/users/userservice/user-service.js +++ b/users/userservice/user-service.js @@ -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); diff --git a/webapp/e2e/steps/close-session-steps.js b/webapp/e2e/steps/close-session-steps.js index c53a1ea4..85c58622 100644 --- a/webapp/e2e/steps/close-session-steps.js +++ b/webapp/e2e/steps/close-session-steps.js @@ -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"); }); }) diff --git a/webapp/e2e/steps/friends.js b/webapp/e2e/steps/friends.js index 0f215ab5..b3b52184 100644 --- a/webapp/e2e/steps/friends.js +++ b/webapp/e2e/steps/friends.js @@ -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'); @@ -22,7 +23,6 @@ defineFeature(feature, test => { waitUntil: "networkidle0", }) .catch(() => {}); - }); test('The user is going to add a friend', ({given,when,then}) => { @@ -47,7 +47,7 @@ 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' }); @@ -55,8 +55,8 @@ defineFeature(feature, test => { 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"}); }); @@ -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' }); }); diff --git a/webapp/e2e/steps/i18n-steps.js b/webapp/e2e/steps/i18n-steps.js index 208affad..82800876 100644 --- a/webapp/e2e/steps/i18n-steps.js +++ b/webapp/e2e/steps/i18n-steps.js @@ -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' }); diff --git a/webapp/e2e/steps/infinite-mode-steps.js b/webapp/e2e/steps/infinite-mode-steps.js index fb1dc9dd..e059bcdf 100644 --- a/webapp/e2e/steps/infinite-mode-steps.js +++ b/webapp/e2e/steps/infinite-mode-steps.js @@ -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 () => { diff --git a/webapp/e2e/steps/login.js b/webapp/e2e/steps/login.js index 282260ba..739a2227 100644 --- a/webapp/e2e/steps/login.js +++ b/webapp/e2e/steps/login.js @@ -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') diff --git a/webapp/e2e/steps/play-classic.js b/webapp/e2e/steps/play-classic.js index 4575cfdd..3079b24e 100644 --- a/webapp/e2e/steps/play-classic.js +++ b/webapp/e2e/steps/play-classic.js @@ -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' }); diff --git a/webapp/e2e/steps/register-form.steps.js b/webapp/e2e/steps/register-form.steps.js index 5ac50232..e2ef22fc 100644 --- a/webapp/e2e/steps/register-form.steps.js +++ b/webapp/e2e/steps/register-form.steps.js @@ -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 () => { diff --git a/webapp/src/components/AddUser.js b/webapp/src/components/AddUser.js index 2870e073..448f6eef 100644 --- a/webapp/src/components/AddUser.js +++ b/webapp/src/components/AddUser.js @@ -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; @@ -153,7 +158,7 @@ const AddUser = ({goTo, changeLanguage, locale, handleToggleView}) => { } /> {error && ( - setError('')} message={`Error: ${error}`} /> + setError('')} message={} /> )} ); diff --git a/webapp/src/components/Login.js b/webapp/src/components/Login.js index aa549cf9..2e9ba71f 100644 --- a/webapp/src/components/Login.js +++ b/webapp/src/components/Login.js @@ -122,7 +122,7 @@ const Login = ({ goTo, changeLanguage, locale, handleToggleView }) => { } /> {error && ( - setError('')} message={`Error: ${error}`} /> + setError('')} message={} /> )} diff --git a/webapp/src/messages/messages_en.json b/webapp/src/messages/messages_en.json index 4c93306a..2a8e3241 100644 --- a/webapp/src/messages/messages_en.json +++ b/webapp/src/messages/messages_en.json @@ -6,6 +6,7 @@ "signIn": "Sign In", "loginSuccessfull": "Login successful", "invalidCredentials": "Invalid credentials", + "Invalid credentials":"Invalid credentials", "register": "Register a user", "confirmPassword": "Confirm Password", @@ -13,7 +14,9 @@ "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", diff --git a/webapp/src/messages/messages_es.json b/webapp/src/messages/messages_es.json index 482c93f2..267e8b24 100644 --- a/webapp/src/messages/messages_es.json +++ b/webapp/src/messages/messages_es.json @@ -6,6 +6,7 @@ "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", @@ -13,7 +14,9 @@ "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", diff --git a/webapp/src/messages/messages_fr.json b/webapp/src/messages/messages_fr.json index 02b8c5b9..8f168812 100644 --- a/webapp/src/messages/messages_fr.json +++ b/webapp/src/messages/messages_fr.json @@ -6,6 +6,7 @@ "signIn": "Se connecter", "loginSuccessfull": "Connexion réussie", "invalidCredentials": "Identifiants invalides", + "Invalid credentials":"Identifiants invalides", "register": "Inscrire", "confirmPassword": "Confirmer le mot de passe", @@ -13,7 +14,9 @@ "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", diff --git a/webapp/src/messages/messages_it.json b/webapp/src/messages/messages_it.json index c45a1e99..345f7658 100644 --- a/webapp/src/messages/messages_it.json +++ b/webapp/src/messages/messages_it.json @@ -6,6 +6,8 @@ "signIn": "Accedi", "loginSuccessfull": "Accesso riuscito", "invalidCredentials": "Credenziali non valide", + "Invalid credentials":"Credenziali non valide", + "register": "Registrati", "confirmPassword": "Conferma Password", @@ -13,7 +15,9 @@ "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",