Publish current app and server
This commit is contained in:
@@ -4,11 +4,12 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/ponzischeme89/memby/server/internal/config"
|
||||
"github.com/ponzischeme89/memby/server/internal/emby"
|
||||
"github.com/ponzischeme89/memby/server/internal/recommend"
|
||||
"github.com/ponzischeme89/memby/server/internal/store"
|
||||
)
|
||||
|
||||
@@ -60,22 +61,47 @@ func TestNewTokenIsUnique(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAuthPolicyPublishesConfiguredDeviceAllowance(t *testing.T) {
|
||||
s := &Server{cfg: config.Config{MaxClientsPerUser: 4}}
|
||||
req := httptest.NewRequest(http.MethodGet, "/v1/auth/policy", nil)
|
||||
func TestRenameDeviceRejectsBlankName(t *testing.T) {
|
||||
s := &Server{}
|
||||
req := httptest.NewRequest(http.MethodPut, "/v1/auth/devices/tv-1", strings.NewReader(`{"deviceName":" "}`))
|
||||
req.SetPathValue("deviceID", "tv-1")
|
||||
rec := httptest.NewRecorder()
|
||||
|
||||
s.handleAuthPolicy(rec, req)
|
||||
s.handleRenameDevice(rec, req, store.Session{EmbyUserID: "user-1"})
|
||||
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("status = %d, want 200", rec.Code)
|
||||
if rec.Code != http.StatusBadRequest {
|
||||
t.Fatalf("status = %d, want 400", rec.Code)
|
||||
}
|
||||
var policy authPolicyResponse
|
||||
if err := json.Unmarshal(rec.Body.Bytes(), &policy); err != nil {
|
||||
t.Fatalf("decode policy: %v", err)
|
||||
}
|
||||
|
||||
func TestRecommendationOnboardingCandidatesMixMoviesAndSeries(t *testing.T) {
|
||||
items := []recommend.Item{
|
||||
{ID: "m1", Name: "Movie 1", Type: "Movie", CommunityRating: 9, Genres: []string{"Drama"}},
|
||||
{ID: "m2", Name: "Movie 2", Type: "Movie", CommunityRating: 8.9, Genres: []string{"Comedy"}},
|
||||
{ID: "s1", Name: "Series 1", Type: "Series", CommunityRating: 8.8, Genres: []string{"Drama"}},
|
||||
{ID: "s2", Name: "Series 2", Type: "Series", CommunityRating: 8.7, Genres: []string{"Comedy"}},
|
||||
{ID: "e1", Name: "Episode", Type: "Episode", CommunityRating: 10},
|
||||
}
|
||||
if policy.MaxClientsPerUser != 4 {
|
||||
t.Fatalf("max clients = %d, want 4", policy.MaxClientsPerUser)
|
||||
|
||||
got := recommendationOnboardingCandidates(items, 4)
|
||||
|
||||
if len(got) != 4 {
|
||||
t.Fatalf("candidate count = %d, want 4", len(got))
|
||||
}
|
||||
for i, kind := range []string{"Movie", "Series", "Movie", "Series"} {
|
||||
if got[i].Type != kind {
|
||||
t.Fatalf("candidate %d type = %q, want %q", i, got[i].Type, kind)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestEpisodeCodeFormatsPlaybackMetadata(t *testing.T) {
|
||||
item := emby.Summary{Type: "Episode", ParentIndexNumber: 2, IndexNumber: 4}
|
||||
if got := episodeCode(item); got != "S02E04" {
|
||||
t.Fatalf("episode code = %q, want S02E04", got)
|
||||
}
|
||||
if got := episodeCode(emby.Summary{Type: "Movie", IndexNumber: 4}); got != "" {
|
||||
t.Fatalf("movie episode code = %q, want empty", got)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,6 +121,22 @@ func TestSonarrScheduleRequiresCapableClient(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRadarrScheduleRequiresMovieScheduleClient(t *testing.T) {
|
||||
tests := map[string]bool{
|
||||
"": false,
|
||||
"0.1.78": false,
|
||||
"0.1.79": true,
|
||||
"0.2.0": true,
|
||||
}
|
||||
for version, want := range tests {
|
||||
req := httptest.NewRequest(http.MethodGet, "/v1/home", nil)
|
||||
req.Header.Set("X-Memby-Version", version)
|
||||
if got := supportsRadarrSchedule(req); got != want {
|
||||
t.Errorf("supportsRadarrSchedule(%q) = %v, want %v", version, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlaybackHintAvoidsAnUpstreamItemLookup(t *testing.T) {
|
||||
req := httptest.NewRequest(
|
||||
http.MethodGet,
|
||||
|
||||
Reference in New Issue
Block a user