UNPKG

ruch

Version:

Revolutionary React TypeScript CLI with hexagonal architecture & AI-powered development assistance. Create maintainable, scalable applications with domain-driven design and integrated AI tooling.

41 lines (33 loc) 1 kB
/** * Tests for the User domain services. * @packageDocumentation */ import { describe, it, expect, vi, beforeEach } from 'vitest'; import { UserService, UserError } from './UserService'; describe('UserService', () => { let service: UserService; let mockPort: any; beforeEach(() => { mockPort = { getAll: vi.fn(), getById: vi.fn(), create: vi.fn(), update: vi.fn(), delete: vi.fn(), }; service = new UserService(mockPort); }); describe('getAll', () => { it('should return all entities', async () => { const mockEntities = [{ id: '1' }]; mockPort.getAll.mockResolvedValue(mockEntities); const result = await service.getAll(); expect(result).toEqual(mockEntities); }); it('should throw error when port fails', async () => { mockPort.getAll.mockRejectedValue(new Error()); await expect(service.getAll()).rejects.toThrow(UserError); }); }); // Add more test cases for other methods... });