package api import ( "bytes" "context" "log/slog" "strings" "testing" serverlogging "github.com/ponzischeme89/memby/server/internal/logging" ) func TestRequestMatchScorePrefersTheSpecificTitle(t *testing.T) { if requestMatchScore("the office", "The Office") >= requestMatchScore("the office", "The Office Christmas Special") { t.Fatal("exact title should rank ahead of a prefix match") } if requestMatchScore("arrival", "Arrival") >= requestMatchScore("arrival", "The Arrival") { t.Fatal("exact title should rank ahead of a contained match") } } func TestMediaRequestLogNamesTitleAndOutcome(t *testing.T) { var output bytes.Buffer server := &Server{log: serverlogging.New(&output, slog.LevelInfo)} server.logMediaRequest(context.Background(), requestPayload{ MediaType: "series", ForeignID: 123, Title: "Severance", }, "successful", nil) line := output.String() for _, want := range []string{ "media request successful", "type=series", "title=Severance", "foreign_id=123", "outcome=successful", } { if !strings.Contains(line, want) { t.Fatalf("log %q does not contain %q", line, want) } } }