test(knowledge): seed 数据完整性测试(RED)

This commit is contained in:
weijuesen
2026-08-12 10:46:46 +08:00
parent 13df3d5190
commit 50dcd65edf
2 changed files with 93 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
package model
import "time"
// Disease 蚕病百科条目(知识库-蚕病百科)
type Disease struct {
ID string `gorm:"type:uuid;primaryKey;default:gen_random_uuid()" json:"id"`
Name string `gorm:"size:64" json:"name"`
Category string `gorm:"size:32;index" json:"category"` // viral/fungal/bacterial/protozoan/other
Pathogen string `gorm:"type:text" json:"pathogen"`
Transmission string `gorm:"type:text" json:"transmission"`
Medium string `gorm:"type:text" json:"medium"`
Incubation string `gorm:"type:text" json:"incubation"`
Symptoms string `gorm:"type:text" json:"symptoms"`
HighRiskStage string `gorm:"column:high_risk_stage;type:text" json:"highRiskStage"`
HighRiskCondition string `gorm:"column:high_risk_condition;type:text" json:"highRiskCondition"`
LethalTime string `gorm:"column:lethal_time;type:text" json:"lethalTime"`
SpreadTrend string `gorm:"column:spread_trend;type:text" json:"spreadTrend"`
Recurrence string `gorm:"type:text" json:"recurrence"`
Detection string `gorm:"type:text" json:"detection"`
Prevention string `gorm:"type:text" json:"prevention"`
ImageURL *string `gorm:"column:image_url;size:512" json:"imageUrl,omitempty"`
SortOrder int `gorm:"column:sort_order;type:int;default:0" json:"sortOrder"`
Enabled bool `gorm:"default:true" json:"enabled"`
CreatedAt time.Time `gorm:"type:timestamptz" json:"createdAt"`
UpdatedAt time.Time `gorm:"type:timestamptz" json:"updatedAt"`
}
func (Disease) TableName() string { return "diseases" }
// KnowledgeArticle 知识文章(AI 结果解读、LAMP/SERS 教程、季节性防控提醒等)
type KnowledgeArticle struct {
ID string `gorm:"type:uuid;primaryKey;default:gen_random_uuid()" json:"id"`
Kind string `gorm:"size:32;index" json:"kind"` // ai_guide/lamp_guide/sers_guide/seasonal_tip
Title string `gorm:"size:128" json:"title"`
Summary string `gorm:"type:text" json:"summary"`
Content string `gorm:"type:text" json:"content"`
SortOrder int `gorm:"column:sort_order;type:int;default:0" json:"sortOrder"`
Enabled bool `gorm:"default:true" json:"enabled"`
CreatedAt time.Time `gorm:"type:timestamptz" json:"createdAt"`
UpdatedAt time.Time `gorm:"type:timestamptz" json:"updatedAt"`
}
func (KnowledgeArticle) TableName() string { return "knowledge_articles" }
@@ -0,0 +1,49 @@
package model
import "testing"
func TestSeedDiseasesCoverCoreFour(t *testing.T) {
core := []string{"核型多角体病", "白僵病", "软化病", "微粒子病"}
got := map[string]bool{}
for _, d := range SeedDiseases {
got[d.Name] = true
}
for _, name := range core {
if !got[name] {
t.Errorf("核心蚕病缺失: %s", name)
}
}
}
func TestSeedDiseasesRequiredFields(t *testing.T) {
for _, d := range SeedDiseases {
if d.Name == "" || d.Category == "" {
t.Errorf("病种名称/类别不能为空: %+v", d)
}
if d.Pathogen == "" || d.Symptoms == "" || d.Transmission == "" || d.Prevention == "" {
t.Errorf("病种必备字段缺失(病原/症状/传播途径/防治指南): %s", d.Name)
}
}
}
func TestSeedDiseasesNamesUnique(t *testing.T) {
seen := map[string]bool{}
for _, d := range SeedDiseases {
if seen[d.Name] {
t.Errorf("病种名称重复: %s", d.Name)
}
seen[d.Name] = true
}
}
func TestSeedKnowledgeArticlesHasAIGuide(t *testing.T) {
found := false
for _, a := range SeedKnowledgeArticles {
if a.Kind == "ai_guide" && a.Title != "" && a.Content != "" {
found = true
}
}
if !found {
t.Error("缺少 AI 结果解读文章(kind=ai_guide")
}
}