From 8dce88d3a1e8bcae77d9aa299dbc769ae0945c66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Jos=C3=A9=20Gonz=C3=A1lez=20Sierra?= Date: Thu, 4 Apr 2024 10:53:22 +0200 Subject: [PATCH 01/15] test temporizador (sin probar) y app test (sin probar) --- .github/workflows/build.yml | 4 +- webapp/src/App.test.js | 62 +++++++++++++++++++++- webapp/src/components/Temporizador.test.js | 49 +++++++++++++++++ 3 files changed, 112 insertions(+), 3 deletions(-) create mode 100644 webapp/src/components/Temporizador.test.js diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 410e842..29e5ad2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,8 +22,8 @@ jobs: - run: npm --prefix userservice/authservice test -- --coverage - run: npm --prefix userservice/userservice test -- --coverage - run: npm --prefix gatewayservice test -- --coverage - #- run: npm --prefix questionservice test -- --coverage - #- run: npm --prefix webapp test -- --coverage + - run: npm --prefix questionservice test -- --coverage + - run: npm --prefix webapp test -- --coverage - name: Analyze with SonarCloud uses: sonarsource/sonarcloud-github-action@master env: diff --git a/webapp/src/App.test.js b/webapp/src/App.test.js index 5e3b731..0c8f791 100644 --- a/webapp/src/App.test.js +++ b/webapp/src/App.test.js @@ -1,8 +1,68 @@ import { render, screen } from '@testing-library/react'; import App from './App'; -test('renders learn react link', () => { +/*test('renders learn react link', () => { render(); const linkElement = screen.getByText(/Welcome to the 2024 edition of the Software Architecture course/i); expect(linkElement).toBeInTheDocument(); }); +*/ + +describe('App', () => { + + it('renders login page when not logged in', () => { + render( + + + + ); + + expect(screen.getByText(/Login/i)).toBeInTheDocument(); + }); + + it('renders home page when logged in', () => { + // Mock local storage to simulate being logged in + const mockLocalStorage = { + getItem: jest.fn(() => 'true'), + setItem: jest.fn(), + clear: jest.fn() + }; + global.localStorage = mockLocalStorage; + + render( + + + + ); + + expect(screen.getByText(/Home/i)).toBeInTheDocument(); + }); + + it('redirects to login when trying to access stats page without logging in', () => { + render( + + + + ); + + expect(screen.getByText(/Login/i)).toBeInTheDocument(); + }); + + it('renders stats page when logged in and trying to access stats page', () => { + // Mock local storage to simulate being logged in + const mockLocalStorage = { + getItem: jest.fn(() => 'true'), + setItem: jest.fn(), + clear: jest.fn() + }; + global.localStorage = mockLocalStorage; + + render( + + + + ); + + expect(screen.getByText(/Estadisticas/i)).toBeInTheDocument(); + }); +}); \ No newline at end of file diff --git a/webapp/src/components/Temporizador.test.js b/webapp/src/components/Temporizador.test.js new file mode 100644 index 0000000..1a22c36 --- /dev/null +++ b/webapp/src/components/Temporizador.test.js @@ -0,0 +1,49 @@ +import React from 'react'; +import { render, screen, fireEvent } from '@testing-library/react'; +import Temporizador from './Temporizador'; + +describe('Temporizador', () => { + it('renders the initial countdown time', () => { + const tiempoInicial = 60; + render(); + const countdownElement = screen.getByText(tiempoInicial); + expect(countdownElement).toBeInTheDocument(); + }); + + it('decreases countdown time when not paused', () => { + jest.useFakeTimers(); + const tiempoInicial = 60; + render(); + jest.advanceTimersByTime(1000); + const updatedCountdownElement = screen.getByText(tiempoInicial - 1); + expect(updatedCountdownElement).toBeInTheDocument(); + jest.useRealTimers(); + }); + + it('stops countdown time when paused', () => { + jest.useFakeTimers(); + const tiempoInicial = 60; + render(); + jest.advanceTimersByTime(1000); + const updatedCountdownElement = screen.getByText(tiempoInicial); + expect(updatedCountdownElement).toBeInTheDocument(); + jest.useRealTimers(); + }); + + it('restarts countdown time when restart prop changes', () => { + jest.useFakeTimers(); + const tiempoInicial = 60; + const { rerender } = render(); + jest.advanceTimersByTime(1000); + const updatedCountdownElement = screen.getByText(tiempoInicial - 1); + expect(updatedCountdownElement).toBeInTheDocument(); + + // Simulate restart by changing the restart prop + rerender(); + + // Countdown should restart + const restartedCountdownElement = screen.getByText(tiempoInicial); + expect(restartedCountdownElement).toBeInTheDocument(); + jest.useRealTimers(); + }); +}); \ No newline at end of file From e41b3a3ec1a89c1312948775f190020e77b2e3f0 Mon Sep 17 00:00:00 2001 From: fer4github Date: Thu, 11 Apr 2024 09:13:26 +0200 Subject: [PATCH 02/15] corregidos errores sonarCloud --- webapp/src/components/Estilos/home.css | 2 +- webapp/src/components/Estilos/juego.css | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/webapp/src/components/Estilos/home.css b/webapp/src/components/Estilos/home.css index a4cbcaf..864ffe6 100644 --- a/webapp/src/components/Estilos/home.css +++ b/webapp/src/components/Estilos/home.css @@ -35,6 +35,6 @@ font-weight: 400; /* Añadimos padding para dar más espacio alrededor del texto del botón */ padding: 1em 4em; - font-family:'Trebuchet MS, sans-serif'; + font-family: Trebuchet MS, sans-serif; } \ No newline at end of file diff --git a/webapp/src/components/Estilos/juego.css b/webapp/src/components/Estilos/juego.css index bf12a61..1654a07 100644 --- a/webapp/src/components/Estilos/juego.css +++ b/webapp/src/components/Estilos/juego.css @@ -67,6 +67,6 @@ body h2 { color: white; - font-family: 'Verdana, sans-serif'; + font-family: Verdana, sans-serif; text-align: center; /* Centra el texto */ } \ No newline at end of file From b0fd75524b6e2008921816205bfbfdc7505b76a8 Mon Sep 17 00:00:00 2001 From: Augusto <49859508+augustocristian@users.noreply.github.com> Date: Fri, 12 Apr 2024 16:58:11 +0200 Subject: [PATCH 03/15] Rename 07_DiagramaDespliegue3.PNG to 07_DiagramaDespliegue3.png --- ...maDespliegue3.PNG => 07_DiagramaDespliegue3.png} | Bin 1 file changed, 0 insertions(+), 0 deletions(-) rename docs/images/{07_DiagramaDespliegue3.PNG => 07_DiagramaDespliegue3.png} (100%) diff --git a/docs/images/07_DiagramaDespliegue3.PNG b/docs/images/07_DiagramaDespliegue3.png similarity index 100% rename from docs/images/07_DiagramaDespliegue3.PNG rename to docs/images/07_DiagramaDespliegue3.png From e85fc504bde74835210e1639cf573c9ece125a56 Mon Sep 17 00:00:00 2001 From: Fernando Jose Gonzalez Sierra <90760906+UO277938@users.noreply.github.com> Date: Wed, 17 Apr 2024 12:31:51 +0200 Subject: [PATCH 04/15] Update Dockerfile --- webapp/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webapp/Dockerfile b/webapp/Dockerfile index 0d1b158..47255b5 100644 --- a/webapp/Dockerfile +++ b/webapp/Dockerfile @@ -6,7 +6,7 @@ WORKDIR /app #Install the dependencies RUN npm install --ignore-scripts -ARG API_URI="http://localhost:8000" +ARG API_URI ENV REACT_APP_API_ENDPOINT=$API_URI #Create an optimized version of the webapp @@ -15,4 +15,4 @@ RUN npm install serve #Execute npm run prod to run the server CMD [ "npm", "run", "prod" ] -#CMD ["npm", "start"] \ No newline at end of file +#CMD ["npm", "start"] From 38b3496c587483c937443094cb95a8fae5f8418f Mon Sep 17 00:00:00 2001 From: Fernando Jose Gonzalez Sierra <90760906+UO277938@users.noreply.github.com> Date: Wed, 17 Apr 2024 12:38:02 +0200 Subject: [PATCH 05/15] Update build.yml --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cccab54..207909d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,6 +6,7 @@ on: - develop - LaraFMz - Pablo-Arreglos + - Jota pull_request: types: [opened, synchronize, reopened] jobs: From a518e3d3b12c138c9ae0a3aaef13877a8003a2bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Rodr=C3=ADguez=20Alonso?= <124291017+uo289432@users.noreply.github.com> Date: Thu, 18 Apr 2024 10:42:16 +0200 Subject: [PATCH 06/15] Wiq es5a update! --- docker-compose.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 49c6ae6..61c1ae1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -26,7 +26,7 @@ services: authservice: container_name: authservice-${teamname:-defaultASW} - image: ghcr.io/arquisoft/wiq_0/authservice:latest + image: ghcr.io/arquisoft/wiq_es05a/authservice:latest profiles: ["dev", "prod"] build: ./userservice/authservice depends_on: @@ -40,7 +40,7 @@ services: userservice: container_name: userservice-${teamname:-defaultASW} - image: ghcr.io/arquisoft/wiq_0/userservice:latest + image: ghcr.io/arquisoft/wiq_es05a/userservice:latest profiles: ["dev", "prod"] build: ./userservice/userservice depends_on: @@ -54,7 +54,7 @@ services: gatewayservice: container_name: gatewayservice-${teamname:-defaultASW} - image: ghcr.io/arquisoft/wiq_0/gatewayservice:latest + image: ghcr.io/arquisoft/wiq_es05a/gatewayservice:latest profiles: ["dev", "prod"] build: ./gatewayservice depends_on: From 1693eb4ff398e583af859f01e0288b10bbf94104 Mon Sep 17 00:00:00 2001 From: Lara Date: Wed, 24 Apr 2024 12:34:49 +0200 Subject: [PATCH 07/15] =?UTF-8?q?Comprobar=20que=20la=20contrase=C3=B1a=20?= =?UTF-8?q?tiene=20al=20menos=208=20caracteres=20en=20el=20registro=20de?= =?UTF-8?q?=20usuarios?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gatewayservice/gateway-service.js | 25 +++++++++++++++---------- gatewayservice/gateway-service.test.js | 22 +++++----------------- 2 files changed, 20 insertions(+), 27 deletions(-) diff --git a/gatewayservice/gateway-service.js b/gatewayservice/gateway-service.js index 31757b4..650bb64 100644 --- a/gatewayservice/gateway-service.js +++ b/gatewayservice/gateway-service.js @@ -28,14 +28,6 @@ app.get('/health', (_req, res) => { }); app.post('/login', async (req, res) => { - const isValidUser = validateCredentials(req.body.username, req.body.password); - - if (!isValidUser) { - // Si las credenciales son inválidas, devuelve un error 401 - res.status(401).json({ error: 'Credenciales incorrectas' }); - return; // Termina la ejecución de la función para evitar ejecutar el código restante - } - try { // Forward the login request to the authentication service const authResponse = await axios.post(authServiceUrl+'/login', req.body); @@ -45,14 +37,26 @@ app.post('/login', async (req, res) => { } }); + function validateCredentials(username, password) { // Verifica si la contraseña es erronea - const invalidPassword = 'no'; + if (password.length < 8) { + return false; + } - return !(password === invalidPassword); + return true; } app.post('/adduser', async (req, res) => { + + const isValidUser = validateCredentials(req.body.username, req.body.password); + + if (!isValidUser) { + // Si las credenciales son inválidas, devuelve un error 401 + res.status(401).json({ error: 'Credenciales incorrectas. La contraseña debe contener al menos 8 caracteres' }); + return; // Termina la ejecución de la función para evitar ejecutar el código restante + } + try { // Forward the add user request to the user service const userResponse = await axios.post(userServiceUrl+'/adduser', req.body); @@ -62,6 +66,7 @@ app.post('/adduser', async (req, res) => { } }); + app.get('/pregunta', async (req, res) => { try{ const questionResponse = await axios.get(questionServiceUrl+'/pregunta') diff --git a/gatewayservice/gateway-service.test.js b/gatewayservice/gateway-service.test.js index 211098e..1905f62 100644 --- a/gatewayservice/gateway-service.test.js +++ b/gatewayservice/gateway-service.test.js @@ -21,30 +21,18 @@ describe('Gateway Service', () => { return Promise.resolve({ data: { userId: 'mockedUserId' } }); } }); - - /* - // Test /login endpoint - it('deberia iniciar sesión correctamente', async () => { - const response = await request(app) - .post('/login') - .send({ username: 'testuser', password: 'testpassword' }); - - expect(response.statusCode).toBe(200); - expect(response.body.token).toBe('mockedToken'); - }); - */ - // Prueba de manejo de errores para el endpoint /login - it('deberia devolver error al iniciar sesion', async () => { - // Datos de prueba para iniciar sesión (incorrectos) + // Prueba de manejo de errores para el endpoint /adduser + it('deberia devolver error al registrate', async () => { + // Datos de prueba para registro (incorrectos) const invalidLoginData = { username: 'userInvalido', - password: 'no' + password: 'holaque' }; // Realizamos una solicitud POST al endpoint /login con datos incorrectos const response = await request(app) - .post('/login') + .post('/adduser') .send(invalidLoginData); // Verificamos que la respuesta tenga un código de estado 401 (Unauthorized) From a758a1357e494a443242ffcccf5a08f284268b42 Mon Sep 17 00:00:00 2001 From: Lara Date: Wed, 24 Apr 2024 12:46:37 +0200 Subject: [PATCH 08/15] =?UTF-8?q?Cambio=20nombre=20de=20archivos=20e2e=20y?= =?UTF-8?q?=20cambio=20contrase=C3=B1a?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../steps/{register-form.steps.js => 01-register-form.steps.js} | 2 +- webapp/e2e/steps/{login.steps.js => 02-login.steps.js} | 2 +- webapp/e2e/steps/{home.steps.js => 03-home.steps.js} | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename webapp/e2e/steps/{register-form.steps.js => 01-register-form.steps.js} (98%) rename webapp/e2e/steps/{login.steps.js => 02-login.steps.js} (98%) rename webapp/e2e/steps/{home.steps.js => 03-home.steps.js} (98%) diff --git a/webapp/e2e/steps/register-form.steps.js b/webapp/e2e/steps/01-register-form.steps.js similarity index 98% rename from webapp/e2e/steps/register-form.steps.js rename to webapp/e2e/steps/01-register-form.steps.js index f805781..ee540bc 100644 --- a/webapp/e2e/steps/register-form.steps.js +++ b/webapp/e2e/steps/01-register-form.steps.js @@ -30,7 +30,7 @@ defineFeature(feature, test => { given('An unregistered user', async () => { username = "pablo@gmail.com" - password = "pabloasw" + password = "pabloasw1" await expect(page).toClick("button", { text: "REGÍSTRATE" }); }); diff --git a/webapp/e2e/steps/login.steps.js b/webapp/e2e/steps/02-login.steps.js similarity index 98% rename from webapp/e2e/steps/login.steps.js rename to webapp/e2e/steps/02-login.steps.js index 8fab6a7..6d4cdb3 100644 --- a/webapp/e2e/steps/login.steps.js +++ b/webapp/e2e/steps/02-login.steps.js @@ -30,7 +30,7 @@ defineFeature(feature, test => { given('A user that is logged in the application', async () => { username = "pablo@gmail.com" - password = "pabloasw" + password = "pabloasw1" await expect(page).toClick("button", { text: "INICIA SESIÓN" }); }); diff --git a/webapp/e2e/steps/home.steps.js b/webapp/e2e/steps/03-home.steps.js similarity index 98% rename from webapp/e2e/steps/home.steps.js rename to webapp/e2e/steps/03-home.steps.js index 9064c93..0e001d0 100644 --- a/webapp/e2e/steps/home.steps.js +++ b/webapp/e2e/steps/03-home.steps.js @@ -30,7 +30,7 @@ defineFeature(feature, test => { given('A user that is logged in the application', async () => { username = "pablo@gmail.com" - password = "pabloasw" + password = "pabloasw1" await expect(page).toClick("button", { text: "INICIA SESIÓN" }); }); From f4256b0b134d54401fde10ce7f56a7493aef66aa Mon Sep 17 00:00:00 2001 From: Lara Date: Wed, 24 Apr 2024 12:57:36 +0200 Subject: [PATCH 09/15] Intentado eliminar el hotspot --- gatewayservice/gateway-service.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gatewayservice/gateway-service.test.js b/gatewayservice/gateway-service.test.js index 1905f62..f7ab259 100644 --- a/gatewayservice/gateway-service.test.js +++ b/gatewayservice/gateway-service.test.js @@ -27,7 +27,7 @@ describe('Gateway Service', () => { // Datos de prueba para registro (incorrectos) const invalidLoginData = { username: 'userInvalido', - password: 'holaque' + password: 'invalid' }; // Realizamos una solicitud POST al endpoint /login con datos incorrectos From c9d5a61c6d5e969c651e55200d9f82b92fdf91be Mon Sep 17 00:00:00 2001 From: Lara Date: Wed, 24 Apr 2024 13:04:59 +0200 Subject: [PATCH 10/15] ups --- gatewayservice/gateway-service.js | 1 - 1 file changed, 1 deletion(-) diff --git a/gatewayservice/gateway-service.js b/gatewayservice/gateway-service.js index 650bb64..5dff392 100644 --- a/gatewayservice/gateway-service.js +++ b/gatewayservice/gateway-service.js @@ -66,7 +66,6 @@ app.post('/adduser', async (req, res) => { } }); - app.get('/pregunta', async (req, res) => { try{ const questionResponse = await axios.get(questionServiceUrl+'/pregunta') From c334caa5df476e8e550e390e89f3b9f38a3403cf Mon Sep 17 00:00:00 2001 From: UO276026 Date: Thu, 25 Apr 2024 09:45:34 +0200 Subject: [PATCH 11/15] prueba para quitar hostpot --- gatewayservice/gateway-service.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gatewayservice/gateway-service.test.js b/gatewayservice/gateway-service.test.js index f7ab259..2d18bd3 100644 --- a/gatewayservice/gateway-service.test.js +++ b/gatewayservice/gateway-service.test.js @@ -27,7 +27,7 @@ describe('Gateway Service', () => { // Datos de prueba para registro (incorrectos) const invalidLoginData = { username: 'userInvalido', - password: 'invalid' + password: process.env.INVALID_PASSWORD }; // Realizamos una solicitud POST al endpoint /login con datos incorrectos From 16f37150efc06df60d960e19a53196a6e0a34a7d Mon Sep 17 00:00:00 2001 From: UO276026 Date: Thu, 25 Apr 2024 09:52:53 +0200 Subject: [PATCH 12/15] prueba --- gatewayservice/gateway-service.test.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/gatewayservice/gateway-service.test.js b/gatewayservice/gateway-service.test.js index 2d18bd3..0162aad 100644 --- a/gatewayservice/gateway-service.test.js +++ b/gatewayservice/gateway-service.test.js @@ -24,16 +24,12 @@ describe('Gateway Service', () => { // Prueba de manejo de errores para el endpoint /adduser it('deberia devolver error al registrate', async () => { - // Datos de prueba para registro (incorrectos) - const invalidLoginData = { - username: 'userInvalido', - password: process.env.INVALID_PASSWORD - }; // Realizamos una solicitud POST al endpoint /login con datos incorrectos const response = await request(app) .post('/adduser') - .send(invalidLoginData); + .send({ username: 'userInvalido', password: 'invalid' }); + // Verificamos que la respuesta tenga un código de estado 401 (Unauthorized) expect(response.statusCode).toBe(401); From 5f61e1bf16c38d8723f2341bbb9e764551d76cc1 Mon Sep 17 00:00:00 2001 From: UO276026 Date: Thu, 25 Apr 2024 09:58:12 +0200 Subject: [PATCH 13/15] pasando a como estaba antes --- gatewayservice/gateway-service.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gatewayservice/gateway-service.test.js b/gatewayservice/gateway-service.test.js index 0162aad..3a08129 100644 --- a/gatewayservice/gateway-service.test.js +++ b/gatewayservice/gateway-service.test.js @@ -28,7 +28,7 @@ describe('Gateway Service', () => { // Realizamos una solicitud POST al endpoint /login con datos incorrectos const response = await request(app) .post('/adduser') - .send({ username: 'userInvalido', password: 'invalid' }); + .send({ username: 'userInvalido', password: 'no' }); // Verificamos que la respuesta tenga un código de estado 401 (Unauthorized) From d9b137816574a65dc3113d7bb40e8c367db94854 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Jos=C3=A9=20Gonz=C3=A1lez=20Sierra?= Date: Thu, 25 Apr 2024 10:07:32 +0200 Subject: [PATCH 14/15] redirect fin partida y api en navegacion --- webapp/src/components/Pages/Juego.js | 4 ++-- webapp/src/components/Pages/Layout.js | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/webapp/src/components/Pages/Juego.js b/webapp/src/components/Pages/Juego.js index ca0dd6a..a7416f4 100644 --- a/webapp/src/components/Pages/Juego.js +++ b/webapp/src/components/Pages/Juego.js @@ -29,7 +29,7 @@ const Juego = ({isLogged, username, numPreguntas}) => { const [numRespuestasIncorrectas, setNumRespuestasIncorrectas] = useState(0) const [disableFinish, setDisableFinish] = useState(false) - //const navigate= useNavigate() + const navigate= useNavigate() //Variables para la obtencion y modificacion de estadisticas del usuario y de preguntas const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000'; @@ -201,7 +201,7 @@ const Juego = ({isLogged, username, numPreguntas}) => { const clickFinalizar = () => { updateStats(); setDisableFinish(true) - //navigate('/') + navigate('/') } const handleRestart = () => { diff --git a/webapp/src/components/Pages/Layout.js b/webapp/src/components/Pages/Layout.js index d49490d..389cb5d 100644 --- a/webapp/src/components/Pages/Layout.js +++ b/webapp/src/components/Pages/Layout.js @@ -3,6 +3,8 @@ import React from 'react'; import {Container, Nav, Navbar} from 'react-bootstrap'; import PropTypes from 'prop-types' +const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000'; + const Layout = ({ isLogged, setIsLogged }) => { function onLogout(){ @@ -22,8 +24,12 @@ import PropTypes from 'prop-types' Estadísticas } +