Files
TradarrV2/backend/internal/models/source_support_test.go

40 lines
1.7 KiB
Go

package models
import "testing"
func TestSourceSupportUsesOnlyCanonicalKeyAndPersistedEnabled(t *testing.T) {
rss := SourceBloomberg
unknown := "reuters"
sources := []Source{
{ID: "supported", Type: "bloomberg", SourceKey: &rss, Enabled: true, ArticleLimit: 83},
{ID: "disabled", SourceKey: &rss, Enabled: false, ArticleLimit: 77},
{ID: "legacy", Type: "stocktwits", Name: "Yahoo Finance", Enabled: true, ArticleLimit: 42},
{ID: "unknown", SourceKey: &unknown, Enabled: true, ArticleLimit: 31},
}
filtered := OperationalSources(sources)
if len(filtered) != 1 || filtered[0].ID != "supported" || filtered[0].ArticleLimit != 83 {
t.Fatalf("filtered=%v", filtered)
}
if !sources[2].Enabled || sources[2].Supported() || sources[2].Operational() {
t.Fatal("legacy enabled must remain persisted, without operational support")
}
if !sources[1].Supported() || sources[1].Operational() {
t.Fatal("disabled target support/operational mismatch")
}
}
func TestRetiredCNBCAndWatcherKeepHistoricalIdentities(t *testing.T) {
cnbc, watcher := SourceCNBCBusiness, SourceWatcherGuru
sources := []Source{{ID: "new-cnbc", SourceKey: &cnbc, Enabled: true, ArticleLimit: 37}, {ID: "old-watcher", SourceKey: &watcher, Enabled: true, ArticleLimit: 64}}
if sources[0].Supported() || sources[0].Operational() || sources[1].Supported() || sources[1].Operational() {
t.Fatal("retired source remains executable")
}
operational := OperationalSources(sources)
if len(operational) != 0 {
t.Fatalf("operational=%+v", operational)
}
if *sources[0].SourceKey != "cnbc_business" || sources[0].ArticleLimit != 37 || !sources[0].Enabled || *sources[1].SourceKey != "watcher_guru" || sources[1].ArticleLimit != 64 {
t.Fatal("historical identity or cap mutated")
}
}