task-146: collectdata 自洽行为契约(后端无 file 字段 VO 快照、前端 success+downloadUrl 判定含空白边界)+ 前后端 13 条测试
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* collectdata 下载判定(Task 146)。
|
||||
*
|
||||
* collectdata 后端 history VO 不返回 file 阶段字段;前端下载判定自洽:
|
||||
* success=true 且 downloadUrl 非空才可下载(任务成功且有结果文件)。
|
||||
*/
|
||||
export interface CollectDataItem {
|
||||
success?: boolean | null
|
||||
downloadUrl?: string | null
|
||||
taskStatus?: string | null
|
||||
}
|
||||
|
||||
/** collectdata 可下载判定:success + downloadUrl(任务成功且有结果文件,空白 URL 无效)。 */
|
||||
export function canDownloadCollectDataItem(item: CollectDataItem | null | undefined): boolean {
|
||||
if (!item) return false
|
||||
const url = typeof item.downloadUrl === 'string' ? item.downloadUrl.trim() : ''
|
||||
return Boolean(item.success && url)
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import { test } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
|
||||
import { canDownloadCollectDataItem } from '../src/shared/collect-download.ts'
|
||||
|
||||
interface Item {
|
||||
success?: boolean | null
|
||||
downloadUrl?: string | null
|
||||
taskStatus?: string | null
|
||||
}
|
||||
|
||||
test('collectdata downloadable when success and url present', () => {
|
||||
assert.equal(canDownloadCollectDataItem({ success: true, downloadUrl: 'https://dl.example/a.xlsx' }), true)
|
||||
})
|
||||
|
||||
test('collectdata not downloadable without url', () => {
|
||||
assert.equal(canDownloadCollectDataItem({ success: true }), false)
|
||||
assert.equal(canDownloadCollectDataItem({ success: true, downloadUrl: null }), false)
|
||||
assert.equal(canDownloadCollectDataItem({ success: true, downloadUrl: '' }), false)
|
||||
})
|
||||
|
||||
test('collectdata failed task not downloadable', () => {
|
||||
assert.equal(canDownloadCollectDataItem({ success: false, downloadUrl: 'https://dl.example/a.xlsx' }), false)
|
||||
})
|
||||
|
||||
test('collectdata url must be non-blank to be valid', () => {
|
||||
assert.equal(canDownloadCollectDataItem({ success: true, downloadUrl: ' ' }), false)
|
||||
assert.equal(canDownloadCollectDataItem({ success: true, downloadUrl: 'https://x' }), true)
|
||||
})
|
||||
|
||||
test('collectdata progress display fields do not include file phase', () => {
|
||||
const item: Item = { success: false, taskStatus: 'RUNNING' }
|
||||
assert.equal('fileStatus' in item, false, 'collectdata 无 file 阶段字段(与后端 VO 自洽)')
|
||||
assert.equal('fileReady' in item, false)
|
||||
assert.equal('fileProgressPercent' in item, false)
|
||||
})
|
||||
|
||||
test('collectdata semantics frozen', () => {
|
||||
assert.equal(canDownloadCollectDataItem(undefined), false)
|
||||
assert.equal(canDownloadCollectDataItem(null), false)
|
||||
assert.equal(canDownloadCollectDataItem({}), false)
|
||||
assert.equal(canDownloadCollectDataItem({ success: true, downloadUrl: 'x', taskStatus: 'SUCCESS' }), true)
|
||||
})
|
||||
Reference in New Issue
Block a user