2021-09-02 16:12:31 +02:00
|
|
|
package form
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSubjectSearchForm(t *testing.T) {
|
2021-11-26 14:28:50 +01:00
|
|
|
form := &SearchSubjects{}
|
2021-09-02 16:12:31 +02:00
|
|
|
|
2021-11-26 14:28:50 +01:00
|
|
|
assert.IsType(t, new(SearchSubjects), form)
|
2021-09-02 16:12:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseQueryStringSubject(t *testing.T) {
|
|
|
|
t.Run("Ok", func(t *testing.T) {
|
2021-11-26 14:28:50 +01:00
|
|
|
form := &SearchSubjects{Query: "type:person favorite:true hidden:all count:5"}
|
2021-09-02 16:12:31 +02:00
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
// log.Debugf("%+v\n", form)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal("err should be nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, "person", form.Type)
|
2021-10-06 15:27:17 +02:00
|
|
|
assert.Equal(t, "true", form.Favorite)
|
|
|
|
assert.Equal(t, "all", form.Hidden)
|
2021-09-02 16:12:31 +02:00
|
|
|
assert.Equal(t, 5, form.Count)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewSubjectSearch(t *testing.T) {
|
|
|
|
r := NewSubjectSearch("john")
|
2021-11-26 14:28:50 +01:00
|
|
|
assert.IsType(t, SearchSubjects{}, r)
|
2021-09-02 16:12:31 +02:00
|
|
|
}
|