Skip to content

Commit

Permalink
Merge pull request #93 from Arquisoft/lucia
Browse files Browse the repository at this point in the history
Añado tests de gateway-service
  • Loading branch information
Pedro-C-M authored Mar 12, 2024
2 parents b66cce8 + d701146 commit 95ac9c9
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 162 deletions.
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.

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)));
});





});

0 comments on commit 95ac9c9

Please sign in to comment.