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
|
|
|
|
2021-11-18 03:47:25 +01:00
|
|
|
if updated, merged, err := photo.Optimize(false, false, true, false); 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
|
|
|
}
|
|
|
|
|
2021-11-18 03:47:25 +01:00
|
|
|
if updated, merged, err := photo.Optimize(false, false, true, false); 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{}
|
2021-11-18 03:47:25 +01:00
|
|
|
result, merged, err := photo.Optimize(false, false, true, false)
|
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
|
|
|
}
|