Files
eip4-web/src/api/recipe.test.ts
zhengwr 4b9c9338f3 feat(modeler): meta/recipe/publish api modules + vitest jest-dom setup
listRecipes 按 §B.9-2 改为静态常量({id,label},不调 /api/ai/page-recipes)。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-20 09:35:43 +08:00

32 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, expect, it, vi, beforeEach } from 'vitest';
import { http } from './http';
import { compileRecipe, listRecipes } from './recipe';
vi.mock('./http', () => ({ http: { get: vi.fn(), post: vi.fn() } }));
const mGet = vi.mocked(http.get);
const mPost = vi.mocked(http.post);
beforeEach(() => { mGet.mockReset(); mPost.mockReset(); });
describe('recipe api', () => {
it('compileRecipe POST /api/design/recipe/compile 并解包', async () => {
mPost.mockResolvedValue({ data: { status: 0, data: { templateId: 'tpl-uuid', etag: 'W/"1"' } } } as never);
const r = await compileRecipe({ tableName: 'OA_DEMO', recipe: 'maintenance-crud-v1', title: '演示维护', displayField: 'TITLE' });
expect(mPost).toHaveBeenCalledWith('/api/design/recipe/compile', {
tableName: 'OA_DEMO', recipe: 'maintenance-crud-v1', title: '演示维护', displayField: 'TITLE',
});
expect(r.templateId).toBe('tpl-uuid');
expect(r.etag).toBe('W/"1"');
});
// §B.9-2:listRecipes 改静态常量(非 async、不调 /api/ai/page-recipes)。
it('listRecipes 返回 v1 固定两 recipe(静态 {id,label})', () => {
const r = listRecipes();
expect(r).toEqual([
{ id: 'maintenance-crud-v1', label: '维护型 CRUD' },
{ id: 'tree-crud-v1', label: '树形 CRUD' },
]);
// 不触网:listRecipes 是同步数组,不调 http.get
expect(mGet).not.toHaveBeenCalled();
});
});