import assert from 'node:assert/strict'
import test from 'node:test'

import { buildAttachmentRiskCards } from '../src/views/scripts/travelRequestDetailInsights.js'
import { mapPreReviewFindingsToRiskFlags } from '../src/views/scripts/travelRequestDetailPreReview.js'


test('structured pre-review findings remain visible as actionable risk cards', () => {
  const flags = mapPreReviewFindingsToRiskFlags({
    findings: [
      {
        risk_id: 'risk-visible-001',
        source: 'platform_risk',
        severity: 'high',
        actionability: 'fixable_by_submitter',
        business_stage: 'reimbursement',
        message: '发票抬头不匹配，请重新上传。',
        item_ids: ['item-001']
      }
    ]
  })

  assert.equal(flags[0].source, 'platform_risk')
  assert.notEqual(flags[0].source, 'ai_pre_review')
  const cards = buildAttachmentRiskCards({
    expenseItems: [{ id: 'item-001', itemNote: '' }],
    claimRiskFlags: flags,
    businessStage: 'reimbursement'
  })
  assert.equal(cards.length, 1)
  assert.equal(cards[0].risk, '发票抬头不匹配，请重新上传。')
  assert.equal(cards[0].actionability, 'fixable_by_submitter')
})
