fix(subsonic): clearing playlist comment and public in Subsonic API (#4258)
* fix(subsonic): allow clearing playlist comment * fix(playlists): simplify comment and public parameter handling Signed-off-by: Deluan <deluan@navidrome.org> * refactor(playlists): streamline fakePlaylists implementation in tests Signed-off-by: Deluan <deluan@navidrome.org> --------- Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
@@ -35,6 +35,25 @@ func (r *Values) String(param string) (string, error) {
|
||||
return v, nil
|
||||
}
|
||||
|
||||
func (r *Values) StringPtr(param string) *string {
|
||||
var v *string
|
||||
if _, exists := r.URL.Query()[param]; exists {
|
||||
s := r.URL.Query().Get(param)
|
||||
v = &s
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func (r *Values) BoolPtr(param string) *bool {
|
||||
var v *bool
|
||||
if _, exists := r.URL.Query()[param]; exists {
|
||||
s := r.URL.Query().Get(param)
|
||||
b := strings.Contains("/true/on/1/", "/"+strings.ToLower(s)+"/")
|
||||
v = &b
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func (r *Values) StringOr(param, def string) string {
|
||||
v, _ := r.String(param)
|
||||
if v == "" {
|
||||
|
||||
@@ -219,4 +219,59 @@ var _ = Describe("Request Helpers", func() {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Describe("ParamStringPtr", func() {
|
||||
BeforeEach(func() {
|
||||
r = req.Params(httptest.NewRequest("GET", "/ping?a=123", nil))
|
||||
})
|
||||
|
||||
It("returns pointer to string if param exists", func() {
|
||||
ptr := r.StringPtr("a")
|
||||
Expect(ptr).ToNot(BeNil())
|
||||
Expect(*ptr).To(Equal("123"))
|
||||
})
|
||||
|
||||
It("returns nil if param does not exist", func() {
|
||||
ptr := r.StringPtr("xx")
|
||||
Expect(ptr).To(BeNil())
|
||||
})
|
||||
|
||||
It("returns pointer to empty string if param exists but is empty", func() {
|
||||
r = req.Params(httptest.NewRequest("GET", "/ping?a=", nil))
|
||||
ptr := r.StringPtr("a")
|
||||
Expect(ptr).ToNot(BeNil())
|
||||
Expect(*ptr).To(Equal(""))
|
||||
})
|
||||
})
|
||||
|
||||
Describe("ParamBoolPtr", func() {
|
||||
Context("value is true", func() {
|
||||
BeforeEach(func() {
|
||||
r = req.Params(httptest.NewRequest("GET", "/ping?b=true", nil))
|
||||
})
|
||||
|
||||
It("returns pointer to true if param is 'true'", func() {
|
||||
ptr := r.BoolPtr("b")
|
||||
Expect(ptr).ToNot(BeNil())
|
||||
Expect(*ptr).To(BeTrue())
|
||||
})
|
||||
})
|
||||
|
||||
Context("value is false", func() {
|
||||
BeforeEach(func() {
|
||||
r = req.Params(httptest.NewRequest("GET", "/ping?b=false", nil))
|
||||
})
|
||||
|
||||
It("returns pointer to false if param is 'false'", func() {
|
||||
ptr := r.BoolPtr("b")
|
||||
Expect(ptr).ToNot(BeNil())
|
||||
Expect(*ptr).To(BeFalse())
|
||||
})
|
||||
})
|
||||
|
||||
It("returns nil if param does not exist", func() {
|
||||
ptr := r.BoolPtr("xx")
|
||||
Expect(ptr).To(BeNil())
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user