Add library view and series drill-down (M8)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package arr
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestUpdateKeepsUnknownFields(t *testing.T) {
|
||||
var put map[string]any
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/api/v3/movie/7" {
|
||||
t.Errorf("path %s", r.URL.Path)
|
||||
}
|
||||
switch r.Method {
|
||||
case http.MethodGet:
|
||||
io.WriteString(w, `{"id":7,"monitored":true,"customThing":{"a":[1,2]},"seasons":[{"seasonNumber":1,"monitored":true,"x":1},{"seasonNumber":2,"monitored":true}]}`)
|
||||
case http.MethodPut:
|
||||
json.NewDecoder(r.Body).Decode(&put)
|
||||
}
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
err := NewClient(srv.URL, "k").Update(context.Background(), "movie", 7, func(o map[string]json.RawMessage) error {
|
||||
SetBool(o, "monitored", false)
|
||||
return SetSeasonMonitored(o, 2, false)
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if put["monitored"] != false || put["customThing"] == nil {
|
||||
t.Errorf("put = %v", put)
|
||||
}
|
||||
seasons := put["seasons"].([]any)
|
||||
if seasons[0].(map[string]any)["monitored"] != true || seasons[1].(map[string]any)["monitored"] != false || seasons[0].(map[string]any)["x"] == nil {
|
||||
t.Errorf("seasons = %v", seasons)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetSeasonMonitoredUnknownSeason(t *testing.T) {
|
||||
obj := map[string]json.RawMessage{"seasons": json.RawMessage(`[{"seasonNumber":1,"monitored":true}]`)}
|
||||
if err := SetSeasonMonitored(obj, 5, true); err == nil {
|
||||
t.Error("want error")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user