import { describe, expect, it, vi } from 'vitest' vi.mock('../../../../../packages/publisher-platforms/src/toutiao', () => ({ publishToutiaoArticle: vi.fn(async () => ({ success: true, status: 'success', articleId: 'pgc-1', mediaName: '头条号测试账号', externalManageUrl: 'https://mp.toutiao.com/profile_v4/index', externalArticleUrl: 'https://www.toutiao.com/article/pgc-1/', message: '头条号发布成功。', })), })) vi.mock('./media-image', () => ({ fetchImageAssetBlob: vi.fn(async () => ({ blob: new Blob(['image'], { type: 'image/png' }), width: 1, height: 1, fileName: 'image.png', })), })) import { publishToutiaoArticle } from '../../../../../packages/publisher-platforms/src/toutiao' import { toutiaoAdapter } from './toutiao' import { fetchImageAssetBlob } from './media-image' describe('toutiao adapter', () => { it('fetches relative public assets through the desktop asset pipeline before platform upload', async () => { const result = await toutiaoAdapter.publish( { taskId: 'task-1', accountId: 'account-1', session: {} as never, view: null, playwright: null, signal: new AbortController().signal, phase: 'initial', reportProgress: vi.fn(), article: { article_id: 889, title: '2026年室内门锁怎么选?五款高适配产品参考', html_content: null, markdown_content: '

', cover_asset_url: '/api/public/assets/cover-token', }, }, {}, ) expect(result.status).toBe('succeeded') expect(publishToutiaoArticle).toHaveBeenCalledOnce() const transport = vi.mocked(publishToutiaoArticle).mock.calls[0]?.[1] expect(transport).toBeTruthy() const bodyBlob = await transport?.fetchImageBlob('/api/public/assets/body-token') const coverBlob = await transport?.fetchImageBlob('/api/public/assets/cover-token') expect(bodyBlob?.type).toBe('image/png') expect(coverBlob?.type).toBe('image/png') expect(fetchImageAssetBlob).toHaveBeenCalledWith('/api/public/assets/body-token') expect(fetchImageAssetBlob).toHaveBeenCalledWith('/api/public/assets/cover-token') }) })