Added childFromFolder helper

Signed-off-by: Patrik Wallström <pawal@amplitut.de>
This commit is contained in:
Patrik Wallström 2026-03-15 01:20:26 +01:00
parent 8de1f8bfff
commit 32200abeb9
2 changed files with 58 additions and 0 deletions

View File

@ -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

View File

@ -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