From d44071408f5d94b78f1d0c6ac8b2ee0544a8bbae Mon Sep 17 00:00:00 2001 From: lili Date: Wed, 17 Jun 2026 16:53:07 -0700 Subject: [PATCH] =?UTF-8?q?test(studio):=20studio=20api=20=E5=AE=A2?= =?UTF-8?q?=E6=88=B7=E7=AB=AF=E5=8D=95=E6=B5=8B(6)=E2=80=94=E2=80=94?= =?UTF-8?q?=E8=A1=A5=E9=BD=90=20U6=20=E5=8D=95=E6=B5=8B=E7=BA=B5=E5=88=87(?= =?UTF-8?q?api+store+=E7=BB=84=E4=BB=B6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit src/api/studio.spec.ts:mock request 验每个 api 函数对 frozen studio.yaml 的 url/method/data 钉(getTemplates/createGame/modifyGame/extendGame/getTaskChain/regenerate)。至此 U6 创作流 api+store+3 组件全有 spec,npm test 25/25 绿;build 绿。 Co-Authored-By: Claude Opus 4.8 --- game-studio/src/api/studio.spec.ts | 50 ++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 game-studio/src/api/studio.spec.ts diff --git a/game-studio/src/api/studio.spec.ts b/game-studio/src/api/studio.spec.ts new file mode 100644 index 00000000..b6ed89be --- /dev/null +++ b/game-studio/src/api/studio.spec.ts @@ -0,0 +1,50 @@ +/** + * studio.spec.ts —— studio api 客户端单测(plan 002 U6;补齐 api 层,与 store/组件测共成 U6 单测纵切)。 + * 验每个 api 函数对 frozen studio.yaml 的 url/method/data 映射(契约钉);request 经 mock 拦截。跑 `npm test`。 + */ +import { describe, it, expect, vi, beforeEach } from 'vitest' + +// mock request 包络(studio.ts: `import { request } from './request'`) +vi.mock('./request', () => ({ request: vi.fn().mockResolvedValue({}) })) + +import { request } from './request' +import { getTemplates, createGame, modifyGame, extendGame, getTaskChain, regenerate } from './studio' + +const req = request as unknown as ReturnType + +describe('studio api 客户端(对 frozen studio.yaml 的 url/method 钉)', () => { + beforeEach(() => vi.clearAllMocks()) + + it('getTemplates → GET /app-api/studio/template/list', async () => { + await getTemplates() + expect(req).toHaveBeenCalledWith({ url: '/app-api/studio/template/list', method: 'get' }) + }) + + it('createGame → POST /app-api/studio/create + data', async () => { + const body = { title: 'T', prompt: 'p', templateId: 'generic' } + await createGame(body) + expect(req).toHaveBeenCalledWith({ url: '/app-api/studio/create', method: 'post', data: body }) + }) + + it('modifyGame → POST /app-api/studio/modify + data', async () => { + const body = { baseVersionId: 9001, mode: 'deterministic' as const, target: { kind: 'config' as const, path: '/config/speed' }, payload: { value: { speed: 5 } } } + await modifyGame(body) + expect(req).toHaveBeenCalledWith({ url: '/app-api/studio/modify', method: 'post', data: body }) + }) + + it('extendGame → POST /app-api/studio/extend + data', async () => { + const body = { baseVersionId: 9001, intent: '再加一关' } + await extendGame(body) + expect(req).toHaveBeenCalledWith({ url: '/app-api/studio/extend', method: 'post', data: body }) + }) + + it('getTaskChain → GET /app-api/studio/task/{id}', async () => { + await getTaskChain(1001) + expect(req).toHaveBeenCalledWith({ url: '/app-api/studio/task/1001', method: 'get' }) + }) + + it('regenerate → POST /app-api/studio/task/{id}/regenerate', async () => { + await regenerate(1001) + expect(req).toHaveBeenCalledWith({ url: '/app-api/studio/task/1001/regenerate', method: 'post' }) + }) +})