generated from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
57b44f3
commit 22dba52
Showing
1 changed file
with
15 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(); | ||
|
@@ -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'); | ||
|
@@ -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); | ||
|