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>
This commit is contained in:
2026-06-20 09:35:43 +08:00
parent ae0155eb2c
commit 4b9c9338f3
8 changed files with 247 additions and 0 deletions

31
src/api/recipe.test.ts Normal file
View File

@@ -0,0 +1,31 @@
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();
});
});