2026-08-11 23:41:10 +12:00
|
|
|
package api
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/ponzischeme89/memby/server/internal/sonarr"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestSonarrSeriesStatusKeyPrefersTVDBIdentity(t *testing.T) {
|
|
|
|
|
series := sonarr.Series{ID: 42, TVDBID: 1234}
|
|
|
|
|
if got := sonarrSeriesStatusKey(series); got != "tvdb:1234" {
|
|
|
|
|
t.Fatalf("status key = %q, want tvdb:1234", got)
|
|
|
|
|
}
|
|
|
|
|
series.TVDBID = 0
|
|
|
|
|
if got := sonarrSeriesStatusKey(series); got != "sonarr:42" {
|
|
|
|
|
t.Fatalf("fallback status key = %q, want sonarr:42", got)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestSonarrCancellationRequiresAnActiveHistory(t *testing.T) {
|
|
|
|
|
for _, transition := range [][2]string{
|
|
|
|
|
{"continuing", "ended"},
|
|
|
|
|
{"upcoming", "deleted"},
|
|
|
|
|
{"Continuing", "cancelled"},
|
|
|
|
|
} {
|
|
|
|
|
if !sonarrBecameCancelled(transition[0], transition[1]) {
|
|
|
|
|
t.Errorf("%q -> %q should be a cancellation", transition[0], transition[1])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for _, transition := range [][2]string{
|
|
|
|
|
{"", "ended"}, // first scan is a baseline, not news
|
|
|
|
|
{"ended", "ended"}, // an unchanged cancelled show is not announced daily
|
|
|
|
|
{"ended", "continuing"},
|
|
|
|
|
{"continuing", "continuing"},
|
|
|
|
|
} {
|
|
|
|
|
if sonarrBecameCancelled(transition[0], transition[1]) {
|
|
|
|
|
t.Errorf("%q -> %q should not be a cancellation", transition[0], transition[1])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-08-12 08:25:15 +12:00
|
|
|
|
|
|
|
|
func TestSonarrLifecycleClassifiesNewSeriesAfterTheBaseline(t *testing.T) {
|
|
|
|
|
if got := sonarrLifecycleNotificationKind("", "continuing"); got != "show-added" {
|
|
|
|
|
t.Fatalf("new series notification = %q, want show-added", got)
|
|
|
|
|
}
|
|
|
|
|
if got := sonarrLifecycleNotificationKind("continuing", "ended"); got != "show-cancelled" {
|
|
|
|
|
t.Fatalf("cancelled series notification = %q, want show-cancelled", got)
|
|
|
|
|
}
|
|
|
|
|
if got := sonarrLifecycleNotificationKind("continuing", "continuing"); got != "" {
|
|
|
|
|
t.Fatalf("unchanged series notification = %q, want none", got)
|
|
|
|
|
}
|
|
|
|
|
}
|