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) } }