Files
arr-tui/internal/arr/queue_test.go
T
nilsandClaude Sonnet 5.5 446cbdd6c5 Show Radarr and Sonarr queues in the Downloads view (M5)
Add queue listing and removal/blocklisting to the shared arr client.
The Downloads view now fetches SABnzbd and both arr queues in parallel,
shows status, progress and import problems, flags items needing
attention in the summary, and supports removing or blocklisting items.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-20 18:03:16 +02:00

73 lines
2.7 KiB
Go

package arr
import (
"context"
"net/http"
"net/http/httptest"
"testing"
)
const queueJSON = `{"page":1,"pageSize":200,"totalRecords":3,"records":[
{"id":1,"title":"Movie.2020.1080p-GRP","status":"downloading","trackedDownloadStatus":"ok","trackedDownloadState":"downloading",
"size":1000,"sizeleft":250,"timeleft":"00:05:00","downloadClient":"SABnzbd","downloadId":"SABnzbd_nzo_a",
"movie":{"title":"Movie","year":2020}},
{"id":2,"title":"Show.S01E02.720p-GRP","status":"completed","trackedDownloadStatus":"warning","trackedDownloadState":"importBlocked",
"size":500,"sizeleft":0,
"statusMessages":[{"title":"Show.S01E02","messages":["No files found are eligible for import"]}],
"series":{"title":"Show"},"episode":{"seasonNumber":1,"episodeNumber":2,"title":"Two"}},
{"id":3,"title":"Unmatched.Release","status":"downloading","trackedDownloadStatus":"ok","errorMessage":"Unknown series"}
]}`
func TestQueueWith(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
q := r.URL.Query()
if r.URL.Path != "/api/v3/queue" || q.Get("includeMovie") != "true" || q.Get("pageSize") != "200" {
t.Errorf("unexpected request %s", r.URL)
}
w.Write([]byte(queueJSON))
}))
defer srv.Close()
items, err := NewClient(srv.URL, "k").QueueWith(context.Background(), map[string][]string{"includeMovie": {"true"}})
if err != nil {
t.Fatal(err)
}
if len(items) != 3 {
t.Fatalf("got %d items", len(items))
}
m, s, u := items[0], items[1], items[2]
if m.Name() != "Movie (2020)" || m.Progress() != 75 || m.DownloadID != "SABnzbd_nzo_a" || m.NeedsAttention() {
t.Errorf("movie item: name=%q progress=%v attention=%v", m.Name(), m.Progress(), m.NeedsAttention())
}
if s.Name() != "Show S01E02" || !s.NeedsAttention() || s.Problem() != "No files found are eligible for import" {
t.Errorf("series item: name=%q problem=%q", s.Name(), s.Problem())
}
if u.Name() != "Unmatched.Release" || u.Problem() != "Unknown series" {
t.Errorf("unmatched item: name=%q problem=%q", u.Name(), u.Problem())
}
}
func TestRemoveQueueItem(t *testing.T) {
var got *http.Request
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
got = r
}))
defer srv.Close()
if err := NewClient(srv.URL, "k").RemoveQueueItem(context.Background(), 42, true); err != nil {
t.Fatal(err)
}
q := got.URL.Query()
if got.Method != http.MethodDelete || got.URL.Path != "/api/v3/queue/42" ||
q.Get("blocklist") != "true" || q.Get("removeFromClient") != "true" {
t.Errorf("request = %s %s", got.Method, got.URL)
}
}
func TestProgressZeroSize(t *testing.T) {
if p := (QueueItem{}).Progress(); p != 0 {
t.Errorf("progress = %v", p)
}
}