package clientnotify import "testing" func TestChooseChannelPrefersTelegramWhenLinked(t *testing.T) { ch, ok := chooseChannel("12345", "", "", true, true, true, true, true, true) if !ok || ch != "telegram" { t.Errorf("chooseChannel = (%q, %v), want (telegram, true)", ch, ok) } } func TestChooseChannelPrefersTelegramOverMaxWhenBothLinked(t *testing.T) { ch, ok := chooseChannel("12345", "67890", "", true, true, true, true, true, true) if !ok || ch != "telegram" { t.Errorf("chooseChannel = (%q, %v), want (telegram, true)", ch, ok) } } func TestChooseChannelFallsBackToMaxWhenNoTelegramLink(t *testing.T) { ch, ok := chooseChannel("", "67890", "", true, true, true, true, true, true) if !ok || ch != "max" { t.Errorf("chooseChannel = (%q, %v), want (max, true)", ch, ok) } } func TestChooseChannelFallsBackToVkWhenNoTelegramOrMaxLink(t *testing.T) { ch, ok := chooseChannel("", "", "112233", true, true, true, true, true, true) if !ok || ch != "vk" { t.Errorf("chooseChannel = (%q, %v), want (vk, true)", ch, ok) } } func TestChooseChannelFallsBackToSMSWhenNoLinkedChannel(t *testing.T) { ch, ok := chooseChannel("", "", "", true, true, true, true, true, true) if !ok || ch != "sms" { t.Errorf("chooseChannel = (%q, %v), want (sms, true)", ch, ok) } } func TestChooseChannelSkipsWhenClientOptedOutOfEverythingAndNoSMS(t *testing.T) { ch, ok := chooseChannel("12345", "67890", "112233", false, false, false, false, true, true) if ok { t.Errorf("chooseChannel = (%q, %v), want ok=false", ch, ok) } } func TestChooseChannelSkipsWhenClientNotifyDisabledGlobally(t *testing.T) { ch, ok := chooseChannel("12345", "", "", true, true, true, true, false, true) if ok { t.Errorf("chooseChannel = (%q, %v), want ok=false (client notify disabled)", ch, ok) } } func TestChooseChannelSkipsSMSWhenSMSDisabledGlobally(t *testing.T) { ch, ok := chooseChannel("", "", "", true, true, true, true, true, false) if ok { t.Errorf("chooseChannel = (%q, %v), want ok=false (sms disabled globally)", ch, ok) } } func TestChooseChannelSkipsSMSWhenClientOptedOut(t *testing.T) { ch, ok := chooseChannel("", "", "", true, true, true, false, true, true) if ok { t.Errorf("chooseChannel = (%q, %v), want ok=false (client opted out of sms)", ch, ok) } } func TestDedupeKeyIncludesTriggerSeedAndChannel(t *testing.T) { got := dedupeKey("status_changed", "evt-123", "telegram") want := "status_changed:evt-123:telegram" if got != want { t.Errorf("dedupeKey = %q, want %q", got, want) } } func TestDedupeKeyDiffersByChannel(t *testing.T) { a := dedupeKey("ready", "evt-1", "telegram") b := dedupeKey("ready", "evt-1", "sms") if a == b { t.Errorf("expected different dedupe keys per channel, got %q for both", a) } }