core tests
This commit is contained in:
721
core/admin/domain/repositories/AdminUserRepository.test.ts
Normal file
721
core/admin/domain/repositories/AdminUserRepository.test.ts
Normal file
@@ -0,0 +1,721 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { AdminUser } from '../entities/AdminUser';
|
||||
import { Email } from '../value-objects/Email';
|
||||
import { UserId } from '../value-objects/UserId';
|
||||
import { UserRole } from '../value-objects/UserRole';
|
||||
import { UserStatus } from '../value-objects/UserStatus';
|
||||
import type {
|
||||
AdminUserRepository,
|
||||
UserFilter,
|
||||
UserSort,
|
||||
UserPagination,
|
||||
UserListQuery,
|
||||
UserListResult,
|
||||
StoredAdminUser
|
||||
} from './AdminUserRepository';
|
||||
|
||||
describe('AdminUserRepository', () => {
|
||||
describe('TDD - Test First', () => {
|
||||
describe('UserFilter interface', () => {
|
||||
it('should allow optional role filter', () => {
|
||||
// Arrange
|
||||
const filter: UserFilter = {
|
||||
role: UserRole.fromString('admin'),
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(filter.role).toBeDefined();
|
||||
expect(filter.role!.value).toBe('admin');
|
||||
});
|
||||
|
||||
it('should allow optional status filter', () => {
|
||||
// Arrange
|
||||
const filter: UserFilter = {
|
||||
status: UserStatus.fromString('active'),
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(filter.status).toBeDefined();
|
||||
expect(filter.status!.value).toBe('active');
|
||||
});
|
||||
|
||||
it('should allow optional email filter', () => {
|
||||
// Arrange
|
||||
const filter: UserFilter = {
|
||||
email: Email.create('test@example.com'),
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(filter.email).toBeDefined();
|
||||
expect(filter.email!.value).toBe('test@example.com');
|
||||
});
|
||||
|
||||
it('should allow optional search filter', () => {
|
||||
// Arrange
|
||||
const filter: UserFilter = {
|
||||
search: 'john',
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(filter.search).toBe('john');
|
||||
});
|
||||
|
||||
it('should allow all filters combined', () => {
|
||||
// Arrange
|
||||
const filter: UserFilter = {
|
||||
role: UserRole.fromString('admin'),
|
||||
status: UserStatus.fromString('active'),
|
||||
email: Email.create('admin@example.com'),
|
||||
search: 'admin',
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(filter.role!.value).toBe('admin');
|
||||
expect(filter.status!.value).toBe('active');
|
||||
expect(filter.email!.value).toBe('admin@example.com');
|
||||
expect(filter.search).toBe('admin');
|
||||
});
|
||||
});
|
||||
|
||||
describe('UserSort interface', () => {
|
||||
it('should allow email field with asc direction', () => {
|
||||
// Arrange
|
||||
const sort: UserSort = {
|
||||
field: 'email',
|
||||
direction: 'asc',
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(sort.field).toBe('email');
|
||||
expect(sort.direction).toBe('asc');
|
||||
});
|
||||
|
||||
it('should allow email field with desc direction', () => {
|
||||
// Arrange
|
||||
const sort: UserSort = {
|
||||
field: 'email',
|
||||
direction: 'desc',
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(sort.field).toBe('email');
|
||||
expect(sort.direction).toBe('desc');
|
||||
});
|
||||
|
||||
it('should allow displayName field', () => {
|
||||
// Arrange
|
||||
const sort: UserSort = {
|
||||
field: 'displayName',
|
||||
direction: 'asc',
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(sort.field).toBe('displayName');
|
||||
});
|
||||
|
||||
it('should allow createdAt field', () => {
|
||||
// Arrange
|
||||
const sort: UserSort = {
|
||||
field: 'createdAt',
|
||||
direction: 'desc',
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(sort.field).toBe('createdAt');
|
||||
});
|
||||
|
||||
it('should allow lastLoginAt field', () => {
|
||||
// Arrange
|
||||
const sort: UserSort = {
|
||||
field: 'lastLoginAt',
|
||||
direction: 'asc',
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(sort.field).toBe('lastLoginAt');
|
||||
});
|
||||
|
||||
it('should allow status field', () => {
|
||||
// Arrange
|
||||
const sort: UserSort = {
|
||||
field: 'status',
|
||||
direction: 'desc',
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(sort.field).toBe('status');
|
||||
});
|
||||
});
|
||||
|
||||
describe('UserPagination interface', () => {
|
||||
it('should allow valid pagination', () => {
|
||||
// Arrange
|
||||
const pagination: UserPagination = {
|
||||
page: 1,
|
||||
limit: 10,
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(pagination.page).toBe(1);
|
||||
expect(pagination.limit).toBe(10);
|
||||
});
|
||||
|
||||
it('should allow pagination with different values', () => {
|
||||
// Arrange
|
||||
const pagination: UserPagination = {
|
||||
page: 5,
|
||||
limit: 50,
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(pagination.page).toBe(5);
|
||||
expect(pagination.limit).toBe(50);
|
||||
});
|
||||
});
|
||||
|
||||
describe('UserListQuery interface', () => {
|
||||
it('should allow query with all optional fields', () => {
|
||||
// Arrange
|
||||
const query: UserListQuery = {
|
||||
filter: {
|
||||
role: UserRole.fromString('admin'),
|
||||
},
|
||||
sort: {
|
||||
field: 'email',
|
||||
direction: 'asc',
|
||||
},
|
||||
pagination: {
|
||||
page: 1,
|
||||
limit: 10,
|
||||
},
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(query.filter).toBeDefined();
|
||||
expect(query.sort).toBeDefined();
|
||||
expect(query.pagination).toBeDefined();
|
||||
});
|
||||
|
||||
it('should allow query with only filter', () => {
|
||||
// Arrange
|
||||
const query: UserListQuery = {
|
||||
filter: {
|
||||
status: UserStatus.fromString('active'),
|
||||
},
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(query.filter).toBeDefined();
|
||||
expect(query.sort).toBeUndefined();
|
||||
expect(query.pagination).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should allow query with only sort', () => {
|
||||
// Arrange
|
||||
const query: UserListQuery = {
|
||||
sort: {
|
||||
field: 'displayName',
|
||||
direction: 'desc',
|
||||
},
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(query.filter).toBeUndefined();
|
||||
expect(query.sort).toBeDefined();
|
||||
expect(query.pagination).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should allow query with only pagination', () => {
|
||||
// Arrange
|
||||
const query: UserListQuery = {
|
||||
pagination: {
|
||||
page: 2,
|
||||
limit: 20,
|
||||
},
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(query.filter).toBeUndefined();
|
||||
expect(query.sort).toBeUndefined();
|
||||
expect(query.pagination).toBeDefined();
|
||||
});
|
||||
|
||||
it('should allow empty query', () => {
|
||||
// Arrange
|
||||
const query: UserListQuery = {};
|
||||
|
||||
// Assert
|
||||
expect(query.filter).toBeUndefined();
|
||||
expect(query.sort).toBeUndefined();
|
||||
expect(query.pagination).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('UserListResult interface', () => {
|
||||
it('should allow valid result with users', () => {
|
||||
// Arrange
|
||||
const user = AdminUser.create({
|
||||
id: 'user-1',
|
||||
email: 'test@example.com',
|
||||
displayName: 'Test User',
|
||||
roles: ['user'],
|
||||
status: 'active',
|
||||
});
|
||||
|
||||
const result: UserListResult = {
|
||||
users: [user],
|
||||
total: 1,
|
||||
page: 1,
|
||||
limit: 10,
|
||||
totalPages: 1,
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(result.users).toHaveLength(1);
|
||||
expect(result.total).toBe(1);
|
||||
expect(result.page).toBe(1);
|
||||
expect(result.limit).toBe(10);
|
||||
expect(result.totalPages).toBe(1);
|
||||
});
|
||||
|
||||
it('should allow result with multiple users', () => {
|
||||
// Arrange
|
||||
const user1 = AdminUser.create({
|
||||
id: 'user-1',
|
||||
email: 'user1@example.com',
|
||||
displayName: 'User 1',
|
||||
roles: ['user'],
|
||||
status: 'active',
|
||||
});
|
||||
|
||||
const user2 = AdminUser.create({
|
||||
id: 'user-2',
|
||||
email: 'user2@example.com',
|
||||
displayName: 'User 2',
|
||||
roles: ['user'],
|
||||
status: 'active',
|
||||
});
|
||||
|
||||
const result: UserListResult = {
|
||||
users: [user1, user2],
|
||||
total: 2,
|
||||
page: 1,
|
||||
limit: 10,
|
||||
totalPages: 1,
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(result.users).toHaveLength(2);
|
||||
expect(result.total).toBe(2);
|
||||
});
|
||||
|
||||
it('should allow result with pagination info', () => {
|
||||
// Arrange
|
||||
const users = Array.from({ length: 50 }, (_, i) =>
|
||||
AdminUser.create({
|
||||
id: `user-${i}`,
|
||||
email: `user${i}@example.com`,
|
||||
displayName: `User ${i}`,
|
||||
roles: ['user'],
|
||||
status: 'active',
|
||||
}),
|
||||
);
|
||||
|
||||
const result: UserListResult = {
|
||||
users: users.slice(0, 10),
|
||||
total: 50,
|
||||
page: 1,
|
||||
limit: 10,
|
||||
totalPages: 5,
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(result.users).toHaveLength(10);
|
||||
expect(result.total).toBe(50);
|
||||
expect(result.page).toBe(1);
|
||||
expect(result.limit).toBe(10);
|
||||
expect(result.totalPages).toBe(5);
|
||||
});
|
||||
});
|
||||
|
||||
describe('StoredAdminUser interface', () => {
|
||||
it('should allow stored user with all required fields', () => {
|
||||
// Arrange
|
||||
const stored: StoredAdminUser = {
|
||||
id: 'user-1',
|
||||
email: 'test@example.com',
|
||||
roles: ['admin'],
|
||||
status: 'active',
|
||||
displayName: 'Test User',
|
||||
createdAt: new Date('2024-01-01'),
|
||||
updatedAt: new Date('2024-01-02'),
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(stored.id).toBe('user-1');
|
||||
expect(stored.email).toBe('test@example.com');
|
||||
expect(stored.roles).toEqual(['admin']);
|
||||
expect(stored.status).toBe('active');
|
||||
expect(stored.displayName).toBe('Test User');
|
||||
expect(stored.createdAt).toBeInstanceOf(Date);
|
||||
expect(stored.updatedAt).toBeInstanceOf(Date);
|
||||
});
|
||||
|
||||
it('should allow stored user with optional fields', () => {
|
||||
// Arrange
|
||||
const stored: StoredAdminUser = {
|
||||
id: 'user-1',
|
||||
email: 'test@example.com',
|
||||
roles: ['admin'],
|
||||
status: 'active',
|
||||
displayName: 'Test User',
|
||||
createdAt: new Date('2024-01-01'),
|
||||
updatedAt: new Date('2024-01-02'),
|
||||
lastLoginAt: new Date('2024-01-03'),
|
||||
primaryDriverId: 'driver-123',
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(stored.lastLoginAt).toBeInstanceOf(Date);
|
||||
expect(stored.primaryDriverId).toBe('driver-123');
|
||||
});
|
||||
|
||||
it('should allow stored user with multiple roles', () => {
|
||||
// Arrange
|
||||
const stored: StoredAdminUser = {
|
||||
id: 'user-1',
|
||||
email: 'test@example.com',
|
||||
roles: ['owner', 'admin', 'user'],
|
||||
status: 'active',
|
||||
displayName: 'Test User',
|
||||
createdAt: new Date('2024-01-01'),
|
||||
updatedAt: new Date('2024-01-02'),
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(stored.roles).toHaveLength(3);
|
||||
expect(stored.roles).toContain('owner');
|
||||
expect(stored.roles).toContain('admin');
|
||||
expect(stored.roles).toContain('user');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Repository interface methods', () => {
|
||||
it('should define findById method signature', () => {
|
||||
// Arrange
|
||||
const mockRepository: AdminUserRepository = {
|
||||
findById: vi.fn(),
|
||||
findByEmail: vi.fn(),
|
||||
emailExists: vi.fn(),
|
||||
existsById: vi.fn(),
|
||||
existsByEmail: vi.fn(),
|
||||
list: vi.fn(),
|
||||
count: vi.fn(),
|
||||
create: vi.fn(),
|
||||
update: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
toStored: vi.fn(),
|
||||
fromStored: vi.fn(),
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(mockRepository.findById).toBeDefined();
|
||||
expect(typeof mockRepository.findById).toBe('function');
|
||||
});
|
||||
|
||||
it('should define findByEmail method signature', () => {
|
||||
// Arrange
|
||||
const mockRepository: AdminUserRepository = {
|
||||
findById: vi.fn(),
|
||||
findByEmail: vi.fn(),
|
||||
emailExists: vi.fn(),
|
||||
existsById: vi.fn(),
|
||||
existsByEmail: vi.fn(),
|
||||
list: vi.fn(),
|
||||
count: vi.fn(),
|
||||
create: vi.fn(),
|
||||
update: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
toStored: vi.fn(),
|
||||
fromStored: vi.fn(),
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(mockRepository.findByEmail).toBeDefined();
|
||||
expect(typeof mockRepository.findByEmail).toBe('function');
|
||||
});
|
||||
|
||||
it('should define emailExists method signature', () => {
|
||||
// Arrange
|
||||
const mockRepository: AdminUserRepository = {
|
||||
findById: vi.fn(),
|
||||
findByEmail: vi.fn(),
|
||||
emailExists: vi.fn(),
|
||||
existsById: vi.fn(),
|
||||
existsByEmail: vi.fn(),
|
||||
list: vi.fn(),
|
||||
count: vi.fn(),
|
||||
create: vi.fn(),
|
||||
update: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
toStored: vi.fn(),
|
||||
fromStored: vi.fn(),
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(mockRepository.emailExists).toBeDefined();
|
||||
expect(typeof mockRepository.emailExists).toBe('function');
|
||||
});
|
||||
|
||||
it('should define existsById method signature', () => {
|
||||
// Arrange
|
||||
const mockRepository: AdminUserRepository = {
|
||||
findById: vi.fn(),
|
||||
findByEmail: vi.fn(),
|
||||
emailExists: vi.fn(),
|
||||
existsById: vi.fn(),
|
||||
existsByEmail: vi.fn(),
|
||||
list: vi.fn(),
|
||||
count: vi.fn(),
|
||||
create: vi.fn(),
|
||||
update: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
toStored: vi.fn(),
|
||||
fromStored: vi.fn(),
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(mockRepository.existsById).toBeDefined();
|
||||
expect(typeof mockRepository.existsById).toBe('function');
|
||||
});
|
||||
|
||||
it('should define existsByEmail method signature', () => {
|
||||
// Arrange
|
||||
const mockRepository: AdminUserRepository = {
|
||||
findById: vi.fn(),
|
||||
findByEmail: vi.fn(),
|
||||
emailExists: vi.fn(),
|
||||
existsById: vi.fn(),
|
||||
existsByEmail: vi.fn(),
|
||||
list: vi.fn(),
|
||||
count: vi.fn(),
|
||||
create: vi.fn(),
|
||||
update: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
toStored: vi.fn(),
|
||||
fromStored: vi.fn(),
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(mockRepository.existsByEmail).toBeDefined();
|
||||
expect(typeof mockRepository.existsByEmail).toBe('function');
|
||||
});
|
||||
|
||||
it('should define list method signature', () => {
|
||||
// Arrange
|
||||
const mockRepository: AdminUserRepository = {
|
||||
findById: vi.fn(),
|
||||
findByEmail: vi.fn(),
|
||||
emailExists: vi.fn(),
|
||||
existsById: vi.fn(),
|
||||
existsByEmail: vi.fn(),
|
||||
list: vi.fn(),
|
||||
count: vi.fn(),
|
||||
create: vi.fn(),
|
||||
update: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
toStored: vi.fn(),
|
||||
fromStored: vi.fn(),
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(mockRepository.list).toBeDefined();
|
||||
expect(typeof mockRepository.list).toBe('function');
|
||||
});
|
||||
|
||||
it('should define count method signature', () => {
|
||||
// Arrange
|
||||
const mockRepository: AdminUserRepository = {
|
||||
findById: vi.fn(),
|
||||
findByEmail: vi.fn(),
|
||||
emailExists: vi.fn(),
|
||||
existsById: vi.fn(),
|
||||
existsByEmail: vi.fn(),
|
||||
list: vi.fn(),
|
||||
count: vi.fn(),
|
||||
create: vi.fn(),
|
||||
update: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
toStored: vi.fn(),
|
||||
fromStored: vi.fn(),
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(mockRepository.count).toBeDefined();
|
||||
expect(typeof mockRepository.count).toBe('function');
|
||||
});
|
||||
|
||||
it('should define create method signature', () => {
|
||||
// Arrange
|
||||
const mockRepository: AdminUserRepository = {
|
||||
findById: vi.fn(),
|
||||
findByEmail: vi.fn(),
|
||||
emailExists: vi.fn(),
|
||||
existsById: vi.fn(),
|
||||
existsByEmail: vi.fn(),
|
||||
list: vi.fn(),
|
||||
count: vi.fn(),
|
||||
create: vi.fn(),
|
||||
update: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
toStored: vi.fn(),
|
||||
fromStored: vi.fn(),
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(mockRepository.create).toBeDefined();
|
||||
expect(typeof mockRepository.create).toBe('function');
|
||||
});
|
||||
|
||||
it('should define update method signature', () => {
|
||||
// Arrange
|
||||
const mockRepository: AdminUserRepository = {
|
||||
findById: vi.fn(),
|
||||
findByEmail: vi.fn(),
|
||||
emailExists: vi.fn(),
|
||||
existsById: vi.fn(),
|
||||
existsByEmail: vi.fn(),
|
||||
list: vi.fn(),
|
||||
count: vi.fn(),
|
||||
create: vi.fn(),
|
||||
update: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
toStored: vi.fn(),
|
||||
fromStored: vi.fn(),
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(mockRepository.update).toBeDefined();
|
||||
expect(typeof mockRepository.update).toBe('function');
|
||||
});
|
||||
|
||||
it('should define delete method signature', () => {
|
||||
// Arrange
|
||||
const mockRepository: AdminUserRepository = {
|
||||
findById: vi.fn(),
|
||||
findByEmail: vi.fn(),
|
||||
emailExists: vi.fn(),
|
||||
existsById: vi.fn(),
|
||||
existsByEmail: vi.fn(),
|
||||
list: vi.fn(),
|
||||
count: vi.fn(),
|
||||
create: vi.fn(),
|
||||
update: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
toStored: vi.fn(),
|
||||
fromStored: vi.fn(),
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(mockRepository.delete).toBeDefined();
|
||||
expect(typeof mockRepository.delete).toBe('function');
|
||||
});
|
||||
|
||||
it('should define toStored method signature', () => {
|
||||
// Arrange
|
||||
const mockRepository: AdminUserRepository = {
|
||||
findById: vi.fn(),
|
||||
findByEmail: vi.fn(),
|
||||
emailExists: vi.fn(),
|
||||
existsById: vi.fn(),
|
||||
existsByEmail: vi.fn(),
|
||||
list: vi.fn(),
|
||||
count: vi.fn(),
|
||||
create: vi.fn(),
|
||||
update: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
toStored: vi.fn(),
|
||||
fromStored: vi.fn(),
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(mockRepository.toStored).toBeDefined();
|
||||
expect(typeof mockRepository.toStored).toBe('function');
|
||||
});
|
||||
|
||||
it('should define fromStored method signature', () => {
|
||||
// Arrange
|
||||
const mockRepository: AdminUserRepository = {
|
||||
findById: vi.fn(),
|
||||
findByEmail: vi.fn(),
|
||||
emailExists: vi.fn(),
|
||||
existsById: vi.fn(),
|
||||
existsByEmail: vi.fn(),
|
||||
list: vi.fn(),
|
||||
count: vi.fn(),
|
||||
create: vi.fn(),
|
||||
update: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
toStored: vi.fn(),
|
||||
fromStored: vi.fn(),
|
||||
};
|
||||
|
||||
// Assert
|
||||
expect(mockRepository.fromStored).toBeDefined();
|
||||
expect(typeof mockRepository.fromStored).toBe('function');
|
||||
});
|
||||
|
||||
it('should handle repository operations with mock implementation', async () => {
|
||||
// Arrange
|
||||
const user = AdminUser.create({
|
||||
id: 'user-1',
|
||||
email: 'test@example.com',
|
||||
displayName: 'Test User',
|
||||
roles: ['user'],
|
||||
status: 'active',
|
||||
});
|
||||
|
||||
const mockRepository: AdminUserRepository = {
|
||||
findById: vi.fn().mockResolvedValue(user),
|
||||
findByEmail: vi.fn().mockResolvedValue(user),
|
||||
emailExists: vi.fn().mockResolvedValue(true),
|
||||
existsById: vi.fn().mockResolvedValue(true),
|
||||
existsByEmail: vi.fn().mockResolvedValue(true),
|
||||
list: vi.fn().mockResolvedValue({
|
||||
users: [user],
|
||||
total: 1,
|
||||
page: 1,
|
||||
limit: 10,
|
||||
totalPages: 1,
|
||||
}),
|
||||
count: vi.fn().mockResolvedValue(1),
|
||||
create: vi.fn().mockResolvedValue(user),
|
||||
update: vi.fn().mockResolvedValue(user),
|
||||
delete: vi.fn().mockResolvedValue(undefined),
|
||||
toStored: vi.fn().mockReturnValue({
|
||||
id: 'user-1',
|
||||
email: 'test@example.com',
|
||||
roles: ['user'],
|
||||
status: 'active',
|
||||
displayName: 'Test User',
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
}),
|
||||
fromStored: vi.fn().mockReturnValue(user),
|
||||
};
|
||||
|
||||
// Act
|
||||
const foundUser = await mockRepository.findById(UserId.create('user-1'));
|
||||
const emailExists = await mockRepository.emailExists(Email.create('test@example.com'));
|
||||
const listResult = await mockRepository.list();
|
||||
|
||||
// Assert
|
||||
expect(foundUser).toBe(user);
|
||||
expect(emailExists).toBe(true);
|
||||
expect(listResult.users).toHaveLength(1);
|
||||
expect(mockRepository.findById).toHaveBeenCalledWith(UserId.create('user-1'));
|
||||
expect(mockRepository.emailExists).toHaveBeenCalledWith(Email.create('test@example.com'));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user