Skip to content

Commit

Permalink
Added test for user model
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Mario committed Apr 28, 2024
1 parent 1fbf3f0 commit 4ff2d02
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions users/userservice/user-service.test.js
Original file line number Diff line number Diff line change
@@ -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', () => ({
Expand Down Expand Up @@ -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: '[email protected]',
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');
})

});

Expand Down

0 comments on commit 4ff2d02

Please sign in to comment.