mirror of
https://github.com/navidrome/navidrome.git
synced 2026-05-03 06:51:16 +00:00
Added SongsByFolder filter
Signed-off-by: Patrik Wallström <pawal@amplitut.de>
This commit is contained in:
parent
c63346de04
commit
8de1f8bfff
17
server/subsonic/filter/filter_suite_test.go
Normal file
17
server/subsonic/filter/filter_suite_test.go
Normal 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")
|
||||
}
|
||||
@ -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",
|
||||
|
||||
32
server/subsonic/filter/filters_test.go
Normal file
32
server/subsonic/filter/filters_test.go
Normal 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}))
|
||||
})
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user