78 lines
2.2 KiB
Go
78 lines
2.2 KiB
Go
package model
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestValidMaintenanceKind(t *testing.T) {
|
|
for _, kind := range []string{"calibration", "fault", "maintenance", "firmware"} {
|
|
if !ValidMaintenanceKind(kind) {
|
|
t.Errorf("%s should be valid", kind)
|
|
}
|
|
}
|
|
if ValidMaintenanceKind("inspection") {
|
|
t.Error("inspection is not a maintenance kind")
|
|
}
|
|
}
|
|
|
|
func TestValidateDeviceMaintenanceRecord(t *testing.T) {
|
|
record := DeviceMaintenanceRecord{Kind: "calibration", Title: "温度传感器校准"}
|
|
if err := ValidateDeviceMaintenanceRecord(record); err != nil {
|
|
t.Fatalf("valid record should pass: %v", err)
|
|
}
|
|
record.Title = ""
|
|
if err := ValidateDeviceMaintenanceRecord(record); err == nil {
|
|
t.Fatal("missing title should fail")
|
|
}
|
|
record.Title = "校准"
|
|
record.Kind = "unknown"
|
|
if err := ValidateDeviceMaintenanceRecord(record); err == nil {
|
|
t.Fatal("invalid kind should fail")
|
|
}
|
|
}
|
|
|
|
func TestValidateProductionLossRecord(t *testing.T) {
|
|
roomID := "room-1"
|
|
yield := 3.2
|
|
record := ProductionLossRecord{RoomID: &roomID, RecordDate: time.Now(), YieldKg: &yield}
|
|
if err := ValidateProductionLossRecord(record); err != nil {
|
|
t.Fatalf("valid record should pass: %v", err)
|
|
}
|
|
record.YieldKg = nil
|
|
if err := ValidateProductionLossRecord(record); err == nil {
|
|
t.Fatal("record without business value should fail")
|
|
}
|
|
}
|
|
|
|
func TestValidCaseStudyTransition(t *testing.T) {
|
|
ok := [][2]string{
|
|
{"draft", "pending_review"},
|
|
{"pending_review", "published"},
|
|
{"pending_review", "rejected"},
|
|
{"published", "rejected"},
|
|
}
|
|
for _, tr := range ok {
|
|
if !ValidCaseStudyTransition(tr[0], tr[1]) {
|
|
t.Errorf("expected %s -> %s", tr[0], tr[1])
|
|
}
|
|
}
|
|
if ValidCaseStudyTransition("draft", "published") {
|
|
t.Error("draft cannot jump to published")
|
|
}
|
|
}
|
|
|
|
func TestValidateLaboratoryResult(t *testing.T) {
|
|
result := LaboratoryResult{
|
|
LabName: "省蚕科所", ReportNo: "LAB-001",
|
|
TestType: "molecular_typing", ResultType: "positive",
|
|
}
|
|
if err := ValidateLaboratoryResult(result); err != nil {
|
|
t.Fatalf("valid result should pass: %v", err)
|
|
}
|
|
result.ResultType = "unknown"
|
|
if err := ValidateLaboratoryResult(result); err == nil {
|
|
t.Fatal("invalid result type should fail")
|
|
}
|
|
}
|