2019-12-11 16:55:18 +01:00
|
|
|
package entity
|
2019-05-03 18:57:28 +02:00
|
|
|
|
|
|
|
import (
|
2019-07-16 12:36:30 +02:00
|
|
|
"testing"
|
2019-12-11 14:10:20 +01:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2019-05-03 18:57:28 +02:00
|
|
|
)
|
|
|
|
|
2020-05-24 22:16:06 +02:00
|
|
|
func TestFirstOrCreateCamera(t *testing.T) {
|
2020-07-08 18:09:18 +02:00
|
|
|
t.Run("existing camera", func(t *testing.T) {
|
2020-04-30 20:07:03 +02:00
|
|
|
camera := NewCamera("iPhone SE", "Apple")
|
2020-05-24 22:16:06 +02:00
|
|
|
|
|
|
|
result := FirstOrCreateCamera(camera)
|
|
|
|
|
|
|
|
if result == nil {
|
|
|
|
t.Fatal("result should not be nil")
|
|
|
|
}
|
|
|
|
|
2020-07-08 17:36:06 +02:00
|
|
|
assert.GreaterOrEqual(t, result.ID, uint(1))
|
|
|
|
})
|
2020-07-08 18:09:18 +02:00
|
|
|
t.Run("not existing camera", func(t *testing.T) {
|
2020-07-08 17:36:06 +02:00
|
|
|
camera := &Camera{ID: 10000000, CameraSlug: "camera-slug"}
|
|
|
|
|
|
|
|
result := FirstOrCreateCamera(camera)
|
|
|
|
|
|
|
|
if result == nil {
|
|
|
|
t.Fatal("result should not be nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.GreaterOrEqual(t, result.ID, uint(1))
|
|
|
|
})
|
2020-07-08 18:09:18 +02:00
|
|
|
/*t.Run("not existing model and make", func(t *testing.T) {
|
2020-07-08 17:36:06 +02:00
|
|
|
camera := &Camera{CameraModel: "xxx", CameraMake: "xxx"}
|
|
|
|
|
|
|
|
result := FirstOrCreateCamera(camera)
|
|
|
|
|
2020-05-24 22:16:06 +02:00
|
|
|
assert.GreaterOrEqual(t, result.ID, uint(1))
|
2020-07-08 18:09:18 +02:00
|
|
|
})*/
|
2020-04-30 20:07:03 +02:00
|
|
|
}
|
|
|
|
|
2019-05-03 18:57:28 +02:00
|
|
|
func TestNewCamera(t *testing.T) {
|
2020-04-25 14:22:47 +02:00
|
|
|
t.Run("unknown camera", func(t *testing.T) {
|
2020-05-29 18:04:30 +02:00
|
|
|
camera := NewCamera("", "")
|
2019-07-16 12:36:30 +02:00
|
|
|
|
2020-04-25 14:22:47 +02:00
|
|
|
assert.Equal(t, &UnknownCamera, camera)
|
2019-07-16 12:36:30 +02:00
|
|
|
})
|
|
|
|
t.Run("model EOS 6D make Canon", func(t *testing.T) {
|
|
|
|
camera := NewCamera("EOS 6D", "Canon")
|
|
|
|
|
|
|
|
expected := &Camera{
|
|
|
|
CameraSlug: "canon-eos-6d",
|
2020-05-29 18:04:30 +02:00
|
|
|
CameraName: "Canon EOS 6D",
|
|
|
|
CameraMake: "Canon",
|
|
|
|
CameraModel: "EOS 6D",
|
2019-07-16 12:36:30 +02:00
|
|
|
}
|
2020-05-29 18:04:30 +02:00
|
|
|
|
2019-07-16 12:36:30 +02:00
|
|
|
assert.Equal(t, expected, camera)
|
|
|
|
})
|
|
|
|
t.Run("model with prefix make Panasonic", func(t *testing.T) {
|
|
|
|
camera := NewCamera("Panasonic Lumix", "Panasonic")
|
|
|
|
|
|
|
|
expected := &Camera{
|
|
|
|
CameraSlug: "panasonic-lumix",
|
2020-05-29 18:04:30 +02:00
|
|
|
CameraName: "Panasonic Lumix",
|
|
|
|
CameraMake: "Panasonic",
|
|
|
|
CameraModel: "Lumix",
|
2019-07-16 12:36:30 +02:00
|
|
|
}
|
2020-05-29 18:04:30 +02:00
|
|
|
|
2019-07-16 12:36:30 +02:00
|
|
|
assert.Equal(t, expected, camera)
|
|
|
|
})
|
2019-07-16 14:11:33 +02:00
|
|
|
t.Run("model TG-4 make Unknown", func(t *testing.T) {
|
2019-07-16 12:36:30 +02:00
|
|
|
camera := NewCamera("TG-4", "")
|
|
|
|
|
|
|
|
expected := &Camera{
|
|
|
|
CameraSlug: "tg-4",
|
2020-05-29 18:04:30 +02:00
|
|
|
CameraName: "TG-4",
|
|
|
|
CameraMake: "",
|
|
|
|
CameraModel: "TG-4",
|
2019-07-16 12:36:30 +02:00
|
|
|
}
|
2020-05-29 18:04:30 +02:00
|
|
|
|
2019-07-16 12:36:30 +02:00
|
|
|
assert.Equal(t, expected, camera)
|
|
|
|
})
|
2019-07-16 14:11:33 +02:00
|
|
|
t.Run("model Unknown make Unknown", func(t *testing.T) {
|
|
|
|
camera := NewCamera("", "")
|
|
|
|
|
2020-04-25 14:22:47 +02:00
|
|
|
assert.Equal(t, &UnknownCamera, camera)
|
2019-07-16 14:11:33 +02:00
|
|
|
})
|
2020-05-29 18:04:30 +02:00
|
|
|
|
|
|
|
t.Run("OLYMPUS", func(t *testing.T) {
|
|
|
|
camera := NewCamera("", "OLYMPUS OPTICAL CO.,LTD")
|
|
|
|
|
|
|
|
assert.Equal(t, "olympus", camera.CameraSlug)
|
|
|
|
assert.Equal(t, "Olympus", camera.CameraName)
|
|
|
|
assert.Equal(t, "Olympus", camera.CameraMake)
|
|
|
|
assert.Equal(t, "", camera.CameraModel)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("P30", func(t *testing.T) {
|
|
|
|
camera := NewCamera("ELE-AL00", "Huawei")
|
|
|
|
|
|
|
|
assert.Equal(t, "huawei-p30", camera.CameraSlug)
|
|
|
|
assert.Equal(t, "Huawei P30", camera.CameraName)
|
|
|
|
assert.Equal(t, "Huawei", camera.CameraMake)
|
|
|
|
assert.Equal(t, "P30", camera.CameraModel)
|
|
|
|
})
|
2019-07-16 12:36:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCamera_String(t *testing.T) {
|
|
|
|
t.Run("model XXX make Nikon", func(t *testing.T) {
|
|
|
|
camera := NewCamera("XXX", "Nikon")
|
|
|
|
cameraString := camera.String()
|
|
|
|
assert.Equal(t, "Nikon XXX", cameraString)
|
|
|
|
})
|
|
|
|
t.Run("model XXX make Unknown", func(t *testing.T) {
|
|
|
|
camera := NewCamera("XXX", "")
|
|
|
|
cameraString := camera.String()
|
|
|
|
assert.Equal(t, "XXX", cameraString)
|
|
|
|
})
|
2020-05-07 17:29:35 +02:00
|
|
|
t.Run("model Unknown make XXX", func(t *testing.T) {
|
|
|
|
camera := NewCamera("", "test")
|
|
|
|
cameraString := camera.String()
|
2020-05-29 18:04:30 +02:00
|
|
|
assert.Equal(t, "test", cameraString)
|
2020-05-07 17:29:35 +02:00
|
|
|
})
|
|
|
|
t.Run("model Unknown make Unknown", func(t *testing.T) {
|
2019-07-16 12:36:30 +02:00
|
|
|
camera := NewCamera("", "")
|
|
|
|
cameraString := camera.String()
|
|
|
|
assert.Equal(t, "Unknown", cameraString)
|
|
|
|
})
|
2019-05-03 18:57:28 +02:00
|
|
|
}
|