2019-12-11 16:55:18 +01:00
|
|
|
package entity
|
2019-07-16 13:02:42 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2019-12-11 14:10:20 +01:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2019-07-16 13:02:42 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewLens(t *testing.T) {
|
|
|
|
t.Run("name F500-99 make Canon", func(t *testing.T) {
|
|
|
|
lens := NewLens("F500-99", "Canon")
|
2020-05-29 18:04:30 +02:00
|
|
|
assert.Equal(t, "canon-f500-99", lens.LensSlug)
|
|
|
|
assert.Equal(t, "Canon F500-99", lens.LensName)
|
2019-07-16 13:02:42 +02:00
|
|
|
assert.Equal(t, "F500-99", lens.LensModel)
|
|
|
|
assert.Equal(t, "Canon", lens.LensMake)
|
|
|
|
})
|
|
|
|
t.Run("name Unknown make Unknown", func(t *testing.T) {
|
|
|
|
lens := NewLens("", "")
|
2020-05-29 18:04:30 +02:00
|
|
|
assert.Equal(t, "zz", lens.LensSlug)
|
|
|
|
assert.Equal(t, "Unknown", lens.LensName)
|
2019-07-16 13:02:42 +02:00
|
|
|
assert.Equal(t, "Unknown", lens.LensModel)
|
|
|
|
assert.Equal(t, "", lens.LensMake)
|
2020-04-26 17:15:17 +02:00
|
|
|
assert.Equal(t, UnknownLens.LensSlug, lens.LensSlug)
|
2020-04-25 14:22:47 +02:00
|
|
|
assert.Equal(t, &UnknownLens, lens)
|
2019-07-16 13:02:42 +02:00
|
|
|
})
|
|
|
|
}
|
2019-12-17 18:26:50 +01:00
|
|
|
|
|
|
|
func TestLens_TableName(t *testing.T) {
|
|
|
|
lens := NewLens("F500-99", "Canon")
|
|
|
|
tableName := lens.TableName()
|
|
|
|
assert.Equal(t, "lenses", tableName)
|
|
|
|
}
|
2020-07-09 16:43:40 +02:00
|
|
|
|
|
|
|
func TestLens_String(t *testing.T) {
|
|
|
|
lens := NewLens("F500-99", "samsung")
|
|
|
|
assert.Equal(t, "Samsung F500-99", lens.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFirstOrCreateLens(t *testing.T) {
|
|
|
|
t.Run("existing lens", func(t *testing.T) {
|
|
|
|
lens := NewLens("iPhone SE", "Apple")
|
|
|
|
|
|
|
|
result := FirstOrCreateLens(lens)
|
|
|
|
|
|
|
|
if result == nil {
|
|
|
|
t.Fatal("result should not be nil")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
t.Run("not existing lens", func(t *testing.T) {
|
|
|
|
lens := &Lens{}
|
|
|
|
|
|
|
|
result := FirstOrCreateLens(lens)
|
|
|
|
|
|
|
|
if result == nil {
|
|
|
|
t.Fatal("result should not be nil")
|
|
|
|
}
|
|
|
|
assert.GreaterOrEqual(t, result.ID, uint(1))
|
|
|
|
})
|
|
|
|
}
|