2020-05-31 17:45:58 +02:00
|
|
|
package entity
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2020-06-29 13:16:55 +02:00
|
|
|
func TestPhoto_Optimize(t *testing.T) {
|
|
|
|
t.Run("update", func(t *testing.T) {
|
|
|
|
photo := PhotoFixtures.Get("Photo19")
|
2020-12-11 17:21:13 +01:00
|
|
|
|
2020-12-30 11:11:58 +01:00
|
|
|
if updated, merged, err := photo.Optimize(false, false, true); err != nil {
|
2020-06-29 13:16:55 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
} else if !updated {
|
|
|
|
t.Error("photo should be updated")
|
2020-12-09 22:15:10 +01:00
|
|
|
} else if len(merged) > 0 {
|
|
|
|
t.Error("no photos should be merged")
|
2020-06-29 13:16:55 +02:00
|
|
|
}
|
|
|
|
|
2020-12-30 11:11:58 +01:00
|
|
|
if updated, merged, err := photo.Optimize(false, false, true); err != nil {
|
2020-06-29 13:16:55 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
} else if updated {
|
2020-12-11 17:21:13 +01:00
|
|
|
t.Errorf("photo should NOT be updated, merged: %+v", merged)
|
2020-12-09 22:15:10 +01:00
|
|
|
} else if len(merged) > 0 {
|
2020-12-11 17:21:13 +01:00
|
|
|
t.Errorf("no photos should be merged")
|
2020-06-29 13:16:55 +02:00
|
|
|
}
|
|
|
|
})
|
2020-10-01 12:15:43 +02:00
|
|
|
t.Run("photo without id", func(t *testing.T) {
|
2020-07-10 15:06:37 +02:00
|
|
|
photo := Photo{}
|
2020-12-30 11:11:58 +01:00
|
|
|
result, merged, err := photo.Optimize(false, false, true)
|
2020-07-10 15:06:37 +02:00
|
|
|
assert.Error(t, err)
|
2020-12-11 17:21:13 +01:00
|
|
|
assert.False(t, result)
|
2020-07-10 15:06:37 +02:00
|
|
|
|
2020-12-09 22:15:10 +01:00
|
|
|
if len(merged) > 0 {
|
|
|
|
t.Error("no photos should be merged")
|
|
|
|
}
|
2020-07-10 15:06:37 +02:00
|
|
|
})
|
2020-06-29 13:16:55 +02:00
|
|
|
}
|