Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webapp interface #124

Merged
merged 133 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from 75 commits
Commits
Show all changes
133 commits
Select commit Hold shift + click to select a range
baf2cfd
configure topics
uo288574 Apr 15, 2024
aafeba0
configure number of questions
uo288574 Apr 15, 2024
626db8f
we dont need thaat file
uo288574 Apr 17, 2024
57f811e
configure number of errors
uo288574 Apr 18, 2024
ef8150d
deleted commented code not needed
uo288574 Apr 18, 2024
658f320
Added new GET endpoint on the service
AbelMH1 Apr 19, 2024
4af160a
Merge branch 'develop' into service_question_generator
AbelMH1 Apr 19, 2024
bd0443f
test to access to history
uo288574 Apr 22, 2024
b1a58a8
minor fix
uo288574 Apr 22, 2024
77369ef
another change
uo288574 Apr 22, 2024
23ce7a9
test to access to appQuestion on nav
uo288574 Apr 22, 2024
63e22fd
test to find text of Game Configuration
uo288574 Apr 22, 2024
e4f6614
dependency remove
uo288574 Apr 22, 2024
3dbe634
trying to solve errors
uo288574 Apr 22, 2024
c136963
added fields for requesting first and last name information from add …
uo288574 Apr 23, 2024
b92ea11
fixed test to add user correctly
uo288574 Apr 23, 2024
f6c3a79
changed the text from English to Spanish
uo288574 Apr 23, 2024
6c587f8
minor fix
uo288574 Apr 23, 2024
b9c5500
another minor fix
uo288574 Apr 23, 2024
3620129
fixed test to handle error when adding user
uo288574 Apr 23, 2024
6b4c954
unnecessary code
uo288574 Apr 23, 2024
c7ee24c
added a field to confirm the password
uo288574 Apr 23, 2024
b13b224
added "prod" to docker compose
uo288574 Apr 23, 2024
7404ac5
test to check different passwords
uo288574 Apr 23, 2024
9837b2e
test to check that is necessary to introduce name or surname
uo288574 Apr 23, 2024
96aaa35
change appbar to stay at the top of the page
uo288574 Apr 23, 2024
c51ad40
traduce login text
uo288574 Apr 23, 2024
498ba1f
Merge branch 'service_question_generator' into webapp_interface
alegarman2002 Apr 23, 2024
53a64cc
Merge branch 'webapp_interface' of https://github.com/Arquisoft/wiq_e…
alegarman2002 Apr 23, 2024
fa2a5e6
Adding the functionality to generate x number of questions with x opt…
alegarman2002 Apr 24, 2024
66f892d
translation
uo288574 Apr 24, 2024
deaa75f
test for the game configuration modified
uo288574 Apr 24, 2024
243e1c1
export problem solved
uo288574 Apr 24, 2024
3ba6f35
trying to solve export problems
uo288574 Apr 24, 2024
c78fa42
updated another things to make the game parametrizable
alegarman2002 Apr 24, 2024
47118a2
FIxed problem with the own branch
alegarman2002 Apr 24, 2024
1aee7dd
Fixed checkbox problem
marco-qg Apr 24, 2024
6db92b4
Fixed test
marco-qg Apr 24, 2024
c8f9f86
Fixed my fix
marco-qg Apr 24, 2024
4c61bfc
Nav and footer upgraded
marco-qg Apr 24, 2024
aa1c00a
Improved config style
marco-qg Apr 24, 2024
5bb6bfb
game configuration test
uo288574 Apr 24, 2024
be46417
new test
uo288574 Apr 24, 2024
d1e061e
test to check number of elements
uo288574 Apr 24, 2024
f36bcd3
minor fix
uo288574 Apr 24, 2024
01b03c6
trying to reduce code duplication
uo288574 Apr 24, 2024
e7693ea
trying to reduce code duplication
uo288574 Apr 24, 2024
45d2a41
reduce code
uo288574 Apr 24, 2024
2099fbb
modified Reliability Rating
uo288574 Apr 24, 2024
0db60ea
issues
uo288574 Apr 24, 2024
3850339
issues
uo288574 Apr 24, 2024
95227de
trying to inc coverage
uo288574 Apr 24, 2024
21063b7
minor fix
uo288574 Apr 24, 2024
ea4dc94
test
uo288574 Apr 24, 2024
64282b0
deleted the test
uo288574 Apr 24, 2024
240d0cb
Fixed all problems with game params and done it
alegarman2002 Apr 24, 2024
6eb0c15
Merge branch 'webapp_interface' of https://github.com/Arquisoft/wiq_e…
alegarman2002 Apr 24, 2024
773a732
test for "/history/questions" (???)
uo288574 Apr 26, 2024
990f2ef
try to add test
uo288574 Apr 26, 2024
eb17e0c
minor fix
uo288574 Apr 26, 2024
0d747f5
remove test
uo288574 Apr 26, 2024
cf9f219
unnecesary code
uo288574 Apr 26, 2024
f341b57
unnecessary code
uo288574 Apr 26, 2024
9a4916d
unnecessary code
uo288574 Apr 26, 2024
f8e9e29
test for game config
uo288574 Apr 26, 2024
b877ddc
add test for number of questions and number for answers
uo288574 Apr 26, 2024
01b4625
minor fix
uo288574 Apr 26, 2024
0df2783
minor fix
uo288574 Apr 26, 2024
aebdfeb
last minor fix
uo288574 Apr 26, 2024
f25b65b
unnecesary code
uo288574 Apr 26, 2024
e322573
check that number of answars cant be < 2
uo288574 Apr 26, 2024
248a26b
reduce duplicate code
uo288574 Apr 26, 2024
f6bd222
test fix
uo288574 Apr 26, 2024
66241d4
Fixed last problems with the question generator
alegarman2002 Apr 26, 2024
69e4881
Merge branch 'webapp_interface' of https://github.com/Arquisoft/wiq_e…
alegarman2002 Apr 26, 2024
0a40591
review last test
uo288574 Apr 26, 2024
7792ec4
Añadido spinner
marco-qg Apr 26, 2024
3f4d54f
El test que falla es porque no esta mockeado
alegarman2002 Apr 26, 2024
17d1dfa
Merge branch 'webapp_interface' of https://github.com/Arquisoft/wiq_e…
alegarman2002 Apr 26, 2024
7b15a36
Merge branch 'webapp_interface' of https://github.com/Arquisoft/wiq_e…
marco-qg Apr 26, 2024
48723ac
at the moment we comment this
uo288574 Apr 27, 2024
4ec1cd9
Merge branch 'webapp_interface' of https://github.com/Arquisoft/wiq_e…
uo288574 Apr 27, 2024
b5370e2
fixed
uo288574 Apr 27, 2024
4f3bf4f
issues
uo288574 Apr 27, 2024
84f3c50
first version of another game
uo288574 Apr 27, 2024
f601860
critical security issues fixed
uo288574 Apr 27, 2024
39d360c
Test for the calculator game. Review secureRandomNumber function of U…
uo288574 Apr 27, 2024
277f9c9
possible solution for secureRandomNumber but I think it'll create sec…
uo288574 Apr 27, 2024
87b4817
Game service test but we have to check the comented one
alegarman2002 Apr 27, 2024
9cdf077
Merge branch 'webapp_interface' of https://github.com/Arquisoft/wiq_e…
alegarman2002 Apr 27, 2024
cab0dc2
Merge branch 'develop' into webapp_interface
alegarman2002 Apr 27, 2024
c9d3a9f
Test 2 arreglado, falta el 3o
marco-qg Apr 27, 2024
8d0ea3d
Merge branch 'webapp_interface' of https://github.com/Arquisoft/wiq_e…
marco-qg Apr 27, 2024
0dde584
Modified spinner
marco-qg Apr 27, 2024
7e4c972
Game service test finished
alegarman2002 Apr 27, 2024
f5e8815
Merge branch 'webapp_interface' of https://github.com/Arquisoft/wiq_e…
alegarman2002 Apr 27, 2024
7a9fc07
Creation of the container of apisgatewayservice
alegarman2002 Apr 27, 2024
455170b
modified tests for handling spinners
uo288574 Apr 28, 2024
f3b51fb
added menu checks for the new game
uo288574 Apr 28, 2024
4b3ab9e
help test
uo288574 Apr 28, 2024
be4601c
spinner test
uo288574 Apr 28, 2024
b0e3e53
button test
uo288574 Apr 28, 2024
24d9aeb
utils test
uo288574 Apr 28, 2024
c2fc32e
fixed security hotspots and some issues
uo288574 Apr 28, 2024
e2c79d8
menu test
uo288574 Apr 28, 2024
149ff6a
Fixed some problems with the question management
alegarman2002 Apr 28, 2024
2dfba98
Merge branch 'webapp_interface' of https://github.com/Arquisoft/wiq_e…
alegarman2002 Apr 28, 2024
d66c6bb
test for the gateway service we have to revise it
alegarman2002 Apr 28, 2024
977843e
Added to sonar gameservice test
alegarman2002 Apr 28, 2024
4beba06
Fixed all problems with the game and fixed the problem with the game …
alegarman2002 Apr 29, 2024
67d4454
Merge branch 'webapp_interface' of https://github.com/Arquisoft/wiq_e…
uo288574 Apr 29, 2024
a48a21c
calculator game fixed. Test for this game commented because an error …
uo288574 Apr 29, 2024
a57bfab
app test
uo288574 Apr 29, 2024
9d75f78
Fixed first game
alegarman2002 Apr 29, 2024
1596792
Fixed calculator
alegarman2002 Apr 29, 2024
690cc42
Mejora del historial Arquisoft/wiq_es6c#131 done
marco-qg Apr 29, 2024
0c925cb
Nav fixed
marco-qg Apr 29, 2024
97fddc2
change color of bts
uo288574 Apr 29, 2024
a45658d
Merge branch 'webapp_interface' of https://github.com/Arquisoft/wiq_e…
uo288574 Apr 29, 2024
dfbd7c8
extracted esperar
marco-qg Apr 29, 2024
5165225
Calculator improved
marco-qg Apr 29, 2024
06662e8
Checks to ensure that a user is not registered with blank fields and …
uo288574 Apr 29, 2024
bf06245
Merge branch 'webapp_interface' of https://github.com/Arquisoft/wiq_e…
uo288574 Apr 29, 2024
fcf79dc
Ya se actualizan las preguntas, falta meter tiempo y almacenar la par…
marco-qg Apr 29, 2024
72c89a6
Merge branch 'webapp_interface' of https://github.com/Arquisoft/wiq_e…
marco-qg Apr 29, 2024
9af5072
Avance calculadora
marco-qg Apr 29, 2024
d4c9065
Fixed problem with storage game
alegarman2002 Apr 29, 2024
b10c335
it doesn't work that two users cannot register with the same name
uo288574 Apr 29, 2024
43ce04f
Calculator works!!!
marco-qg Apr 29, 2024
4fe11ff
Merge branch 'webapp_interface' of https://github.com/Arquisoft/wiq_e…
marco-qg Apr 29, 2024
9f7d507
Shuffled array
marco-qg Apr 29, 2024
f35edf3
Fixed problem with game number of questions if we switch view
alegarman2002 Apr 29, 2024
5bd48c4
Merge branch 'webapp_interface' of https://github.com/Arquisoft/wiq_e…
alegarman2002 Apr 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ services:
prometheus:
image: prom/prometheus
container_name: prometheus-${teamname:-defaultASW}
profiles: ["dev"]
profiles: ["dev", "prod"]
networks:
- mynetwork
volumes:
Expand All @@ -153,7 +153,7 @@ services:
grafana:
image: grafana/grafana
container_name: grafana-${teamname:-defaultASW}
profiles: ["dev"]
profiles: ["dev", "prod"]
networks:
- mynetwork
volumes:
Expand Down
17 changes: 14 additions & 3 deletions gameservice/game-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ app.use(cors());

