2020-05-06 17:05:06 +02:00
|
|
|
package form
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2022-10-15 21:54:11 +02:00
|
|
|
func TestSearchServices(t *testing.T) {
|
|
|
|
form := &SearchServices{}
|
2020-05-06 17:05:06 +02:00
|
|
|
|
2022-10-15 21:54:11 +02:00
|
|
|
assert.IsType(t, new(SearchServices), form)
|
2020-05-06 17:05:06 +02:00
|
|
|
}
|
|
|
|
|
2022-10-15 21:54:11 +02:00
|
|
|
func TestSearchServices_GetQuery(t *testing.T) {
|
|
|
|
form := &SearchServices{Query: "q: webdav, share:true, sync:false, status:test"}
|
2020-05-06 17:05:06 +02:00
|
|
|
|
|
|
|
r := form.GetQuery()
|
2022-08-01 15:57:19 +02:00
|
|
|
assert.Equal(t, "q: webdav, share:true, sync:false, status:test", r)
|
2020-05-06 17:05:06 +02:00
|
|
|
}
|
|
|
|
|
2022-10-15 21:54:11 +02:00
|
|
|
func TestSearchServices_SetQuery(t *testing.T) {
|
|
|
|
form := &SearchServices{}
|
2020-05-06 17:05:06 +02:00
|
|
|
assert.Equal(t, "", form.GetQuery())
|
|
|
|
form.SetQuery("query test")
|
|
|
|
assert.Equal(t, "query test", form.GetQuery())
|
|
|
|
}
|
|
|
|
|
2022-10-15 21:54:11 +02:00
|
|
|
func TestSearchServices_ParseQueryString(t *testing.T) {
|
2020-05-06 17:05:06 +02:00
|
|
|
|
|
|
|
t.Run("valid query", func(t *testing.T) {
|
2022-10-15 21:54:11 +02:00
|
|
|
form := &SearchServices{Query: "q: webdäv share:true sync:false status:test"}
|
2020-05-06 17:05:06 +02:00
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
|
2021-08-29 16:16:49 +02:00
|
|
|
// log.Debugf("%+v\n", form)
|
2020-05-06 17:05:06 +02:00
|
|
|
|
|
|
|
assert.Equal(t, "webdäv", form.Query)
|
|
|
|
assert.Equal(t, true, form.Share)
|
|
|
|
assert.Equal(t, false, form.Sync)
|
2022-08-01 15:57:19 +02:00
|
|
|
assert.Equal(t, 0, form.Count)
|
2020-05-06 17:05:06 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("query for invalid filter", func(t *testing.T) {
|
2022-10-15 21:54:11 +02:00
|
|
|
form := &SearchServices{Query: "xxx:false"}
|
2020-05-06 17:05:06 +02:00
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
|
2021-08-29 16:16:49 +02:00
|
|
|
// log.Debugf("%+v\n", form)
|
2020-05-06 17:05:06 +02:00
|
|
|
|
2022-08-01 15:57:19 +02:00
|
|
|
assert.Equal(t, "unknown filter: xxx", err.Error())
|
2020-05-06 17:05:06 +02:00
|
|
|
})
|
|
|
|
t.Run("query for sync with uncommon bool value", func(t *testing.T) {
|
2022-10-15 21:54:11 +02:00
|
|
|
form := &SearchServices{Query: "sync:cat"}
|
2020-05-06 17:05:06 +02:00
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal("err should be nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.True(t, form.Sync)
|
|
|
|
})
|
|
|
|
t.Run("query for count with invalid type", func(t *testing.T) {
|
2021-11-26 14:28:50 +01:00
|
|
|
form := &SearchAlbums{Query: "count:cat"}
|
2020-05-06 17:05:06 +02:00
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
2022-08-01 15:57:19 +02:00
|
|
|
assert.Error(t, err)
|
2020-05-06 17:05:06 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-10-15 21:54:11 +02:00
|
|
|
func TestNewSearchServices(t *testing.T) {
|
|
|
|
r := NewSearchServices("holiday")
|
|
|
|
assert.IsType(t, SearchServices{}, r)
|
2020-05-06 17:05:06 +02:00
|
|
|
}
|