Added SongsByFolder filter

Signed-off-by: Patrik Wallström <pawal@amplitut.de>
This commit is contained in:
Patrik Wallström 2026-03-15 01:17:53 +01:00
parent c63346de04
commit 8de1f8bfff
3 changed files with 56 additions and 0 deletions

View File

@ -0,0 +1,17 @@
package filter_test
import (
"testing"
"github.com/navidrome/navidrome/log"
"github.com/navidrome/navidrome/tests"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
func TestFilter(t *testing.T) {
tests.Init(t, false)
log.SetLevel(log.LevelFatal)
RegisterFailHandler(Fail)
RunSpecs(t, "Subsonic Filter Suite")
}

View File

@ -90,6 +90,13 @@ func SongsByAlbum(albumId string) Options {
})
}
func SongsByFolder(folderID string) Options {
return addDefaultFilters(Options{
Filters: Eq{"folder_id": folderID},
Sort: "path",
})
}
func SongsByRandom(genre string, fromYear, toYear int) Options {
options := Options{
Sort: "random",

View File

@ -0,0 +1,32 @@
package filter_test
import (
sq "github.com/Masterminds/squirrel"
. "github.com/navidrome/navidrome/server/subsonic/filter"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("SongsByFolder", func() {
It("sets sort to path", func() {
opts := SongsByFolder("folder-1")
Expect(opts.Sort).To(Equal("path"))
})
It("filters by the given folder ID", func() {
opts := SongsByFolder("folder-1")
Expect(opts.Filters).To(Equal(sq.And{sq.Eq{"missing": false}, sq.Eq{"folder_id": "folder-1"}}))
})
It("uses a different folder ID per call", func() {
opts := SongsByFolder("folder-2")
Expect(opts.Filters).To(Equal(sq.And{sq.Eq{"missing": false}, sq.Eq{"folder_id": "folder-2"}}))
})
It("excludes missing files via default filter", func() {
opts := SongsByFolder("any-folder")
filters, ok := opts.Filters.(sq.And)
Expect(ok).To(BeTrue())
Expect(filters).To(ContainElement(sq.Eq{"missing": false}))
})
})