diff --git a/gatewayservice/gateway-service.js b/gatewayservice/gateway-service.js index 9fe898b..49b59c0 100644 --- a/gatewayservice/gateway-service.js +++ b/gatewayservice/gateway-service.js @@ -41,6 +41,7 @@ app.post('/adduser', async (req, res) => { try { // Forward the add user request to the user service const userResponse = await axios.post(userServiceUrl+'/adduser', req.body); + console.log(userResponse) res.json(userResponse.data); } catch (error) { manageError(res, error); @@ -231,7 +232,7 @@ function manageError(res, error){ if(error.response) //Some microservice responded with an error res.status(error.response.status).json({ error: error.response.data.error }); else //Some other error - res.status(500).json({error : "Interanl server error"}) + res.status(500).json({error : "Internal server error"}) } module.exports = server diff --git a/gatewayservice/gateway-service.test.js b/gatewayservice/gateway-service.test.js index 550c402..a51f5f1 100644 --- a/gatewayservice/gateway-service.test.js +++ b/gatewayservice/gateway-service.test.js @@ -14,7 +14,7 @@ jest.mock('axios'); -describe('Gateway Service with token mock', () => { +describe('Gateway Service with mocked micro services', () => { // Mock responses from external services axios.post.mockImplementation((url, data) => { @@ -156,4 +156,36 @@ function checkRecord(response){ function checkQuestion(response){ expect(response.statusCode).toBe(200); expect(response.body[0]).toHaveProperty('question', "¿Cuál es la población de Oviedo?"); -} \ No newline at end of file +} + +describe('Gateway Service without mocked micro services', () => { + + it('should not forward login request and give 500', async () => { + try{ + await request(app) + .post('/login') + .send({ username: 'testuser', password: 'testpassword' }); + + } catch(error){ + expect(error.response.status).toBe(500); + expect(error.response.data.error).toBe('Internal server error'); + } + }); + + it('should not forward login request and give 500', async () => { + axios.post.mockImplementation((url, data) => { + if (url.endsWith('/login')) { + throw new Error("Important information"); + } + }); + try{ + await request(app) + .post('/login') + .send({ username: 'testuser', password: 'testpassword' }); + + } catch(error){ + expect(error.response.status).toBe(500); + expect(error.response.data.error).toBe('Internal server error'); + } + }); +});