package model import ( "encoding/json" "testing" ) func TestDiseaseEventRequiresEvidenceToConfirm(t *testing.T) { event := DiseaseEvent{Status: "confirmed"} if err := ValidateDiseaseEventEvidence(event); err == nil { t.Fatal("confirmed 无证据应返回错误") } event.Evidence = json.RawMessage(`{"result":"positive"}`) if err := ValidateDiseaseEventEvidence(event); err != nil { t.Fatalf("confirmed 有证据应通过: %v", err) } } func TestDiseaseEventTransition(t *testing.T) { transitions := [][2]string{ {"suspected", "confirmed"}, {"confirmed", "controlled"}, {"controlled", "closed"}, {"closed", "reopened"}, {"reopened", "confirmed"}, } for _, tr := range transitions { if !ValidDiseaseEventTransition(tr[0], tr[1]) { t.Errorf("expected %s -> %s", tr[0], tr[1]) } } if ValidDiseaseEventTransition("suspected", "controlled") { t.Error("suspected 不能直接 controlled") } }