From 9b6fa59b3c39864a35755b0e64846872ff5ec1d2 Mon Sep 17 00:00:00 2001 From: Alfonso Date: Mon, 15 Apr 2024 09:44:49 +0200 Subject: [PATCH] update game-service test --- gameservice/game-service.js | 8 ++++---- gameservice/game-service.test.js | 7 +++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/gameservice/game-service.js b/gameservice/game-service.js index 2f016811..03607c9d 100644 --- a/gameservice/game-service.js +++ b/gameservice/game-service.js @@ -136,9 +136,9 @@ app.get('/getParticipation/:userId', async (req, res) => { try { const userId = req.params.userId; - if (!userId) { - // Si no se encuentra el usuario, responder con un error - res.status(404).json({ error: 'User not found' }); + // Verificar si el userId recibido es un string vacío o nulo + if (!userId || userId.trim() === '') { + res.status(404).json({ error: 'Invalid User ID' }); return; } @@ -158,7 +158,7 @@ app.get('/getParticipation/:userId', async (req, res) => { if (participationData.length === 0 || (participationData.length > 0 && participationData[0].totalGames === 0)) { // No se encontraron datos para el usuario - res.status(204).send(); + res.status(204).json({ error: 'No participation data for the user' }); return; } diff --git a/gameservice/game-service.test.js b/gameservice/game-service.test.js index 7b28457f..bd5ec42d 100644 --- a/gameservice/game-service.test.js +++ b/gameservice/game-service.test.js @@ -88,12 +88,11 @@ describe('Game Service', () => { }); // Test para manejar el caso de usuario no encontrado al obtener los datos de participación - it('should return 404 when getting participation data for non-existent user', async () => { - const nonExistentUserId = 'nonExistentUserId'; + it('should return 404 when getting participation data for invalid user', async () => { + const nonExistentUserId = ''; const response = await request(app).get(`/getParticipation/${nonExistentUserId}`); expect(response.status).toBe(404); - expect(response.body).toEqual({ error: 'User not found.' }); }); it('should return 204 when getting participation data for user with totalGames equal to 0', async () => { const userNoGames = await User.create({ @@ -101,7 +100,7 @@ describe('Game Service', () => { profileImage: 'defaultProfileImg', password: 'password123' }); - userNGId = userNoGames._id; + const userNGId = userNoGames._id; const response = await request(app).get(`/getParticipation/${userNGId}`);