Skip to content

Commit

Permalink
Merge pull request #42 from MatheusSanchez/add-country-to-user-entity
Browse files Browse the repository at this point in the history
Adding country to User
  • Loading branch information
MatheusSanchez authored Feb 3, 2024
2 parents 9218cb1 + 4d19bb9 commit 3342868
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "User" ADD COLUMN "country" TEXT NOT NULL DEFAULT 'brasil';
1 change: 1 addition & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ model User {
is_google Boolean @default(false)
created_at DateTime @default(now())
updated_at DateTime @updatedAt
country String @default("brasil")
projects Project[]
}
Expand Down
1 change: 1 addition & 0 deletions src/controller/user/getUserByEmail.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe('Get User By email E2E', () => {
name,
surname,
password_hash: expect.any(String),
country: 'brasil',
}),
)

Expand Down
1 change: 1 addition & 0 deletions src/controller/user/getUserById.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe('Get User By Id E2E', () => {
expect(getUserByIdResponse.body.user).toEqual(
expect.objectContaining({
id,
country: 'brasil',
}),
)
})
Expand Down
31 changes: 4 additions & 27 deletions src/repositories/in-memory-db/inMemoryUserRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,8 @@ import { randomUUID } from 'crypto'
export class InMemoryUserRepository implements UserRepository {
private 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)

Expand Down Expand Up @@ -58,9 +35,10 @@ export class InMemoryUserRepository implements UserRepository {
surname,
email,
password_hash,
country,
}: Prisma.UserCreateInput) {
const user: User = {
id: (id == undefined) ? randomUUID() : id,
id: id == undefined ? randomUUID() : id,
name,
surname,

Expand All @@ -69,11 +47,10 @@ export class InMemoryUserRepository implements UserRepository {

created_at: new Date(),
updated_at: new Date(),
country: country || 'brasil',
}

this.db.push(user)

return user
}

}
1 change: 1 addition & 0 deletions src/use-cases/user/getUserByEmailUseCase.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe('Get User By Email Use Case', () => {
expect(user.name).toEqual(name)
expect(user.surname).toEqual(surname)
expect(user.email).toEqual(email)
expect(user.country).toEqual('brasil')
})

it('should not be able to get user that does not exists', async () => {
Expand Down
5 changes: 2 additions & 3 deletions src/use-cases/user/getUserByIdUseCase.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ let userRepository: InMemoryUserRepository

let getUserByIdUseCase: GetUserByIdUseCase


describe('Get User By Id Use Case', () => {
beforeEach(() => {
userRepository = new InMemoryUserRepository()
Expand All @@ -24,7 +23,7 @@ describe('Get User By Id Use Case', () => {
const newUser = await userRepository.create({
email,
name,
surname,
surname,
password_hash: await hash(password, 6),
})

Expand All @@ -34,7 +33,7 @@ describe('Get User By Id Use Case', () => {
expect(user.name).toEqual(name)
expect(user.surname).toEqual(surname)
expect(user.email).toEqual(email)

expect(user.country).toEqual('brasil')
})

it('should not be able to get user that does not exists', async () => {
Expand Down

0 comments on commit 3342868

Please sign in to comment.