check-mp-pl-plan-card.mjs 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. /**
  2. * Mirrors formatPartyLine in src/utils/mp-pl-plan-card.ts — keep in sync.
  3. * Usage: node web-admin/scripts/check-mp-pl-plan-card.mjs
  4. */
  5. function formatPartyLine(supplier, buyer) {
  6. const s = (supplier || '').trim() || '—'
  7. const b = (buyer || '').trim() || '—'
  8. return `${s} → ${b}`
  9. }
  10. function assert(cond, msg) {
  11. if (!cond) {
  12. console.error(msg)
  13. process.exit(1)
  14. }
  15. }
  16. assert(formatPartyLine('安庆仓', '合肥某化') === '安庆仓 → 合肥某化', 'party')
  17. assert(formatPartyLine('', null) === '— → —', 'empty')
  18. assert(formatPartyLine(' ', undefined) === '— → —', 'whitespace')
  19. // buildPlanCard supplier/buyer/partyLine defaults (mirrors TS || '—' + formatPartyLine)
  20. function resolveBuyer(plan) {
  21. return plan.customerName || plan.destinationName || '—'
  22. }
  23. assert(resolveBuyer({ customerName: 'A' }) === 'A', 'buyer customer')
  24. assert(resolveBuyer({ destinationName: 'B' }) === 'B', 'buyer destination')
  25. assert(resolveBuyer({}) === '—', 'buyer empty')
  26. assert(formatPartyLine(undefined, undefined) === '— → —', 'partyLine empty')
  27. console.log('check-mp-pl-plan-card: ok')