2020-05-31 17:45:58 +02:00
|
|
|
package entity
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPhoto_EstimateCountry(t *testing.T) {
|
|
|
|
t.Run("uk", func(t *testing.T) {
|
|
|
|
m := Photo{PhotoName: "20200102_194030_9EFA9E5E", PhotoPath: "2000/05", OriginalName: "flickr import/changing-of-the-guard--buckingham-palace_7925318070_o.jpg"}
|
|
|
|
assert.Equal(t, UnknownCountry.ID, m.CountryCode())
|
|
|
|
assert.Equal(t, UnknownCountry.CountryName, m.CountryName())
|
|
|
|
m.EstimateCountry()
|
|
|
|
assert.Equal(t, "gb", m.CountryCode())
|
|
|
|
assert.Equal(t, "United Kingdom", m.CountryName())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("zz", func(t *testing.T) {
|
2020-05-31 18:19:24 +02:00
|
|
|
m := Photo{PhotoName: "20200102_194030_ADADADAD", PhotoPath: "2020/Berlin", OriginalName: "Zimmermannstrasse.jpg"}
|
2020-05-31 17:45:58 +02:00
|
|
|
assert.Equal(t, UnknownCountry.ID, m.CountryCode())
|
|
|
|
assert.Equal(t, UnknownCountry.CountryName, m.CountryName())
|
|
|
|
m.EstimateCountry()
|
|
|
|
assert.Equal(t, UnknownCountry.ID, m.CountryCode())
|
|
|
|
assert.Equal(t, UnknownCountry.CountryName, m.CountryName())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("de", func(t *testing.T) {
|
2020-06-12 18:01:22 +02:00
|
|
|
m := Photo{PhotoName: "Brauhaus", PhotoPath: "2020/Bayern", OriginalName: "München.jpg"}
|
2020-05-31 17:45:58 +02:00
|
|
|
assert.Equal(t, UnknownCountry.ID, m.CountryCode())
|
|
|
|
assert.Equal(t, UnknownCountry.CountryName, m.CountryName())
|
|
|
|
m.EstimateCountry()
|
|
|
|
assert.Equal(t, "de", m.CountryCode())
|
|
|
|
assert.Equal(t, "Germany", m.CountryName())
|
|
|
|
})
|
2020-06-01 09:45:24 +02:00
|
|
|
|
|
|
|
t.Run("ca", func(t *testing.T) {
|
|
|
|
m := Photo{PhotoTitle: "Port Lands / Gardiner Expressway / Toronto", PhotoPath: "2012/09", PhotoName: "20120910_231851_CA06E1AD", OriginalName: "demo/Toronto/port-lands--gardiner-expressway--toronto_7999515645_o.jpg"}
|
|
|
|
assert.Equal(t, UnknownCountry.ID, m.CountryCode())
|
|
|
|
assert.Equal(t, UnknownCountry.CountryName, m.CountryName())
|
|
|
|
m.EstimateCountry()
|
|
|
|
assert.Equal(t, "ca", m.CountryCode())
|
|
|
|
assert.Equal(t, "Canada", m.CountryName())
|
|
|
|
})
|
2020-05-31 17:45:58 +02:00
|
|
|
}
|
2020-06-29 13:16:55 +02:00
|
|
|
|
|
|
|
func TestPhoto_Optimize(t *testing.T) {
|
|
|
|
t.Run("update", func(t *testing.T) {
|
|
|
|
photo := PhotoFixtures.Get("Photo19")
|
|
|
|
if updated, err := photo.Optimize(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
} else if !updated {
|
|
|
|
t.Error("photo should be updated")
|
|
|
|
}
|
|
|
|
|
|
|
|
if updated, err := photo.Optimize(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
} else if updated {
|
|
|
|
t.Error("photo should NOT be updated")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|