From 144fa5aed7f00bb7a4a4ce5aebb27ff548ac749f Mon Sep 17 00:00:00 2001 From: uo283182 Date: Fri, 26 Apr 2024 16:10:41 +0200 Subject: [PATCH 1/5] Test de question service --- .../question-service.test.js | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 questions/template-questions/question-service.test.js diff --git a/questions/template-questions/question-service.test.js b/questions/template-questions/question-service.test.js new file mode 100644 index 00000000..d654f5ea --- /dev/null +++ b/questions/template-questions/question-service.test.js @@ -0,0 +1,24 @@ +const request = require('supertest'); +let app; + +beforeAll(async () => { + app = require('./question-service'); +}); + +afterAll(async () => { + app.close(); +}); + +describe('GET /questions', () => { + it('should respond with a question, one correct answer and three incorrect answers', async () => { + const response = await request(app) + .post('/questions') + .expect(200); + + expect(response.body).toHaveProperty('pregunta'); + expect(response.body).toHaveProperty('correcta'); + expect(response.body).toHaveProperty('incorrectas'); + expect(response.body.incorrectas).toHaveLength(3); + }); + +}); \ No newline at end of file From b4e90d84795e4f0c402ad1db42abc3660c112275 Mon Sep 17 00:00:00 2001 From: uo283182 Date: Fri, 26 Apr 2024 16:15:28 +0200 Subject: [PATCH 2/5] Arreglo pregunta --- questions/template-questions/question-service.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/questions/template-questions/question-service.js b/questions/template-questions/question-service.js index ff7fcaac..e6113c53 100644 --- a/questions/template-questions/question-service.js +++ b/questions/template-questions/question-service.js @@ -95,7 +95,7 @@ const jsonPreg = [ } , { - textStart: 'En qué país se encuentra la atracción turística ', + textStart: '¿En qué país se encuentra la atracción turística ', textEnd: '?', queryCorrect: 'SELECT ?preguntaLabel ?respuestaLabel WHERE {'+ '?pregunta wdt:P31 wd:Q570116; wdt:P17 ?respuesta.'+ From f48152d4488fcd4a44fbd230ae2ab4125f182f23 Mon Sep 17 00:00:00 2001 From: uo283182 Date: Fri, 26 Apr 2024 17:34:40 +0200 Subject: [PATCH 3/5] =?UTF-8?q?M=C3=A1s=20test=20game?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webapp/src/components/Game.js | 4 +- webapp/src/components/Game.test.js | 63 +++++++++++++++++++++++++++++- 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/webapp/src/components/Game.js b/webapp/src/components/Game.js index c2f3f39e..1375eef7 100644 --- a/webapp/src/components/Game.js +++ b/webapp/src/components/Game.js @@ -15,7 +15,7 @@ const StyledContainer = styled(Container)({ const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000'; -const Game = () => { +const Game = ({ esperaFinalizacion = 3000 }) => { const [respuestas, setRespuestas] = useState(Array(4).fill({ data: '', isCorrect: '' })); const [textoPregunta, setTextoPregunta] = useState('Cargando...'); const [preguntasAcertadas, setPreguntasAcertadas] = useState(0); @@ -91,7 +91,7 @@ const Game = () => { input.disabled = true; }); if(numPreguntas==numQuestions){ - setTimeout(addPregunta, 3000); //esperar un poco para que se vean los resultados de la ultima pregunta + setTimeout(addPregunta, esperaFinalizacion); //esperar un poco para que se vean los resultados de la ultima pregunta } else { addPregunta(); diff --git a/webapp/src/components/Game.test.js b/webapp/src/components/Game.test.js index 3344bb6f..3eb36e07 100644 --- a/webapp/src/components/Game.test.js +++ b/webapp/src/components/Game.test.js @@ -51,7 +51,7 @@ describe('Game', () => { it('should select the correct answer and add 1 to the total', async () => { const mockResponse = { - pregunta: '¿Cual es la capital de Italia?', + pregunta: '¿Cuál es la capital de Italia?', correcta: 'Roma', incorrectas: ['Seul', 'Berlin', 'Madrid'], }; @@ -74,4 +74,65 @@ describe('Game', () => { expect(getByText('Preguntas acertadas: 1')).toBeInTheDocument(); }); + it('should select a incorrect answer and total is 0', async () => { + + const mockResponse = { + pregunta: '¿Dónde se encuentra el monumento Torre Eiffel?', + correcta: 'Francia', + incorrectas: ['Japón', 'Alemania', 'Suiza'], + }; + + mockAxios.onPost(`http://localhost:8000/questions`).reply(200, mockResponse); + + const { getByText } = render( + + + ); + + // Esperar a que se cargue la pregunta + await waitFor(() => expect(getByText(mockResponse.pregunta)).toBeInTheDocument()); + + //Doy click a una incorrecta + const incorrectButton = screen.getByText('Alemania'); + fireEvent.click(incorrectButton); + + // Verificar que la puntuación sigue en 0 + expect(getByText('Preguntas acertadas: 0')).toBeInTheDocument(); + }); + + it('should finish a game and show the number of correct answers', async () => { + localStorage.setItem('numQuestions', 1); + const mockResponse = { + pregunta: '¿Dónde se encuentra el monumento Torre Eiffel?', + correcta: 'Francia', + incorrectas: ['Japón', 'Alemania', 'Suiza'], + }; + + mockAxios.onPost(`http://localhost:8000/questions`).reply(200, mockResponse); + + const { getByText } = render( + + + ); + + // Esperar a que se cargue la pregunta + await waitFor(() => expect(getByText(mockResponse.pregunta)).toBeInTheDocument()); + + //Doy click a la correcta + const correcta = screen.getByText('Francia'); + fireEvent.click(correcta); + + expect(localStorage.getItem('numQuestions')).toBe("1"); + await waitFor(() => expect(getByText(/Has acertado 1\/1 preguntas/i)).toBeInTheDocument()); + + mockAxios.onPost('http://localhost:8000/addRecord').reply(200, + { user_id: "testUsername", + correctQuestions: 1, + totalQuestions: 1, + totalTime: 10}); + //Vuelvo al inicio + const inicioButton = screen.getByText('Volver al inicio'); + fireEvent.click(inicioButton); + expect(window.location.pathname).toBe('/'); + }); }); \ No newline at end of file From da41080c5b9bee5e17942359a03ddde3744726c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandra=20Garc=C3=ADa?= <145351939+uo283182@users.noreply.github.com> Date: Fri, 26 Apr 2024 17:38:14 +0200 Subject: [PATCH 4/5] Update build.yml --- .github/workflows/build.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c1f317ff..2dd3976b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,11 +15,13 @@ jobs: node-version: 20 - run: npm --prefix users/authservice ci - run: npm --prefix users/userservice ci + - run: npm --prefix questions/template-questions ci - run: npm --prefix recordhistory ci - run: npm --prefix gatewayservice ci - run: npm --prefix webapp ci - run: npm --prefix users/authservice test -- --coverage - run: npm --prefix users/userservice test -- --coverage + - run: npm --prefix questions/template-questions test -- --coverage - run: npm --prefix recordhistory test -- --coverage - run: npm --prefix gatewayservice test -- --coverage - run: npm --prefix webapp test -- --coverage From 8fe48899e8d8aacf54fdcf20a725f555fd1e3d91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandra=20Garc=C3=ADa?= <145351939+uo283182@users.noreply.github.com> Date: Fri, 26 Apr 2024 17:42:14 +0200 Subject: [PATCH 5/5] Update release.yml --- .github/workflows/release.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2446ef6e..1fb38c72 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,11 +14,13 @@ jobs: node-version: 20 - run: npm --prefix users/authservice ci - run: npm --prefix users/userservice ci + - run: npm --prefix questions/template-questions ci - run: npm --prefix recordhistory ci - run: npm --prefix gatewayservice ci - run: npm --prefix webapp ci - run: npm --prefix users/authservice test -- --coverage - run: npm --prefix users/userservice test -- --coverage + - run: npm --prefix questions/template-questions test -- --coverage - run: npm --prefix recordhistory test -- --coverage - run: npm --prefix gatewayservice test -- --coverage - run: npm --prefix webapp test -- --coverage @@ -37,6 +39,7 @@ jobs: node-version: 20 - run: npm --prefix users/authservice install - run: npm --prefix users/userservice install + - run: npm --prefix questions/template-questions install - run: npm --prefix recordhistory install - run: npm --prefix gatewayservice install - run: npm --prefix webapp install