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.
44 lines (36 loc) • 1.29 kB
text/typescript
export const getServicesTestTemplate = (domainName: string): string => {
const capitalizedName = domainName.charAt(0).toUpperCase() + domainName.slice(1);
return `/**
* Tests for the ${capitalizedName} domain services.
* @packageDocumentation
*/
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { ${capitalizedName}Service, ${capitalizedName}Error } from './${capitalizedName}Service';
describe('${capitalizedName}Service', () => {
let service: ${capitalizedName}Service;
let mockPort: any;
beforeEach(() => {
mockPort = {
getAll: vi.fn(),
getById: vi.fn(),
create: vi.fn(),
update: vi.fn(),
delete: vi.fn(),
};
service = new ${capitalizedName}Service(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(${capitalizedName}Error);
});
});
// Add more test cases for other methods...
});`;
};