2026-08-02 22:10:19 +12:00
|
|
|
package api
|
|
|
|
|
|
2026-08-12 09:57:56 +12:00
|
|
|
import (
|
|
|
|
|
"bytes"
|
|
|
|
|
"context"
|
|
|
|
|
"log/slog"
|
|
|
|
|
"strings"
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
serverlogging "github.com/ponzischeme89/memby/server/internal/logging"
|
|
|
|
|
)
|
2026-08-02 22:10:19 +12:00
|
|
|
|
|
|
|
|
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")
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-08-12 09:57:56 +12:00
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|