jellyfin-tools/jellyfin-news/digest_test.go
jellyfin-news/digest_test.goRaw
1package main
2
3import (
4 "testing"
5 "time"
6)
7
8func intp(n int) *int { return &n }
9
10func TestFormatGroupsEpisodes(t *testing.T) {
11 items := []Item{
12 {Type: "Movie", Name: "Dune", ProductionYear: intp(2021)},
13 {Type: "Episode", SeriesID: "a", SeriesName: "Example Show", SeasonNumber: intp(3), EpisodeNumber: intp(12)},
14 {Type: "Episode", SeriesID: "a", SeriesName: "Example Show", SeasonNumber: intp(3), EpisodeNumber: intp(1)},
15 {Type: "Episode", SeriesID: "a", SeriesName: "Example Show", SeasonNumber: intp(3), EpisodeNumber: intp(2)},
16 {Type: "Episode", SeriesID: "a", SeriesName: "Example Show", SeasonNumber: intp(3), EpisodeNumber: intp(3)},
17 {Type: "Episode", SeriesID: "a", SeriesName: "Example Show", SeasonNumber: intp(3), EpisodeNumber: intp(5)},
18 }
19 start := time.Date(2026, 8, 18, 0, 0, 0, 0, time.UTC)
20 end := time.Date(2026, 8, 25, 0, 0, 0, 0, time.UTC)
21 want := "2026-08-18 - 2026-08-25 jellyfin weekly update:\n\nMovies:\n• Dune (2021)\n\nShows:\n• Example Show — Season 3, episodes 1-3, 5, 12"
22 if got := FormatWeek(start, end, items, DefaultLabels()); got != want {
23 t.Fatalf("FormatWeek() = %q, want %q", got, want)
24 }
25}
26
27func TestFormatEmpty(t *testing.T) {
28 start := time.Date(2026, 8, 18, 0, 0, 0, 0, time.UTC)
29 end := time.Date(2026, 8, 25, 0, 0, 0, 0, time.UTC)
30 want := "2026-08-18 - 2026-08-25 jellyfin weekly update:\n\nNo new movies or show episodes this week."
31 if got := FormatWeek(start, end, nil, DefaultLabels()); got != want {
32 t.Fatalf("FormatWeek() = %q, want %q", got, want)
33 }
34}
35
36func TestFormatMonth(t *testing.T) {
37 want := "2026-07 jellyfin monthly update:\n\nNo new movies or show episodes last month."
38 if got := FormatMonth(time.Date(2026, 7, 1, 0, 0, 0, 0, time.UTC), nil, DefaultLabels()); got != want {
39 t.Fatalf("FormatMonth() = %q, want %q", got, want)
40 }
41}
42
43func TestFormatWithTranslatedLabels(t *testing.T) {
44 labels := Labels{
45 WeeklyUpdate: "actualización semanal",
46 MonthlyUpdate: "actualización mensual",
47 Movies: "Películas",
48 Shows: "Series",
49 Season: "Temporada",
50 Specials: "Especiales",
51 Episode: "episodio",
52 Episodes: "episodios",
53 UnknownShow: "Serie desconocida",
54 NoWeeklyItems: "No hay novedades esta semana.",
55 NoMonthlyItems: "No hay novedades el mes pasado.",
56 }
57 items := []Item{
58 {Type: "Movie", Name: "Una película"},
59 {Type: "Episode", SeriesName: "Una serie", SeasonNumber: intp(2), EpisodeNumber: intp(4)},
60 }
61 start := time.Date(2026, 8, 18, 0, 0, 0, 0, time.UTC)
62 end := time.Date(2026, 8, 25, 0, 0, 0, 0, time.UTC)
63 want := "2026-08-18 - 2026-08-25 actualización semanal:\n\nPelículas:\n• Una película\n\nSeries:\n• Una serie — Temporada 2, episodio 4"
64 if got := FormatWeek(start, end, items, labels); got != want {
65 t.Fatalf("FormatWeek() = %q, want %q", got, want)
66 }
67}