Add test for mapTrackTitle

This commit is contained in:
Deluan 2022-12-30 15:13:04 -05:00
parent cc14485194
commit 80ded63d35
2 changed files with 26 additions and 5 deletions

View File

@ -5,12 +5,29 @@ import (
"github.com/navidrome/navidrome/conf"
"github.com/navidrome/navidrome/model"
"github.com/navidrome/navidrome/scanner/metadata"
"github.com/navidrome/navidrome/tests"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("mapping", func() {
Describe("mediaFileMapper", func() {
var mapper *mediaFileMapper
BeforeEach(func() {
mapper = newMediaFileMapper("/music", nil)
})
Describe("mapTrackTitle", func() {
It("returns the Title when it is available", func() {
md := metadata.NewTag("/music/artist/album01/Song.mp3", nil, metadata.ParsedTags{"title": []string{"This is not a love song"}})
Expect(mapper.mapTrackTitle(md)).To(Equal("This is not a love song"))
})
It("returns the filename if Title is not set", func() {
md := metadata.NewTag("/music/artist/album01/Song.mp3", nil, metadata.ParsedTags{})
Expect(mapper.mapTrackTitle(md)).To(Equal("artist/album01/Song"))
})
})
})
Describe("sanitizeFieldForSorting", func() {
BeforeEach(func() {
conf.Server.IgnoredArticles = "The O"

View File

@ -49,16 +49,20 @@ func Extract(files ...string) (map[string]Tags, error) {
}
tags = tags.Map(p.CustomMappings())
result[filePath] = Tags{
filePath: filePath,
fileInfo: fileInfo,
tags: tags,
}
result[filePath] = NewTag(filePath, fileInfo, tags)
}
return result, nil
}
func NewTag(filePath string, fileInfo os.FileInfo, tags ParsedTags) Tags {
return Tags{
filePath: filePath,
fileInfo: fileInfo,
tags: tags,
}
}
type ParsedTags map[string][]string
func (p ParsedTags) Map(customMappings ParsedTags) ParsedTags {