-
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.
Checking if the user data is coming.
- Loading branch information
1 parent
2fcf61e
commit 350d2f9
Showing
9 changed files
with
188 additions
and
83 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
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 |
---|---|---|
|
@@ -3,33 +3,10 @@ import { UserRepository } from '../user-repository' | |
import { randomUUID } from 'crypto' | ||
|
||
export class InMemoryUserRepository implements UserRepository { | ||
private db: User[] = [] | ||
public db: User[] = [] | ||
|
||
|
||
// This is a way to test our controllers without necessartralyy add the | ||
// db repository; Once the program starts, one user is added to User[] and | ||
// you can get http://localhost:3333/user/9600de4f-8d18-4e69-ba7a-ed7fa210618d | ||
// to check the routes; | ||
constructor() {} | ||
|
||
// this constructor will be delete later; | ||
constructor(){ | ||
|
||
const email = '[email protected]' | ||
const name = 'John' | ||
const surname = 'Doe' | ||
const password_hash = 'password_hash' | ||
const id = '9600de4f-8d18-4e69-ba7a-ed7fa210618d' | ||
|
||
this.create({ | ||
id, | ||
name, | ||
surname, | ||
email, | ||
password_hash, | ||
}) | ||
|
||
} | ||
|
||
async findByEmail(email: string): Promise<User | null> { | ||
const User = this.db.find((User) => User.email === email) | ||
|
||
|
@@ -50,8 +27,6 @@ export class InMemoryUserRepository implements UserRepository { | |
return User | ||
} | ||
|
||
// create in a in-memory database is just used to help us on unit tests; | ||
// that's why is not in our interface :) | ||
async create({ | ||
id, | ||
name, | ||
|
@@ -60,7 +35,7 @@ export class InMemoryUserRepository implements UserRepository { | |
password_hash, | ||
}: Prisma.UserCreateInput) { | ||
const user: User = { | ||
id: (id == undefined) ? randomUUID() : id, | ||
id: id === undefined ? randomUUID() : id, | ||
name, | ||
surname, | ||
|
||
|
@@ -69,11 +44,11 @@ export class InMemoryUserRepository implements UserRepository { | |
|
||
created_at: new Date(), | ||
updated_at: new Date(), | ||
avatar_url: null, | ||
} | ||
|
||
this.db.push(user) | ||
|
||
return user | ||
} | ||
|
||
} |
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,17 +1,24 @@ | ||
import { expect, describe, it, beforeEach } from 'vitest' | ||
|
||
import { InMemoryProjectRepository } from '../../repositories/in-memory-db/inMemoryProjectRepository' | ||
import { ProjectRepository } from '../../repositories/project-repository' | ||
import { ResourceNotFoundError } from '../errors/ResourceNotFoundError' | ||
import { EditProjectUseCase } from './editProjectUseCase' | ||
import { User } from '@prisma/client' | ||
|
||
let projectRepository: ProjectRepository | ||
let projectRepository: InMemoryProjectRepository | ||
let editProjectUseCase: EditProjectUseCase | ||
let newUser: User | ||
|
||
describe('Edit Project By Id Use Case', () => { | ||
beforeEach(() => { | ||
beforeEach(async () => { | ||
projectRepository = new InMemoryProjectRepository() | ||
editProjectUseCase = new EditProjectUseCase(projectRepository) | ||
newUser = await projectRepository.dbUser.create({ | ||
name: 'John', | ||
surname: 'Doe', | ||
email: '[email protected]', | ||
password_hash: '123456', | ||
}) | ||
}) | ||
|
||
it('should be able edit one project by ID', async () => { | ||
|
@@ -20,7 +27,7 @@ describe('Edit Project By Id Use Case', () => { | |
description: 'Best Project', | ||
tags: ['react', 'node'], | ||
link: 'https://github.com/luiseduardo3/nodets-petcanil', | ||
user_id: 'user_id', | ||
user_id: newUser.id, | ||
}) | ||
|
||
const { project: projectEdited } = await editProjectUseCase.execute({ | ||
|
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,11 +1,10 @@ | ||
import { expect, describe, it, beforeEach } from 'vitest' | ||
|
||
import { InMemoryProjectRepository } from '../../repositories/in-memory-db/inMemoryProjectRepository' | ||
import { ProjectRepository } from '../../repositories/project-repository' | ||
import { ResourceNotFoundError } from '../errors/ResourceNotFoundError' | ||
import { GetProjectsByIdUseCase } from './getProjectsByIdUseCase' | ||
|
||
let projectRepository: ProjectRepository | ||
let projectRepository: InMemoryProjectRepository | ||
let getProjectByIdUseCase: GetProjectsByIdUseCase | ||
|
||
describe('Get Project By Id Use Case', () => { | ||
|
@@ -15,12 +14,18 @@ describe('Get Project By Id Use Case', () => { | |
}) | ||
|
||
it('should be able get project by ID', async () => { | ||
const newUser = await projectRepository.dbUser.create({ | ||
name: 'John', | ||
surname: 'Doe', | ||
email: '[email protected]', | ||
password_hash: '123456', | ||
}) | ||
const newProject = await projectRepository.create({ | ||
title: 'React Typescript 1', | ||
description: 'Best Project', | ||
tags: ['react', 'node'], | ||
link: 'https://github.com/luiseduardo3/nodets-petcanil', | ||
user_id: 'user_id', | ||
user_id: newUser.id, | ||
}) | ||
|
||
const { project } = await getProjectByIdUseCase.execute({ | ||
|
@@ -32,6 +37,7 @@ describe('Get Project By Id Use Case', () => { | |
title: 'React Typescript 1', | ||
id: newProject.id, | ||
tags: ['react', 'node'], | ||
user: { name: 'John', surname: 'Doe', avatar_url: null }, | ||
}), | ||
) | ||
}) | ||
|
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
Oops, something went wrong.