package api import ( "strings" "testing" "github.com/ponzischeme89/memby/server/internal/library" ) func TestLibrarySyncTitleCountsWhatChanged(t *testing.T) { if got := librarySyncTitle(1); got != "1 title added or updated" { t.Errorf("one change reads %q", got) } if got := librarySyncTitle(24); !strings.HasPrefix(got, "24 titles") { t.Errorf("many changes read %q", got) } } func TestReachabilityAlertsAreDistinctAndSelfExplaining(t *testing.T) { s := &Server{} down := s.reachabilityAlert(false) up := s.reachabilityAlert(true) if down.Kind != alertKindServerDown || up.Kind != alertKindServerUp { t.Fatalf("kinds = %q/%q, want the two reachability kinds", down.Kind, up.Kind) } // The recovery banner must never overwrite the outage banner it follows: they are // two pieces of news, and a TV that saw neither should be able to show both. if down.ID == up.ID { t.Errorf("both transitions share id %q", down.ID) } for _, alert := range []clientAlert{down, up} { if alert.Label == "" || alert.Title == "" || alert.Message == "" { t.Errorf("alert %q has nothing to render: %+v", alert.Kind, alert) } // These are the alerts most likely to land mid-film, where there is no remote // interaction to be had — they must state a fact, not ask for one. if strings.Contains(alert.Message, "?") { t.Errorf("alert %q asks the viewer something: %q", alert.Kind, alert.Message) } } } // A sync that changed nothing must be silent: the import is scheduled, most passes find // nothing, and an hourly "no news" banner would train viewers to ignore the real ones. func TestAnnounceLibrarySyncIgnoresAQuietPass(t *testing.T) { // A nil cache would panic if this tried to publish, which is the assertion. s := &Server{log: discardLogger()} s.AnnounceLibrarySync(t.Context(), library.Result{Seen: 4200, Changed: 0, Removed: 0}) }