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.

49 lines (42 loc) 1.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAdapterTestTemplate = void 0; const getAdapterTestTemplate = (domainName) => { const capitalizedName = domainName.charAt(0).toUpperCase() + domainName.slice(1); return `import { describe, it, expect, vi, beforeEach } from 'vitest'; import { ${capitalizedName}Adapter } from './${capitalizedName}Adapter'; import { ${capitalizedName}Error } from '../services/${capitalizedName}Service'; describe('${capitalizedName}Adapter', () => { let adapter: ${capitalizedName}Adapter; const mockBaseUrl = 'http://api.example.com'; beforeEach(() => { adapter = new ${capitalizedName}Adapter(mockBaseUrl); vi.stubGlobal('fetch', vi.fn()); }); describe('getAll', () => { it('should fetch all entities', async () => { const mockEntities = [{ id: '1' }]; (global.fetch as any).mockResolvedValueOnce({ ok: true, json: () => Promise.resolve(mockEntities), }); const result = await adapter.getAll(); expect(result).toEqual(mockEntities); expect(global.fetch).toHaveBeenCalledWith( \`\${mockBaseUrl}/${domainName}\`, expect.any(Object) ); }); it('should throw error when request fails', async () => { (global.fetch as any).mockResolvedValueOnce({ ok: false, status: 500, }); await expect(adapter.getAll()).rejects.toThrow(${capitalizedName}Error); }); }); // Add more test cases for other methods... });`; }; exports.getAdapterTestTemplate = getAdapterTestTemplate; //# sourceMappingURL=adapters.test.js.map