diff --git a/gatewayservice/gateway-service.test.js b/gatewayservice/gateway-service.test.js index 32aeaaf..e61ac63 100644 --- a/gatewayservice/gateway-service.test.js +++ b/gatewayservice/gateway-service.test.js @@ -42,7 +42,7 @@ describe('Gateway Service', () => { .post('/adduser') .send({ username: 'newuser', password: 'newpassword' }); - // expect(response.statusCode).toBe(200); + expect(response.body.userId).toBe('mockedUserId'); }); diff --git a/users/userservice/UserController.js b/users/userservice/UserController.js index 2fa92f5..deeb273 100644 --- a/users/userservice/UserController.js +++ b/users/userservice/UserController.js @@ -6,32 +6,29 @@ const isValidUuidV4 = require('./util/ValidateUUID'); let UserController = { updateLastGame: async (req, res) => { - const { gameUUID, players } = req.body; - for (const p of players) { - try { - let user; - - const isValid = isValidUuidV4(p.uuid); - if(!isValid){ - throw new Error(`Invalid UUID provided`); - } - - user = await User.findOne({ uuid: p.uuid }); + const { gameUUID, players } = req.body; - if (user) { - user.lastGameId = gameUUID; - await user.save(); - } else { - throw new Error(`User with UUID ${p.uuid} not found.`); - } - } catch (error) { - return res.status(500).json({ error: error.message }); - } - + for (const p of players) { + try { + const isValid = isValidUuidV4(p.uuid); + if (!isValid) { + throw new Error(`Invalid UUID provided`); + } + const user = await User.findOne({ uuid: p.uuid }); + + if (user) { + user.lastGameId = gameUUID; + await user.save(); + } else { + throw new Error(`User with UUID ${p.uuid} not found`); + } + } catch (error) { + return res.status(500).json({ error: error.message }); } + } - const nPlayers = players.length; - res.json({ "message": `Last game updated for ${nPlayers} users.` }); + const nPlayers = players.length; + res.json({ message: `Last game updated for ${nPlayers} users.` }); }, addUser: async (req, res) => { try {