From db9882329b39dfecc1e10dadcae3435958a733f0 Mon Sep 17 00:00:00 2001 From: mkelvers Date: Sat, 2 May 2026 17:26:53 +0200 Subject: [PATCH] fix: update watchlist service tests --- api/playback/handler.go | 4 ++-- api/playback/types.go | 20 ++++++++++---------- api/watchlist/service_test.go | 14 ++++---------- integrations/jikan/episodes.go | 6 +++--- 4 files changed, 19 insertions(+), 25 deletions(-) diff --git a/api/playback/handler.go b/api/playback/handler.go index 58c8deb..a09623c 100644 --- a/api/playback/handler.go +++ b/api/playback/handler.go @@ -123,10 +123,10 @@ func (h *Handler) HandleWatchPage(w http.ResponseWriter, r *http.Request) { for i := start; i <= maxCount; i++ { epStr := strconv.Itoa(i) meta, err := h.svc.GetEpisodeMetadata(r.Context(), id, epStr) - + title := fmt.Sprintf("Episode %d", i) imgURL := "" - + if err == nil && meta != nil { if info, ok := meta["episodeInfo"].(map[string]any); ok { if thumbs, ok := info["thumbnails"].([]any); ok && len(thumbs) > 0 { diff --git a/api/playback/types.go b/api/playback/types.go index 12d8119..ca9db4d 100644 --- a/api/playback/types.go +++ b/api/playback/types.go @@ -35,14 +35,14 @@ type SkipSegment struct { } type WatchPageData struct { - MalID int - Title string - CurrentEpisode string - StartTimeSeconds float64 - CurrentStatus string - InitialMode string - AvailableModes []string - ModeSources map[string]ModeSource - Segments []SkipSegment - FallbackEpisodes map[string]int + MalID int + Title string + CurrentEpisode string + StartTimeSeconds float64 + CurrentStatus string + InitialMode string + AvailableModes []string + ModeSources map[string]ModeSource + Segments []SkipSegment + FallbackEpisodes map[string]int } diff --git a/api/watchlist/service_test.go b/api/watchlist/service_test.go index ddb2c2f..08988ad 100644 --- a/api/watchlist/service_test.go +++ b/api/watchlist/service_test.go @@ -32,12 +32,9 @@ func TestAddEntry_RejectsInvalidAnimeID(t *testing.T) { t.Parallel() q := &fakeQuerier{} - svc := NewService(q, nil) + svc := NewService(q, nil, nil) - err := svc.AddEntry(context.Background(), "user-1", AddRequest{ - AnimeID: 0, - Status: "watching", - }) + err := svc.AddToWatchlist(context.Background(), "user-1", 0, "watching") if err != ErrInvalidAnimeID { t.Fatalf("expected ErrInvalidAnimeID, got %v", err) @@ -52,12 +49,9 @@ func TestAddEntry_RejectsInvalidStatus(t *testing.T) { t.Parallel() q := &fakeQuerier{} - svc := NewService(q, nil) + svc := NewService(q, nil, nil) - err := svc.AddEntry(context.Background(), "user-1", AddRequest{ - AnimeID: 1, - Status: "invalid", - }) + err := svc.AddToWatchlist(context.Background(), "user-1", 1, "invalid") if err != ErrInvalidStatus { t.Fatalf("expected ErrInvalidStatus, got %v", err) diff --git a/integrations/jikan/episodes.go b/integrations/jikan/episodes.go index 185f727..04eda5d 100644 --- a/integrations/jikan/episodes.go +++ b/integrations/jikan/episodes.go @@ -43,7 +43,7 @@ func (e *Episode) GetFallbackImage(animeID int) string { // MAL URLs usually follow this format, and it redirects to the slug version episodeURL := fmt.Sprintf("https://myanimelist.net/anime/%d/_/episode/%d", animeID, episodeNum) fallbackURL := scrapeAnimeImageFromEpisodePage(episodeURL, episodeNum) - + if fallbackURL != "" { return fallbackURL } @@ -79,7 +79,7 @@ func scrapeAnimeImageFromEpisodePage(episodeURL string, episodeNum int) string { html := string(body) - // MAL sometimes redirects to a URL with a slug. + // MAL sometimes redirects to a URL with a slug. // The JSON object is very likely to be present in the full page. // We extract the object {} containing "episode_number":X episodeStr := strconv.Itoa(episodeNum) @@ -90,7 +90,7 @@ func scrapeAnimeImageFromEpisodePage(episodeURL string, episodeNum int) string { objPattern = regexp.MustCompile(`\{[^}]*"episode_number":\s*` + episodeStr + `[^}]*\}`) match = objPattern.FindString(html) } - + if match != "" { thumbRe := regexp.MustCompile(`"thumbnail":\s*"([^"]+)"`) thumbMatch := thumbRe.FindStringSubmatch(match)