Files
crawler-plugin/admin-frontend-vue/tests/pure/pending-phase4-大档上传接线.test.ts
T

74 lines
2.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// AC-11(R4):后管大档上传接线的「行为用例」那一半。
//
// Pending Phase 4 激活。9MB 安装包(跨分片阈值)调 uploadSoftwareVersion,
// 必须出现 POST /files/chunk/init;今天它走 presign → 一次 PUT 直传,
// 512MB 断网只能从 0 重来。本文件不出网,mock 掉 http 与 axios 直传实例。
import { describe, it, expect, vi } from 'vitest'
const mocks = vi.hoisted(() => ({
post: vi.fn(),
get: vi.fn(),
put: vi.fn(),
delete: vi.fn(),
directPut: vi.fn(),
}))
vi.mock('axios', () => ({
default: {
create: () => ({ put: mocks.directPut }),
},
}))
vi.mock('@/api/http', () => ({
http: { post: mocks.post, get: mocks.get, put: mocks.put, delete: mocks.delete },
unwrap: (value: unknown) => {
const envelope = value as { success?: boolean; data?: unknown; message?: string }
if (envelope && typeof envelope === 'object' && 'success' in envelope) {
if (!envelope.success) {
throw new Error(envelope.message || '请求失败')
}
return envelope.data
}
return value
},
}))
import { uploadSoftwareVersion } from '@/pages/records/version-api.ts'
const SKIP = 'Pending Phase 4: 断点续传大档接线(AC-11)'
describe.skip('AC-11 后管大档上传', () => {
it('9MB 安装包必须走分片 init', async () => {
// 预签名与分片两套响应揉成一个超集:哪条实现路径先走都能拿到自己要的字段。
mocks.post.mockResolvedValue({
data: {
success: true,
data: {
upload_url: 'https://oss.example/put',
file_url: 'https://oss.example/pkg.zip',
version: '9.9.9',
object_key: 'client/versions/pkg.zip',
upload_id: 'a'.repeat(32),
uploaded_parts: [],
item: null,
},
},
})
mocks.get.mockResolvedValue({
data: { success: true, data: { upload_id: 'a'.repeat(32), uploaded_parts: [] } },
})
mocks.directPut.mockResolvedValue({})
const file = new Blob([new Uint8Array(9 * 1024 * 1024)], {
type: 'application/octet-stream',
})
await uploadSoftwareVersion('9.9.9', file)
const urls = mocks.post.mock.calls.map(([url]) => String(url))
expect(
urls.some((url) => url.includes('/files/chunk/init')),
`AC-11:9MB 安装包仍走 presign 直传,实际出口:${urls.join(', ')}`,
).toBe(true)
})
})