Skip to content

Commit

Permalink
Try to reduce duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Mario committed Apr 14, 2024
1 parent 57b44f3 commit 22dba52
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions users/userservice/user-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ const { MongoMemoryServer } = require('mongodb-memory-server');
let mongoServer;
let app;


let newUser = {
email: '[email protected]',
username: 'testuser',
password: 'testpassword'
};

beforeAll(async () => {
mongoServer = await MongoMemoryServer.create();
Expand All @@ -18,14 +22,16 @@ afterAll(async () => {
await mongoServer.stop();
});

afterEach(async () => {
newUser = {
email: '[email protected]',
username: 'testuser',
password: 'testpassword'
};
})

describe('User Service', () => {
it('should add a new user on POST /adduser', async () => {
const newUser = {
email: '[email protected]',
username: 'testuser',
password: 'testpassword'
};

const response = await request(app).post('/adduser').send(newUser);
expect(response.status).toBe(200);
expect(response.body).toHaveProperty('username', 'testuser');
Expand All @@ -38,23 +44,15 @@ describe('User Service', () => {
});

it('Should not register user /adduser', async () => {
const newUser = {
email: '[email protected]',
username: 'testuser',
password: 'test'
};
newUser.email = '[email protected]';

const response = await request(app).post('/adduser').send(newUser);
expect(response.status).toBe(400);
expect(response.body).toHaveProperty('error', 'Username already in use');
});

it('Should not register user /adduser', async () => {
const newUser = {
email: '[email protected]',
username: 'testuser2',
password: 'password'
};
newUser.username = 'testuser2';

const response = await request(app).post('/adduser').send(newUser);
expect(response.status).toBe(400);
Expand Down

0 comments on commit 22dba52

Please sign in to comment.