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