Adds internal/arr with a shared HTTP layer and per-service clients that look up candidates and POST the chosen one back with monitored=true and search-on-add enabled. Lidarr requires metadata_profile_id, now part of ArrConfig and validated when lidarr is set.
70 lines
2.2 KiB
Go
70 lines
2.2 KiB
Go
package arr
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"io"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"bellhop/internal/config"
|
|
)
|
|
|
|
func TestLidarrSearch(t *testing.T) {
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
if r.URL.Path != "/api/v1/artist/lookup" {
|
|
t.Errorf("path = %q", r.URL.Path)
|
|
}
|
|
if r.URL.Query().Get("term") != "radiohead" {
|
|
t.Errorf("term = %q", r.URL.Query().Get("term"))
|
|
}
|
|
_, _ = io.WriteString(w, `[{"artistName":"Radiohead","foreignArtistId":"a74b1b7f-71a5-4011-9441-d0b5e4122711"}]`)
|
|
}))
|
|
defer srv.Close()
|
|
|
|
l := NewLidarr(&config.ArrConfig{URL: srv.URL, APIKey: "k", QualityProfileID: 2, MetadataProfileID: 1, RootFolder: "/music"})
|
|
results, err := l.Search(context.Background(), "radiohead")
|
|
if err != nil {
|
|
t.Fatalf("search: %v", err)
|
|
}
|
|
if len(results) != 1 || results[0].Title != "Radiohead" {
|
|
t.Fatalf("unexpected results: %+v", results)
|
|
}
|
|
}
|
|
|
|
func TestLidarrAdd(t *testing.T) {
|
|
var got map[string]any
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
if r.Method != http.MethodPost || r.URL.Path != "/api/v1/artist" {
|
|
t.Errorf("unexpected %s %s", r.Method, r.URL.Path)
|
|
}
|
|
_ = json.NewDecoder(r.Body).Decode(&got)
|
|
w.WriteHeader(http.StatusCreated)
|
|
}))
|
|
defer srv.Close()
|
|
|
|
l := NewLidarr(&config.ArrConfig{URL: srv.URL, APIKey: "k", QualityProfileID: 2, MetadataProfileID: 1, RootFolder: "/music"})
|
|
res := makeResult("Radiohead", 0, `{"artistName":"Radiohead","foreignArtistId":"a74b1b7f-71a5-4011-9441-d0b5e4122711"}`)
|
|
if err := l.Add(context.Background(), res); err != nil {
|
|
t.Fatalf("add: %v", err)
|
|
}
|
|
|
|
if got["qualityProfileId"].(float64) != 2 {
|
|
t.Errorf("qualityProfileId = %v", got["qualityProfileId"])
|
|
}
|
|
if got["metadataProfileId"].(float64) != 1 {
|
|
t.Errorf("metadataProfileId = %v", got["metadataProfileId"])
|
|
}
|
|
if got["rootFolderPath"] != "/music" {
|
|
t.Errorf("rootFolderPath = %v", got["rootFolderPath"])
|
|
}
|
|
if got["foreignArtistId"] != "a74b1b7f-71a5-4011-9441-d0b5e4122711" {
|
|
t.Errorf("foreignArtistId not preserved: %v", got["foreignArtistId"])
|
|
}
|
|
opts := got["addOptions"].(map[string]any)
|
|
if opts["searchForMissingAlbums"] != true || opts["monitor"] != "all" {
|
|
t.Errorf("addOptions wrong: %v", opts)
|
|
}
|
|
}
|