2020-01-06 20:16:31 +01:00
|
|
|
package query
|
|
|
|
|
|
|
|
import (
|
2020-01-08 09:27:39 +01:00
|
|
|
"testing"
|
|
|
|
|
2020-01-06 20:16:31 +01:00
|
|
|
"github.com/photoprism/photoprism/internal/config"
|
|
|
|
"github.com/photoprism/photoprism/internal/entity"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewCountry(t *testing.T) {
|
|
|
|
t.Run("name Fantasy code fy", func(t *testing.T) {
|
|
|
|
country := entity.NewCountry("fy", "Fantasy")
|
|
|
|
assert.Equal(t, "fy", country.ID)
|
|
|
|
assert.Equal(t, "Fantasy", country.CountryName)
|
|
|
|
assert.Equal(t, "fantasy", country.CountrySlug)
|
|
|
|
})
|
|
|
|
t.Run("name Unknown code Unknown", func(t *testing.T) {
|
|
|
|
country := entity.NewCountry("", "")
|
|
|
|
assert.Equal(t, "zz", country.ID)
|
|
|
|
assert.Equal(t, "Unknown", country.CountryName)
|
|
|
|
assert.Equal(t, "unknown", country.CountrySlug)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
func TestCountry_FirstOrCreate(t *testing.T) {
|
|
|
|
t.Run("country already existing", func(t *testing.T) {
|
2020-01-08 09:27:39 +01:00
|
|
|
country := entity.NewCountry("de", "Germany")
|
2020-01-06 20:16:31 +01:00
|
|
|
c := config.TestConfig()
|
|
|
|
country.FirstOrCreate(c.Db())
|
2020-01-08 09:27:39 +01:00
|
|
|
assert.Equal(t, "de", country.Code())
|
|
|
|
assert.Equal(t, "Germany", country.Name())
|
|
|
|
assert.Equal(t, "Country Description", country.CountryDescription)
|
|
|
|
assert.Equal(t, "Country Notes", country.CountryNotes)
|
|
|
|
assert.Equal(t, uint(0), country.CountryPhotoID)
|
2020-01-06 20:16:31 +01:00
|
|
|
})
|
|
|
|
t.Run("country not yet existing", func(t *testing.T) {
|
|
|
|
country := entity.NewCountry("wl", "Wonder Land")
|
|
|
|
c := config.TestConfig()
|
|
|
|
country.FirstOrCreate(c.Db())
|
|
|
|
assert.Equal(t, "wl", country.Code())
|
|
|
|
assert.Equal(t, "Wonder Land", country.Name())
|
|
|
|
})
|
|
|
|
}
|