From a5730c6885ed2695e8113361bdeaf0d96c9d868c Mon Sep 17 00:00:00 2001 From: uo283055 Date: Thu, 22 Feb 2024 21:48:00 +0100 Subject: [PATCH 01/20] prueba --- docs/package-lock.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/package-lock.json b/docs/package-lock.json index ab1646f2..1d49f5c9 100644 --- a/docs/package-lock.json +++ b/docs/package-lock.json @@ -1,5 +1,8 @@ { "name": "docs", + + + "version": "1.0.0", "lockfileVersion": 3, "requires": true, From 37d884153e97f7a4f9107bba43cccf26f487140c Mon Sep 17 00:00:00 2001 From: uo277310 Date: Sun, 3 Mar 2024 15:46:39 +0100 Subject: [PATCH 02/20] Quitados warnings --- webapp/src/components/Game.js | 11 ++++++----- webapp/src/components/Login.js | 2 +- webapp/src/components/UsersList.js | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/webapp/src/components/Game.js b/webapp/src/components/Game.js index b6eace0e..179d9c47 100644 --- a/webapp/src/components/Game.js +++ b/webapp/src/components/Game.js @@ -1,18 +1,19 @@ // src/components/Game.js import axios from 'axios'; import React, { useState, useEffect } from 'react'; -import { Container, Typography, TextField, Button, Snackbar } from '@mui/material'; +//import { Container, Typography, TextField, Button, Snackbar } from '@mui/material'; +import {Typography, Button } from '@mui/material'; -import Link from '@mui/material/Link'; +//import Link from '@mui/material/Link'; const Game=() =>{ const [questionBody, setQuestionBody] = useState('');//pregunta aleatoria cuerpo const [informacionWikidata, setInformacionWikidata] = useState(''); const [respuestaCorrecta, setRespuestaCorrecta] = useState(''); - const [questionType, setQuestionType] = useState('');//para el tipo de pregunta a buscar - const [answerType, setAnswerType] = useState('');//para el tipo de respuesta a buscar + //const [questionType, setQuestionType] = useState('');//para el tipo de pregunta a buscar + //const [answerType, setAnswerType] = useState('');//para el tipo de respuesta a buscar const [numberClics, setNumberClics] = useState(1); const [timer, setTimer] = useState(0); // estado con el temporizador iniciado a 0 seg @@ -30,7 +31,7 @@ const Game=() =>{ obtenerPreguntaAleatoria(); // Luego ejecuta la segunda función }; fetchData(); // Llamada a la función async - }, []); + }, [obtenerPreguntaAleatoria, peticionPOST]); // se ejecuta una vez cuando se cargue el componente y establece aumentar "timer" en una diff --git a/webapp/src/components/Login.js b/webapp/src/components/Login.js index a32c94e0..386d87ee 100644 --- a/webapp/src/components/Login.js +++ b/webapp/src/components/Login.js @@ -7,7 +7,7 @@ import { Container, Typography, TextField, Button, Snackbar } from '@mui/materia import Game from './Game'; import UsersList from './UsersList'; -import Link from '@mui/material/Link'; +//import Link from '@mui/material/Link'; const Login = () => { const [username, setUsername] = useState(''); diff --git a/webapp/src/components/UsersList.js b/webapp/src/components/UsersList.js index 2600867e..4507c93c 100644 --- a/webapp/src/components/UsersList.js +++ b/webapp/src/components/UsersList.js @@ -1,7 +1,7 @@ import React, { useState, useEffect } from 'react'; import axios from 'axios'; -import { Container, Typography, TextField, Button, Snackbar } from '@mui/material'; +//import { Container, Typography, TextField, Button, Snackbar } from '@mui/material'; const UsersList = () => { @@ -30,7 +30,7 @@ const UsersList = () => { }; fetchUsers(); - }, []); + }, [apiEndpoint]); return ( From 3793bcf47d28454a6ed2f340af4b62c1741ee656 Mon Sep 17 00:00:00 2001 From: uo277310 Date: Sun, 3 Mar 2024 15:52:51 +0100 Subject: [PATCH 03/20] =?UTF-8?q?Comentadas=20l=C3=ADneas=20que=20no=20hac?= =?UTF-8?q?en=20nada=20y=20dan=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webapp/src/components/Game.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webapp/src/components/Game.js b/webapp/src/components/Game.js index 179d9c47..ca18c341 100644 --- a/webapp/src/components/Game.js +++ b/webapp/src/components/Game.js @@ -67,8 +67,8 @@ const Game=() =>{ const response = await axios.post(`${apiEndpoint}/getQuestionBody`); setQuestionBody(response.data.questionBody);//obtengo los datos del cuerpo de la pregunta - setQuestionType(response.data.typeQuestion); - setAnswerType(response.data.typeAnswer); + //setQuestionType(response.data.typeQuestion); + //setAnswerType(response.data.typeAnswer); obtenerDatos(response.data.typeQuestion); From f2e795e669011236dd1343c3c65fa48306b390fb Mon Sep 17 00:00:00 2001 From: uo277310 Date: Sun, 3 Mar 2024 16:03:20 +0100 Subject: [PATCH 04/20] =?UTF-8?q?Solucionado=20warning=20definici=C3=B3n?= =?UTF-8?q?=20previa?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webapp/src/components/Game.js | 66 +++++++++++++++++------------------ 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/webapp/src/components/Game.js b/webapp/src/components/Game.js index ca18c341..2953fa18 100644 --- a/webapp/src/components/Game.js +++ b/webapp/src/components/Game.js @@ -19,20 +19,6 @@ const Game=() =>{ const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000'; - - //useEffect(() => { - // obtenerPreguntaAleatoria(); - //}, []); - // se ejecuta una vez cuando se cargue el componente y llena la BD con las plantillas posibles - // además de generar la pregunta nº1 - useEffect(() => { - const fetchData = async () => { - await peticionPOST(); // Espera a que la primera función se complete - obtenerPreguntaAleatoria(); // Luego ejecuta la segunda función - }; - fetchData(); // Llamada a la función async - }, [obtenerPreguntaAleatoria, peticionPOST]); - // se ejecuta una vez cuando se cargue el componente y establece aumentar "timer" en una // unidad cada 1000ms @@ -57,25 +43,40 @@ const Game=() =>{ } }; - //para el tipo de respuesta a buscar - // Obtener pregunta una pregunta aleatoria al acceder a la url - const obtenerPreguntaAleatoria = async () => { - try { - - const response = await axios.post(`${apiEndpoint}/getQuestionBody`); - - setQuestionBody(response.data.questionBody);//obtengo los datos del cuerpo de la pregunta - //setQuestionType(response.data.typeQuestion); - //setAnswerType(response.data.typeAnswer); - - obtenerDatos(response.data.typeQuestion); - - } catch (error) { - console.error("Error al obtener la pregunta aleatoria", error); - } + // Obtener pregunta una pregunta aleatoria al acceder a la url + const obtenerPreguntaAleatoria = async () => { + try { + + const response = await axios.post(`${apiEndpoint}/getQuestionBody`); + + setQuestionBody(response.data.questionBody);//obtengo los datos del cuerpo de la pregunta + //setQuestionType(response.data.typeQuestion); + //setAnswerType(response.data.typeAnswer); + + obtenerDatos(response.data.typeQuestion); + + } catch (error) { + console.error("Error al obtener la pregunta aleatoria", error); + } + }; + + //useEffect(() => { + // obtenerPreguntaAleatoria(); + //}, []); + // se ejecuta una vez cuando se cargue el componente y llena la BD con las plantillas posibles + // además de generar la pregunta nº1 + useEffect(() => { + const fetchData = async () => { + await peticionPOST(); // Espera a que la primera función se complete + obtenerPreguntaAleatoria(); // Luego ejecuta la segunda función }; + fetchData(); // Llamada a la función async + }, [obtenerPreguntaAleatoria, peticionPOST]); + + + // Diccionario con el tipo de pregunta y la consulta SPARQL correspondiente const questionTypes = { @@ -161,9 +162,8 @@ const Game=() =>{ )} -); + ); - - } +} export default Game; From 8e2da75edffe82d5eb1833814d1fa836b7d2dccd Mon Sep 17 00:00:00 2001 From: uo277310 Date: Sun, 3 Mar 2024 16:10:40 +0100 Subject: [PATCH 05/20] Fallo useCallback --- webapp/src/components/Game.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/webapp/src/components/Game.js b/webapp/src/components/Game.js index 2953fa18..97e25b54 100644 --- a/webapp/src/components/Game.js +++ b/webapp/src/components/Game.js @@ -30,7 +30,7 @@ const Game=() =>{ }, []); // Función para realizar la petición POST para cargar los tipos de pregunta en la base de datos de mongo - const peticionPOST = async () => { + const peticionPOST = useCallback(async () => { try { const response = await axios.post(`${apiEndpoint}/addQuestion`, { questionBody: '¿Cuál es la capital de ', @@ -41,12 +41,12 @@ const Game=() =>{ } catch (error) { console.error('Error en la petición POST:', error); } - }; + }, []); //para el tipo de respuesta a buscar // Obtener pregunta una pregunta aleatoria al acceder a la url - const obtenerPreguntaAleatoria = async () => { + const obtenerPreguntaAleatoria = useCallback(async () => { try { const response = await axios.post(`${apiEndpoint}/getQuestionBody`); @@ -60,7 +60,7 @@ const Game=() =>{ } catch (error) { console.error("Error al obtener la pregunta aleatoria", error); } - }; + }, [peticionPOST]); //useEffect(() => { // obtenerPreguntaAleatoria(); From 700e9d1adbc9436ccbd5c6aa0bd9561ea0fdc9d8 Mon Sep 17 00:00:00 2001 From: uo277310 Date: Sun, 3 Mar 2024 16:16:13 +0100 Subject: [PATCH 06/20] Importado useCallback --- webapp/src/components/Game.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webapp/src/components/Game.js b/webapp/src/components/Game.js index 97e25b54..bc4a5f09 100644 --- a/webapp/src/components/Game.js +++ b/webapp/src/components/Game.js @@ -1,6 +1,6 @@ // src/components/Game.js import axios from 'axios'; -import React, { useState, useEffect } from 'react'; +import React, { useState, useEffect, useCallback } from 'react'; //import { Container, Typography, TextField, Button, Snackbar } from '@mui/material'; import {Typography, Button } from '@mui/material'; From 999309084a0d849e828208868ea211c307be24cb Mon Sep 17 00:00:00 2001 From: uo277310 Date: Sun, 3 Mar 2024 16:29:15 +0100 Subject: [PATCH 07/20] Bugs usando useCallback --- webapp/src/components/Game.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webapp/src/components/Game.js b/webapp/src/components/Game.js index bc4a5f09..eefaa50c 100644 --- a/webapp/src/components/Game.js +++ b/webapp/src/components/Game.js @@ -41,7 +41,7 @@ const Game=() =>{ } catch (error) { console.error('Error en la petición POST:', error); } - }, []); + }, [apiEndpoint]); //para el tipo de respuesta a buscar @@ -60,7 +60,7 @@ const Game=() =>{ } catch (error) { console.error("Error al obtener la pregunta aleatoria", error); } - }, [peticionPOST]); + }, [apiEndpoint, obtenerDatos, peticionPOST]); //useEffect(() => { // obtenerPreguntaAleatoria(); From cdc585a79b26f83c4a78f08005fa66c743bd3f4f Mon Sep 17 00:00:00 2001 From: uo277310 Date: Sun, 3 Mar 2024 16:35:55 +0100 Subject: [PATCH 08/20] =?UTF-8?q?M=C3=A9todos=20definidos=20antes=20de=20s?= =?UTF-8?q?u=20uso=20(mas=20warnings)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webapp/src/components/Game.js | 98 +++++++++++++++++------------------ 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/webapp/src/components/Game.js b/webapp/src/components/Game.js index eefaa50c..9d643d3a 100644 --- a/webapp/src/components/Game.js +++ b/webapp/src/components/Game.js @@ -29,6 +29,54 @@ const Game=() =>{ return () => clearInterval(interval); }, []); + + // Diccionario con el tipo de pregunta y la consulta SPARQL correspondiente + const questionTypes = { + "pais": { + query: ` + SELECT ?country ?countryLabel ?capital ?capitalLabel + WHERE { + ?country wdt:P31 wd:Q6256. + ?country wdt:P36 ?capital. + SERVICE wikibase:label { + bd:serviceParam wikibase:language "[AUTO_LANGUAGE],es". + } + } + ORDER BY RAND() + LIMIT 150 + `, + questionLabel: 'countryLabel', + answerLabel: 'capitalLabel' + }, + // Añadir el resto de tipos de preguntas + }; + + // Obtener info de wikidata segun el tipo de la pregunta y la respuesta para esa pregunta + const obtenerDatos = async (questionType) => { + try { + const { query, questionLabel, answerLabel } = questionTypes[questionType]; + + const apiUrl = `https://query.wikidata.org/sparql?query=${encodeURIComponent(query)}`; + const headers = { "Accept": "application/json" }; + + const respuestaWikidata = await fetch(apiUrl, {headers}); + + if (respuestaWikidata.ok) { + const data = await respuestaWikidata.json(); + const numEles = data.results.bindings.length; + const index = Math.floor(Math.random() * numEles); + const result = data.results.bindings[index]; + + setInformacionWikidata(result[questionLabel].value + '?'); + setRespuestaCorrecta(result[answerLabel].value); + } else { + console.error("Error al realizar la consulta en Wikidata. Estado de respuesta:", respuestaWikidata.status); + } + } catch (error) { + console.error("Error al realizar la consulta en Wikidata", error); + } + }; + // Función para realizar la petición POST para cargar los tipos de pregunta en la base de datos de mongo const peticionPOST = useCallback(async () => { try { @@ -60,7 +108,7 @@ const Game=() =>{ } catch (error) { console.error("Error al obtener la pregunta aleatoria", error); } - }, [apiEndpoint, obtenerDatos, peticionPOST]); + }, [apiEndpoint, obtenerDatos]); //useEffect(() => { // obtenerPreguntaAleatoria(); @@ -76,54 +124,6 @@ const Game=() =>{ }, [obtenerPreguntaAleatoria, peticionPOST]); - - - // Diccionario con el tipo de pregunta y la consulta SPARQL correspondiente - const questionTypes = { - "pais": { - query: ` - SELECT ?country ?countryLabel ?capital ?capitalLabel - WHERE { - ?country wdt:P31 wd:Q6256. - ?country wdt:P36 ?capital. - SERVICE wikibase:label { - bd:serviceParam wikibase:language "[AUTO_LANGUAGE],es". - } - } - ORDER BY RAND() - LIMIT 150 - `, - questionLabel: 'countryLabel', - answerLabel: 'capitalLabel' - }, - // Añadir el resto de tipos de preguntas - }; - - // Obtener info de wikidata segun el tipo de la pregunta y la respuesta para esa pregunta - const obtenerDatos = async (questionType) => { - try { - const { query, questionLabel, answerLabel } = questionTypes[questionType]; - - const apiUrl = `https://query.wikidata.org/sparql?query=${encodeURIComponent(query)}`; - const headers = { "Accept": "application/json" }; - - const respuestaWikidata = await fetch(apiUrl, {headers}); - - if (respuestaWikidata.ok) { - const data = await respuestaWikidata.json(); - const numEles = data.results.bindings.length; - const index = Math.floor(Math.random() * numEles); - const result = data.results.bindings[index]; - - setInformacionWikidata(result[questionLabel].value + '?'); - setRespuestaCorrecta(result[answerLabel].value); - } else { - console.error("Error al realizar la consulta en Wikidata. Estado de respuesta:", respuestaWikidata.status); - } - } catch (error) { - console.error("Error al realizar la consulta en Wikidata", error); - } - }; const handleButtonClick = () => { setNumberClics(numberClics + 1); From bcf9c52de8d086b6fde27180985df7afe62f6efd Mon Sep 17 00:00:00 2001 From: uo277310 Date: Sun, 3 Mar 2024 16:47:05 +0100 Subject: [PATCH 09/20] Otro fallo por usecallback --- webapp/src/components/Game.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webapp/src/components/Game.js b/webapp/src/components/Game.js index 9d643d3a..97d9e45a 100644 --- a/webapp/src/components/Game.js +++ b/webapp/src/components/Game.js @@ -52,7 +52,7 @@ const Game=() =>{ }; // Obtener info de wikidata segun el tipo de la pregunta y la respuesta para esa pregunta - const obtenerDatos = async (questionType) => { + const obtenerDatos = useCallback(async (questionType) => { try { const { query, questionLabel, answerLabel } = questionTypes[questionType]; @@ -75,7 +75,7 @@ const Game=() =>{ } catch (error) { console.error("Error al realizar la consulta en Wikidata", error); } - }; + }, [questionTypes, setInformacionWikidata, setRespuestaCorrecta]); // Función para realizar la petición POST para cargar los tipos de pregunta en la base de datos de mongo const peticionPOST = useCallback(async () => { From 8d3b86b319e748ae3160760703df2654afe459a5 Mon Sep 17 00:00:00 2001 From: uo277310 Date: Sun, 3 Mar 2024 16:53:37 +0100 Subject: [PATCH 10/20] Utilizado useMemo --- webapp/src/components/Game.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/webapp/src/components/Game.js b/webapp/src/components/Game.js index 97d9e45a..644a13db 100644 --- a/webapp/src/components/Game.js +++ b/webapp/src/components/Game.js @@ -1,6 +1,6 @@ // src/components/Game.js import axios from 'axios'; -import React, { useState, useEffect, useCallback } from 'react'; +import React, { useState, useEffect, useCallback, useMemo } from 'react'; //import { Container, Typography, TextField, Button, Snackbar } from '@mui/material'; import {Typography, Button } from '@mui/material'; @@ -31,7 +31,7 @@ const Game=() =>{ // Diccionario con el tipo de pregunta y la consulta SPARQL correspondiente - const questionTypes = { + const questionTypes = useMemo(() => ({ "pais": { query: ` SELECT ?country ?countryLabel ?capital ?capitalLabel @@ -49,7 +49,7 @@ const Game=() =>{ answerLabel: 'capitalLabel' }, // Añadir el resto de tipos de preguntas - }; + }), []); // Obtener info de wikidata segun el tipo de la pregunta y la respuesta para esa pregunta const obtenerDatos = useCallback(async (questionType) => { From f2aae45b99c06371a4548a2ccf05d5c05da71cc8 Mon Sep 17 00:00:00 2001 From: uo277310 Date: Sun, 3 Mar 2024 19:37:38 +0100 Subject: [PATCH 11/20] Comentados servicios --- webapp/e2e/test-environment-setup.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/webapp/e2e/test-environment-setup.js b/webapp/e2e/test-environment-setup.js index 81f40b74..5380be24 100644 --- a/webapp/e2e/test-environment-setup.js +++ b/webapp/e2e/test-environment-setup.js @@ -4,9 +4,9 @@ const { MongoMemoryServer } = require('mongodb-memory-server'); let mongoserver; let userservice; let authservice; -let gatewayservice; -let createservice; -let answerservice; +//let gatewayservice; +//let createservice; +//let answerservice; async function startServer() { console.log('Starting MongoDB memory server...'); @@ -15,11 +15,11 @@ async function startServer() { process.env.MONGODB_URI = mongoUri; userservice = await require("../../users/userservice/user-service"); authservice = await require("../../users/authservice/auth-service"); - createservice = await require("../../questions/createservice/create-service"); - answerservice = await require("../../questions/answerservice/answer-service"); - recordservice = await require("../../questions/recordservice/record-service"); - gatewayservice = await require("../../gatewayservice/gateway-service"); - generatedquestservice = await require("../../questions/generatedquestservice/generatedquest-service"); + //createservice = await require("../../questions/createservice/create-service"); + //answerservice = await require("../../questions/answerservice/answer-service"); + //recordservice = await require("../../questions/recordservice/record-service"); + //gatewayservice = await require("../../gatewayservice/gateway-service"); + //generatedquestservice = await require("../../questions/generatedquestservice/generatedquest-service"); } startServer(); From 815cd00daaa530c0679181c9fc74ecd1091b8718 Mon Sep 17 00:00:00 2001 From: uo277310 Date: Sun, 3 Mar 2024 19:58:47 +0100 Subject: [PATCH 12/20] Descomentado gatewayservice --- webapp/e2e/test-environment-setup.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webapp/e2e/test-environment-setup.js b/webapp/e2e/test-environment-setup.js index 5380be24..ab2bdb41 100644 --- a/webapp/e2e/test-environment-setup.js +++ b/webapp/e2e/test-environment-setup.js @@ -4,7 +4,7 @@ const { MongoMemoryServer } = require('mongodb-memory-server'); let mongoserver; let userservice; let authservice; -//let gatewayservice; +let gatewayservice; //let createservice; //let answerservice; @@ -18,7 +18,7 @@ async function startServer() { //createservice = await require("../../questions/createservice/create-service"); //answerservice = await require("../../questions/answerservice/answer-service"); //recordservice = await require("../../questions/recordservice/record-service"); - //gatewayservice = await require("../../gatewayservice/gateway-service"); + gatewayservice = await require("../../gatewayservice/gateway-service"); //generatedquestservice = await require("../../questions/generatedquestservice/generatedquest-service"); } From 0d2e63f6b7d9514a595de7593c210ba3b4fe7b83 Mon Sep 17 00:00:00 2001 From: uo277310 Date: Sun, 3 Mar 2024 20:29:29 +0100 Subject: [PATCH 13/20] Correccion de bugs --- .github/workflows/build.yml | 8 ++ .github/workflows/release.yml | 82 +++++++++++++++++++- docker-compose.yml | 56 ++++++------- questions/answerservice/package.json | 2 +- questions/createservice/package.json | 2 +- questions/generatedquestservice/package.json | 2 +- questions/recordservice/package.json | 2 +- webapp/e2e/test-environment-setup.js | 14 ++-- 8 files changed, 130 insertions(+), 38 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c9265703..f8297df5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,10 +17,18 @@ jobs: node-version: 20 - run: npm --prefix users/authservice ci - run: npm --prefix users/userservice ci + - run: npm --prefix questions/answerservice ci + - run: npm --prefix questions/createservice ci + - run: npm --prefix questions/generatedquestservice ci + - run: npm --prefix questions/recordservice 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/answerservice test -- --coverage + - run: npm --prefix questions/createservice test -- --coverage + - run: npm --prefix questions/generatedquestservice test -- --coverage + - run: npm --prefix questions/recordservice test -- --coverage - run: npm --prefix gatewayservice test -- --coverage - run: npm --prefix webapp test -- --coverage - name: Analyze with SonarCloud diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f1fe99e8..eeec170f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,10 +14,18 @@ jobs: node-version: 20 - run: npm --prefix users/authservice ci - run: npm --prefix users/userservice ci + - run: npm --prefix questions/answerservice ci + - run: npm --prefix questions/createservice ci + - run: npm --prefix questions/generatedquestservice ci + - run: npm --prefix questions/recordservice 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/answerservice test -- --coverage + - run: npm --prefix questions/createservice test -- --coverage + - run: npm --prefix questions/generatedquestservice test -- --coverage + - run: npm --prefix questions/recordservice test -- --coverage - run: npm --prefix gatewayservice test -- --coverage - run: npm --prefix webapp test -- --coverage - name: Analyze with SonarCloud @@ -35,6 +43,10 @@ jobs: node-version: 20 - run: npm --prefix users/authservice install - run: npm --prefix users/userservice install + - run: npm --prefix questions/answerservice install + - run: npm --prefix questions/createservice install + - run: npm --prefix questions/generatedquestservice install + - run: npm --prefix questions/recordservice install - run: npm --prefix gatewayservice install - run: npm --prefix webapp install - run: npm --prefix webapp run build @@ -93,6 +105,74 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} registry: ghcr.io workdir: users/userservice + docker-push-answerservice: + name: Push answer service Docker Image to GitHub Packages + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + needs: [e2e-tests] + steps: + - uses: actions/checkout@v4 + - name: Publish to Registry + uses: elgohr/Publish-Docker-Github-Action@v5 + with: + name: arquisoft/wiq_es6b/answerservice + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + registry: ghcr.io + workdir: questions/answerservice + docker-push-createservice: + name: Push create service Docker Image to GitHub Packages + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + needs: [e2e-tests] + steps: + - uses: actions/checkout@v4 + - name: Publish to Registry + uses: elgohr/Publish-Docker-Github-Action@v5 + with: + name: arquisoft/wiq_es6b/createservice + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + registry: ghcr.io + workdir: questions/createservice + docker-push-recordservice: + name: Push record service Docker Image to GitHub Packages + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + needs: [e2e-tests] + steps: + - uses: actions/checkout@v4 + - name: Publish to Registry + uses: elgohr/Publish-Docker-Github-Action@v5 + with: + name: arquisoft/wiq_es6b/recordservice + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + registry: ghcr.io + workdir: questions/recordservice + docker-push-generatedquestservice: + name: Push generated quest service Docker Image to GitHub Packages + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + needs: [e2e-tests] + steps: + - uses: actions/checkout@v4 + - name: Publish to Registry + uses: elgohr/Publish-Docker-Github-Action@v5 + with: + name: arquisoft/wiq_es6b/generatedquestservice + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + registry: ghcr.io + workdir: questions/generatedquestservice docker-push-gatewayservice: name: Push gateway service Docker Image to GitHub Packages runs-on: ubuntu-latest @@ -113,7 +193,7 @@ jobs: deploy: name: Deploy over SSH runs-on: ubuntu-latest - needs: [docker-push-userservice,docker-push-authservice,docker-push-gatewayservice,docker-push-webapp] + needs: [docker-push-userservice,docker-push-authservice,docker-push-gatewayservice,docker-push-webapp,docker-push-createservice,docker-push-answerservice,docker-push-recordservice,docker-push-generatedquestservice] steps: - name: Deploy over SSH uses: fifsky/ssh-action@master diff --git a/docker-compose.yml b/docker-compose.yml index 45ffcac7..6fe8fde4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,34 +11,33 @@ services: networks: - mynetwork - recordservice: - container_name: recordservice-${teamname:-defaultASW} - image: ghcr.io/arquisoft/wiq_es6b/recordservice:latest + authservice: + container_name: authservice-${teamname:-defaultASW} + image: ghcr.io/arquisoft/wiq_es6b/authservice:latest profiles: ["dev", "prod"] - build: ./questions/recordservice + build: ./users/authservice depends_on: - mongodb ports: - - "8006:8006" + - "8002:8002" networks: - mynetwork environment: - MONGODB_URI: mongodb://mongodb:27017/recorddb + MONGODB_URI: mongodb://mongodb:27017/userdb - createservice: - container_name: createservice-${teamname:-defaultASW} - image: ghcr.io/arquisoft/wiq_es6b/createservice:latest + userservice: + container_name: userservice-${teamname:-defaultASW} + image: ghcr.io/arquisoft/wiq_es6b/userservice:latest profiles: ["dev", "prod"] - build: ./questions/createservice + build: ./users/userservice depends_on: - mongodb ports: - - "8005:8005" + - "8001:8001" networks: - mynetwork environment: - MONGODB_URI: mongodb://mongodb:27017/questiondb - + MONGODB_URI: mongodb://mongodb:27017/userdb answerservice: container_name: answerservice-${teamname:-defaultASW} @@ -54,34 +53,33 @@ services: environment: MONGODB_URI: mongodb://mongodb:27017/questiondb - - authservice: - container_name: authservice-${teamname:-defaultASW} - image: ghcr.io/arquisoft/wiq_es6b/authservice:latest + createservice: + container_name: createservice-${teamname:-defaultASW} + image: ghcr.io/arquisoft/wiq_es6b/createservice:latest profiles: ["dev", "prod"] - build: ./users/authservice + build: ./questions/createservice depends_on: - mongodb ports: - - "8002:8002" + - "8005:8005" networks: - mynetwork environment: - MONGODB_URI: mongodb://mongodb:27017/userdb + MONGODB_URI: mongodb://mongodb:27017/questiondb - userservice: - container_name: userservice-${teamname:-defaultASW} - image: ghcr.io/arquisoft/wiq_es6b/userservice:latest + recordservice: + container_name: recordservice-${teamname:-defaultASW} + image: ghcr.io/arquisoft/wiq_es6b/recordservice:latest profiles: ["dev", "prod"] - build: ./users/userservice + build: ./questions/recordservice depends_on: - mongodb ports: - - "8001:8001" + - "8006:8006" networks: - mynetwork environment: - MONGODB_URI: mongodb://mongodb:27017/userdb + MONGODB_URI: mongodb://mongodb:27017/recorddb generatedquestservice: container_name: generatedquestservice-${teamname:-defaultASW} @@ -106,6 +104,10 @@ services: - mongodb - userservice - authservice + - answerservice + - createservice + - recordservice + - generatedquestservice ports: - "8000:8000" networks: @@ -113,8 +115,8 @@ services: environment: AUTH_SERVICE_URL: http://authservice:8002 USER_SERVICE_URL: http://userservice:8001 - QUES_SERVICE_URL: http://createservice:8005 ANSW_SERVICE_URL: http://answerservice:8004 + QUES_SERVICE_URL: http://createservice:8005 REC_SERVICE_URL: http://recordservice:8006 GEN_SERVICE_URL: http://generatedquestservice:8007 diff --git a/questions/answerservice/package.json b/questions/answerservice/package.json index 9d763cc3..cc51fad4 100644 --- a/questions/answerservice/package.json +++ b/questions/answerservice/package.json @@ -4,7 +4,7 @@ "description": " Authentication service, in charge of authenticating users in the application", "main": "service.js", "scripts": { - "start": "node auth-service.js", + "start": "node answer-service.js", "test": "jest" }, "repository": { diff --git a/questions/createservice/package.json b/questions/createservice/package.json index c1843205..efa5b9e6 100644 --- a/questions/createservice/package.json +++ b/questions/createservice/package.json @@ -4,7 +4,7 @@ "description": " Creacion de preguntas automaticas", "main": "service.js", "scripts": { - "start": "node auth-service.js", + "start": "node create-service.js", "test": "jest" }, "repository": { diff --git a/questions/generatedquestservice/package.json b/questions/generatedquestservice/package.json index fcb8c1a6..2d569a3e 100644 --- a/questions/generatedquestservice/package.json +++ b/questions/generatedquestservice/package.json @@ -4,7 +4,7 @@ "description": "Almacenamiento de las preguntas automaticas generadas y su respuesta correcta correspondiente", "main": "service.js", "scripts": { - "start": "node auth-service.js", + "start": "node generatedquest-service.js", "test": "jest" }, "repository": { diff --git a/questions/recordservice/package.json b/questions/recordservice/package.json index 1f7395b5..4a238fd7 100644 --- a/questions/recordservice/package.json +++ b/questions/recordservice/package.json @@ -4,7 +4,7 @@ "description": " Creacion de preguntas automaticas", "main": "service.js", "scripts": { - "start": "node auth-service.js", + "start": "node record-service.js", "test": "jest" }, "repository": { diff --git a/webapp/e2e/test-environment-setup.js b/webapp/e2e/test-environment-setup.js index ab2bdb41..fcc529d5 100644 --- a/webapp/e2e/test-environment-setup.js +++ b/webapp/e2e/test-environment-setup.js @@ -5,8 +5,10 @@ let mongoserver; let userservice; let authservice; let gatewayservice; -//let createservice; -//let answerservice; +let createservice; +let answerservice; +let recordservice; +let generatedquestservice; async function startServer() { console.log('Starting MongoDB memory server...'); @@ -15,11 +17,11 @@ async function startServer() { process.env.MONGODB_URI = mongoUri; userservice = await require("../../users/userservice/user-service"); authservice = await require("../../users/authservice/auth-service"); - //createservice = await require("../../questions/createservice/create-service"); - //answerservice = await require("../../questions/answerservice/answer-service"); - //recordservice = await require("../../questions/recordservice/record-service"); + createservice = await require("../../questions/createservice/create-service"); + answerservice = await require("../../questions/answerservice/answer-service"); + recordservice = await require("../../questions/recordservice/record-service"); gatewayservice = await require("../../gatewayservice/gateway-service"); - //generatedquestservice = await require("../../questions/generatedquestservice/generatedquest-service"); + generatedquestservice = await require("../../questions/generatedquestservice/generatedquest-service"); } startServer(); From e196687b8b8f607e8dc9464ac3f7896b749fcfac Mon Sep 17 00:00:00 2001 From: uo277310 Date: Sun, 3 Mar 2024 20:33:54 +0100 Subject: [PATCH 14/20] =?UTF-8?q?Tests=20vacios=20a=C3=B1adidos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- questions/createservice/create-service.test.js | 0 questions/generatedquestservice/generatedquest-service.test.js | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 questions/createservice/create-service.test.js create mode 100644 questions/generatedquestservice/generatedquest-service.test.js diff --git a/questions/createservice/create-service.test.js b/questions/createservice/create-service.test.js new file mode 100644 index 00000000..e69de29b diff --git a/questions/generatedquestservice/generatedquest-service.test.js b/questions/generatedquestservice/generatedquest-service.test.js new file mode 100644 index 00000000..e69de29b From c0d6bf4a485425e133fb372d1f25bd49ee6a222c Mon Sep 17 00:00:00 2001 From: uo277310 Date: Sun, 3 Mar 2024 20:41:20 +0100 Subject: [PATCH 15/20] =?UTF-8?q?A=C3=B1adidos=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../createservice/create-service.test.js | 49 +++++++++++++++++++ .../generatedquest-service.test.js | 46 +++++++++++++++++ 2 files changed, 95 insertions(+) diff --git a/questions/createservice/create-service.test.js b/questions/createservice/create-service.test.js index e69de29b..a8a9e405 100644 --- a/questions/createservice/create-service.test.js +++ b/questions/createservice/create-service.test.js @@ -0,0 +1,49 @@ +const request = require('supertest'); +const { MongoMemoryServer } = require('mongodb-memory-server'); +const bcrypt = require('bcrypt'); +const Answer = require('./create-model'); + +let mongoServer; +let app; + +//test question +const questionTest = { + questionBody: '¿Cuál es la capital de ', + typeQuestion: 'pais', + typeAnswer: 'capital' +}; + +async function addQuestion(questionTest){ + const newQuestion = new Question({ + questionBody: questionTest.questionBody, + typeQuestion: questionTest.typeQuestion, + typeAnswer: questionTest.typeAnswer + }); + + await newQuestion.save(); +} + +beforeAll(async () => { + mongoServer = await MongoMemoryServer.create(); + const mongoUri = mongoServer.getUri(); + process.env.MONGODB_URI = mongoUri; + app = require('./create-service'); + //Load database with initial conditions + await addQuestion(questionTest); +}); + +afterAll(async () => { + app.close(); + await mongoServer.stop(); +}); + +describe('Create Service', () => { + it('Should perform an addRecord operation /addQuestion', async () => { + const response = await request(app).post('/addQuestion').send(questionTest); + expect(response.status).toBe(200); + expect(response.body).toHaveProperty('questionBody', '¿Cuál es la capital de '); + expect(response.body).toHaveProperty('typeQuestion', 'pais'); + expect(response.body).toHaveProperty('typeAnswer', 'capital'); + }); + +}); diff --git a/questions/generatedquestservice/generatedquest-service.test.js b/questions/generatedquestservice/generatedquest-service.test.js index e69de29b..199b246a 100644 --- a/questions/generatedquestservice/generatedquest-service.test.js +++ b/questions/generatedquestservice/generatedquest-service.test.js @@ -0,0 +1,46 @@ +const request = require('supertest'); +const { MongoMemoryServer } = require('mongodb-memory-server'); +const bcrypt = require('bcrypt'); +const Answer = require('./create-model'); + +let mongoServer; +let app; + +//test generated question +const generatedQuestionTest = { + generatedQuestionBody: '¿Cuál es la capital de España?', + correctAnswer: 'Madrid', +}; + +async function addGeneratedQuestion(generatedQuestionTest){ + const newGeneratedQuestion = new GeneratedQuestion({ + generatedQuestionBody: generatedQuestionTest.generatedQuestionBody, + correctAnswer: generatedQuestionTest.correctAnswer + }); + + await newGeneratedQuestion.save(); +} + +beforeAll(async () => { + mongoServer = await MongoMemoryServer.create(); + const mongoUri = mongoServer.getUri(); + process.env.MONGODB_URI = mongoUri; + app = require('./generatedquest-service'); + //Load database with initial conditions + await addGeneratedQuestion(generatedQuestionTest); +}); + +afterAll(async () => { + app.close(); + await mongoServer.stop(); +}); + +describe('Generatedquest Service', () => { + it('Should perform an addRecord operation /addGeneratedQuestion', async () => { + const response = await request(app).post('/addGeneratedQuestion').send(generatedQuestionTest); + expect(response.status).toBe(200); + expect(response.body).toHaveProperty('generatedQuestionBody', '¿Cuál es la capital de España?'); + expect(response.body).toHaveProperty('correctAnswer', 'Madrid'); + }); + +}); From 6a53e02183bbb52849d17aefa8e8d28555749a3a Mon Sep 17 00:00:00 2001 From: uo277310 Date: Sun, 3 Mar 2024 20:44:53 +0100 Subject: [PATCH 16/20] Modificados nombres --- questions/createservice/create-service.test.js | 2 +- questions/generatedquestservice/generatedquest-service.test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/questions/createservice/create-service.test.js b/questions/createservice/create-service.test.js index a8a9e405..b7c15dcb 100644 --- a/questions/createservice/create-service.test.js +++ b/questions/createservice/create-service.test.js @@ -1,7 +1,7 @@ const request = require('supertest'); const { MongoMemoryServer } = require('mongodb-memory-server'); const bcrypt = require('bcrypt'); -const Answer = require('./create-model'); +const Question = require('./create-model'); let mongoServer; let app; diff --git a/questions/generatedquestservice/generatedquest-service.test.js b/questions/generatedquestservice/generatedquest-service.test.js index 199b246a..6d5c1a7e 100644 --- a/questions/generatedquestservice/generatedquest-service.test.js +++ b/questions/generatedquestservice/generatedquest-service.test.js @@ -1,7 +1,7 @@ const request = require('supertest'); const { MongoMemoryServer } = require('mongodb-memory-server'); const bcrypt = require('bcrypt'); -const Answer = require('./create-model'); +const GeneratedQuestion = require('./create-model'); let mongoServer; let app; From 3ab2eb858902e1599db527233f86074225357bab Mon Sep 17 00:00:00 2001 From: uo277310 Date: Sun, 3 Mar 2024 20:47:23 +0100 Subject: [PATCH 17/20] Bug nombre --- questions/generatedquestservice/generatedquest-service.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/questions/generatedquestservice/generatedquest-service.test.js b/questions/generatedquestservice/generatedquest-service.test.js index 6d5c1a7e..8437deb7 100644 --- a/questions/generatedquestservice/generatedquest-service.test.js +++ b/questions/generatedquestservice/generatedquest-service.test.js @@ -1,7 +1,7 @@ const request = require('supertest'); const { MongoMemoryServer } = require('mongodb-memory-server'); const bcrypt = require('bcrypt'); -const GeneratedQuestion = require('./create-model'); +const GeneratedQuestion = require('./generatedquest-model'); let mongoServer; let app; From b37701fcc95d0bb0a9ec2a438b776b2994819e22 Mon Sep 17 00:00:00 2001 From: uo277310 Date: Sun, 3 Mar 2024 20:52:57 +0100 Subject: [PATCH 18/20] Comillas invertidas por las simples --- questions/recordservice/record-service.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/questions/recordservice/record-service.test.js b/questions/recordservice/record-service.test.js index 8ba4eca2..3399b170 100644 --- a/questions/recordservice/record-service.test.js +++ b/questions/recordservice/record-service.test.js @@ -51,8 +51,8 @@ describe('Record Service', () => { }); it('Should get user records by userId /getRecords/:userId', async () => { - const response = await request(app).get('/getRecords/${record.userId}'); - + const response = await request(app).get(`/getRecords/${record.userId}`); + expect(response.status).toBe(200); expect(response.body.some(record => record.userId === 'testuserid')).toBe(true); expect(response.body[0]).toMatchObject(record); From f7d77c569bfd1748439444fdf1c50596d85bcd24 Mon Sep 17 00:00:00 2001 From: uo277310 Date: Sun, 3 Mar 2024 20:57:25 +0100 Subject: [PATCH 19/20] Arreglo problema con fecha --- questions/recordservice/record-service.test.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/questions/recordservice/record-service.test.js b/questions/recordservice/record-service.test.js index 3399b170..7b6a0c9d 100644 --- a/questions/recordservice/record-service.test.js +++ b/questions/recordservice/record-service.test.js @@ -48,14 +48,17 @@ describe('Record Service', () => { const response = await request(app).post('/addRecord').send(record); expect(response.status).toBe(200); expect(response.body).toHaveProperty('userId', 'testuserid'); - }); + });s it('Should get user records by userId /getRecords/:userId', async () => { const response = await request(app).get(`/getRecords/${record.userId}`); - + expect(response.status).toBe(200); expect(response.body.some(record => record.userId === 'testuserid')).toBe(true); - expect(response.body[0]).toMatchObject(record); + + // Convert the date to a string before comparing + const expectedRecord = { ...record, date: record.date.toISOString() }; + expect(response.body[0]).toMatchObject(expectedRecord); }); }); From e5193086165f33e6810898be7be16a5ddeea7809 Mon Sep 17 00:00:00 2001 From: uo277310 Date: Sun, 3 Mar 2024 20:59:56 +0100 Subject: [PATCH 20/20] Bug --- questions/recordservice/record-service.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/questions/recordservice/record-service.test.js b/questions/recordservice/record-service.test.js index 7b6a0c9d..9cd49fc4 100644 --- a/questions/recordservice/record-service.test.js +++ b/questions/recordservice/record-service.test.js @@ -48,7 +48,7 @@ describe('Record Service', () => { const response = await request(app).post('/addRecord').send(record); expect(response.status).toBe(200); expect(response.body).toHaveProperty('userId', 'testuserid'); - });s + }); it('Should get user records by userId /getRecords/:userId', async () => { const response = await request(app).get(`/getRecords/${record.userId}`);