fix(short-drama-agent-front): 修复资产库请求与管理流程
This commit is contained in:
1 parent
41d1cfe3ed
commit
f8b0fbb8ca
10 files changed
+672
-77
No files matched your search
@@ -20,6 +20,36 @@ const asset: ProjectAsset = {
|
||||
afterEach(() => vi.unstubAllGlobals())
|
||||
|
||||
describe('项目资产 API', () => {
|
||||
it.each(['upload', 'update', 'remove'] as const)('素材%s结果归属错误时不能当成成功', async action => {
|
||||
vi.stubGlobal(
|
||||
'fetch',
|
||||
vi
|
||||
.fn<typeof fetch>()
|
||||
.mockResolvedValue(new Response(JSON.stringify({ data: { ...asset, projectId: 'other-project' } })))
|
||||
)
|
||||
const result =
|
||||
action === 'upload'
|
||||
? projectAssetsApi.upload(asset.projectId, {
|
||||
file: new File(['fixture'], 'fixture.png', { type: 'image/png' }),
|
||||
name: '参考',
|
||||
category: 'reference'
|
||||
})
|
||||
: action === 'update'
|
||||
? projectAssetsApi.update(asset.projectId, asset.id, { name: '新名称' })
|
||||
: projectAssetsApi.remove(asset.projectId, asset.id)
|
||||
await expect(result).rejects.toThrow('结果')
|
||||
})
|
||||
|
||||
it.each([
|
||||
{ data: null },
|
||||
{ data: {} },
|
||||
{ data: [{ ...asset, project: null }] },
|
||||
{ data: [{ ...asset, project: { id: 'other', title: null, topic: '主题', status: 'completed' } }] }
|
||||
])('无效全局素材列表不能当成成功数据:%j', async ({ data }) => {
|
||||
vi.stubGlobal('fetch', vi.fn<typeof fetch>().mockResolvedValue(new Response(JSON.stringify({ data }))))
|
||||
await expect(projectAssetsApi.listAll()).rejects.toThrow('素材列表')
|
||||
})
|
||||
|
||||
it('通过单个全局接口读取全部项目素材', async () => {
|
||||
const globalAsset = {
|
||||
...asset,
|
||||
@@ -56,9 +86,17 @@ describe('项目资产 API', () => {
|
||||
})
|
||||
|
||||
it('按正式项目和素材 ID 读取、编辑及删除', async () => {
|
||||
const fetcher = vi
|
||||
.fn<typeof fetch>()
|
||||
.mockImplementation(async () => new Response(JSON.stringify({ data: asset })))
|
||||
const fetcher = vi.fn<typeof fetch>().mockImplementation(
|
||||
async (url, init) =>
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
data:
|
||||
String(url).endsWith('/assets') && (!init?.method || init.method === 'GET')
|
||||
? [{ ...asset, id: 'asset/db', projectId: 'project/db' }]
|
||||
: { ...asset, id: 'asset/db', projectId: 'project/db' }
|
||||
})
|
||||
)
|
||||
)
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
|
||||
await projectAssetsApi.list('project/db')
|
||||
|
||||
Reference in new issue
Block a user