test(web): 前端 Store 单元测试 + patient_service tracing 补全
Some checks failed
CI / rust-check (push) Has been cancelled
CI / rust-test (push) Has been cancelled
CI / frontend-build (push) Has been cancelled
CI / security-audit (push) Has been cancelled

Store 测试 (71 个):
- auth.test.ts: 22 tests — 登录/登出/权限/JWT解析/localStorage持久化
- app.test.ts: 24 tests — 主题切换/侧边栏/配置加载/状态隔离
- message.test.ts: 25 tests — 未读计数/消息列表/SSE连接/标记已读

Tracing 补全:
- create_patient: 身份证号重复时 warn 日志
- update_patient/delete_patient: 版本冲突时 warn 日志含 expected/actual
This commit is contained in:
iven
2026-05-03 09:58:13 +08:00
parent 84afeaf9f2
commit 9d07ea0be0
4 changed files with 1227 additions and 2 deletions

View File

@@ -152,6 +152,7 @@ pub async fn create_patient(
.one(&state.db)
.await?;
if dup.is_some() {
tracing::warn!(action = "create_patient", tenant_id = %tenant_id, "身份证号重复,拒绝创建");
return Err(HealthError::Validation("该身份证号已存在患者档案".to_string()));
}
}
@@ -257,7 +258,10 @@ pub async fn update_patient(
tracing::info!(action = "update_patient", patient_id = %id, "Updating patient");
let model = find_patient(&state.db, tenant_id, id).await?;
let next_ver = check_version(expected_version, model.version)
.map_err(|_| HealthError::VersionMismatch)?;
.map_err(|_| {
tracing::warn!(action = "update_patient", patient_id = %id, expected = expected_version, actual = model.version, "版本冲突");
HealthError::VersionMismatch
})?;
if let Some(ref g) = req.gender { validate_gender(g)?; }
if let Some(ref bt) = req.blood_type { validate_blood_type(bt)?; }
@@ -371,7 +375,10 @@ pub async fn delete_patient(
tracing::info!(action = "delete_patient", patient_id = %id, "Soft deleting patient");
let model = find_patient(&state.db, tenant_id, id).await?;
let next_ver = check_version(expected_version, model.version)
.map_err(|_| HealthError::VersionMismatch)?;
.map_err(|_| {
tracing::warn!(action = "delete_patient", patient_id = %id, expected = expected_version, actual = model.version, "版本冲突");
HealthError::VersionMismatch
})?;
let mut active: patient::ActiveModel = model.into();
active.deleted_at = Set(Some(Utc::now()));