PayrollManagementSystem/backend/tests/unit/test_approval_schema.py
liuwenxin 4c32a556de feat(approval): 审批单内容快照与二次分配方案版本化
补齐 code-review 遗留 2 项:审批单此前只固化 ref_id/refer_no 指针,复核者看到
的是业务当前内容;二次分配方案在编辑替换与驳回清空时一律物理删除,方案事实
无处回溯。

- 审批单加 version_no 与 snapshot_json(信封 schema_version/order_type/
  captured_at/data);二次分配、月结、调整单三类提交均固化送审内容,开关关闭
  的自动通过路径同样写快照;详情按 snapshot/live/missing 三态回显,历史单
  只读回退当前内容并显式告警,不回填历史快照
- 二次分配方案行改 append-only 版本化(version_no/is_active,唯一键扩为
  business+version+personnel):编辑替换与驳回清空只置历史,核算与详情默认
  只取生效行,业务详情新增 allocation_history
- 送审内容未变不重提、方案未变不新增版本:判据统一为送审内容,两个
  version_no 语义解耦(方案版本=内容第几版,审批单版本=第几次送审)
- 审批单列表、工作台待办、审批超时预警三处 defer 快照列,避免整列拉取
- 月结提交取行加 for_update,防并发提交算出重复的审批单版本号
- 修复审批类型筛选上界 le=2(调整单无法筛选)、快照金额把空值写成 0.00
- V11 迁移三件套同步(Alembic / db/migration / init-dev.sql)

测试:单元 +16(方案内容比较 10、审批入参 6)、集成 +12;全量 891 passed。

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-10-20 18:30:51 +08:00

39 lines
1.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""审批管理入参校验(schema 层,秒级)。
守的是:对象类型筛选必须覆盖三类审批对象(1 二次分配方案 / 2 月度结算 /
3 调整单)——早期上界写死在 2,调整单审批单在列表里无法筛选;越界值在
参数绑定阶段即拒绝。驳回必须带意见(空驳无从追溯)。
"""
import pytest
from pydantic import ValidationError
from app.schemas.approval import ApprovalActionIn, ApprovalQuery
class TestQueryOrderType:
"""对象类型筛选边界。"""
@pytest.mark.parametrize("value", [1, 2, 3])
def test_三类对象均可筛选(self, value: int) -> None:
assert ApprovalQuery(order_type=value).order_type == value
@pytest.mark.parametrize("value", [0, 4])
def test_越界类型被拒(self, value: int) -> None:
with pytest.raises(ValidationError):
ApprovalQuery(order_type=value)
def test_不传类型表示全部(self) -> None:
assert ApprovalQuery().order_type is None
class TestActionOpinion:
"""节点动作的驳回意见要求。"""
def test_驳回必须填意见(self) -> None:
with pytest.raises(ValidationError):
ApprovalActionIn(action=2)
def test_通过可不填意见(self) -> None:
assert ApprovalActionIn(action=1).opinion is None