feat(server-go): 专家会诊(病例快照/状态流转/意见与方案,#18)

This commit is contained in:
weijuesen
2026-08-12 19:04:08 +08:00
parent 3db6943c63
commit bf734c1a52
6 changed files with 370 additions and 0 deletions
@@ -0,0 +1,57 @@
package model
import (
"encoding/json"
"testing"
"time"
)
func TestValidConsultationTransition(t *testing.T) {
ok := [][2]string{
{"pending", "consulting"},
{"pending", "resolved"},
{"consulting", "resolved"},
{"resolved", "archived"},
}
for _, c := range ok {
if !ValidConsultationTransition(c[0], c[1]) {
t.Errorf("%s → %s 应合法", c[0], c[1])
}
}
bad := [][2]string{
{"pending", "archived"},
{"resolved", "resolved"},
{"archived", "pending"},
{"", "resolved"},
}
for _, c := range bad {
if ValidConsultationTransition(c[0], c[1]) {
t.Errorf("%s → %s 不应合法", c[0], c[1])
}
}
}
func TestConsultationSnapshotJSON(t *testing.T) {
now := time.Now()
s := ConsultationSnapshot{
RoomName: "蚕房1#",
LampTest: &LampTest{ID: "lamp-1", Status: "resulted"},
Inspection: &InspectionRecord{ID: "insp-1", AIStatus: "done"},
Batch: &Batch{ID: "batch-1", Name: "批次A"},
WeatherAlerts: []WeatherAlert{{Disease: "白僵病", Level: "orange"}},
CreatedAt: now,
}
raw, err := json.Marshal(s)
if err != nil {
t.Fatalf("快照序列化失败: %v", err)
}
var m map[string]any
if err := json.Unmarshal(raw, &m); err != nil {
t.Fatalf("快照反序列化失败: %v", err)
}
for _, key := range []string{"roomName", "lampTest", "inspection", "batch", "weatherAlerts", "createdAt"} {
if _, ok := m[key]; !ok {
t.Errorf("快照缺少字段 %s", key)
}
}
}