Skip to content

Commit

Permalink
Añado tests de gateway-service
Browse files Browse the repository at this point in the history
  • Loading branch information
UO283535 committed Mar 12, 2024
1 parent 407d226 commit d701146
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 159 deletions.
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 d701146

Please sign in to comment.