photoprism/internal/entity/address_test.go

51 lines
1.2 KiB
Go
Raw Normal View History

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()
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())
})
}