import test from 'node:test' import assert from 'node:assert/strict' import {historyFields,historyChanges,historyDisplay} from '../../src/utils/purchase-history-correction.js' test('history patches include only explicitly selected maintained fields, not server-owned state or totals',()=>{ const old={id:9,remark:'原备注',quantity:2,actualUnitPrice:3,finalUnitPrice:4} assert.deepEqual(historyChanges(old,{...old,remark:'新备注',purchaseStatus:0,quantity:99},['remark','purchaseStatus']),{remark:'新备注'}) assert.equal(old.remark,'原备注') for(const key of ['materialName','materialParams','unit','category','quantity','actualUnitPrice','finalUnitPrice','projectId','expenseCategoryId'])assert.ok(historyFields.some(f=>f.key===key)) for(const key of ['purchaseStatus','acceptedQuantity','receivedQuantity','historical','actualAmount','id'])assert.ok(!historyFields.some(f=>f.key===key)) }) test('empty actual price is an explicit clear, never zero; zero prices remain numeric business input',()=>{ assert.deepEqual(historyChanges({}, {actualUnitPrice:'',finalUnitPrice:0},['actualUnitPrice','finalUnitPrice']),{actualUnitPrice:null,finalUnitPrice:0}) assert.deepEqual(historyChanges({}, {actualUnitPrice:3},['remark']),{remark:''}) assert.equal(historyDisplay(null),'未填写');assert.equal(historyDisplay(0),'0') })