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

Me añado los cambios de mis compañeros a mi rama #98

Merged
merged 11 commits into from
Mar 13, 2024
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,19 @@ This repo is a basic application composed of several components.
Both the user and auth service share a Mongo database that is accessed with mongoose.

## Members of the group
Adrián Santamarina

Sonia Moro Lauda

Lucía Villanueva Rodríguez

Pedro Castro Montes

Adrián Santamarina Romero

David González González

## Quick start guide

## Team Members
### David Gonzalez

### Using docker

Expand Down
158 changes: 0 additions & 158 deletions WikidataPrueba/consultas.txt

This file was deleted.

Binary file added docs/images/06-generateQuestion.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/06-loginSecuencia.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/images/06-nextQuestion.png
Binary file not shown.
Binary file modified docs/images/06-registerSecuencia.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/07-diagramaDespliegue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/images/Sin título.png
Binary file not shown.
17 changes: 7 additions & 10 deletions docs/src/06_runtime_view.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,10 @@ image::06-loginSecuencia.png["Login secuence diagram image"]

=== Request a question

image::06-nextQuestion.png["NextQuestion secuence diagram image"]

1. The user asks for a new question
2. The app redirects that request to the QuestionGenerator
3. The QuestionGenerator generates a heather for the question
4. The QuestionGenerator requests the correct answer to WikiData
5. WikiData sends that answer data
6. The QuestionGenerator builds the question with the answer and wrong options
7. The built question is sent to the app
8. The app shows the question to the User
image::06-generateQuestion.png["NextQuestion secuence diagram image"]

1. The QuestionService wants to generate a question
2. It requests all the necesary info to build a question to WikiData
3. WikiData responds with the requested data
4. The QuestionService builds the question with the data recieved
5. Finally the QuestionService writes the new question in the QuestionsDB
12 changes: 6 additions & 6 deletions docs/src/07_deployment_view.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ ifndef::imagesdir[:imagesdir: ../images]
== Deployment View


image::07-diagramaDespliegue.png["Building Block general diagram"]
image::07-diagramaDespliegue.PNG["Building Block general diagram"]

Basically when a user wants to use the application, using his web browser
he can connect to the application server where the web app will use some
services also alocated there such as the QuestionGenerator or the LoginManager.
Also these services make use of the WikiData API and database and also of
a database unique for the application to save things as player statistics
or info of them.
he can connect to the application server that is a VM in hosted in Azure
orientated to microservices. That means that all the modules inside it
are dockerized in a container. The QuestionGenerator interacts with WikiData
throught their API and we have also two MongoDB databases one for users
and another to store questions.
81 changes: 80 additions & 1 deletion gatewayservice/gateway-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ describe('Gateway Service', () => {
}
});


// Test de /health endpoint
it('should perform the health request', async () => {
const response = await request(app).get('/health').send();

expect(response.statusCode).toBe(200);
});

// Test /login endpoint
it('should forward login request to auth service', async () => {
const response = await request(app)
Expand All @@ -28,6 +36,8 @@ describe('Gateway Service', () => {
expect(response.body.token).toBe('mockedToken');
});



// Test /adduser endpoint
it('should forward add user request to user service', async () => {
const response = await request(app)
Expand All @@ -37,4 +47,73 @@ describe('Gateway Service', () => {
expect(response.statusCode).toBe(200);
expect(response.body.userId).toBe('mockedUserId');
});
});



//CAso de prueba para un endpoint inexistente


it('should return 404 for nonexistent endpoint', async()=>{
const response = await request(app)
.get('/nonexistent');

expect(response.statusCode).toBe(404);
});


// Test /getQuestion endpoint
axios.get.mockImplementation((url, data) => {
if (url.endsWith("/getQuestion")) {
return Promise.resolve({
data: [
{
pregunta: "¿Cuál es la capital de España?",
respuestas: ["Madrid", "Paris", "Londres", "Berlin"],
correcta: "Madrid"
}
],
});
}
});

//Verifica si el manejo de errores funciona correctamente cuando la llamada al servicio de preguntas falla.
it('should handle error when fetching question', async () => {
const questionServiceUrl = 'http://localhost:8003';
const errorMessage = 'Network Error';
axios.get.mockImplementationOnce(() => Promise.reject(new Error(errorMessage)));
});

it('should forward get question request to question service', async () => {
const questionServiceUrl = 'http://localhost:8003';
const data = {
pregunta: '¿Cuál es la capital de Francia?',
respuestas: ['Berlin', 'Paris', 'Londres', 'Madrid'],
correcta: 'Helsinki',
};
axios.get.mockImplementationOnce(() => Promise.resolve({ data }));
// Agrega tus expectativas aquí
});

it('should forward get question request to question generate service', async () => {
const questionServiceUrl = 'http://localhost:8003/generateQuestions';
const data = {
pregunta: '¿Cuál es la capital de Francia?',
respuestas: ['Berlin', 'Paris', 'Londres', 'Madrid'],
correcta: 'Helsinki',
};
axios.get.mockImplementationOnce(() => Promise.resolve({ data }));
// Agrega tus expectativas aquí
});

//Verifica si el manejo de errores funciona correctamente cuando la llamada al servicio de preguntas falla.
it('should handle error when fetching question', async () => {
const questionServiceUrl = 'http://localhost:8003/generateQuestions';
const errorMessage = 'Network Error';
axios.get.mockImplementationOnce(() => Promise.reject(new Error(errorMessage)));
});





});
7 changes: 7 additions & 0 deletions webapp/links.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Paleta de colores-->
fondo: https://www.canva.com/colors/color-palettes/northern-lights-4/
botones: https://www.canva.com/colors/color-palettes/arts-and-crafts/
Generador css-->https://front-end-tools.com/en/generateButton/
Chakra UI-->https://chakra-ui.com/docs/styled-system/style-props

Para empezar en local: npm start
3 changes: 2 additions & 1 deletion webapp/src/components/AnswerButton.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Button} from '@chakra-ui/react'

export function AnswerButton({text, colorFondo}){
export function AnswerButton({text, colorFondo, onClick}){

return(
<Button
Expand All @@ -14,6 +14,7 @@ export function AnswerButton({text, colorFondo}){
_hover={{
transform:"scale(1.05)",
}}
onClick = {onClick}
>
{text}</Button>
)
Expand Down
Loading