test(subsonic): pin getMusicFolders wire shape (#295)

This commit is contained in:
2026-04-19 19:08:18 +00:00
parent ca92cec159
commit d982bcb2ff
+41
View File
@@ -0,0 +1,41 @@
package subsonic
import (
"encoding/json"
"net/http/httptest"
"testing"
)
// TestGetMusicFoldersShape pins the wire shape — a single folder with id=1,
// name "Music". Clients cache this response; breaking the shape invalidates
// their library state.
func TestGetMusicFoldersShape(t *testing.T) {
b := &browseHandlers{}
rec := httptest.NewRecorder()
req := httptest.NewRequest("GET", "/rest/getMusicFolders.view", nil)
b.getMusicFolders(rec, req)
var payload map[string]map[string]any
if err := json.Unmarshal(rec.Body.Bytes(), &payload); err != nil {
t.Fatalf("unmarshal: %v — body=%s", err, rec.Body)
}
inner := payload["subsonic-response"]
if inner["status"] != "ok" {
t.Fatalf("status = %v", inner["status"])
}
folders, ok := inner["musicFolders"].(map[string]any)
if !ok {
t.Fatalf("musicFolders missing: %+v", inner)
}
list, ok := folders["musicFolder"].([]any)
if !ok || len(list) != 1 {
t.Fatalf("musicFolder list = %+v", folders["musicFolder"])
}
first := list[0].(map[string]any)
if first["id"].(float64) != 1 {
t.Errorf("folder id = %v, want 1", first["id"])
}
if first["name"] != "Music" {
t.Errorf("folder name = %v, want Music", first["name"])
}
}