A library-agnostic home section that surfaces external global trending
(TMDB or Trakt, admin-selectable) mixing movies + series, matched to
titles in the viewer's enabled libraries. TMDB uses /trending/all/{window}
(natively mixed); Trakt merges trending movies + shows. Fetched live with
a 1h in-process cache, so no background job or stored collection — and no
per-library duplication.
Appears in the admin section gallery via its recipe presets (TMDB Trending
Today/This Week, Trakt Trending); featured -> hero via the existing flag.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
68 lines
2.1 KiB
Go
68 lines
2.1 KiB
Go
package sections
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/Silo-Server/silo-server/internal/catalog"
|
|
)
|
|
|
|
func TestOrderedTrendingContentIDs_PreservesOrderAndSeriesPrefersTVDB(t *testing.T) {
|
|
entries := []trendingDiscoverEntry{
|
|
{tmdbID: "1", mediaType: "movie"},
|
|
{tmdbID: "2", tvdbID: "20", mediaType: "tv"},
|
|
{imdbID: "tt3", mediaType: "movie"},
|
|
}
|
|
movieLookup := &catalog.ExternalIDLookup{
|
|
ByTMDB: map[string]string{"1": "cm1"},
|
|
ByIMDb: map[string]string{"tt3": "cm3"},
|
|
ByTVDB: map[string]string{},
|
|
}
|
|
seriesLookup := &catalog.ExternalIDLookup{
|
|
ByTVDB: map[string]string{"20": "cs2"},
|
|
ByTMDB: map[string]string{"2": "cs2_tmdb"}, // TVDB should win for series
|
|
ByIMDb: map[string]string{},
|
|
}
|
|
got := orderedTrendingContentIDs(entries, movieLookup, seriesLookup)
|
|
want := []string{"cm1", "cs2", "cm3"}
|
|
if len(got) != len(want) {
|
|
t.Fatalf("got %v, want %v", got, want)
|
|
}
|
|
for i := range want {
|
|
if got[i] != want[i] {
|
|
t.Fatalf("pos %d = %q want %q (full %v)", i, got[i], want[i], got)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestOrderedTrendingContentIDs_SkipsUnmatchedAndDedups(t *testing.T) {
|
|
entries := []trendingDiscoverEntry{
|
|
{tmdbID: "1", mediaType: "movie"}, // matches cX
|
|
{tmdbID: "404", mediaType: "movie"}, // no match -> skipped
|
|
{imdbID: "ttX", mediaType: "movie"}, // also resolves to cX -> deduped
|
|
}
|
|
movieLookup := &catalog.ExternalIDLookup{
|
|
ByTMDB: map[string]string{"1": "cX"},
|
|
ByIMDb: map[string]string{"ttX": "cX"},
|
|
ByTVDB: map[string]string{},
|
|
}
|
|
got := orderedTrendingContentIDs(entries, movieLookup, &catalog.ExternalIDLookup{})
|
|
if len(got) != 1 || got[0] != "cX" {
|
|
t.Fatalf("expected [cX], got %v", got)
|
|
}
|
|
}
|
|
|
|
func TestOrderedTrendingContentIDs_MovieIgnoresTVDB(t *testing.T) {
|
|
entries := []trendingDiscoverEntry{
|
|
{tvdbID: "50", tmdbID: "5", mediaType: "movie"},
|
|
}
|
|
movieLookup := &catalog.ExternalIDLookup{
|
|
ByTVDB: map[string]string{"50": "cTV"}, // must be ignored for movies
|
|
ByTMDB: map[string]string{"5": "cTMDB"},
|
|
ByIMDb: map[string]string{},
|
|
}
|
|
got := orderedTrendingContentIDs(entries, movieLookup, &catalog.ExternalIDLookup{})
|
|
if len(got) != 1 || got[0] != "cTMDB" {
|
|
t.Fatalf("movie should match TMDB not TVDB; got %v", got)
|
|
}
|
|
}
|