2020-10-19 17:06:09 +02:00
|
|
|
package entity
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestFirstOrCreateAddress(t *testing.T) {
|
|
|
|
t.Run("existing address", func(t *testing.T) {
|
|
|
|
address := Address{ID: 1234567, AddressLine1: "Line 1", AddressCountry: "DE"}
|
|
|
|
|
|
|
|
result := FirstOrCreateAddress(&address)
|
|
|
|
|
|
|
|
if result == nil {
|
|
|
|
t.Fatal("result should not be nil")
|
|
|
|
}
|
|
|
|
t.Log(result)
|
|
|
|
|
|
|
|
assert.Equal(t, 1234567, result.ID)
|
|
|
|
})
|
|
|
|
t.Run("not existing address", func(t *testing.T) {
|
|
|
|
address := &Address{}
|
|
|
|
|
|
|
|
result := FirstOrCreateAddress(address)
|
|
|
|
|
|
|
|
if result == nil {
|
|
|
|
t.Fatal("result should not be nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Log(result)
|
|
|
|
|
|
|
|
assert.Equal(t, 1234568, result.ID)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAddress_String(t *testing.T) {
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
address := Address{ID: 1234567, AddressLine1: "Line 1", AddressLine2: "Line 2", AddressCity: "Berlin", AddressCountry: "DE"}
|
|
|
|
addressString := address.String()
|
2021-12-14 17:07:38 +01:00
|
|
|
assert.Equal(t, "'Line 1, Berlin, DE'", addressString)
|
2020-10-19 17:06:09 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAddress_Unknown(t *testing.T) {
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
address := Address{ID: 1234567, AddressLine1: "Line 1", AddressLine2: "Line 2", AddressCity: "Berlin", AddressCountry: "DE"}
|
|
|
|
assert.False(t, address.Unknown())
|
|
|
|
})
|
|
|
|
}
|