2020-05-07 17:29:35 +02:00
|
|
|
package entity
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2020-11-21 18:08:41 +01:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2020-05-07 17:29:35 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewCountry(t *testing.T) {
|
|
|
|
t.Run("unknown country", func(t *testing.T) {
|
|
|
|
country := NewCountry("", "")
|
|
|
|
|
|
|
|
assert.Equal(t, &UnknownCountry, country)
|
|
|
|
})
|
|
|
|
t.Run("United States", func(t *testing.T) {
|
|
|
|
country := NewCountry("us", "United States")
|
|
|
|
|
|
|
|
assert.Equal(t, "USA", country.CountryName)
|
|
|
|
assert.Equal(t, "usa", country.CountrySlug)
|
|
|
|
})
|
|
|
|
t.Run("Germany", func(t *testing.T) {
|
|
|
|
country := NewCountry("de", "Germany")
|
|
|
|
|
|
|
|
assert.Equal(t, "Germany", country.CountryName)
|
|
|
|
assert.Equal(t, "germany", country.CountrySlug)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-05-26 11:00:39 +02:00
|
|
|
func TestFirstOrCreateCountry(t *testing.T) {
|
2020-05-07 17:29:35 +02:00
|
|
|
t.Run("es", func(t *testing.T) {
|
|
|
|
country := NewCountry("es", "spain")
|
2020-05-26 11:00:39 +02:00
|
|
|
country = FirstOrCreateCountry(country)
|
|
|
|
if country == nil {
|
|
|
|
t.Fatal("country should not be nil")
|
|
|
|
}
|
2020-05-07 17:29:35 +02:00
|
|
|
})
|
2020-07-08 18:09:18 +02:00
|
|
|
t.Run("de", func(t *testing.T) {
|
|
|
|
country := &Country{ID: "de"}
|
2020-07-08 17:36:06 +02:00
|
|
|
r := FirstOrCreateCountry(country)
|
|
|
|
if r == nil {
|
|
|
|
t.Fatal("country should not be nil")
|
|
|
|
}
|
|
|
|
})
|
2020-05-07 17:29:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCountry_Name(t *testing.T) {
|
|
|
|
country := NewCountry("xy", "Neverland")
|
|
|
|
assert.Equal(t, "Neverland", country.Name())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCountry_Code(t *testing.T) {
|
|
|
|
country := NewCountry("xy", "Neverland")
|
|
|
|
assert.Equal(t, "xy", country.Code())
|
|
|
|
}
|