-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: ♻️ name from find to findOne
- Loading branch information
1 parent
d171615
commit 1c6aa0a
Showing
11 changed files
with
44 additions
and
40 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 |
---|---|---|
|
@@ -7,8 +7,8 @@ describe('GetUserByEmailUseCase', () => { | |
|
||
beforeEach(() => { | ||
usersRepository = { | ||
findById: jest.fn(), | ||
findByEmail: jest.fn(), | ||
findOneById: jest.fn(), | ||
findOneByEmail: jest.fn(), | ||
}; | ||
getUserByEmailUseCase = new GetUserByEmailUseCase(usersRepository); | ||
}); | ||
|
@@ -21,21 +21,25 @@ describe('GetUserByEmailUseCase', () => { | |
firstName: 'John', | ||
lastName: 'Doe', | ||
}; | ||
(usersRepository.findByEmail as jest.Mock).mockResolvedValue(mockUser); | ||
(usersRepository.findOneByEmail as jest.Mock).mockResolvedValue(mockUser); | ||
|
||
const result = await getUserByEmailUseCase.execute('[email protected]'); | ||
|
||
expect(result).toEqual(mockUser); | ||
expect(usersRepository.findByEmail).toHaveBeenCalledWith("[email protected]"); | ||
expect(usersRepository.findOneByEmail).toHaveBeenCalledWith( | ||
'[email protected]', | ||
); | ||
}); | ||
|
||
it('should return null when user not found', async () => { | ||
(usersRepository.findByEmail as jest.Mock).mockResolvedValue(null); | ||
(usersRepository.findOneByEmail as jest.Mock).mockResolvedValue(null); | ||
|
||
const result = await getUserByEmailUseCase.execute('[email protected]'); | ||
|
||
expect(result).toBeNull(); | ||
expect(usersRepository.findByEmail).toHaveBeenCalledWith("[email protected]"); | ||
expect(usersRepository.findOneByEmail).toHaveBeenCalledWith( | ||
'[email protected]', | ||
); | ||
}); | ||
}); | ||
}); |
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
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 |
---|---|---|
|
@@ -12,11 +12,11 @@ class MockUsersRepository implements UsersRepository { | |
}, | ||
]; | ||
|
||
async findById(id: string): Promise<User | null> { | ||
async findOneById(id: string): Promise<User | null> { | ||
return this.users.find((user) => user.id === id) || null; | ||
} | ||
|
||
async findByEmail(email: string): Promise<User | null> { | ||
async findOneByEmail(email: string): Promise<User | null> { | ||
return this.users.find((user) => user.email === email) || null; | ||
} | ||
} | ||
|
@@ -28,23 +28,23 @@ describe('UsersRepository', () => { | |
usersRepository = new MockUsersRepository(); | ||
}); | ||
|
||
test('findById should return a user by id', async () => { | ||
const user = await usersRepository.findById('1'); | ||
test('findOneById should return a user by id', async () => { | ||
const user = await usersRepository.findOneById('1'); | ||
expect(user).toEqual({ | ||
id: '1', | ||
email: '[email protected]', | ||
firstName: 'John', | ||
lastName: 'Doe' | ||
lastName: 'Doe', | ||
}); | ||
}); | ||
|
||
test('findById should return null if user not found', async () => { | ||
const user = await usersRepository.findById('3'); | ||
test('findOneById should return null if user not found', async () => { | ||
const user = await usersRepository.findOneById('3'); | ||
expect(user).toBeNull(); | ||
}); | ||
|
||
test('findByEmail should return a user by email', async () => { | ||
const user = await usersRepository.findByEmail('[email protected]'); | ||
test('findOneByEmail should return a user by email', async () => { | ||
const user = await usersRepository.findOneByEmail('[email protected]'); | ||
expect(user).toEqual({ | ||
id: '2', | ||
email: '[email protected]', | ||
|
@@ -53,8 +53,8 @@ describe('UsersRepository', () => { | |
}); | ||
}); | ||
|
||
test('findByEmail should return null if user not found', async () => { | ||
const user = await usersRepository.findByEmail('[email protected]'); | ||
test('findOneByEmail should return null if user not found', async () => { | ||
const user = await usersRepository.findOneByEmail('[email protected]'); | ||
expect(user).toBeNull(); | ||
}); | ||
}); |
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,8 +1,8 @@ | ||
import { User } from './user.entity'; | ||
|
||
export interface UsersRepository { | ||
findById(id: string): Promise<User | null>; | ||
findByEmail(email: string): Promise<User | null>; | ||
findOneById(id: string): Promise<User | null>; | ||
findOneByEmail(email: string): Promise<User | null>; | ||
} | ||
|
||
export const USERS_REPOSITORY = Symbol('USERS_REPOSITORY'); |
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