From c36d1809614afd64ce110560e92b7d4f2aa0cc70 Mon Sep 17 00:00:00 2001 From: mkelvers Date: Mon, 6 Jul 2026 20:46:59 +0200 Subject: [PATCH] feat: add episode classifications handler test --- internal/playback/handler/watch_page_test.go | 28 ++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/internal/playback/handler/watch_page_test.go b/internal/playback/handler/watch_page_test.go index 84b5a6cc..23e7d6d2 100644 --- a/internal/playback/handler/watch_page_test.go +++ b/internal/playback/handler/watch_page_test.go @@ -22,6 +22,7 @@ type watchPagePlaybackService struct { err error refreshRequested bool titles []domain.CanonicalEpisode + classifications []domain.CanonicalEpisode } func (s *watchPagePlaybackService) BuildWatchData(ctx context.Context, _ int, _ []string, _ string, _ string, _ string) (domain.WatchPageData, error) { @@ -34,6 +35,10 @@ func (s *watchPagePlaybackService) EnrichEpisodeTitles(context.Context, int) ([] return s.titles, s.err } +func (s *watchPagePlaybackService) EnrichEpisodeClassifications(context.Context, int) ([]domain.CanonicalEpisode, error) { + return s.classifications, s.err +} + func TestHandleEpisodeDataRequestsForcedSourceRefresh(t *testing.T) { data := baseWatchPageData() data.WatchData.ModeSources = map[string]domain.ModeSource{ @@ -79,6 +84,29 @@ func TestHandleEpisodeTitlesReturnsMinimalEnrichedList(t *testing.T) { } } +func TestHandleEpisodeClassificationsReturnsMinimalList(t *testing.T) { + svc := &watchPagePlaybackService{classifications: []domain.CanonicalEpisode{ + {Number: 1}, + {Number: 2, Filler: true}, + {Number: 3, Recap: true}, + }} + h := &PlaybackHandler{svc: svc} + gin.SetMode(gin.TestMode) + router := gin.New() + router.GET("/api/watch/episodes/:animeId/classifications", h.HandleEpisodeClassifications) + + req := httptest.NewRequestWithContext(context.Background(), http.MethodGet, "/api/watch/episodes/123/classifications", nil) + rec := httptest.NewRecorder() + router.ServeHTTP(rec, req) + + if rec.Code != http.StatusOK { + t.Fatalf("status = %d, want %d", rec.Code, http.StatusOK) + } + if got := strings.TrimSpace(rec.Body.String()); got != `[{"filler":false,"number":1,"recap":false},{"filler":true,"number":2,"recap":false},{"filler":false,"number":3,"recap":true}]` { + t.Fatalf("body = %s", got) + } +} + type watchPageAnimeService struct { domain.AnimePlaybackService t *testing.T