warningAttachments.test.mjs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import test from 'node:test'
  2. import assert from 'node:assert/strict'
  3. import { attachmentsForDisposal, unlinkedWarningAttachments, normalizeWarningAttachment } from '../src/views/subSystem/lifeCompany/warningAttachments.js'
  4. // 仅在内存中使用的 TEST 数据;不写入数据库或对象存储。
  5. const records = [{ disposal_id: 'TEST-HANDLE' }, { disposalId: 'TEST-SUPERVISION' }]
  6. const files = [
  7. { attachmentId: 'TEST-PNG', disposalId: 'TEST-HANDLE', attachmentName: '[处理反馈] 现场.png', attachmentSize: 1024 },
  8. { attachment_id: 'TEST-PDF', disposal_id: 'TEST-SUPERVISION', attachment_name: '[督办附件] 督办.pdf', attachment_type: 'application/pdf', attachment_size: 2048 },
  9. { attachmentId: 'TEST-REPORT', attachmentName: '[预警报告] 报告.docx' },
  10. { attachmentId: 'TEST-LEGACY', disposalId: 'TEST-MISSING', attachmentName: '历史附件.pdf' }
  11. ]
  12. test('不同处置记录只展示各自的附件,兼容下划线和驼峰字段', () => {
  13. assert.deepEqual(attachmentsForDisposal(records[0], files), [files[0]])
  14. assert.deepEqual(attachmentsForDisposal(records[1], files), [files[1]])
  15. })
  16. test('无关联编号的记录不能认领所有历史附件', () => {
  17. assert.deepEqual(attachmentsForDisposal({}, files), [])
  18. assert.deepEqual(attachmentsForDisposal(records[0], null), [])
  19. assert.deepEqual(unlinkedWarningAttachments(records, files), files.slice(2))
  20. })
  21. test('PDF 和图片可预览,文档保留原始扩展名供下载', () => {
  22. assert.equal(normalizeWarningAttachment(files[0]).previewKind, 'image')
  23. assert.equal(normalizeWarningAttachment(files[1]).previewKind, 'pdf')
  24. assert.equal(normalizeWarningAttachment(files[1]).name, '督办.pdf')
  25. assert.equal(normalizeWarningAttachment(files[1]).sizeText, '2.0 KB')
  26. assert.equal(normalizeWarningAttachment(files[2]).previewKind, '')
  27. assert.equal(normalizeWarningAttachment(files[2]).name, '报告.docx')
  28. assert.equal(normalizeWarningAttachment({ attachmentName: '页面.html', attachmentType: 'text/html' }).previewKind, '')
  29. })
  30. test('零字节与未知大小分别展示', () => {
  31. assert.equal(normalizeWarningAttachment({ attachmentSize: 0 }).sizeText, '0 B')
  32. assert.equal(normalizeWarningAttachment({ attachmentSize: null }).sizeText, '')
  33. })