navidrome/scanner/mapping_test.go

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

77 lines
2.1 KiB
Go
Raw Normal View History

2020-07-27 17:12:39 +02:00
package scanner
import (
2021-07-16 17:03:28 +02:00
"context"
2020-07-27 17:12:39 +02:00
"github.com/navidrome/navidrome/conf"
2021-07-16 17:03:28 +02:00
"github.com/navidrome/navidrome/model"
2021-08-22 17:46:52 +02:00
"github.com/navidrome/navidrome/tests"
2020-07-27 17:12:39 +02:00
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("mapping", func() {
Describe("sanitizeFieldForSorting", func() {
BeforeEach(func() {
2020-09-08 15:40:41 +02:00
conf.Server.IgnoredArticles = "The O"
2020-07-27 17:12:39 +02:00
})
It("sanitize accents", func() {
Expect(sanitizeFieldForSorting("Céu")).To(Equal("Ceu"))
})
It("removes articles", func() {
Expect(sanitizeFieldForSorting("The Beatles")).To(Equal("Beatles"))
})
2020-09-08 15:40:41 +02:00
It("removes accented articles", func() {
Expect(sanitizeFieldForSorting("Õ Blésq Blom")).To(Equal("Blesq Blom"))
})
2020-07-27 17:12:39 +02:00
})
2021-07-16 17:03:28 +02:00
Describe("mapGenres", func() {
var mapper *mediaFileMapper
var gr model.GenreRepository
var ctx context.Context
BeforeEach(func() {
ctx = context.Background()
2021-08-22 17:46:52 +02:00
ds := &tests.MockDataStore{}
gr = ds.Genre(ctx)
2021-07-16 17:03:28 +02:00
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"))
})
2021-09-21 19:37:44 +02:00
It("trims genres names", func() {
_, gs := mapper.mapGenres([]string{"Rock ; Dance", " Electronic "})
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"))
})
It("does not break on spaces", func() {
_, gs := mapper.mapGenres([]string{"New Wave"})
Expect(gs).To(HaveLen(1))
Expect(gs[0].Name).To(Equal("New Wave"))
})
2021-07-16 17:03:28 +02:00
})
2020-07-27 17:12:39 +02:00
})