mirror of
https://github.com/navidrome/navidrome.git
synced 2026-05-03 06:51:16 +00:00
Added childFromFolder helper
Signed-off-by: Patrik Wallström <pawal@amplitut.de>
This commit is contained in:
parent
8de1f8bfff
commit
32200abeb9
@ -317,6 +317,16 @@ func sanitizeSlashes(target string) string {
|
|||||||
return strings.ReplaceAll(target, "/", "_")
|
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 {
|
func childFromAlbum(ctx context.Context, al model.Album) responses.Child {
|
||||||
child := responses.Child{}
|
child := responses.Child{}
|
||||||
child.Id = al.ID
|
child.Id = al.ID
|
||||||
|
|||||||
@ -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() {
|
Describe("AverageRating in responses", func() {
|
||||||
var ctx context.Context
|
var ctx context.Context
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user