52 lines
2.8 KiB
Go
52 lines
2.8 KiB
Go
package generation
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"github.com/tradarr/backend/internal/models"
|
|
"github.com/tradarr/backend/internal/scraper"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestTicket40CanonicalSourceKeyAndReachabilitySeparateFromContent(t *testing.T) {
|
|
for _, key := range []string{models.SourceBloomberg, models.SourceInvesting} {
|
|
t.Run(key, func(t *testing.T) {
|
|
feed := &ticket39ContentFeed{}
|
|
repo := &contractRepository{inputs: map[string]UserInput{"u": {Language: "fr", RankingMode: "title_content", GlobalLimit: 3, Assets: []models.UserAsset{{Name: "Followed fixture"}}, Sources: []models.Source{{ID: "s", Type: "stocktwits", SourceKey: &key, Enabled: true, ArticleLimit: 3}}}}, saved: map[string][]GenerationRecord{}}
|
|
r, err := NewUseCase(Dependencies{Repository: repo, Decider: &allYesMention{}, Summarizer: &contractSummarizer{}, Scrapers: map[string]scraper.Scraper{key: feed}}).Generate(context.Background(), "u")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
raw, _ := json.Marshal(r.Outcome)
|
|
var outcome struct {
|
|
SourceStats []map[string]any `json:"source_stats"`
|
|
}
|
|
json.Unmarshal(raw, &outcome)
|
|
stat := outcome.SourceStats[0]
|
|
if stat["source_key"] != key || stat["status"] != "ok" || stat["content_complete"] != float64(1) || stat["content_incomplete"] != float64(1) || stat["content_unavailable"] != float64(1) {
|
|
t.Fatal("canonical key or distinct content states missing")
|
|
}
|
|
saved, _ := json.Marshal(repo.saved["u"][0].Outcome)
|
|
if strings.Contains(string(saved), "fixture.invalid") || strings.Contains(string(saved), "Entire editorial") {
|
|
t.Fatal("sensitive article persisted in diagnostics")
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestTicket42HistoricalSourceKeysAndTypesRemainReadable(t *testing.T) {
|
|
const payload = `{"status":"partial","source_stats":[{"source_key":"yahoo_finance","source_type":"stocktwits","source_id":"old-y","article_limit":83,"status":"ok"},{"source_key":"cnbc_business","source_type":"cnbc_business","source_id":"old-c","article_limit":31,"status":"ok"}]}`
|
|
var historical GenerationOutcome
|
|
if err := json.Unmarshal([]byte(payload), &historical); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if historical.Status != "partial" || len(historical.SourceStats) != 2 || historical.SourceStats[0].SourceKey != models.SourceYahooFinance || historical.SourceStats[0].SourceType != "stocktwits" || historical.SourceStats[0].ArticleLimit != 83 || historical.SourceStats[1].SourceKey != models.SourceCNBCBusiness || historical.SourceStats[1].SourceType != "cnbc_business" || historical.SourceStats[1].ArticleLimit != 31 {
|
|
t.Fatal("historical outcome was reclassified")
|
|
}
|
|
raw, err := json.Marshal(historical)
|
|
if err != nil || !strings.Contains(string(raw), `"source_key":"yahoo_finance"`) || !strings.Contains(string(raw), `"source_key":"cnbc_business"`) {
|
|
t.Fatal("legacy source keys disappeared from history")
|
|
}
|
|
}
|