42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
|
|
package domain
|
||
|
|
|
||
|
|
import (
|
||
|
|
"errors"
|
||
|
|
"testing"
|
||
|
|
)
|
||
|
|
|
||
|
|
func contextWatch() *RadarWatch {
|
||
|
|
return &RadarWatch{ID: "w", OwnerUID: 7, Terms: []string{"找水電"}, Status: WatchActive, UpdatedAt: 10}
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestWatchContextLegacyAndPairInvariant(t *testing.T) {
|
||
|
|
w := contextWatch()
|
||
|
|
if err := w.Normalize(); err != nil {
|
||
|
|
t.Fatal(err)
|
||
|
|
}
|
||
|
|
if w.ContextMode != WatchContextGeneric {
|
||
|
|
t.Fatalf("legacy mode=%q", w.ContextMode)
|
||
|
|
}
|
||
|
|
w.BrandID = "brand-only"
|
||
|
|
if err := w.NormalizeContext(); !errors.Is(err, ErrValidation) {
|
||
|
|
t.Fatalf("expected paired ID validation, got %v", err)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestWatchProductBindingIsOneWay(t *testing.T) {
|
||
|
|
w := contextWatch()
|
||
|
|
if err := w.Normalize(); err != nil {
|
||
|
|
t.Fatal(err)
|
||
|
|
}
|
||
|
|
if err := w.BindProduct("b1", "p1", "Brand", "Product", 20); err != nil {
|
||
|
|
t.Fatal(err)
|
||
|
|
}
|
||
|
|
if err := w.BindProduct("b2", "p2", "Other", "Other", 30); !errors.Is(err, ErrValidation) {
|
||
|
|
t.Fatalf("expected conflict, got %v", err)
|
||
|
|
}
|
||
|
|
w.Status, w.PauseReason = WatchPaused, PauseReasonProductUnavailable
|
||
|
|
if err := w.Transition(WatchActive); !errors.Is(err, ErrValidation) {
|
||
|
|
t.Fatalf("expected unavailable resume guard, got %v", err)
|
||
|
|
}
|
||
|
|
}
|