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) })