From 7d57ea5f1b133f990ba29811d1b6ef6af0b24666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Fern=C3=A1ndez=20Noriega?= Date: Sun, 7 Apr 2024 13:37:25 +0200 Subject: [PATCH] User service test fixed --- users/userservice/user-service.js | 3 ++- users/userservice/user-service.test.js | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/users/userservice/user-service.js b/users/userservice/user-service.js index 7cdf1c3..2e0e67e 100644 --- a/users/userservice/user-service.js +++ b/users/userservice/user-service.js @@ -122,8 +122,9 @@ app.post('/adduser', async (req, res) => { }); await newUser.save(); - res.json(newUser); + res.status(200).json(newUser); } catch (error) { + console.log(error) res.status(400).json({ error: error.message }); }}); diff --git a/users/userservice/user-service.test.js b/users/userservice/user-service.test.js index 8dd8ea1..89fc9d9 100644 --- a/users/userservice/user-service.test.js +++ b/users/userservice/user-service.test.js @@ -20,11 +20,16 @@ describe('User Service', () => { it('should add a new user on POST /adduser', async () => { const newUser = { username: 'testuser', + email: 'testemail', password: 'testpassword', }; - const response = await request(app).post('/adduser').send(newUser); + const response = await request(app) + .post('/adduser') + .send(newUser); expect(response.status).toBe(200); - expect(response.body).toHaveProperty('username', 'testuser'); + expect(response.body).toHaveProperty('username', newUser.username); + expect(response.body).toHaveProperty('email', newUser.email); + expect(response.body.password).not.toBe(newUser.password); }); });