0.1.52 Gateway

This commit is contained in:
ponzischeme89
2026-08-17 19:09:17 +12:00
parent d5a8d3ad88
commit 1da91e40a1
46 changed files with 1626 additions and 106 deletions
+65 -24
View File
@@ -8,50 +8,91 @@ import (
"github.com/ponzischeme89/memby/server/internal/radarr"
)
func TestBuildRadarrRowUsesDigitalReleasesAndEstimatedCinemaFallbackInFiveDayWindow(t *testing.T) {
func TestBuildRadarrRowUsesDigitalReleasesAndEstimatedCinemaFallbackInMonthWindow(t *testing.T) {
location := time.FixedZone("NZST", 12*60*60)
now := time.Date(2026, 7, 30, 9, 0, 0, 0, location)
digitalToday := time.Date(2026, 7, 30, 0, 0, 0, 0, location).UTC()
digitalSunday := time.Date(2026, 8, 2, 0, 0, 0, 0, location).UTC()
outside := time.Date(2026, 8, 4, 0, 0, 0, 0, location).UTC()
theatricalOnly := time.Date(2026, 7, 1, 0, 0, 0, 0, location).UTC()
oldDigital := time.Date(1993, 4, 9, 0, 0, 0, 0, location).UTC()
modernRerelease := time.Date(2026, 7, 2, 0, 0, 0, 0, location).UTC()
day := func(y int, m time.Month, d int) time.Time {
return time.Date(y, m, d, 0, 0, 0, 0, location).UTC()
}
digitalToday := day(2026, 7, 30)
digitalSunday := day(2026, 8, 2)
// Three weeks out: inside the month window, past the point a weekday still names a day.
digitalLater := day(2026, 8, 20)
// The day the window closes, which is exclusive.
beyondWindow := day(2026, 8, 29)
theatricalOnly := day(2026, 7, 1)
oldDigital := day(1993, 4, 9)
modernRerelease := day(2026, 7, 2)
row, err := buildRadarrRow([]radarr.Movie{
{ID: 1, Title: "Today", DigitalRelease: &digitalToday, Monitored: true},
{ID: 2, Title: "Sunday", DigitalRelease: &digitalSunday, Monitored: true},
{ID: 3, Title: "Outside", DigitalRelease: &outside, Monitored: true},
{ID: 3, Title: "Three Weeks Out", DigitalRelease: &digitalLater, Monitored: true},
{ID: 4, Title: "Cinema Only", InCinemas: &theatricalOnly, Monitored: true},
{ID: 5, Title: "Old Digital Release", Year: 1993, DigitalRelease: &oldDigital, InCinemas: &modernRerelease, Monitored: true},
{ID: 6, Title: "Beyond Window", DigitalRelease: &beyondWindow, Monitored: true},
}, now, location)
if err != nil {
t.Fatal(err)
}
if row.ID != "radarr-upcoming-movies" || row.Kind != "movie-schedule" ||
row.Title != "Upcoming Movie releases" || len(row.Items) != 3 {
row.Title != "Upcoming Movie releases" || len(row.Items) != 4 {
t.Fatalf("unexpected row: %+v", row)
}
var first, second radarrScheduleItem
if err := json.Unmarshal(row.Items[0], &first); err != nil {
t.Fatal(err)
items := make([]radarrScheduleItem, len(row.Items))
for i, raw := range row.Items {
if err := json.Unmarshal(raw, &items[i]); err != nil {
t.Fatal(err)
}
}
if err := json.Unmarshal(row.Items[1], &second); err != nil {
t.Fatal(err)
want := []struct {
id, airLabel, dayLabel string
}{
{"radarr:1", "Digital release today", "Today"},
{"radarr:4", "Estimated digital release tomorrow", "Tomorrow"},
{"radarr:2", "Digital release Sunday", "Sunday"},
{"radarr:3", "Digital release 20 August", "20 Aug"},
}
if first.ID != "radarr:1" || first.MembyAirLabel != "Digital release today" {
t.Fatalf("unexpected first item: %+v", first)
for i, expect := range want {
got := items[i]
if got.ID != expect.id || got.MembyAirLabel != expect.airLabel ||
got.MembyAirDayLabel != expect.dayLabel {
t.Fatalf("item %d: got id=%s air=%q day=%q, want id=%s air=%q day=%q",
i, got.ID, got.MembyAirLabel, got.MembyAirDayLabel,
expect.id, expect.airLabel, expect.dayLabel)
}
}
if second.ID != "radarr:4" || second.MembyAirLabel != "Estimated digital release tomorrow" ||
second.MembyAvailabilityText != "Estimated digital release" {
t.Fatalf("unexpected second item: %+v", second)
if items[1].MembyAvailabilityText != "Estimated digital release" {
t.Fatalf("unexpected estimated availability: %+v", items[1])
}
var third radarrScheduleItem
if err := json.Unmarshal(row.Items[2], &third); err != nil {
t.Fatal(err)
}
// A weekday only names an unambiguous day inside the coming week. The month-long window
// routinely holds dates past that, where "Friday" would read as this Friday.
func TestRadarrReleaseLabelsCarryADateBeyondTheComingWeek(t *testing.T) {
location := time.FixedZone("NZST", 12*60*60)
now := time.Date(2026, 7, 30, 9, 0, 0, 0, location)
cases := []struct {
offset int
dayLabel string
airLabel string
}{
{0, "Today", "Digital release today"},
{1, "Tomorrow", "Digital release tomorrow"},
{2, "Saturday", "Digital release Saturday"},
{radarrWeekdayLabelDays, "Wednesday", "Digital release Wednesday"},
{radarrWeekdayLabelDays + 1, "6 Aug", "Digital release 6 August"},
{21, "20 Aug", "Digital release 20 August"},
}
if third.ID != "radarr:2" || third.MembyAirLabel != "Digital release Sunday" {
t.Fatalf("unexpected third item: %+v", third)
for _, tc := range cases {
release := now.AddDate(0, 0, tc.offset)
if got := radarrReleaseDayLabel(release, now, location); got != tc.dayLabel {
t.Errorf("offset %d: day label = %q, want %q", tc.offset, got, tc.dayLabel)
}
if got := digitalReleaseLabel(release, now, location, false); got != tc.airLabel {
t.Errorf("offset %d: air label = %q, want %q", tc.offset, got, tc.airLabel)
}
}
}