-
Notifications
You must be signed in to change notification settings - Fork 1
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
d72bb07
commit 2fa7f01
Showing
5 changed files
with
80 additions
and
35 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 |
---|---|---|
|
@@ -22,12 +22,44 @@ describe('Register User E2E', () => { | |
const name = 'John' | ||
const surname = 'Doe' | ||
const password = 'password' | ||
const avatar_url = 'avatar_url' | ||
|
||
const is_google = true | ||
|
||
const registerUserResponse = await request(app.server).post('/user').send({ | ||
email, | ||
name, | ||
surname, | ||
password, | ||
avatar_url, | ||
is_google, | ||
}) | ||
|
||
const userFoundedDb = await userRepository.findByEmail(email) | ||
|
||
expect(registerUserResponse.statusCode).toEqual(201) | ||
expect(userFoundedDb).not.toBeNull() | ||
expect(userFoundedDb).toEqual( | ||
expect.objectContaining({ | ||
email, | ||
avatar_url, | ||
is_google, | ||
}), | ||
) | ||
|
||
const passwordMatches = await compare(password, userFoundedDb.password_hash) | ||
expect(passwordMatches).toEqual(true) | ||
}) | ||
|
||
it('should be able to register a new user without avatar_url and without surname', async () => { | ||
const email = '[email protected]' | ||
const name = 'John' | ||
const password = 'password' | ||
|
||
const registerUserResponse = await request(app.server).post('/user').send({ | ||
email, | ||
name, | ||
password, | ||
}) | ||
|
||
const userFoundedDb = await userRepository.findByEmail(email) | ||
|
@@ -37,6 +69,9 @@ describe('Register User E2E', () => { | |
expect(userFoundedDb).toEqual( | ||
expect.objectContaining({ | ||
email, | ||
is_google: false, | ||
avatar_url: | ||
'https://orangeapp-contents-prod.s3.amazonaws.com/avatar1.png', | ||
}), | ||
) | ||
|
||
|
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,34 +1,48 @@ | ||
import { expect, describe, it, beforeEach } from 'vitest'; | ||
import { CreateUserUseCase } from '../user/createUserUseCase'; | ||
import { compare } from 'bcryptjs'; | ||
import { InMemoryUserRepository } from '../../repositories/in-memory-db/inMemoryUserRepository'; | ||
import { UserAlreadyExistsError } from '../errors/user-already-exists-error'; | ||
import { UserRepository } from '../../repositories/user-repository'; | ||
import { expect, describe, it, beforeEach } from 'vitest' | ||
import { CreateUserUseCase } from '../user/createUserUseCase' | ||
import { compare } from 'bcryptjs' | ||
import { InMemoryUserRepository } from '../../repositories/in-memory-db/inMemoryUserRepository' | ||
import { UserAlreadyExistsError } from '../errors/user-already-exists-error' | ||
import { UserRepository } from '../../repositories/user-repository' | ||
|
||
let usersRepository: UserRepository; | ||
let createUserUseCase: CreateUserUseCase; | ||
let usersRepository: UserRepository | ||
let createUserUseCase: CreateUserUseCase | ||
|
||
describe('Register Use Case', () => { | ||
|
||
beforeEach(() => { | ||
usersRepository = new InMemoryUserRepository() | ||
createUserUseCase = new CreateUserUseCase(usersRepository) | ||
}) | ||
|
||
it('should be able to register', async () => { | ||
|
||
it('should be able to register', async () => { | ||
const { user } = await createUserUseCase.execute({ | ||
name: 'John', | ||
surname: 'Doe', | ||
email: '[email protected]', | ||
password: '123456', | ||
avatar_url: 'avatar_url', | ||
is_google: true, | ||
}) | ||
|
||
expect(user.email).toEqual('[email protected]') | ||
expect(user.is_google).toEqual(true) | ||
}) | ||
|
||
it('should be able to register a user without avatar_url and without surname ', async () => { | ||
const { user } = await createUserUseCase.execute({ | ||
name: 'John', | ||
email: '[email protected]', | ||
password: '123456', | ||
}) | ||
|
||
expect(user.email).toEqual('[email protected]') | ||
expect(user.is_google).toEqual(false) | ||
expect(user.avatar_url).toEqual( | ||
'https://orangeapp-contents-prod.s3.amazonaws.com/avatar1.png', | ||
) | ||
}) | ||
|
||
it('should hash user password upon registration', async () => { | ||
|
||
const { user } = await createUserUseCase.execute({ | ||
name: 'John', | ||
surname: 'Doe', | ||
|
@@ -45,7 +59,6 @@ describe('Register Use Case', () => { | |
}) | ||
|
||
it('should not be able to register with same email twice', async () => { | ||
|
||
const email = '[email protected]' | ||
|
||
await createUserUseCase.execute({ | ||
|
@@ -63,7 +76,5 @@ describe('Register Use Case', () => { | |
password: '123456', | ||
}), | ||
).rejects.toBeInstanceOf(UserAlreadyExistsError) | ||
|
||
}) | ||
|
||
}) |
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