package lifecycle import ( "testing" "github.com/gogf/gf/v2/encoding/gjson" ) func TestPreferredLifecycleChanKey(t *testing.T) { tests := []struct { name string appBatch bool snapshot string card string want string }{ {name: "app resolved snapshot wins", appBatch: true, snapshot: " legacy-129 ", card: "stale-1", want: "legacy-129"}, {name: "console keeps card channel", snapshot: "legacy-129", card: " card-112 ", want: "card-112"}, {name: "card fallback", card: " card-112 ", want: "card-112"}, {name: "empty", want: ""}, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { if got := preferredLifecycleChanKey(test.appBatch, test.snapshot, test.card); got != test.want { t.Fatalf("preferredLifecycleChanKey() = %q, want %q", got, test.want) } }) } } func TestAppBatchUsesSnapshotChannel(t *testing.T) { if !appBatchUsesSnapshotChannel(gjson.New(map[string]any{"source": "APP"})) { t.Fatal("app batch should use the resolved snapshot channel") } if appBatchUsesSnapshotChannel(gjson.New(map[string]any{"source": "console"})) { t.Fatal("console batch must continue using the current card channel") } }