2020-12-12 22:02:14 +01:00
|
|
|
package entity
|
|
|
|
|
2021-02-25 15:17:47 +01:00
|
|
|
import (
|
|
|
|
"testing"
|
2021-11-24 14:32:40 +01:00
|
|
|
"time"
|
2021-04-19 13:48:46 +02:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2021-02-25 15:17:47 +01:00
|
|
|
)
|
2020-12-12 22:02:14 +01:00
|
|
|
|
2021-11-24 14:32:40 +01:00
|
|
|
func TestPhoto_Stackable(t *testing.T) {
|
|
|
|
t.Run("IsStackable", func(t *testing.T) {
|
|
|
|
m := Photo{ID: 1, PhotoUID: "pr32t8j3feogit2t", PhotoName: "foo", PhotoStack: IsStackable, TakenAt: TimeStamp(), TakenAtLocal: time.Time{}, TakenSrc: SrcMeta, TimeZone: "Europe/Berlin"}
|
|
|
|
assert.True(t, m.Stackable())
|
|
|
|
})
|
|
|
|
t.Run("IsStacked", func(t *testing.T) {
|
|
|
|
m := Photo{ID: 1, PhotoUID: "pr32t8j3feogit2t", PhotoName: "foo", PhotoStack: IsStacked, TakenAt: TimeStamp(), TakenAtLocal: time.Time{}, TakenSrc: SrcMeta, TimeZone: "Europe/Berlin"}
|
|
|
|
assert.True(t, m.Stackable())
|
|
|
|
})
|
|
|
|
t.Run("NoName", func(t *testing.T) {
|
|
|
|
m := Photo{ID: 1, PhotoUID: "pr32t8j3feogit2t", PhotoName: "", TakenAt: time.Time{}, TakenAtLocal: TimeStamp(), TakenSrc: SrcMeta, TimeZone: "Europe/Berlin"}
|
|
|
|
assert.False(t, m.Stackable())
|
|
|
|
})
|
|
|
|
t.Run("IsUnstacked", func(t *testing.T) {
|
|
|
|
m := Photo{ID: 1, PhotoUID: "pr32t8j3feogit2t", PhotoName: "foo", PhotoStack: IsUnstacked, TakenAt: TimeStamp(), TakenAtLocal: time.Time{}, TakenSrc: SrcMeta, TimeZone: "Europe/Berlin"}
|
|
|
|
assert.False(t, m.Stackable())
|
|
|
|
})
|
|
|
|
t.Run("NoID", func(t *testing.T) {
|
|
|
|
m := Photo{ID: 0, PhotoUID: "pr32t8j3feogit2t", PhotoName: "foo", PhotoStack: IsStacked, TakenAt: TimeStamp(), TakenAtLocal: time.Time{}, TakenSrc: SrcMeta, TimeZone: "Europe/Berlin"}
|
|
|
|
assert.False(t, m.Stackable())
|
|
|
|
})
|
|
|
|
t.Run("NoPhotoUID", func(t *testing.T) {
|
|
|
|
m := Photo{ID: 1, PhotoUID: "", PhotoName: "foo", PhotoStack: IsStacked, TakenAt: TimeStamp(), TakenAtLocal: time.Time{}, TakenSrc: SrcMeta, TimeZone: "Europe/Berlin"}
|
|
|
|
assert.False(t, m.Stackable())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-12-12 22:02:14 +01:00
|
|
|
func TestPhoto_IdenticalIdentical(t *testing.T) {
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
photo := PhotoFixtures.Get("Photo19")
|
|
|
|
|
|
|
|
result, err := photo.Identical(true, true)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Logf("result: %#v", result)
|
2021-02-25 15:17:47 +01:00
|
|
|
assert.Equal(t, 1, len(result))
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("unstacked photo", func(t *testing.T) {
|
|
|
|
photo := &Photo{PhotoStack: IsUnstacked, PhotoName: "testName"}
|
|
|
|
|
|
|
|
result, err := photo.Identical(true, true)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
assert.Equal(t, 0, len(result))
|
|
|
|
})
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
photo := PhotoFixtures.Get("Photo23")
|
|
|
|
|
|
|
|
result, err := photo.Identical(true, true)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Logf("result: %#v", result)
|
|
|
|
assert.Equal(t, 2, len(result))
|
|
|
|
})
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
photo := PhotoFixtures.Get("Photo23")
|
|
|
|
result, err := photo.Identical(true, false)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Logf("result: %#v", result)
|
|
|
|
assert.Equal(t, 2, len(result))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPhoto_Merge(t *testing.T) {
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
photo := PhotoFixtures.Get("Photo23")
|
|
|
|
original, merged, err := photo.Merge(true, false)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
assert.Equal(t, 1000023, int(original.ID))
|
|
|
|
assert.Equal(t, 1000024, int(merged[0].ID))
|
2020-12-12 22:02:14 +01:00
|
|
|
})
|
|
|
|
}
|