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
62d7d76
commit 46ca537
Showing
6 changed files
with
43 additions
and
12 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
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 |
---|---|---|
|
@@ -8,13 +8,15 @@ let app; | |
|
||
//test user | ||
const user = { | ||
email: '[email protected]', | ||
username: 'testuser', | ||
password: 'testpassword', | ||
}; | ||
|
||
async function addUser(user){ | ||
const hashedPassword = await bcrypt.hash(user.password, 10); | ||
const newUser = new User({ | ||
email: user.email, | ||
username: user.username, | ||
password: hashedPassword, | ||
createdAt: new Date() | ||
|
@@ -47,11 +49,11 @@ describe('Auth Service', () => { | |
it('Should show missing field user /login', async () => { | ||
const response = await request(app).post('/login').send(); | ||
expect(response.status).toBe(400); | ||
expect(response.body).toHaveProperty('error', 'Missing required field: username'); | ||
expect(response.body).toHaveProperty('error', 'Missing required field: email'); | ||
}); | ||
|
||
it('Should show invalid credentials /login', async () => { | ||
const user2 = {username:"Hello", password:"world"} | ||
const user2 = {email:"[email protected]" ,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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
const request = require('supertest'); | ||
const { MongoMemoryServer } = require('mongodb-memory-server'); | ||
const { email } = require('asciidoctor-emoji/dist/node/twemoji-map'); | ||
|
||
let mongoServer; | ||
let app; | ||
|
@@ -21,6 +22,7 @@ afterAll(async () => { | |
describe('User Service', () => { | ||
it('should add a new user on POST /adduser', async () => { | ||
const newUser = { | ||
email: '[email protected]', | ||
username: 'testuser', | ||
password: 'testpassword' | ||
}; | ||
|
@@ -33,11 +35,12 @@ describe('User Service', () => { | |
it('Should show missing field user /adduser', async () => { | ||
const response = await request(app).post('/adduser').send(); | ||
expect(response.status).toBe(400); | ||
expect(response.body).toHaveProperty('error', 'Missing required field: username'); | ||
expect(response.body).toHaveProperty('error', 'Missing required field: email'); | ||
}); | ||
|
||
it('Should not register user /adduser', async () => { | ||
const newUser = { | ||
email: '[email protected]', | ||
username: 'testuser', | ||
password: 'testpassword' | ||
}; | ||
|
@@ -47,6 +50,16 @@ describe('User Service', () => { | |
expect(response.body).toHaveProperty('error', 'Username already in use'); | ||
}); | ||
|
||
|
||
it('Should not register user /adduser', async () => { | ||
const newUser = { | ||
email: '[email protected]', | ||
username: 'testuser2', | ||
password: 'testpassword' | ||
}; | ||
|
||
const response = await request(app).post('/adduser').send(newUser); | ||
expect(response.status).toBe(400); | ||
expect(response.body).toHaveProperty('error', 'Email already in use'); | ||
}); | ||
|
||
}); |