diff --git a/libs/users/application/src/lib/use-cases/get-user-by-email.use-case.spec.ts b/libs/users/application/src/lib/use-cases/get-user-by-email.use-case.spec.ts index 85c753e..d575708 100644 --- a/libs/users/application/src/lib/use-cases/get-user-by-email.use-case.spec.ts +++ b/libs/users/application/src/lib/use-cases/get-user-by-email.use-case.spec.ts @@ -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('test@example.com'); expect(result).toEqual(mockUser); - expect(usersRepository.findByEmail).toHaveBeenCalledWith("test@example.com"); + expect(usersRepository.findOneByEmail).toHaveBeenCalledWith( + 'test@example.com', + ); }); 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('test@example.com'); expect(result).toBeNull(); - expect(usersRepository.findByEmail).toHaveBeenCalledWith("test@example.com"); + expect(usersRepository.findOneByEmail).toHaveBeenCalledWith( + 'test@example.com', + ); }); }); }); diff --git a/libs/users/application/src/lib/use-cases/get-user-by-id.use-case.spec.ts b/libs/users/application/src/lib/use-cases/get-user-by-id.use-case.spec.ts index e57326e..a167ff8 100644 --- a/libs/users/application/src/lib/use-cases/get-user-by-id.use-case.spec.ts +++ b/libs/users/application/src/lib/use-cases/get-user-by-id.use-case.spec.ts @@ -7,8 +7,8 @@ describe('GetUserByIdUseCase', () => { beforeEach(() => { usersRepository = { - findById: jest.fn(), - findByEmail: jest.fn(), + findOneById: jest.fn(), + findOneByEmail: jest.fn(), }; getUserByIdUseCase = new GetUserByIdUseCase(usersRepository); }); @@ -21,21 +21,21 @@ describe('GetUserByIdUseCase', () => { firstName: 'John', lastName: 'Doe', }; - (usersRepository.findById as jest.Mock).mockResolvedValue(mockUser); + (usersRepository.findOneById as jest.Mock).mockResolvedValue(mockUser); const result = await getUserByIdUseCase.execute('1'); expect(result).toEqual(mockUser); - expect(usersRepository.findById).toHaveBeenCalledWith('1'); + expect(usersRepository.findOneById).toHaveBeenCalledWith('1'); }); it('should return null when user not found', async () => { - (usersRepository.findById as jest.Mock).mockResolvedValue(null); + (usersRepository.findOneById as jest.Mock).mockResolvedValue(null); const result = await getUserByIdUseCase.execute('1'); expect(result).toBeNull(); - expect(usersRepository.findById).toHaveBeenCalledWith('1'); + expect(usersRepository.findOneById).toHaveBeenCalledWith('1'); }); }); }); diff --git a/libs/users/application/src/lib/use-cases/get-user-by-id.use-case.ts b/libs/users/application/src/lib/use-cases/get-user-by-id.use-case.ts index aa6ba98..ec72ca8 100644 --- a/libs/users/application/src/lib/use-cases/get-user-by-id.use-case.ts +++ b/libs/users/application/src/lib/use-cases/get-user-by-id.use-case.ts @@ -9,6 +9,6 @@ export class GetUserByIdUseCase { ) {} async execute(id: string): Promise { - return await this.usersRepository.findById(id); + return await this.usersRepository.findOneById(id); } } diff --git a/libs/users/application/src/lib/users.service.spec.ts b/libs/users/application/src/lib/users.service.spec.ts index adb98d5..0947d92 100644 --- a/libs/users/application/src/lib/users.service.spec.ts +++ b/libs/users/application/src/lib/users.service.spec.ts @@ -42,7 +42,7 @@ describe('UsersService', () => { }; (getUserByIdUseCase.execute as jest.Mock).mockResolvedValue(mockUser); - const result = await service.findById('1'); + const result = await service.findOneById('1'); expect(result).toEqual(mockUser); expect(getUserByIdUseCase.execute).toHaveBeenCalledWith('1'); @@ -51,7 +51,7 @@ describe('UsersService', () => { it('should return null when user not found', async () => { (getUserByIdUseCase.execute as jest.Mock).mockResolvedValue(null); - const result = await service.findById('1'); + const result = await service.findOneById('1'); expect(result).toBeNull(); expect(getUserByIdUseCase.execute).toHaveBeenCalledWith('1'); diff --git a/libs/users/application/src/lib/users.service.ts b/libs/users/application/src/lib/users.service.ts index 87d2b50..c8a0897 100644 --- a/libs/users/application/src/lib/users.service.ts +++ b/libs/users/application/src/lib/users.service.ts @@ -11,11 +11,11 @@ export class UsersService { private readonly getUserByEmailUseCase: GetUserByEmailUseCase, ) {} - async findById(id: string): Promise { + async findOneById(id: string): Promise { return this.getUserByIdUseCase.execute(id); } - async findByEmail(email: string): Promise { + async findOneByEmail(email: string): Promise { return this.getUserByEmailUseCase.execute(email); } } diff --git a/libs/users/domain/src/lib/users.repository.spec.ts b/libs/users/domain/src/lib/users.repository.spec.ts index d560e1e..242ab4e 100644 --- a/libs/users/domain/src/lib/users.repository.spec.ts +++ b/libs/users/domain/src/lib/users.repository.spec.ts @@ -12,11 +12,11 @@ class MockUsersRepository implements UsersRepository { }, ]; - async findById(id: string): Promise { + async findOneById(id: string): Promise { return this.users.find((user) => user.id === id) || null; } - async findByEmail(email: string): Promise { + async findOneByEmail(email: string): Promise { 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: 'john@example.com', 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('jane@example.com'); + test('findOneByEmail should return a user by email', async () => { + const user = await usersRepository.findOneByEmail('jane@example.com'); expect(user).toEqual({ id: '2', email: 'jane@example.com', @@ -53,8 +53,8 @@ describe('UsersRepository', () => { }); }); - test('findByEmail should return null if user not found', async () => { - const user = await usersRepository.findByEmail('nonexistent@example.com'); + test('findOneByEmail should return null if user not found', async () => { + const user = await usersRepository.findOneByEmail('nonexistent@example.com'); expect(user).toBeNull(); }); }); diff --git a/libs/users/domain/src/lib/users.repository.ts b/libs/users/domain/src/lib/users.repository.ts index 593a649..90f45a8 100644 --- a/libs/users/domain/src/lib/users.repository.ts +++ b/libs/users/domain/src/lib/users.repository.ts @@ -1,8 +1,8 @@ import { User } from './user.entity'; export interface UsersRepository { - findById(id: string): Promise; - findByEmail(email: string): Promise; + findOneById(id: string): Promise; + findOneByEmail(email: string): Promise; } export const USERS_REPOSITORY = Symbol('USERS_REPOSITORY'); \ No newline at end of file diff --git a/libs/users/infrastructure/mongoose/src/lib/mongoose-users.repository.spec.ts b/libs/users/infrastructure/mongoose/src/lib/mongoose-users.repository.spec.ts index 0a4bc93..ad79019 100644 --- a/libs/users/infrastructure/mongoose/src/lib/mongoose-users.repository.spec.ts +++ b/libs/users/infrastructure/mongoose/src/lib/mongoose-users.repository.spec.ts @@ -16,7 +16,7 @@ describe('MongooseUsersRepository', () => { { provide: getModelToken(UserDocument.name), useValue: { - findById: jest.fn(), + findOneById: jest.fn(), }, }, ], @@ -36,11 +36,11 @@ describe('MongooseUsersRepository', () => { lastName: 'Doe', }; - jest.spyOn(userModel, 'findById').mockReturnValue({ + jest.spyOn(userModel, 'findOneById').mockReturnValue({ exec: jest.fn().mockResolvedValue(mockUser), } as any); - const user = await repository.findById(mockUser.id); + const user = await repository.findOneById(mockUser.id); expect(user).toBeInstanceOf(User); expect(user?.id).toBe(mockUser.id); expect(user?.email).toBe(mockUser.email); @@ -49,11 +49,11 @@ describe('MongooseUsersRepository', () => { }); it('should return null when user is not found', async () => { - jest.spyOn(userModel, 'findById').mockReturnValue({ + jest.spyOn(userModel, 'findOneById').mockReturnValue({ exec: jest.fn().mockResolvedValue(null), } as any); - const user = await repository.findById('507f1f77bcf86cd799439011'); + const user = await repository.findOneById('507f1f77bcf86cd799439011'); expect(user).toBeNull(); }); }); diff --git a/libs/users/infrastructure/mongoose/src/lib/mongoose-users.repository.ts b/libs/users/infrastructure/mongoose/src/lib/mongoose-users.repository.ts index c61f9a8..51f143e 100644 --- a/libs/users/infrastructure/mongoose/src/lib/mongoose-users.repository.ts +++ b/libs/users/infrastructure/mongoose/src/lib/mongoose-users.repository.ts @@ -11,9 +11,9 @@ export class MongooseUsersRepository implements UsersRepository { @InjectModel(UserDocument.name) private userModel: Model, ) {} - async findById(id: string): Promise { + async findOneById(id: string): Promise { const _id = new Types.ObjectId(id); - const userDocument = await this.userModel.findById(_id).exec(); + const userDocument = await this.userModel.findOne(_id).exec(); if (!userDocument) { return null; @@ -26,7 +26,7 @@ export class MongooseUsersRepository implements UsersRepository { ); } - async findByEmail(email: string): Promise { + async findOneByEmail(email: string): Promise { const userDocument = await this.userModel.findOne({ email }).exec(); if (!userDocument) { diff --git a/libs/users/interface-adapters/src/lib/resolver/users.resolver.spec.ts b/libs/users/interface-adapters/src/lib/resolver/users.resolver.spec.ts index 1b71a8c..da6aed2 100644 --- a/libs/users/interface-adapters/src/lib/resolver/users.resolver.spec.ts +++ b/libs/users/interface-adapters/src/lib/resolver/users.resolver.spec.ts @@ -14,7 +14,7 @@ describe('UsersResolver', () => { { provide: UsersService, useValue: { - findById: jest.fn(), + findOneById: jest.fn(), }, }, ], diff --git a/libs/users/interface-adapters/src/lib/resolver/users.resolver.ts b/libs/users/interface-adapters/src/lib/resolver/users.resolver.ts index 5e665db..ca099db 100644 --- a/libs/users/interface-adapters/src/lib/resolver/users.resolver.ts +++ b/libs/users/interface-adapters/src/lib/resolver/users.resolver.ts @@ -10,7 +10,7 @@ export class UsersResolver { @Query(() => UserDto, { nullable: true }) async getUser(@Args({ name: 'id', type: () => ID }) id: string): Promise { - const user: User| null = await this.usersService.findById(id); + const user: User| null = await this.usersService.findOneById(id); if (!user) { return null;