diff --git a/libs/user/domain/src/index.ts b/libs/user/domain/src/index.ts index 2dbc61e..9602d75 100644 --- a/libs/user/domain/src/index.ts +++ b/libs/user/domain/src/index.ts @@ -1 +1,3 @@ +// user export * from './lib/user.entity'; +export * from './lib/user.repository'; diff --git a/libs/user/domain/src/lib/user.repository.spec.ts b/libs/user/domain/src/lib/user.repository.spec.ts new file mode 100644 index 0000000..b8d7397 --- /dev/null +++ b/libs/user/domain/src/lib/user.repository.spec.ts @@ -0,0 +1,43 @@ +import { UserRepository } from './user.repository'; +import { User } from './user.entity'; + +class MockUserRepository implements UserRepository { + private users: User[] = [ + { id: '1', name: 'John Doe' }, + { id: '2', name: 'Jane Doe' }, + ]; + + async findById(id: string): Promise { + return this.users.find((user) => user.id === id) || null; + } + + async findAll(): Promise { + return this.users; + } +} + +describe('UserRepository', () => { + let userRepository: UserRepository; + + beforeEach(() => { + userRepository = new MockUserRepository(); + }); + + test('findById should return a user by id', async () => { + const user = await userRepository.findById('1'); + expect(user).toEqual({ id: '1', name: 'John Doe' }); + }); + + test('findById should return null if user not found', async () => { + const user = await userRepository.findById('3'); + expect(user).toBeNull(); + }); + + test('findAll should return all users', async () => { + const users = await userRepository.findAll(); + expect(users).toEqual([ + { id: '1', name: 'John Doe' }, + { id: '2', name: 'Jane Doe' }, + ]); + }); +}); diff --git a/libs/user/domain/src/lib/user.repository.ts b/libs/user/domain/src/lib/user.repository.ts new file mode 100644 index 0000000..45e63c9 --- /dev/null +++ b/libs/user/domain/src/lib/user.repository.ts @@ -0,0 +1,6 @@ +import { User } from './user.entity'; + +export interface UserRepository { + findById(id: string): Promise; + findAll(): Promise; +} \ No newline at end of file