From d982bcb2ff988e3aa5c58b85fab422b2f79e1985 Mon Sep 17 00:00:00 2001 From: bvandeusen Date: Sun, 19 Apr 2026 19:08:18 +0000 Subject: [PATCH] test(subsonic): pin getMusicFolders wire shape (#295) --- internal/subsonic/browse_test.go | 41 ++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 internal/subsonic/browse_test.go diff --git a/internal/subsonic/browse_test.go b/internal/subsonic/browse_test.go new file mode 100644 index 00000000..5919551d --- /dev/null +++ b/internal/subsonic/browse_test.go @@ -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"]) + } +}