test(studio): studio api 客户端单测(6)——补齐 U6 单测纵切(api+store+组件)
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 <noreply@anthropic.com>
This commit is contained in:
parent
439115d8b5
commit
d44071408f
50
game-studio/src/api/studio.spec.ts
Normal file
50
game-studio/src/api/studio.spec.ts
Normal file
@ -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<typeof vi.fn>
|
||||
|
||||
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' })
|
||||
})
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user