test(health): validation.rs 纯函数测试 57 用例
覆盖所有枚举校验和状态机转换: - gender/blood_type/appointment_type 等 13 种枚举白名单 - appointment 状态转换 8 条路径 - follow_up 状态转换 11 条路径(含 overdue)
This commit is contained in:
@@ -151,3 +151,152 @@ pub fn validate_follow_up_status_transition(current: &str, new: &str) -> HealthR
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
// --- gender ---
|
||||
#[test]
|
||||
fn gender_valid() { assert!(validate_gender("male").is_ok()); }
|
||||
#[test]
|
||||
fn gender_valid_female() { assert!(validate_gender("female").is_ok()); }
|
||||
#[test]
|
||||
fn gender_valid_other() { assert!(validate_gender("other").is_ok()); }
|
||||
#[test]
|
||||
fn gender_invalid() { assert!(validate_gender("unknown").is_err()); }
|
||||
|
||||
// --- blood_type ---
|
||||
#[test]
|
||||
fn blood_type_a() { assert!(validate_blood_type("A").is_ok()); }
|
||||
#[test]
|
||||
fn blood_type_o_neg() { assert!(validate_blood_type("O-").is_ok()); }
|
||||
#[test]
|
||||
fn blood_type_invalid() { assert!(validate_blood_type("X").is_err()); }
|
||||
|
||||
// --- appointment_type ---
|
||||
#[test]
|
||||
fn appointment_type_dialysis() { assert!(validate_appointment_type("dialysis").is_ok()); }
|
||||
#[test]
|
||||
fn appointment_type_consultation() { assert!(validate_appointment_type("consultation").is_ok()); }
|
||||
#[test]
|
||||
fn appointment_type_invalid() { assert!(validate_appointment_type("surgery").is_err()); }
|
||||
|
||||
// --- appointment_status_transition ---
|
||||
#[test]
|
||||
fn appt_pending_to_confirmed() { assert!(validate_appointment_status_transition("pending", "confirmed").is_ok()); }
|
||||
#[test]
|
||||
fn appt_pending_to_cancelled() { assert!(validate_appointment_status_transition("pending", "cancelled").is_ok()); }
|
||||
#[test]
|
||||
fn appt_pending_to_completed_fails() { assert!(validate_appointment_status_transition("pending", "completed").is_err()); }
|
||||
#[test]
|
||||
fn appt_confirmed_to_completed() { assert!(validate_appointment_status_transition("confirmed", "completed").is_ok()); }
|
||||
#[test]
|
||||
fn appt_confirmed_to_no_show() { assert!(validate_appointment_status_transition("confirmed", "no_show").is_ok()); }
|
||||
#[test]
|
||||
fn appt_confirmed_to_cancelled() { assert!(validate_appointment_status_transition("confirmed", "cancelled").is_ok()); }
|
||||
#[test]
|
||||
fn appt_completed_to_pending_fails() { assert!(validate_appointment_status_transition("completed", "pending").is_err()); }
|
||||
#[test]
|
||||
fn appt_same_status_ok() { assert!(validate_appointment_status_transition("pending", "pending").is_ok()); }
|
||||
|
||||
// --- period_type ---
|
||||
#[test]
|
||||
fn period_am() { assert!(validate_period_type("am").is_ok()); }
|
||||
#[test]
|
||||
fn period_night() { assert!(validate_period_type("night").is_ok()); }
|
||||
#[test]
|
||||
fn period_invalid() { assert!(validate_period_type("evening").is_err()); }
|
||||
|
||||
// --- schedule_status ---
|
||||
#[test]
|
||||
fn schedule_enabled() { assert!(validate_schedule_status("enabled").is_ok()); }
|
||||
#[test]
|
||||
fn schedule_disabled() { assert!(validate_schedule_status("disabled").is_ok()); }
|
||||
#[test]
|
||||
fn schedule_invalid() { assert!(validate_schedule_status("active").is_err()); }
|
||||
|
||||
// --- follow_up_type ---
|
||||
#[test]
|
||||
fn follow_up_phone() { assert!(validate_follow_up_type("phone").is_ok()); }
|
||||
#[test]
|
||||
fn follow_up_online() { assert!(validate_follow_up_type("online").is_ok()); }
|
||||
#[test]
|
||||
fn follow_up_invalid() { assert!(validate_follow_up_type("email").is_err()); }
|
||||
|
||||
// --- sender_role ---
|
||||
#[test]
|
||||
fn sender_patient() { assert!(validate_sender_role("patient").is_ok()); }
|
||||
#[test]
|
||||
fn sender_system() { assert!(validate_sender_role("system").is_ok()); }
|
||||
#[test]
|
||||
fn sender_invalid() { assert!(validate_sender_role("admin").is_err()); }
|
||||
|
||||
// --- content_type ---
|
||||
#[test]
|
||||
fn content_text() { assert!(validate_content_type("text").is_ok()); }
|
||||
#[test]
|
||||
fn content_image() { assert!(validate_content_type("image").is_ok()); }
|
||||
#[test]
|
||||
fn content_invalid() { assert!(validate_content_type("video").is_err()); }
|
||||
|
||||
// --- consultation_type ---
|
||||
#[test]
|
||||
fn consultation_customer_service() { assert!(validate_consultation_type("customer_service").is_ok()); }
|
||||
#[test]
|
||||
fn consultation_psychologist() { assert!(validate_consultation_type("psychologist").is_ok()); }
|
||||
#[test]
|
||||
fn consultation_invalid() { assert!(validate_consultation_type("general").is_err()); }
|
||||
|
||||
// --- record_type ---
|
||||
#[test]
|
||||
fn record_checkup() { assert!(validate_record_type("checkup").is_ok()); }
|
||||
#[test]
|
||||
fn record_invalid() { assert!(validate_record_type("emergency").is_err()); }
|
||||
|
||||
// --- patient_status ---
|
||||
#[test]
|
||||
fn patient_active() { assert!(validate_patient_status("active").is_ok()); }
|
||||
#[test]
|
||||
fn patient_deceased() { assert!(validate_patient_status("deceased").is_ok()); }
|
||||
#[test]
|
||||
fn patient_invalid() { assert!(validate_patient_status("suspended").is_err()); }
|
||||
|
||||
// --- verification_status ---
|
||||
#[test]
|
||||
fn verification_pending() { assert!(validate_verification_status("pending").is_ok()); }
|
||||
#[test]
|
||||
fn verification_verified() { assert!(validate_verification_status("verified").is_ok()); }
|
||||
#[test]
|
||||
fn verification_invalid() { assert!(validate_verification_status("approved").is_err()); }
|
||||
|
||||
// --- online_status ---
|
||||
#[test]
|
||||
fn online_busy() { assert!(validate_online_status("busy").is_ok()); }
|
||||
#[test]
|
||||
fn online_invalid() { assert!(validate_online_status("away").is_err()); }
|
||||
|
||||
// --- follow_up_status_transition ---
|
||||
#[test]
|
||||
fn fu_pending_to_in_progress() { assert!(validate_follow_up_status_transition("pending", "in_progress").is_ok()); }
|
||||
#[test]
|
||||
fn fu_pending_to_overdue() { assert!(validate_follow_up_status_transition("pending", "overdue").is_ok()); }
|
||||
#[test]
|
||||
fn fu_pending_to_cancelled() { assert!(validate_follow_up_status_transition("pending", "cancelled").is_ok()); }
|
||||
#[test]
|
||||
fn fu_pending_to_completed_fails() { assert!(validate_follow_up_status_transition("pending", "completed").is_err()); }
|
||||
#[test]
|
||||
fn fu_in_progress_to_completed() { assert!(validate_follow_up_status_transition("in_progress", "completed").is_ok()); }
|
||||
#[test]
|
||||
fn fu_in_progress_to_cancelled() { assert!(validate_follow_up_status_transition("in_progress", "cancelled").is_ok()); }
|
||||
#[test]
|
||||
fn fu_overdue_to_in_progress() { assert!(validate_follow_up_status_transition("overdue", "in_progress").is_ok()); }
|
||||
#[test]
|
||||
fn fu_overdue_to_cancelled() { assert!(validate_follow_up_status_transition("overdue", "cancelled").is_ok()); }
|
||||
#[test]
|
||||
fn fu_overdue_to_completed_fails() { assert!(validate_follow_up_status_transition("overdue", "completed").is_err()); }
|
||||
#[test]
|
||||
fn fu_completed_to_any_fails() { assert!(validate_follow_up_status_transition("completed", "pending").is_err()); }
|
||||
#[test]
|
||||
fn fu_same_status_ok() { assert!(validate_follow_up_status_transition("pending", "pending").is_ok()); }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user