2020-01-28 22:16:59 +01:00
|
|
|
package query
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2020-05-13 11:57:54 +02:00
|
|
|
"time"
|
2020-01-28 22:16:59 +01:00
|
|
|
|
2020-05-08 15:41:01 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/form"
|
|
|
|
"github.com/stretchr/testify/assert"
|
2020-01-28 22:16:59 +01:00
|
|
|
)
|
|
|
|
|
2020-05-08 15:41:01 +02:00
|
|
|
func TestGeo(t *testing.T) {
|
2020-01-28 22:16:59 +01:00
|
|
|
t.Run("search all photos", func(t *testing.T) {
|
|
|
|
query := form.NewGeoSearch("")
|
2020-05-08 15:41:01 +02:00
|
|
|
result, err := Geo(query)
|
2020-01-28 22:16:59 +01:00
|
|
|
|
2020-05-13 11:57:54 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
assert.LessOrEqual(t, 5, len(result))
|
2020-01-28 22:16:59 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("search for bridge", func(t *testing.T) {
|
|
|
|
query := form.NewGeoSearch("Query:bridge Before:3006-01-02")
|
2020-05-08 15:41:01 +02:00
|
|
|
result, err := Geo(query)
|
2020-01-28 22:16:59 +01:00
|
|
|
|
2020-05-13 11:57:54 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-05-14 14:18:28 +02:00
|
|
|
assert.LessOrEqual(t, 2, len(result))
|
2020-01-28 22:16:59 +01:00
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("search for timeframe", func(t *testing.T) {
|
|
|
|
query := form.NewGeoSearch("After:2014-12-02 Before:3006-01-02")
|
2020-05-08 15:41:01 +02:00
|
|
|
result, err := Geo(query)
|
2020-01-28 22:16:59 +01:00
|
|
|
|
2020-05-13 11:57:54 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2020-01-28 22:16:59 +01:00
|
|
|
assert.Equal(t, "Reunion", result[0].PhotoTitle)
|
|
|
|
|
|
|
|
})
|
2020-05-13 11:57:54 +02:00
|
|
|
t.Run("search for review true, quality 0", func(t *testing.T) {
|
|
|
|
f := form.GeoSearch{
|
|
|
|
Query: "",
|
|
|
|
Before: time.Time{},
|
|
|
|
After: time.Time{},
|
|
|
|
Favorite: true,
|
|
|
|
Lat: 1.234,
|
|
|
|
Lng: 4.321,
|
|
|
|
S2: "",
|
|
|
|
Olc: "",
|
|
|
|
Dist: 0,
|
|
|
|
Quality: 0,
|
|
|
|
Review: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
result, err := Geo(f)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
assert.LessOrEqual(t, 1, len(result))
|
|
|
|
assert.Equal(t, "1000017", result[0].ID)
|
|
|
|
assert.IsType(t, GeoResults{}, result)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("search for review false, quality > 0", func(t *testing.T) {
|
|
|
|
f := form.GeoSearch{
|
|
|
|
Query: "",
|
|
|
|
Before: time.Time{},
|
|
|
|
After: time.Time{},
|
|
|
|
Favorite: false,
|
|
|
|
Lat: 0,
|
|
|
|
Lng: 0,
|
|
|
|
S2: "",
|
|
|
|
Olc: "",
|
|
|
|
Dist: 0,
|
|
|
|
Quality: 3,
|
|
|
|
Review: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
result, err := Geo(f)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
assert.LessOrEqual(t, 4, len(result))
|
|
|
|
assert.IsType(t, GeoResults{}, result)
|
|
|
|
})
|
|
|
|
t.Run("search for s2", func(t *testing.T) {
|
|
|
|
f := form.GeoSearch{
|
|
|
|
Query: "",
|
|
|
|
Before: time.Time{},
|
|
|
|
After: time.Time{},
|
|
|
|
Favorite: false,
|
|
|
|
Lat: 0,
|
|
|
|
Lng: 0,
|
|
|
|
S2: "85",
|
|
|
|
Olc: "",
|
|
|
|
Dist: 0,
|
|
|
|
Quality: 0,
|
|
|
|
Review: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
result, err := Geo(f)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
assert.Empty(t, result)
|
|
|
|
assert.IsType(t, GeoResults{}, result)
|
|
|
|
})
|
|
|
|
t.Run("search for Olc", func(t *testing.T) {
|
|
|
|
f := form.GeoSearch{
|
|
|
|
Query: "",
|
|
|
|
Before: time.Time{},
|
|
|
|
After: time.Time{},
|
|
|
|
Favorite: false,
|
|
|
|
Lat: 0,
|
|
|
|
Lng: 0,
|
|
|
|
S2: "",
|
|
|
|
Olc: "9",
|
|
|
|
Dist: 0,
|
|
|
|
Quality: 0,
|
|
|
|
Review: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
result, err := Geo(f)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
assert.IsType(t, GeoResults{}, result)
|
|
|
|
})
|
2020-01-28 22:16:59 +01:00
|
|
|
}
|