Add optional MDBList movie ratings

This commit is contained in:
ponzischeme89
2026-08-03 08:55:52 +12:00
parent b6b2a9c25a
commit 666da9c5d3
18 changed files with 840 additions and 4 deletions
+39
View File
@@ -0,0 +1,39 @@
package api
import (
"testing"
"github.com/ponzischeme89/memby/server/internal/mdblist"
)
func TestSelectedMovieRatingsFiltersOrdersAndLabelsAvailableValues(t *testing.T) {
got := selectedMovieRatings(
[]string{"letterboxd", "imdb", "tomatoes", "rogerebert", "metacritic"},
[]mdblist.Rating{
{Source: "imdb", Value: 8.2},
{Source: "rttomatoes", Value: 91},
{Source: "letterboxd", Value: 4.15},
{Source: "rogerebert", Value: 0},
{Source: "metacritic", Value: 101},
},
)
if len(got) != 3 {
t.Fatalf("ratings = %+v", got)
}
if got[0] != (movieRating{Source: "letterboxd", Name: "Letterboxd", Score: "4.15", Scale: "/5"}) ||
got[1].Name != "IMDb" || got[1].Score != "8.2" || got[1].Scale != "/10" ||
got[2].Name != "Rotten Tomatoes" || got[2].Score != "91" || got[2].Scale != "%" {
t.Fatalf("formatted ratings = %+v", got)
}
}
func TestMovieProviderPrefersTMDBAndFallsBackToIMDb(t *testing.T) {
provider, id := movieProvider(map[string]string{"ImDb": "tt0111161", "TmDb": "278"})
if provider != "tmdb" || id != "278" {
t.Fatalf("provider = %q %q", provider, id)
}
provider, id = movieProvider(map[string]string{"IMDb": "tt0111161"})
if provider != "imdb" || id != "tt0111161" {
t.Fatalf("fallback provider = %q %q", provider, id)
}
}