"""质检检测结果留痕:字段差异与空保存。""" from app.crud.qc_task_result_change_log import build_result_changes def test_build_changes_for_status_and_param(): before = { "taskStatus": "dzx", "conclusion": "", "remark": "", "attachments": "", "params": {"paramCode:HBsAg": {"label": "HBsAg", "value": "阴性"}}, } after = { "taskStatus": "ywc", "conclusion": "tg", "remark": "", "attachments": "", "params": {"paramCode:HBsAg": {"label": "HBsAg", "value": "阳性"}}, } changes = build_result_changes(before, after) keys = {c["fieldKey"] for c in changes} assert "taskStatus" in keys assert "conclusion" in keys assert "paramCode:HBsAg" in keys hbs = next(c for c in changes if c["fieldKey"] == "paramCode:HBsAg") assert hbs["oldValue"] == "阴性" assert hbs["newValue"] == "阳性" def test_build_changes_empty_when_identical(): state = { "taskStatus": "ywc", "conclusion": "tg", "remark": "ok", "attachments": "a.png", "params": {"paramCode:X": {"label": "X", "value": "1"}}, } assert build_result_changes(state, state) == []