Add multiple genres to MediaFile
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
package scanner
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/navidrome/navidrome/conf"
|
||||
"github.com/navidrome/navidrome/model"
|
||||
"github.com/navidrome/navidrome/persistence"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
@@ -21,4 +26,40 @@ var _ = Describe("mapping", func() {
|
||||
Expect(sanitizeFieldForSorting("Õ Blésq Blom")).To(Equal("Blesq Blom"))
|
||||
})
|
||||
})
|
||||
|
||||
Describe("mapGenres", func() {
|
||||
var mapper *mediaFileMapper
|
||||
var gr model.GenreRepository
|
||||
var ctx context.Context
|
||||
BeforeEach(func() {
|
||||
ctx = context.Background()
|
||||
o := orm.NewOrm()
|
||||
gr = persistence.NewGenreRepository(ctx, o)
|
||||
gr = newCachedGenreRepository(ctx, gr)
|
||||
mapper = newMediaFileMapper("/", gr)
|
||||
})
|
||||
|
||||
It("returns empty if no genres are available", func() {
|
||||
g, gs := mapper.mapGenres(nil)
|
||||
Expect(g).To(BeEmpty())
|
||||
Expect(gs).To(BeEmpty())
|
||||
})
|
||||
|
||||
It("returns genres", func() {
|
||||
g, gs := mapper.mapGenres([]string{"Rock", "Electronic"})
|
||||
Expect(g).To(Equal("Rock"))
|
||||
Expect(gs).To(HaveLen(2))
|
||||
Expect(gs[0].Name).To(Equal("Rock"))
|
||||
Expect(gs[1].Name).To(Equal("Electronic"))
|
||||
})
|
||||
|
||||
It("parses multi-valued genres", func() {
|
||||
g, gs := mapper.mapGenres([]string{"Rock;Dance", "Electronic", "Rock"})
|
||||
Expect(g).To(Equal("Rock"))
|
||||
Expect(gs).To(HaveLen(3))
|
||||
Expect(gs[0].Name).To(Equal("Rock"))
|
||||
Expect(gs[1].Name).To(Equal("Dance"))
|
||||
Expect(gs[2].Name).To(Equal("Electronic"))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user