52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
package model
|
|
|
|
import "testing"
|
|
|
|
func TestDetectionTaskRejectsInvalidTransition(t *testing.T) {
|
|
if ValidDetectionTaskTransition("pending", "testing") {
|
|
t.Error("pending 不能直接跳 testing")
|
|
}
|
|
if ValidDetectionTaskTransition("draft", "completed") {
|
|
t.Error("draft 不能直接 completed")
|
|
}
|
|
if ValidDetectionTaskTransition("completed", "review") {
|
|
t.Error("completed 不能回退")
|
|
}
|
|
}
|
|
|
|
func TestDetectionTaskAllowsRequiredTransitions(t *testing.T) {
|
|
transitions := [][2]string{
|
|
{"draft", "pending"},
|
|
{"pending", "assigned"},
|
|
{"assigned", "sampling"},
|
|
{"sampling", "testing"},
|
|
{"testing", "review"},
|
|
{"review", "completed"},
|
|
{"pending", "cancelled"},
|
|
}
|
|
for _, tr := range transitions {
|
|
if !ValidDetectionTaskTransition(tr[0], tr[1]) {
|
|
t.Errorf("expected %s -> %s", tr[0], tr[1])
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestSampleTransition(t *testing.T) {
|
|
transitions := [][2]string{
|
|
{"created", "collected"},
|
|
{"collected", "handed_over"},
|
|
{"handed_over", "received"},
|
|
{"received", "testing"},
|
|
{"testing", "consumed"},
|
|
{"consumed", "disposed"},
|
|
}
|
|
for _, tr := range transitions {
|
|
if !ValidSampleTransition(tr[0], tr[1]) {
|
|
t.Errorf("expected %s -> %s", tr[0], tr[1])
|
|
}
|
|
}
|
|
if ValidSampleTransition("created", "testing") {
|
|
t.Error("created 不能直接 testing")
|
|
}
|
|
}
|