41 lines
2.2 KiB
TypeScript
41 lines
2.2 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
import { subjectIdentityApi } from '@/features/subject-identity/api'
|
|
|
|
/** 每个契约用例完成后清理网络替身。 */
|
|
afterEach(() => vi.unstubAllGlobals())
|
|
|
|
/** 验证正式身份路由和付费请求没有自动重试。 */
|
|
describe('身份正式接口契约', () => {
|
|
it('预览与实际生成传递相同参数,并支持取消预览', async () => {
|
|
const fetcher = vi
|
|
.fn<typeof fetch>()
|
|
.mockImplementation(async () => new Response(JSON.stringify({ data: {} }), { status: 200 }))
|
|
vi.stubGlobal('fetch', fetcher)
|
|
const input = {
|
|
viewType: 'primary' as const,
|
|
provider: 'qwen-image',
|
|
generationOptions: { size: '2048*2048' },
|
|
referenceImageId: 'image-1',
|
|
prompt: '真实完整提示词'
|
|
}
|
|
await subjectIdentityApi.previewImage('subject-1', input, new AbortController().signal)
|
|
await subjectIdentityApi.generateImage('subject-1', input)
|
|
expect(fetcher.mock.calls[0]?.[0]).toContain('/subjects/subject-1/identity/images/preview')
|
|
expect(fetcher.mock.calls[0]?.[1]?.body).toBe(JSON.stringify(input))
|
|
expect(fetcher.mock.calls[1]?.[1]?.body).toBe(fetcher.mock.calls[0]?.[1]?.body)
|
|
})
|
|
it('校验指定正式图片,质量生成保留有限修复次数和模型参数', async () => {
|
|
const fetcher = vi
|
|
.fn<typeof fetch>()
|
|
.mockImplementation(async () => new Response(JSON.stringify({ data: {} }), { status: 200 }))
|
|
vi.stubGlobal('fetch', fetcher)
|
|
await subjectIdentityApi.validateImage('subject-1', 'image-1')
|
|
const input = { maxRepairAttempts: 1, provider: 'qwen-image', generationOptions: { size: '2048*2048' } }
|
|
await subjectIdentityApi.generateStableAnchorQuality('subject-1', input)
|
|
expect(fetcher.mock.calls[0]?.[0]).toContain('/subjects/subject-1/identity/images/image-1/validate')
|
|
expect(fetcher.mock.calls[1]?.[0]).toContain('/subjects/subject-1/identity/stable-anchor/generate-quality')
|
|
expect(fetcher.mock.calls[1]?.[1]?.body).toBe(JSON.stringify(input))
|
|
expect(fetcher).toHaveBeenCalledTimes(2)
|
|
})
|
|
})
|