feat(sources): retire Yahoo and CNBC feeds (#42)
This commit is contained in:
@ -149,7 +149,7 @@ func (r *Repository) ListSources() ([]Source, error) {
|
||||
func (r *Repository) GetSourceByType(sourceType string) (*Source, error) {
|
||||
s := &Source{}
|
||||
err := r.db.QueryRow(`
|
||||
SELECT id, name, type, enabled, created_at, article_limit, source_key FROM sources WHERE type=$1 AND source_key IN ('yahoo_finance','bloomberg','cnbc_business','investing_com')`, sourceType,
|
||||
SELECT id, name, type, enabled, created_at, article_limit, source_key FROM sources WHERE type=$1 AND source_key IN ('bloomberg','investing_com')`, sourceType,
|
||||
).Scan(&s.ID, &s.Name, &s.Type, &s.Enabled, &s.CreatedAt, &s.ArticleLimit, &s.SourceKey)
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil
|
||||
|
||||
22
backend/internal/models/source_retirement_ticket42_test.go
Normal file
22
backend/internal/models/source_retirement_ticket42_test.go
Normal file
@ -0,0 +1,22 @@
|
||||
package models
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestTicket42OnlyRSSSourcesAreOperationalEvenIfLegacyRowsWereReenabled(t *testing.T) {
|
||||
sources := []Source{}
|
||||
for _, key := range []string{SourceYahooFinance, SourceCNBCBusiness, SourceWatcherGuru, SourceBloomberg, SourceInvesting} {
|
||||
key := key
|
||||
sources = append(sources, Source{ID: key, SourceKey: &key, Enabled: true, ArticleLimit: 77})
|
||||
want := key == SourceBloomberg || key == SourceInvesting
|
||||
if SupportedSourceKey(key) != want {
|
||||
t.Errorf("source %s supported=%v, want %v", key, SupportedSourceKey(key), want)
|
||||
}
|
||||
}
|
||||
got := OperationalSources(sources)
|
||||
if len(got) != 2 || *got[0].SourceKey != SourceBloomberg || *got[1].SourceKey != SourceInvesting {
|
||||
t.Fatal("legacy SQL-enabled source remained operational")
|
||||
}
|
||||
if !sources[0].Enabled || *sources[0].SourceKey != "yahoo_finance" || sources[0].ArticleLimit != 77 || *sources[1].SourceKey != "cnbc_business" {
|
||||
t.Fatal("filter mutated historical identities/caps")
|
||||
}
|
||||
}
|
||||
@ -10,7 +10,7 @@ const (
|
||||
|
||||
func SupportedSourceKey(key string) bool {
|
||||
switch key {
|
||||
case SourceYahooFinance, SourceBloomberg, SourceCNBCBusiness, SourceInvesting:
|
||||
case SourceBloomberg, SourceInvesting:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
||||
@ -3,11 +3,11 @@ package models
|
||||
import "testing"
|
||||
|
||||
func TestSourceSupportUsesOnlyCanonicalKeyAndPersistedEnabled(t *testing.T) {
|
||||
yahoo := SourceYahooFinance
|
||||
rss := SourceBloomberg
|
||||
unknown := "reuters"
|
||||
sources := []Source{
|
||||
{ID: "supported", Type: "stocktwits", SourceKey: &yahoo, Enabled: true, ArticleLimit: 83},
|
||||
{ID: "disabled", SourceKey: &yahoo, Enabled: false, ArticleLimit: 77},
|
||||
{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},
|
||||
}
|
||||
@ -23,17 +23,17 @@ func TestSourceSupportUsesOnlyCanonicalKeyAndPersistedEnabled(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCNBCReplacesWatcherGuruWithoutAliasingHistoricalIdentity(t *testing.T) {
|
||||
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[1].Supported() || sources[1].Operational() {
|
||||
t.Fatal("retired WatcherGuru remains executable or CNBC unsupported")
|
||||
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) != 1 || operational[0].ID != "new-cnbc" || operational[0].ArticleLimit != 37 {
|
||||
if len(operational) != 0 {
|
||||
t.Fatalf("operational=%+v", operational)
|
||||
}
|
||||
if *sources[1].SourceKey != "watcher_guru" || sources[1].ArticleLimit != 64 {
|
||||
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")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user