2021-10-22 18:00:09 +02:00
|
|
|
package form
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2021-11-09 11:42:10 +01:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2021-10-22 18:00:09 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewFaceSearch(t *testing.T) {
|
|
|
|
r := NewFaceSearch("yes")
|
2021-11-26 14:28:50 +01:00
|
|
|
assert.IsType(t, SearchFaces{}, r)
|
2021-10-22 18:00:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestFaceSearch_GetQuery(t *testing.T) {
|
2021-11-26 14:28:50 +01:00
|
|
|
form := &SearchFaces{Query: "test"}
|
2021-10-22 18:00:09 +02:00
|
|
|
|
|
|
|
assert.Equal(t, "test", form.GetQuery())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFaceSearch_SetQuery(t *testing.T) {
|
2021-11-26 14:28:50 +01:00
|
|
|
form := &SearchFaces{Query: "test"}
|
2021-10-22 18:00:09 +02:00
|
|
|
form.SetQuery("new query")
|
|
|
|
|
|
|
|
assert.Equal(t, "new query", form.GetQuery())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFaceSearch_ParseQueryString(t *testing.T) {
|
|
|
|
t.Run("valid query", func(t *testing.T) {
|
2022-08-01 15:57:19 +02:00
|
|
|
form := &SearchFaces{Query: "subject:test"}
|
2021-10-22 18:00:09 +02:00
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
// log.Debugf("%+v\n", form)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal("err should be nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, "test", form.Subject)
|
2022-08-01 15:57:19 +02:00
|
|
|
assert.Equal(t, 0, form.Count)
|
|
|
|
assert.Equal(t, 0, form.Offset)
|
2021-10-22 18:00:09 +02:00
|
|
|
|
|
|
|
})
|
|
|
|
t.Run("valid query with umlauts", func(t *testing.T) {
|
2022-08-01 15:57:19 +02:00
|
|
|
form := &SearchFaces{Query: "q:\"tübingen\""}
|
2021-10-22 18:00:09 +02:00
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
// log.Debugf("%+v\n", form)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal("err should be nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, "tübingen", form.Query)
|
|
|
|
})
|
|
|
|
t.Run("query for invalid filter", func(t *testing.T) {
|
2021-11-26 14:28:50 +01:00
|
|
|
form := &SearchFaces{Query: "xxx:false"}
|
2021-10-22 18:00:09 +02:00
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
|
|
|
|
// log.Debugf("%+v\n", form)
|
|
|
|
|
2022-08-01 15:57:19 +02:00
|
|
|
assert.Equal(t, "unknown filter: xxx", err.Error())
|
2021-10-22 18:00:09 +02:00
|
|
|
})
|
|
|
|
t.Run("query for count with invalid type", func(t *testing.T) {
|
2021-11-26 14:28:50 +01:00
|
|
|
form := &SearchFaces{Query: "count:cat"}
|
2021-10-22 18:00:09 +02:00
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
2022-08-01 15:57:19 +02:00
|
|
|
assert.Error(t, err)
|
2021-10-22 18:00:09 +02:00
|
|
|
})
|
|
|
|
}
|