-
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.
Fix addressing comments and removing prisma repository.
- Loading branch information
1 parent
bb6eed1
commit 64c2f88
Showing
3 changed files
with
30 additions
and
50 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,29 +1,35 @@ | ||
import { expect, describe, it } from "vitest"; | ||
import { CreateUseCase } from "./createUseCase"; | ||
import { compare } from "bcryptjs"; | ||
import { InMemoryUserRepository } from "../repositories/in-memory-db/inMemoryUserRepository"; | ||
import { UserAlreadyExistsError } from "./errors/user-already-exists-error"; | ||
import { expect, describe, it, beforeEach } from 'vitest'; | ||
import { CreateUserUseCase } from './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; | ||
|
||
describe('Register Use Case', () => { | ||
|
||
beforeEach(() => { | ||
usersRepository = new InMemoryUserRepository() | ||
createUserUseCase = new CreateUserUseCase(usersRepository) | ||
}) | ||
|
||
it('should be able to register', async () => { | ||
const usersRepository = new InMemoryUserRepository | ||
const createUseCase = new CreateUseCase(usersRepository) | ||
|
||
const { user } = await createUseCase.execute({ | ||
const { user } = await createUserUseCase.execute({ | ||
name: 'John', | ||
surname: 'Doe', | ||
email: '[email protected]', | ||
password: '123456', | ||
}) | ||
|
||
expect(user.id).toEqual(expect.any(String)) | ||
expect(user.email).toEqual('[email protected]') | ||
}) | ||
|
||
it('should hash user password upon registration', async () => { | ||
const usersRepository = new InMemoryUserRepository | ||
const createUseCase = new CreateUseCase(usersRepository) | ||
|
||
const { user } = await createUseCase.execute({ | ||
|
||
const { user } = await createUserUseCase.execute({ | ||
name: 'John', | ||
surname: 'Doe', | ||
email: '[email protected]', | ||
|
@@ -39,20 +45,18 @@ describe('Register Use Case', () => { | |
}) | ||
|
||
it('should not be able to register with same email twice', async () => { | ||
const usersRepository = new InMemoryUserRepository | ||
const createUseCase = new CreateUseCase(usersRepository) | ||
|
||
const email = '[email protected]' | ||
|
||
await createUseCase.execute({ | ||
await createUserUseCase.execute({ | ||
name: 'John', | ||
surname: 'Doe', | ||
email, | ||
password: '123456', | ||
}) | ||
|
||
await expect(() => | ||
createUseCase.execute({ | ||
createUserUseCase.execute({ | ||
name: 'John', | ||
surname: 'Doe', | ||
email, | ||
|
@@ -63,4 +67,3 @@ describe('Register Use Case', () => { | |
}) | ||
|
||
}) | ||
|
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