photoprism/internal/entity/location_test.go

61 lines
1.8 KiB
Go
Raw Normal View History

2019-12-17 18:27:08 +01:00
package entity
import (
"testing"
"github.com/stretchr/testify/assert"
2019-12-17 18:27:08 +01:00
)
2020-05-08 11:46:09 +02:00
func TestNewLocation(t *testing.T) {
t.Run("new label", func(t *testing.T) {
l := NewLocation(1, 1)
l.LocCategory = "restaurant"
l.LocName = "LocationName"
l.Place = PlaceFixtures.Pointer("zinkwazi")
2020-05-08 11:46:09 +02:00
l.LocSource = "places"
2019-12-17 18:27:08 +01:00
2020-05-08 11:46:09 +02:00
assert.Equal(t, "restaurant", l.Category())
2020-05-08 14:18:11 +02:00
assert.Equal(t, false, l.NoCategory())
2020-05-08 11:46:09 +02:00
assert.Equal(t, false, l.Unknown())
assert.Equal(t, "LocationName", l.Name())
assert.Equal(t, false, l.NoName())
assert.Equal(t, "KwaDukuza, KwaZulu-Natal, South Africa", l.Label())
assert.Equal(t, "KwaDukuza", l.City())
assert.Equal(t, false, l.LongCity())
assert.Equal(t, false, l.CityContains("xxx"))
assert.Equal(t, false, l.NoCity())
assert.Equal(t, "KwaZulu-Natal", l.State())
assert.Equal(t, false, l.NoState())
assert.Equal(t, "za", l.CountryCode())
assert.Equal(t, "South Africa", l.CountryName())
assert.Equal(t, "places", l.Source())
assert.Equal(t, "africa", l.Notes())
})
}
func TestLocation_Keywords(t *testing.T) {
t.Run("mexico", func(t *testing.T) {
m := LocationFixtures["mexico"]
r := m.Keywords()
2020-05-08 11:46:09 +02:00
assert.Equal(t, []string{"adosada", "ancient", "mexico", "platform", "pyramid", "teotihuacán", "tourism"}, r)
})
t.Run("caravan park", func(t *testing.T) {
m := LocationFixtures["caravan park"]
r := m.Keywords()
assert.Equal(t, []string{"camping", "caravan", "kwazulu-natal", "lobotes", "mandeni", "park", "south-africa"}, r)
2020-05-08 11:46:09 +02:00
})
}
func TestLocation_Find(t *testing.T) {
t.Run("place in db", func(t *testing.T) {
m := LocationFixtures["mexico"]
r := m.Find("")
2020-05-08 11:46:09 +02:00
assert.Nil(t, r)
})
t.Run("invalid api", func(t *testing.T) {
l := NewLocation(2, 1)
err := l.Find("")
assert.Equal(t, "maps: reverse lookup disabled", err.Error())
})
2019-12-17 18:27:08 +01:00
}