Files
huangzd1997 45fdd8a294 feat(software-version): 安装包改浏览器直传 MinIO,支持批量删除
- 后端新增 /api/admin/version/presign、confirm、delete 端点;直传后服务端校验对象并写 web_config
- OSS 层新增软件版本对象 presign PUT/大小校验/删除与 client 桶 URL 识别
- 后台前端上传改 presign→PUT→confirm 三段式直传,带进度条;成功提示精简为"发布成功"
- 版本列表加勾选/表头全选、批量删除与单行删除;操作按钮样式对齐其他子菜单
2026-09-08 23:51:18 +08:00

73 lines
3.6 KiB
TypeScript
Raw Permalink 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.
import test from 'node:test'
import assert from 'node:assert/strict'
import { readSource } from './helpers.ts'
import { validateSoftwareVersionUpload } from '../src/pages/records/version-upload-model.ts'
import { parseSoftwareVersionUpload } from '../src/pages/records/version-model.ts'
import { formatFileSize } from '../src/pages/records/version-format.ts'
// module 13 task 260:软件版本页对齐 admin panel-versionzip 校验文案/发布成功含链接/列表+下载/空态)。
test('test_task_260_version_normal_primary_path', () => {
// 正常主路径:上传表单校验通过;发布成功解析返回新版本行。
const { valid, errors } = validateSoftwareVersionUpload({ version: '1.0.2', file: { name: 'a.zip', size: 2048 } })
assert.equal(valid, true)
assert.deepEqual(errors, {})
const item = parseSoftwareVersionUpload({
success: true,
data: { item: { id: 1, version: '1.0.2', file_url: 'https://oss/x/1.0.2.zip', created_at: '2026-09-05T10:00:00' } },
})
assert.equal(item?.version, '1.0.2')
assert.equal(item?.fileUrl, 'https://oss/x/1.0.2.zip')
})
test('test_task_260_version_normal_variant_input', () => {
// 正常变体:上传无 item 时回 null,不抛。
assert.equal(parseSoftwareVersionUpload({ success: true, data: {} }), null)
assert.equal(parseSoftwareVersionUpload({ success: true }), null)
})
test('test_task_260_version_normal_repeated_operation_is_idempotent', () => {
assert.equal(parseSoftwareVersionUpload({ success: true, data: { item: { id: 1, version: 'v' } } })?.version, 'v')
assert.equal(parseSoftwareVersionUpload({ success: true, data: { item: { id: 1, version: 'v' } } })?.version, 'v')
})
test('test_task_260_version_boundary_empty_input', () => {
// 边界:空版本/空文件报对应文案(对齐 admin.js)。
const { errors } = validateSoftwareVersionUpload({ version: '', file: null })
assert.equal(errors.version, '请填写版本号')
assert.equal(errors.file, '请选择 zip 压缩包')
})
test('test_task_260_version_boundary_single_item', () => {
// 边界:非 zip 扩展名被拒。
const { errors } = validateSoftwareVersionUpload({ version: '1.0.0', file: { name: 'x.exe', size: 100 } })
assert.equal(errors.file, '仅支持 .zip 格式')
const ok = validateSoftwareVersionUpload({ version: '1.0.0', file: { name: 'X.ZIP', size: 100 } })
assert.equal(ok.valid, true, '扩展名大小写不敏感')
})
test('test_task_260_version_boundary_limit_or_missing_field', () => {
// 边界上限:文件字节格式化仍可用。
assert.equal(formatFileSize(1536), '1.5 KB')
})
test('test_task_260_version_invalid_input_rejected', () => {
// 异常:发布失败有兜底文案、页面上传 accept 限 .zip。
const page = readSource('src/pages/records/RecordsSoftwareVersionPage.vue')
assert.match(page, /请填写版本号/)
assert.match(page, /请选择 zip 压缩包/)
assert.match(page, /仅支持 \.zip 格式/)
assert.match(page, /accept="\.zip"/)
assert.match(page, /上传失败/, '上传失败兜底文案')
})
test('test_task_260_version_dependency_failure_returns_actionable_message', () => {
// 依赖失败:成功提示精简为“发布成功”;上传经 API 适配并解析新版本;空态兜底。
const page = readSource('src/pages/records/RecordsSoftwareVersionPage.vue')
assert.match(page, /发布成功/, '成功提示留驻弹窗')
assert.match(page, /正在上传/, '上传过程提示含进度')
assert.match(page, /暂无版本/, '空态文案')
const api = readSource('src/pages/records/version-api.ts')
assert.match(api, /parseSoftwareVersionUpload/, '上传适配解析新版本行')
})