Skip to content

Commit

Permalink
Merge pull request #62 from Arquisoft/PruebaConjunto
Browse files Browse the repository at this point in the history
Prueba conjunto
  • Loading branch information
uo283182 authored Apr 26, 2024
2 parents f545b7d + 8fe4889 commit 07c3f81
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion questions/template-questions/question-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.'+
Expand Down
24 changes: 24 additions & 0 deletions questions/template-questions/question-service.test.js
Original file line number Diff line number Diff line change
@@ -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);
});

});
4 changes: 2 additions & 2 deletions webapp/src/components/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
63 changes: 62 additions & 1 deletion webapp/src/components/Game.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
};
Expand All @@ -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(
<BrowserRouter>
<Game />
</BrowserRouter>);

// 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(
<BrowserRouter>
<Game esperaFinalizacion={0}/>
</BrowserRouter>);

// 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('/');
});
});

0 comments on commit 07c3f81

Please sign in to comment.