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
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
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.'+
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
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