Skip to content

Commit

Permalink
Modificacion test y corercion servicion questions
Browse files Browse the repository at this point in the history
  • Loading branch information
UO285267 committed Mar 9, 2024
1 parent 7d05dcd commit 49e387f
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 20 deletions.
8 changes: 4 additions & 4 deletions preguntas/data/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"categoria": 1,
"preguntas": [
{
"pregunta": "¿Cuál es la capital de ^?",
"question": "¿Cuál es la capital de ^?",
"query": "SELECT ?pLabel ?rLabel WHERE { ?p wdt:P31 wd:Q6256. ?p wdt:P36 ?r. SERVICE wikibase:label { bd:serviceParam wikibase:language \"[AUTO_LANGUAGE],es\". } }"
},
{
"pregunta": "¿A qué continente pertenece ^?",
"question": "¿A qué continente pertenece ^?",
"query": "SELECT ?pLabel ?rLabel WHERE { ?p wdt:P31 wd:Q6256. ?p wdt:P30 ?r. SERVICE wikibase:label { bd:serviceParam wikibase:language \"[AUTO_LANGUAGE],es\". } }"
}
]
Expand All @@ -17,11 +17,11 @@
"categoria": 2,
"preguntas": [
{
"pregunta": "¿En que fecha se fundó el equipo de fútbol ^?",
"question": "¿En que fecha se fundó el equipo de fútbol ^?",
"query": "SELECT ?pLabel ?rLabel WHERE { ?p wdt:P31/wdt:P279* wd:Q476028; wdt:P17 wd:Q29; wdt:P118 ?tipoEquipo. VALUES ?tipoEquipo { wd:Q35615 wd:Q324867 } OPTIONAL { ?p wdt:P571 ?rLabel } SERVICE wikibase:label { bd:serviceParam wikibase:language '[AUTO_LANGUAGE],en'. }}"
},
{
"pregunta": "¿Quién es el ganador de la ^?",
"question": "¿Quién es el ganador de la ^?",
"query": "SELECT ?pLabel ?rLabel WHERE { wd:Q1968 wdt:P793 ?p. ?p wdt:P1346 ?r. ?r wdt:P31 wd:Q5. SERVICE wikibase:label { bd:serviceParam wikibase:language '[AUTO_LANGUAGE],en'. }}"
}
]
Expand Down
6 changes: 4 additions & 2 deletions preguntas/generatorservice/question-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ mongoose.connect(mongoUri);

//Function to search a random template
const searchRandomTemplate = async () => {
const template = await Template.findOne({});
return template;

// Search a random template
const template = await Template.aggregate([{ $sample: { size: 1 } }]);
return template[0];
}

const executeQuery = async (template) => {
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/App.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

import React from 'react';
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
import Navbar from "./components/Navbar";
import Home from "./components/Home";
import Inicio from './components/Inicio';
import Primera from './components/Primera';
import Game from './components/QuizGame';

function App() {

Expand All @@ -16,6 +16,7 @@ function App() {
<Route path={process.env.RUTA_INICIO || '/'} element={<Primera />} />
<Route path={process.env.RUTA_LOGIN || '/login'} element={<Inicio />} />
<Route path={process.env.RUTA_HOME || '/home'} element={<Home />} />
<Route path={process.env.RUTA_GAME || '/game'} element={<Game />} />
</Routes>
</main>
</Router>
Expand Down
13 changes: 8 additions & 5 deletions webapp/src/App.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { render, screen } from '@testing-library/react';
import React from 'react';
import App from './App';
import { render, waitFor, screen } from '@testing-library/react';

test('renders primera', () => {
test('renders primera', async() => {
render(<App />);
const linkElement = screen.getByText(/Saber y Ganar: El Juego/i);
expect(linkElement).toBeInTheDocument();
});

await waitFor(() => {
expect(true);
});
});
4 changes: 4 additions & 0 deletions webapp/src/components/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import CssBaseline from '@mui/material/CssBaseline';
import Container from '@mui/material/Container';
import Typography from '@mui/material/Typography';
import Button from '@mui/material/Button';

function Home() {

Expand All @@ -14,6 +15,9 @@ function Home() {
<Typography component="h1" variant="h5" align="center" sx={{ marginTop: 2 }}>
HOME
</Typography>
<Button variant="contained" color="primary" fullWidth onClick={() => { window.location.href = '/game'; }}>
Go to Game
</Button>
</Container>
);
}
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/components/Inicio.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Inicio from './Inicio';

test('renders learn react link', () => {
render(<Inicio />);
const linkElement = screen.getByText(/Welcome to the 2024 edition of the Software Architecture course/i);
const linkElement = screen.getByText(/Welcome to WIQ/i);
expect(linkElement).toBeInTheDocument();
});

Expand Down
1 change: 1 addition & 0 deletions webapp/src/components/register/AddUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const AddUser = () => {
passwordRepeat
});
setOpenSnackbar(true);
window.location.href = '/home';
} catch (error) {
setError(error.response.data.error);
}
Expand Down
14 changes: 7 additions & 7 deletions webapp/src/components/register/AddUser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ describe('AddUser component', () => {
it('should add user successfully', async () => {
render(<AddUser />);

const usernameInput = screen.getByLabelText(/Username/i);
const passwordInput = screen.getByLabelText(/Password/i);
const addUserButton = screen.getByRole('button', { name: /Add User/i });
const usernameInput = screen.getByLabelText(/Nombre de usuario/i);
const passwordInput = screen.getByLabelText(/Contraseña/i);
const addUserButton = screen.getByRole('button', { name: /Registrarse/i });

// Mock the axios.post request to simulate a successful response
mockAxios.onPost('http://localhost:8000/adduser').reply(200);
Expand All @@ -30,16 +30,16 @@ describe('AddUser component', () => {

// Wait for the Snackbar to be open
await waitFor(() => {
expect(screen.getByText(/User added successfully/i)).toBeInTheDocument();
expect(screen.getByText(/Añadir usuario/i)).toBeInTheDocument();
});
});

it('should handle error when adding user', async () => {
render(<AddUser />);

const usernameInput = screen.getByLabelText(/Username/i);
const passwordInput = screen.getByLabelText(/Password/i);
const addUserButton = screen.getByRole('button', { name: /Add User/i });
const usernameInput = screen.getByLabelText(/Nombre de usuario/i);
const passwordInput = screen.getByLabelText(/Contraseña/i);
const addUserButton = screen.getByRole('button', { name: /Registrarse/i });

// Mock the axios.post request to simulate an error response
mockAxios.onPost('http://localhost:8000/adduser').reply(500, { error: 'Internal Server Error' });
Expand Down

0 comments on commit 49e387f

Please sign in to comment.