From 32200abeb91df5ba42fe572274f9eba89f48e419 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Wallstr=C3=B6m?= Date: Sun, 15 Mar 2026 01:20:26 +0100 Subject: [PATCH] Added childFromFolder helper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Patrik Wallström --- server/subsonic/helpers.go | 10 +++++++ server/subsonic/helpers_test.go | 48 +++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/server/subsonic/helpers.go b/server/subsonic/helpers.go index e930aa630..1fd2c2795 100644 --- a/server/subsonic/helpers.go +++ b/server/subsonic/helpers.go @@ -317,6 +317,16 @@ func sanitizeSlashes(target string) string { return strings.ReplaceAll(target, "/", "_") } +func childFromFolder(_ context.Context, folder model.Folder) responses.Child { + child := responses.Child{} + child.Id = folder.ID + child.Parent = folder.ParentID + child.IsDir = true + child.Title = folder.Name + child.Name = folder.Name + return child +} + func childFromAlbum(ctx context.Context, al model.Album) responses.Child { child := responses.Child{} child.Id = al.ID diff --git a/server/subsonic/helpers_test.go b/server/subsonic/helpers_test.go index d20ca89ad..7935ac351 100644 --- a/server/subsonic/helpers_test.go +++ b/server/subsonic/helpers_test.go @@ -477,6 +477,54 @@ var _ = Describe("helpers", func() { }) }) + Describe("childFromFolder", func() { + var folder model.Folder + var ctx context.Context + + BeforeEach(func() { + folder = model.Folder{ + ID: "folder-1", + ParentID: "parent-1", + Name: "Jazz", + NumAudioFiles: 12, + } + ctx = context.Background() + }) + + It("sets Id from folder ID", func() { + child := childFromFolder(ctx, folder) + Expect(child.Id).To(Equal("folder-1")) + }) + + It("sets Parent from folder ParentID", func() { + child := childFromFolder(ctx, folder) + Expect(child.Parent).To(Equal("parent-1")) + }) + + It("marks the child as a directory", func() { + child := childFromFolder(ctx, folder) + Expect(child.IsDir).To(BeTrue()) + }) + + It("sets Title and Name from folder Name", func() { + child := childFromFolder(ctx, folder) + Expect(child.Title).To(Equal("Jazz")) + Expect(child.Name).To(Equal("Jazz")) + }) + + It("leaves CoverArt empty (populated in task 1.3)", func() { + child := childFromFolder(ctx, folder) + Expect(child.CoverArt).To(BeEmpty()) + }) + + It("works for a root folder with no parent", func() { + folder.ParentID = "" + child := childFromFolder(ctx, folder) + Expect(child.Parent).To(BeEmpty()) + Expect(child.IsDir).To(BeTrue()) + }) + }) + Describe("AverageRating in responses", func() { var ctx context.Context