package staticsite import ( "testing" "github.com/alexei/tinyforge/internal/notify" "github.com/alexei/tinyforge/internal/store" ) // TestResolveSiteTarget locks the per-site → global precedence for static // site sync notifications. Distinct from the deploy resolver because there // is no project tier between site and settings; a regression that swapped // the order would silently route per-site events to the global receiver. func TestResolveSiteTarget(t *testing.T) { cases := []struct { name string site store.StaticSite settings store.Settings wantURL string wantSec string wantTier notify.Tier }{ { name: "site wins when URL set", site: store.StaticSite{NotificationURL: "https://site.example/wh", NotificationSecret: "site-key"}, settings: store.Settings{NotificationURL: "https://global.example/wh", NotificationSecret: "global-key"}, wantURL: "https://site.example/wh", wantSec: "site-key", wantTier: notify.TierSite, }, { name: "site URL empty → global wins", site: store.StaticSite{}, settings: store.Settings{NotificationURL: "https://global.example/wh", NotificationSecret: "global-key"}, wantURL: "https://global.example/wh", wantSec: "global-key", wantTier: notify.TierSettings, }, { name: "both empty → empty URL with settings tier", site: store.StaticSite{}, settings: store.Settings{}, wantURL: "", wantSec: "", wantTier: notify.TierSettings, }, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { gotURL, gotSec, gotTier := resolveSiteTarget(tc.site, tc.settings) if gotURL != tc.wantURL { t.Errorf("url = %q, want %q", gotURL, tc.wantURL) } if gotSec != tc.wantSec { t.Errorf("secret = %q, want %q", gotSec, tc.wantSec) } if gotTier != tc.wantTier { t.Errorf("tier = %q, want %q", gotTier, tc.wantTier) } }) } }