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.
Added email field on login and register and be able to login with use…
…rname or email
- Loading branch information
1 parent
22dba52
commit bb17d39
Showing
6 changed files
with
36 additions
and
26 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
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 |
---|---|---|
|
@@ -7,16 +7,15 @@ let mongoServer; | |
let app; | ||
|
||
//test user | ||
const user = { | ||
email: '[email protected]', | ||
let user = { | ||
username: 'testuser', | ||
password: 'testpassword', | ||
}; | ||
|
||
async function addUser(user){ | ||
const hashedPassword = await bcrypt.hash(user.password, 10); | ||
const newUser = new User({ | ||
email: user.email, | ||
email: "user@gmail.com", | ||
username: user.username, | ||
password: hashedPassword, | ||
createdAt: new Date() | ||
|
@@ -46,14 +45,21 @@ describe('Auth Service', () => { | |
expect(response.body).toHaveProperty('username', 'testuser'); | ||
}); | ||
|
||
it('Should show missing field user /login', async () => { | ||
it('Should perform a login operation with email /login', async () => { | ||
user.username = "[email protected]"; | ||
const response = await request(app).post('/login').send(user); | ||
expect(response.status).toBe(200); | ||
expect(response.body).toHaveProperty('username', 'testuser'); | ||
}); | ||
|
||
it('Should show missing field username /login', async () => { | ||
const response = await request(app).post('/login').send(); | ||
expect(response.status).toBe(400); | ||
expect(response.body).toHaveProperty('error', 'Missing required field: email'); | ||
expect(response.body).toHaveProperty('error', 'Missing required field: username'); | ||
}); | ||
|
||
it('Should show invalid credentials /login', async () => { | ||
const user2 = {email:"[email protected]" ,username:"Hello", password:"world"} | ||
const user2 = {username:"Hello", password:"world"} | ||
const response = await request(app).post('/login').send(user2); | ||
expect(response.status).toBe(400); | ||
expect(response.body).toHaveProperty('error', 'Invalid credentials'); | ||
|
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
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
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
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