This commit is contained in:
ponzischeme89
2026-08-19 14:25:44 +12:00
parent 2b43b9ef12
commit 590e069366
83 changed files with 8948 additions and 1266 deletions
+78 -8
View File
@@ -1,6 +1,7 @@
package api
import (
"strings"
"testing"
"time"
)
@@ -38,14 +39,62 @@ func TestRequestStatusReportsRemovalBeforeReleaseState(t *testing.T) {
}
}
func TestRequestStatusSeparatesPendingFromProcessing(t *testing.T) {
func TestRequestStatusSeparatesPendingFromSearching(t *testing.T) {
pending := requestStatusFor(RequestSubject{Tracked: true, Released: false})
if pending != RequestStatusPending {
t.Fatalf("expected %q, got %q", RequestStatusPending, pending)
}
processing := requestStatusFor(RequestSubject{Tracked: true, Released: true})
if processing != RequestStatusProcessing {
t.Fatalf("expected %q, got %q", RequestStatusProcessing, processing)
// Tracked, released, and the download client has never heard of it: nothing has been
// found. This is the distinction the whole feature rests on — before it, this case and
// a download two minutes from finishing were the same word.
searching := requestStatusFor(RequestSubject{Tracked: true, Released: true})
if searching != RequestStatusSearching {
t.Fatalf("expected %q, got %q", RequestStatusSearching, searching)
}
}
func TestQueueOutranksTheReleaseState(t *testing.T) {
// Radarr's minimum-availability setting decides when to start looking, not whether bytes
// are moving. A household that fetches on the cinema date has films that are "not
// released" and half downloaded at once, and the honest answer is the half.
got := requestStatusFor(RequestSubject{
Tracked: true,
Released: false,
Progress: requestProgress{Status: RequestStatusDownloading, Progress: 50},
})
if got != RequestStatusDownloading {
t.Fatalf("expected %q, got %q", RequestStatusDownloading, got)
}
// But nothing outranks having it. A queue row against a title already on the shelf is an
// upgrade, and a card somebody can press Play on must not read as downloading.
got = requestStatusFor(RequestSubject{
Tracked: true,
InLibrary: true,
Progress: requestProgress{Status: RequestStatusDownloading, Progress: 50},
})
if got != RequestStatusAvailable {
t.Fatalf("expected %q, got %q", RequestStatusAvailable, got)
}
}
func TestCollapseNarrowsOnlyTheDownloadStates(t *testing.T) {
// An older television is told "processing" for the whole span it used to cover, and
// nothing else it understands is disturbed.
for _, state := range []string{
RequestStatusSearching, RequestStatusFound,
RequestStatusDownloading, RequestStatusFailed,
} {
if got := collapseRequestStatus(state); got != RequestStatusProcessing {
t.Fatalf("%q should collapse to %q, got %q", state, RequestStatusProcessing, got)
}
}
for _, state := range []string{
RequestStatusAvailable, RequestStatusPending, RequestStatusRequested,
RequestStatusUnavailable, RequestStatusRequestable, RequestStatusProcessing,
} {
if got := collapseRequestStatus(state); got != state {
t.Fatalf("%q must survive collapsing, got %q", state, got)
}
}
}
@@ -114,8 +163,10 @@ func TestRequestStatusLabelAndDetailCoverEveryState(t *testing.T) {
// a state that fell through to the default would show "Requested" on a card that is
// actually available.
states := []string{
RequestStatusAvailable, RequestStatusProcessing, RequestStatusPending,
RequestStatusUnavailable, RequestStatusRequestable, RequestStatusRequested,
RequestStatusAvailable, RequestStatusSearching, RequestStatusFound,
RequestStatusDownloading, RequestStatusProcessing, RequestStatusPending,
RequestStatusFailed, RequestStatusUnavailable, RequestStatusRequestable,
RequestStatusRequested,
}
seen := map[string]bool{}
for _, state := range states {
@@ -128,8 +179,27 @@ func TestRequestStatusLabelAndDetailCoverEveryState(t *testing.T) {
}
seen[label] = true
}
if requestStatusDetail(RequestStatusPending, "series") ==
requestStatusDetail(RequestStatusPending, "movie") {
for _, state := range states {
if requestStatusDetail(state, "movie", 0) == "" {
t.Fatalf("state %q has no detail line", state)
}
}
if requestStatusDetail(RequestStatusPending, "series", 0) ==
requestStatusDetail(RequestStatusPending, "movie", 0) {
t.Fatal("a pending series and a pending film are waiting for different things")
}
// The one rule this feature is judged on: an estimate is offered when the download
// client gave one and never otherwise. Both sentences are legitimate; saying the second
// while holding a number, or the first while holding none, is not.
withEstimate := requestStatusDetail(RequestStatusDownloading, "movie", 840)
withoutEstimate := requestStatusDetail(RequestStatusDownloading, "movie", 0)
if withEstimate == withoutEstimate {
t.Fatal("a download with an estimate must not read the same as one without")
}
if !strings.Contains(withEstimate, "14 minutes") {
t.Fatalf("840 seconds should read as about 14 minutes, got %q", withEstimate)
}
if strings.Contains(withoutEstimate, "~") {
t.Fatalf("a download with no estimate must not print one, got %q", withoutEstimate)
}
}