2022-04-10 14:38:51 +02:00
|
|
|
package entity
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/rand"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2022-09-28 09:01:17 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
2022-04-10 14:38:51 +02:00
|
|
|
"github.com/photoprism/photoprism/pkg/rnd"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSave(t *testing.T) {
|
|
|
|
var r = rand.New(rand.NewSource(time.Now().UnixNano()))
|
|
|
|
|
|
|
|
t.Run("HasCreatedUpdatedAt", func(t *testing.T) {
|
|
|
|
id := 99999 + r.Intn(10000)
|
2022-09-28 09:01:17 +02:00
|
|
|
m := Photo{ID: uint(id), PhotoUID: rnd.GenerateUID(PhotoUID), UpdatedAt: TimeStamp(), CreatedAt: TimeStamp()}
|
2022-04-10 14:38:51 +02:00
|
|
|
|
|
|
|
if err := m.Save(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-09-28 09:01:17 +02:00
|
|
|
assert.NotNil(t, FindPhoto(m))
|
2022-04-10 14:38:51 +02:00
|
|
|
})
|
|
|
|
t.Run("HasCreatedAt", func(t *testing.T) {
|
|
|
|
id := 99999 + r.Intn(10000)
|
2022-09-28 09:01:17 +02:00
|
|
|
m := Photo{ID: uint(id), PhotoUID: rnd.GenerateUID(PhotoUID), CreatedAt: TimeStamp()}
|
2022-04-10 14:38:51 +02:00
|
|
|
|
|
|
|
if err := m.Save(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-09-28 09:01:17 +02:00
|
|
|
assert.NotNil(t, FindPhoto(m))
|
2022-04-10 14:38:51 +02:00
|
|
|
})
|
|
|
|
t.Run("NoCreatedAt", func(t *testing.T) {
|
|
|
|
id := 99999 + r.Intn(10000)
|
2022-09-28 09:01:17 +02:00
|
|
|
m := Photo{ID: uint(id), PhotoUID: rnd.GenerateUID(PhotoUID), CreatedAt: TimeStamp()}
|
2022-04-10 14:38:51 +02:00
|
|
|
|
|
|
|
if err := m.Save(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-09-28 09:01:17 +02:00
|
|
|
assert.NotNil(t, FindPhoto(m))
|
2022-04-10 14:38:51 +02:00
|
|
|
})
|
|
|
|
}
|