Files
silo-server/internal/sections/trending_read_test.go
QuickandClaude Opus 4.8 f105361658 fix(sections): harden trending refresher per PR review
- Interleave Trakt movies/shows by rank so the mixed row shows both types
  instead of burying all series past the display limit.
- Treat any Trakt sub-fetch failure as fatal (errors.Join) so a partial
  result never overwrites the last-good snapshot with a media type missing.
- Skip non-title entries (TMDB trending/all returns media_type "person") in
  both ID batching and ordering so they can't match an unrelated library title.
- Guard the refresh task against a nil refresher.
- Tests: person skip, Trakt interleave, Trakt partial-failure preserves
  last-good, snapshot read error propagation.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-05-29 11:28:59 -04:00

66 lines
1.8 KiB
Go

package sections
import (
"context"
"errors"
"testing"
)
type fakeSnapshotGetter struct {
snap TrendingSnapshot
found bool
err error
}
func (f fakeSnapshotGetter) Get(context.Context, string, string) (TrendingSnapshot, bool, error) {
return f.snap, f.found, f.err
}
func TestLoadTrendingDiscoverContentIDsReadsSnapshot(t *testing.T) {
f := &Fetcher{TrendingSnapshots: fakeSnapshotGetter{
snap: TrendingSnapshot{ContentIDs: []string{"a", "b"}},
found: true,
}}
ids, err := f.loadTrendingDiscoverContentIDs(context.Background(), "tmdb", "week")
if err != nil {
t.Fatalf("loadTrendingDiscoverContentIDs: %v", err)
}
if len(ids) != 2 || ids[0] != "a" || ids[1] != "b" {
t.Fatalf("ids = %v; want [a b]", ids)
}
}
func TestLoadTrendingDiscoverContentIDsNilGetter(t *testing.T) {
f := &Fetcher{}
ids, err := f.loadTrendingDiscoverContentIDs(context.Background(), "tmdb", "week")
if err != nil {
t.Fatalf("loadTrendingDiscoverContentIDs: %v", err)
}
if ids != nil {
t.Fatalf("ids = %v; want nil for nil getter", ids)
}
}
func TestLoadTrendingDiscoverContentIDsNotFound(t *testing.T) {
f := &Fetcher{TrendingSnapshots: fakeSnapshotGetter{found: false}}
ids, err := f.loadTrendingDiscoverContentIDs(context.Background(), "tmdb", "week")
if err != nil {
t.Fatalf("loadTrendingDiscoverContentIDs: %v", err)
}
if ids != nil {
t.Fatalf("ids = %v; want nil when no snapshot exists", ids)
}
}
func TestLoadTrendingDiscoverContentIDsPropagatesError(t *testing.T) {
boom := errors.New("boom")
f := &Fetcher{TrendingSnapshots: fakeSnapshotGetter{err: boom}}
ids, err := f.loadTrendingDiscoverContentIDs(context.Background(), "tmdb", "week")
if !errors.Is(err, boom) {
t.Fatalf("err = %v; want boom", err)
}
if ids != nil {
t.Fatalf("ids = %v; want nil on error", ids)
}
}