From d4c906591f8de0e9546be5d199417252586ffb06 Mon Sep 17 00:00:00 2001 From: alegarman2002 <116609314+alegarman2002@users.noreply.github.com> Date: Mon, 29 Apr 2024 20:11:43 +0200 Subject: [PATCH 1/2] Fixed problem with storage game --- webapp/src/components/game/GameConfiguration.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/webapp/src/components/game/GameConfiguration.js b/webapp/src/components/game/GameConfiguration.js index 22e12120..c51d84f4 100644 --- a/webapp/src/components/game/GameConfiguration.js +++ b/webapp/src/components/game/GameConfiguration.js @@ -58,14 +58,12 @@ const GameConfiguration = () => { console.log(numPreguntas); console.log(numRes); - await generateGameId(); + gameId = await generateGameId(); await getQuestions(); //isApiCalledRef = true//ASK - is this necessary? navigation("/firstGame", {state: {questions, gameId}}) } - gameId = generateGameId(); - function formatearTopics() { let topicsFormated = ''; From b10c335824fbc7f0b629868ead3b8c03747f6e6a Mon Sep 17 00:00:00 2001 From: Liliana Date: Mon, 29 Apr 2024 20:14:46 +0200 Subject: [PATCH 2/2] it doesn't work that two users cannot register with the same name --- webapp/src/components/AddUser.js | 22 ++++++---------------- webapp/src/components/AddUser.test.js | 10 +++++++++- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/webapp/src/components/AddUser.js b/webapp/src/components/AddUser.js index 010b1d7b..4c51c6e7 100644 --- a/webapp/src/components/AddUser.js +++ b/webapp/src/components/AddUser.js @@ -24,30 +24,20 @@ const AddUser = () => { setError('Las contraseñas no coinciden.'); } else { try { - const isAvailable = await checkUsernameAvailability(username, password); - if (isAvailable != false) { + try { + await axios.post(`${apiEndpoint}/login`, { username, password }); setError('Usuario ya registrado.'); - return; + setOpenSnackbar(false); + } catch (error) { + await axios.post(`${apiEndpoint}/adduser`, { username, password }); + setOpenSnackbar(true); } - - await axios.post(`${apiEndpoint}/adduser`, { username, password }); - setOpenSnackbar(true); } catch (error) { setError(error.response.data.error); } } }; - const checkUsernameAvailability = async (username, password) => { - try { - const response = await axios.post(`${apiEndpoint}/check-username`, { username }); - return response.data; - } catch (error) { - console.error("Error al comprobar la disponibilidad del nombre de usuario:", error); - return false; - } - } - const handleCloseSnackbar = () => { setOpenSnackbar(false); }; diff --git a/webapp/src/components/AddUser.test.js b/webapp/src/components/AddUser.test.js index a52f8e5f..a0e56e4e 100644 --- a/webapp/src/components/AddUser.test.js +++ b/webapp/src/components/AddUser.test.js @@ -19,7 +19,7 @@ describe('AddUser component', () => { const usernameInput = screen.getByLabelText(/Usuario/i); const passwordInput = screen.getAllByLabelText(/Contraseña/i)[0]; const confirmPasswordInput = screen.getByLabelText(/Repetir contraseña/i); - const addUserButton = document.getElementsByClassName('inner')[0] + const addUserButton = document.getElementsByClassName('inner')[0]; // Mock the axios.post request to simulate a successful response mockAxios.onPost('http://localhost:8000/adduser').reply(200); @@ -38,6 +38,14 @@ describe('AddUser component', () => { await waitFor(() => { expect(screen.getByText(/Usuario añadido correctamente/i)).toBeInTheDocument(); }); + + /* + fireEvent.click(addUserButton); + // Wait for the Snackbar to be open + await waitFor(() => { + expect(screen.getByText(/Usuario ya registrado./i)).toBeInTheDocument(); + }); + */ }); it('try to add user but not introduce name', async () => {