2020-01-15 04:04:33 +01:00
|
|
|
package form
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGeoSearch(t *testing.T) {
|
2021-08-29 16:16:49 +02:00
|
|
|
t.Run("subjects", func(t *testing.T) {
|
2021-09-19 13:35:44 +02:00
|
|
|
form := &PhotoSearchGeo{Query: "subjects:\"Jens Mander\""}
|
2021-08-29 16:16:49 +02:00
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, "Jens Mander", form.Subjects)
|
|
|
|
})
|
2021-09-20 12:36:59 +02:00
|
|
|
t.Run("aliases", func(t *testing.T) {
|
|
|
|
form := &PhotoSearchGeo{Query: "people:\"Jens & Mander\" folder:Foo person:Bar"}
|
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
assert.Equal(t, "", form.Folder)
|
|
|
|
assert.Equal(t, "", form.Person)
|
|
|
|
assert.Equal(t, "", form.People)
|
|
|
|
assert.Equal(t, "Foo", form.Path)
|
|
|
|
assert.Equal(t, "Bar", form.Subject)
|
|
|
|
assert.Equal(t, "Jens & Mander", form.Subjects)
|
|
|
|
})
|
2021-08-29 16:16:49 +02:00
|
|
|
t.Run("keywords", func(t *testing.T) {
|
2021-09-19 13:35:44 +02:00
|
|
|
form := &PhotoSearchGeo{Query: "keywords:\"Foo Bar\""}
|
2021-08-29 16:16:49 +02:00
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, "Foo Bar", form.Keywords)
|
|
|
|
})
|
2020-01-15 04:04:33 +01:00
|
|
|
t.Run("valid query", func(t *testing.T) {
|
2021-09-19 13:35:44 +02:00
|
|
|
form := &PhotoSearchGeo{Query: "query:\"fooBar baz\" before:2019-01-15 dist:25000 lat:33.45343166666667"}
|
2020-01-15 04:04:33 +01:00
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
2020-01-31 15:29:06 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal("err should be nil")
|
|
|
|
}
|
|
|
|
|
2021-08-29 16:16:49 +02:00
|
|
|
// log.Debugf("%+v\n", form)
|
2020-01-15 04:04:33 +01:00
|
|
|
|
2020-05-21 10:03:56 +02:00
|
|
|
assert.Equal(t, "fooBar baz", form.Query)
|
2020-01-15 04:04:33 +01:00
|
|
|
assert.Equal(t, time.Date(2019, 01, 15, 0, 0, 0, 0, time.UTC), form.Before)
|
|
|
|
assert.Equal(t, uint(0x61a8), form.Dist)
|
2020-04-26 11:41:54 +02:00
|
|
|
assert.Equal(t, float32(33.45343), form.Lat)
|
2020-01-15 04:04:33 +01:00
|
|
|
})
|
2020-07-08 08:36:10 +02:00
|
|
|
t.Run("valid query path empty folder not empty", func(t *testing.T) {
|
2021-09-19 13:35:44 +02:00
|
|
|
form := &PhotoSearchGeo{Query: "query:\"fooBar baz\" before:2019-01-15 dist:25000 lat:33.45343166666667 folder:test"}
|
2020-07-08 08:36:10 +02:00
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal("err should be nil")
|
|
|
|
}
|
|
|
|
|
2021-08-29 16:16:49 +02:00
|
|
|
// log.Debugf("%+v\n", form)
|
2020-07-08 08:36:10 +02:00
|
|
|
|
|
|
|
assert.Equal(t, "fooBar baz", form.Query)
|
|
|
|
assert.Equal(t, "test", form.Path)
|
2021-09-20 12:36:59 +02:00
|
|
|
assert.Equal(t, "", form.Folder)
|
2020-07-08 08:36:10 +02:00
|
|
|
assert.Equal(t, time.Date(2019, 01, 15, 0, 0, 0, 0, time.UTC), form.Before)
|
|
|
|
assert.Equal(t, uint(0x61a8), form.Dist)
|
|
|
|
assert.Equal(t, float32(33.45343), form.Lat)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGeoSearch_Serialize(t *testing.T) {
|
2021-09-19 13:35:44 +02:00
|
|
|
form := &PhotoSearchGeo{Query: "query:\"fooBar baz\"", Favorite: true}
|
2020-07-08 08:36:10 +02:00
|
|
|
|
|
|
|
assert.Equal(t, "q:\"query:fooBar baz\" favorite:true", form.Serialize())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGeoSearch_SerializeAll(t *testing.T) {
|
2021-09-19 13:35:44 +02:00
|
|
|
form := &PhotoSearchGeo{Query: "query:\"fooBar baz\"", Favorite: true}
|
2020-07-08 08:36:10 +02:00
|
|
|
|
|
|
|
assert.Equal(t, "q:\"query:fooBar baz\" favorite:true", form.SerializeAll())
|
2020-01-15 04:04:33 +01:00
|
|
|
}
|
2020-05-06 17:05:06 +02:00
|
|
|
|
|
|
|
func TestNewGeoSearch(t *testing.T) {
|
|
|
|
r := NewGeoSearch("Berlin")
|
2021-09-19 13:35:44 +02:00
|
|
|
assert.IsType(t, PhotoSearchGeo{}, r)
|
2020-05-06 17:05:06 +02:00
|
|
|
}
|