Skip to content

Commit

Permalink
Merge pull request #88 from Arquisoft/Ruben
Browse files Browse the repository at this point in the history
Nuevos test de cobertura de código y eliminación de Partida
  • Loading branch information
UO289337 authored Apr 5, 2024
2 parents 2ac0afc + 5528a23 commit 941fc21
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 31 deletions.
44 changes: 44 additions & 0 deletions gatewayservice/gateway-service.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const request = require('supertest');
const axios = require('axios');
const app = require('./gateway-service');
const { createServer } = require('http');

const server = createServer(app);

afterAll(async () => {
app.close();
Expand Down Expand Up @@ -37,4 +40,45 @@ describe('Gateway Service', () => {
expect(response.statusCode).toBe(200);
expect(response.body.userId).toBe('mockedUserId');
});

// Test /generateQuestion endpoint
it('should receive the question', async () => {
server.listen(8003);

jest.spyOn(axios, 'get').mockResolvedValueOnce({ data: { responseQuestion: "¿Cual es la capital de España?", responseOptions: ["Madrid", "Barcelona", "Oviedo", "Valladolid"],
responseCorrectOption: "Madrid", responseImage: null, question_id:"12345abcdef"} });

const response = await request(app).get('/generateQuestion').query({
user: 'user',
newGame: true,
numberOfQuestions: 5
});

expect(response.status).toBe(200);
expect(response.body).toEqual({ responseQuestion: "¿Cual es la capital de España?", responseOptions: ["Madrid", "Barcelona", "Oviedo", "Valladolid"],
responseCorrectOption: "Madrid", responseImage: null, question_id:"12345abcdef"});

jest.restoreAllMocks();
server.close(true);
});

it('should update the question', async () => {
const updatedQuestion = {
_id: '660434f228670016dfcac277',
enunciado: '¿Cual es la capital de España?',
respuesta_correcta: 'Madrid',
respuesta_falsa1: 'Barcelona',
respuesta_falsa2: 'Oviedo',
respuesta_falsa3: 'Valladolid',
__v: 0
}
jest.spyOn(axios, 'get').mockResolvedValueOnce({ data: { message: "Tiempo de pregunta actualizado exitosamente", updatedQuestion: updatedQuestion } });

const response = await request(app)
.get('/updateQuestion')
.send({ message: 'Pregunta actualizada', updatedQuestion: updatedQuestion });

expect(response.status).toBe(200);
expect(response.body).toEqual({ message: "Tiempo de pregunta actualizado exitosamente", updatedQuestion });
})
});
12 changes: 11 additions & 1 deletion webapp/src/components/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,17 @@ const Game = () => {


return (
<Container component="main" maxWidth="xs" sx={{ marginTop: 4 }}>
<Container component="main" maxWidth="xl"
sx={{
marginTop: 4,
backgroundColor: '#F3D3FA',
borderRadius: '10px',
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
height: '95vh'
}}>
{question && (
<>
<Typography variant="body1" sx={{ textAlign: 'center' }}>
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/components/Game.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import MockAdapter from 'axios-mock-adapter';
import Game from './Game';

const mockAxios = new MockAdapter(axios);
jest.useFakeTimers(); // Para simular el paso del tiempo

describe('Start game', () => {
beforeEach(() => {
Expand Down Expand Up @@ -78,7 +79,7 @@ describe('Start game', () => {

const error = queryByText("Error:");
expect(error).toBeNull();
});
});

// Simulate user input
await act(async () => {
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/components/PantallaInicio.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const PantallaInicio = () => {
const navigate = useNavigate();

function nuevaPartida() {
navigate("/Partida")
navigate("/Game");
}

const logoutUser = async () => {
Expand Down
26 changes: 0 additions & 26 deletions webapp/src/components/Partida.js

This file was deleted.

4 changes: 2 additions & 2 deletions webapp/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import {
} from "react-router-dom";

import PantallaInicio from './components/PantallaInicio';
import Partida from './components/Partida';
import Login from './components/Login';
import AddUser from './components/AddUser';
import Game from './components/Game';

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
Expand All @@ -24,10 +24,10 @@ root.render(
<Routes>
<Route path="/" element={<App/>}></Route>
<Route path="/PantallaInicio" element={<PantallaInicio/>}></Route>
<Route path="/Partida" element={<Partida/>}></Route>
<Route path="/Login" element={<Login />} />
<Route path="/AddUser" element={<AddUser />} />
<Route path="/App" element={<App />} />
<Route path="/Game" element={<Game />} />
</Routes>
</Router>
</UserProvider>
Expand Down

0 comments on commit 941fc21

Please sign in to comment.