var gameId = 0;

app.get('/generateGameUnlimitedQuestions', async (req, res) => {
app.get('/generateGame', async (req, res) => {
try {
console.log("Llegamos a crear un id del juego")
var gameId = generateAleatoryString()
Expand All @@ -39,12 +39,14 @@ app.get('/generateGameUnlimitedQuestions', async (req, res) => {


// Route for getting questions
app.get('/gameUnlimitedQuestions', async (req, res) => {
app.get('/questions', async (req, res) => {
try {
// TODO: Implement logic to fetch questions from MongoDB and send response
// const questions = await Question.find()
console.log("Llegamos a pedir preguntas")
const questionGenerated = await axios.get(`${questionService}/questions?n_preguntas=${1}`);
console.log(req.body.n_preg)
console.log(req.body.topics)
const questionGenerated = await axios.get(questionService + req.url);

Check warning

Code scanning / SonarCloud

Server-side requests should not be vulnerable to forging attacks Medium

Change this code to not construct the URL from user-controlled data. See more on SonarCloud
console.log("Pedimos las preguntas")
res.json(questionGenerated.data);
} catch (error) {
Expand All @@ -69,6 +71,15 @@ app.post('/storeGame', async (req, res) => {
}
})

app.get('/topics', async (req, res) => {
try {
const topics = await axios.get(`${questionService}/topics`)
res.json(topics.data)
} catch (error) {
res.status(500).json({ error: 'Internal Server Error' });
}
})

app.use((err, req, res, next) => {
console.error(`An error occurred: ${err}`);
res.status(500).send(`An error occurred: ${err.message}`);
Expand Down
19 changes: 15 additions & 4 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,21 @@ app.get('/history/questions', async (req, res) => {
// }
// })

app.get('/generateGameUnlimitedQuestions', async (req, res) => {
app.get('/generateGame', async (req, res) => {
try {
const response = await axios.get(gameService + '/generateGameUnlimitedQuestions')
const response = await axios.get(gameService + '/generateGame')
res.json(response.data)
} catch (error) {
catchAction(error, res)
}
})

app.get('/gameUnlimitedQuestions', async (req, res) => {
app.get('/questions', async (req, res) => {
try {
console.log("Antes de la llamada")
const response = await axios.get(gameService + `/gameUnlimitedQuestions`, req.body)
console.log(req.query)

const response = await axios.get(gameService + req.url)
Fixed Show fixed Hide fixed
console.log(response.data)
res.json(response.data)
} catch (error) {
Expand All @@ -124,6 +126,15 @@ app.post('/storeGame', async (req, res) => {
}
})

app.get('/topics', async (req, res) => {
try {
const response = await axios.get(`${gameService}/topics`)
res.json(response.data)
} catch (error) {
catchAction(error, res)
}
})

//libraries required for OpenAPI-Swagger
const swaggerUi = require('swagger-ui-express');
const fs = require("fs")
Expand Down
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esto se comiteará desde la propia rama de question-generator-service

Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function validateFields(query) {
// Route for getting questions
app.get('/questions', async (req, res) => {
try {

const { preguntas, respuestas, temas } = validateFields(req.query);
try {
const retQuestions = await QuestionGenerator.generateQuestions(preguntas, respuestas, temas);
Expand All @@ -66,6 +67,17 @@ app.get('/questions', async (req, res) => {
}
});

// Route for getting topics for questions
app.get('/topics', async (req, res) => {
try {
const topics = QuestionGenerator.getAvailableTopics();
res.send(topics);
} catch (error) {
console.error(`An error occurred: ${error.message}`);
res.status(500).json({ error: 'Internal Server Error' });
}
});

app.use((err, req, res, next) => {
console.error(`An error occurred: ${err}`);
res.status(500).send(`An error occurred: ${err.message}`);
Expand Down
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esto se comiteará desde la propia rama de question-generator-service

Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ class QuestionGenerator {
// }
];

static getAvailableTopics(){
return [ ...this.temas.keys() ];
}

static async generateQuestion(plantilla, respuestas) {
console.log("\nPlantilla:");
console.log(plantilla);
Expand Down
1 change: 1 addition & 0 deletions webapp/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<link rel="stylesheet" type="text/css" href="//use.fontawesome.com/releases/v5.7.2/css/all.css">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#f0f0f0" />
<meta name="color-scheme" content="dark">
Expand Down
65 changes: 55 additions & 10 deletions webapp/src/components/AddUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,28 @@ import Button from './Button';
const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000';

const AddUser = () => {

const [name, setName] = useState('');
const [surname, setSurname] = useState('');
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
const [confirmPassword, setConfirmPassword] = useState('');

const [error, setError] = useState('');
const [openSnackbar, setOpenSnackbar] = useState(false);

const addUser = async () => {
try {
await axios.post(`${apiEndpoint}/adduser`, { username, password });
setOpenSnackbar(true);
} catch (error) {
setError(error.response.data.error);
if (name.trim() === '' || surname.trim() === '') {
setError('Por favor, introduzca tanto el nombre como los apellidos.');
} else if(password !== confirmPassword){
setError('Las contraseñas no coinciden.');
} else {
try {
await axios.post(`${apiEndpoint}/adduser`, { username, password });
setOpenSnackbar(true);
} catch (error) {
setError(error.response.data.error);
}
}
};

Expand All @@ -27,31 +38,65 @@ const AddUser = () => {

return (
<Container className='addUser' component="main" maxWidth="xs" sx={{ marginTop: 4 }}>

<Typography component="h1" variant="h5">
Add User
Añadir Usuario
</Typography>

<TextField
name="name"
margin="normal"
fullWidth
label="Nombre"
value={name}
onChange={(e) => setName(e.target.value)}
/>

<TextField
name="surname"
margin="normal"
fullWidth
label="Apellidos"
value={surname}
onChange={(e) => setSurname(e.target.value)}
/>

<TextField
name="username"
margin="normal"
fullWidth
label="Username"
label="Usuario"
value={username}
onChange={(e) => setUsername(e.target.value)}
/>

<TextField
name="password"
margin="normal"
fullWidth
label="Password"
label="Contraseña"
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
/>
<Button text="Add user" onClick={addUser} name = "Add user"/>
<Snackbar open={openSnackbar} autoHideDuration={6000} onClose={handleCloseSnackbar} message="User added successfully" />

<TextField
name="confirmPassword"
margin="normal"
fullWidth
label="Repetir contraseña"
type="password"
value={confirmPassword}
onChange={(e) => setConfirmPassword(e.target.value)}
/>

<Button text="Añadir" onClick={addUser} name = "Add user"/>

<Snackbar open={openSnackbar} autoHideDuration={6000} onClose={handleCloseSnackbar} message="Usuario añadido correctamente" />
{error && (
<Snackbar open={!!error} autoHideDuration={6000} onClose={() => setError('')} message={`Error: ${error}`} />
)}

</Container>
);
};
Expand Down
58 changes: 48 additions & 10 deletions webapp/src/components/AddUser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,80 @@ describe('AddUser component', () => {
it('should add user successfully', async () => {
render(<AddUser />);

const usernameInput = screen.getByLabelText(/Username/i);
const passwordInput = screen.getByLabelText(/Password/i);
const nameInput = screen.getByLabelText(/Nombre/);
const surnameInput = screen.getByLabelText(/Apellidos/i);
const usernameInput = screen.getByLabelText(/Usuario/i);
const passwordInput = screen.getAllByLabelText(/Contraseña/i)[0];
const confirmPasswordInput = screen.getByLabelText(/Repetir contraseña/i);
const addUserButton = document.getElementsByClassName('inner')[0]

// Mock the axios.post request to simulate a successful response
mockAxios.onPost('http://localhost:8000/adduser').reply(200);

// Simulate user input
fireEvent.change(nameInput, { target: { value: 'testUser' } });
fireEvent.change(surnameInput, { target: { value: 'testUser' } });
fireEvent.change(usernameInput, { target: { value: 'testUser' } });
fireEvent.change(passwordInput, { target: { value: 'testPassword' } });
fireEvent.change(confirmPasswordInput, { target: { value: 'testPassword' } });

// Trigger the add user button click
fireEvent.click(addUserButton);

// Wait for the Snackbar to be open
await waitFor(() => {
expect(screen.getByText(/User added successfully/i)).toBeInTheDocument();
expect(screen.getByText(/Usuario añadido correctamente/i)).toBeInTheDocument();
});
});

it('should handle error when adding user', async () => {
it('try to add user but not introduce name', async () => {
render(<AddUser />);

const usernameInput = screen.getByLabelText(/Username/i);
const passwordInput = screen.getByLabelText(/Password/i);
const addUserButton = document.getElementsByClassName('inner')[0]
const addUserButton = document.getElementsByClassName('inner')[0];

// Trigger the add user button click
fireEvent.click(addUserButton);

// Wait for the Snackbar to be open
await waitFor(() => {
expect(screen.getByText(/Por favor, introduzca tanto el nombre como los apellidos./i)).toBeInTheDocument();
});
});

it('try to add user but different passwords', async () => {
render(<AddUser />);

// Simulate user input
fireEvent.change(screen.getByLabelText(/Nombre/), { target: { value: 'userForTest' } });
fireEvent.change(screen.getByLabelText(/Apellidos/i), { target: { value: 'userForTest' } });
fireEvent.change(screen.getByLabelText(/Usuario/i), { target: { value: 'userForTest' } });
fireEvent.change(screen.getAllByLabelText(/Contraseña/i)[0], { target: { value: 'testPassword' } });
fireEvent.change(screen.getByLabelText(/Repetir contraseña/i), { target: { value: 'password' } });

// Trigger the add user button click
fireEvent.click(document.getElementsByClassName('inner')[0]);

// Wait for the Snackbar to be open
await waitFor(() => {
expect(screen.getByText(/Las contraseñas no coinciden./i)).toBeInTheDocument();
});
});

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

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

// Simulate user input
fireEvent.change(usernameInput, { target: { value: 'testUser' } });
fireEvent.change(passwordInput, { target: { value: 'testPassword' } });
fireEvent.change(screen.getByLabelText(/Nombre/), { target: { value: 'testUser' } });
fireEvent.change(screen.getByLabelText(/Apellidos/i), { target: { value: 'testUser' } });
fireEvent.change(screen.getByLabelText(/Usuario/i), { target: { value: 'testUser' } });
fireEvent.change(screen.getAllByLabelText(/Contraseña/i)[0], { target: { value: 'testPassword' } });
fireEvent.change(screen.getByLabelText(/Repetir contraseña/i), { target: { value: 'testPassword' } });

// Trigger the add user button click
fireEvent.click(addUserButton);
fireEvent.click(document.getElementsByClassName('inner')[0]);

// Wait for the error Snackbar to be open
await waitFor(() => {
Expand Down
Loading