From 4ff2d02a673b66530eca6311c0e7dce7e42cab0d Mon Sep 17 00:00:00 2001 From: Mister-Mario Date: Sun, 28 Apr 2024 02:34:15 +0200 Subject: [PATCH] Added test for user model --- users/userservice/user-service.test.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/users/userservice/user-service.test.js b/users/userservice/user-service.test.js index 19cff1d..f408d9e 100644 --- a/users/userservice/user-service.test.js +++ b/users/userservice/user-service.test.js @@ -1,6 +1,7 @@ const request = require('supertest'); const { MongoMemoryServer } = require('mongodb-memory-server'); const jwt = require('jsonwebtoken'); +const User = require('./user-model'); // Mock the `jsonwebtoken` module jest.mock('jsonwebtoken', () => ({ @@ -68,6 +69,24 @@ describe('User Service /adduser', () => { expect(response.status).toBe(400); expect(response.body).toHaveProperty('error', 'Email already in use'); }); + + it('Should not register user /adduser', async () => { + + var newUser4 = { + email: 'example4@example.com', + username: 'testuser4', + password: 'testpassword', + repeatPassword: 'testpassword' + }; + + var newUser4DB = new User(newUser4); + await newUser4DB.save(); + + + const response = await request(app).post('/adduser').send(newUser); + expect(response.status).toBe(400); + expect(response.body).toHaveProperty('error', 'Username already in use'); + }) });