listRecipes 按 §B.9-2 改为静态常量({id,label},不调 /api/ai/page-recipes)。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
50 lines
2.0 KiB
TypeScript
50 lines
2.0 KiB
TypeScript
import { describe, expect, it, vi, beforeEach } from 'vitest';
|
|
import { http } from './http';
|
|
import { createEntity, listEntities, listEntityColumns } from './meta';
|
|
|
|
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('meta api', () => {
|
|
it('createEntity POST /api/meta/entity 并解包 data', async () => {
|
|
mPost.mockResolvedValue({
|
|
data: { status: 0, data: { entityId: 'E1', tablename: 'OA_DEMO', attributeCount: 4, indexCount: 1, listApi: '/api/entity/OA_DEMO/list' } },
|
|
} as never);
|
|
const r = await createEntity({ tablename: 'OA_DEMO', name: '演示', attributes: [{ column: 'TITLE', type: 'string', length: 200, mandatory: true }] });
|
|
expect(mPost).toHaveBeenCalledWith('/api/meta/entity', {
|
|
tablename: 'OA_DEMO',
|
|
name: '演示',
|
|
attributes: [{ column: 'TITLE', type: 'string', length: 200, mandatory: true }],
|
|
});
|
|
expect(r.entityId).toBe('E1');
|
|
expect(r.listApi).toBe('/api/entity/OA_DEMO/list');
|
|
});
|
|
|
|
it('listEntities GET /api/meta/entities 并解包数组', async () => {
|
|
mGet.mockResolvedValue({ data: { status: 0, data: [{ entityId: 'E1', tablename: 'OA_DEMO', name: '演示' }] } } as never);
|
|
const r = await listEntities();
|
|
expect(mGet).toHaveBeenCalledWith('/api/meta/entities');
|
|
expect(r).toHaveLength(1);
|
|
expect(r[0].tablename).toBe('OA_DEMO');
|
|
});
|
|
|
|
it('listEntityColumns GET /api/meta/entity/{table}/attributes 并解包', async () => {
|
|
mGet.mockResolvedValue({
|
|
data: { status: 0, data: { tablename: 'SYS_DEPART', displayColumn: 'DEPARTNAME', columns: [{ column: 'DEPARTNAME', display: '部门名', type: 'string' }] } },
|
|
} as never);
|
|
const r = await listEntityColumns('SYS_DEPART');
|
|
expect(mGet).toHaveBeenCalledWith('/api/meta/entity/SYS_DEPART/attributes');
|
|
expect(r.displayColumn).toBe('DEPARTNAME');
|
|
expect(r.columns[0].column).toBe('DEPARTNAME');
|
|
});
|
|
});
|