mirror of
https://github.com/photoprism/photoprism.git
synced 2025-10-05 16:57:17 +08:00
47 lines
984 B
Go
47 lines
984 B
Go
package entity
|
|
|
|
import (
|
|
"math/rand/v2"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/photoprism/photoprism/pkg/rnd"
|
|
)
|
|
|
|
func TestSave(t *testing.T) {
|
|
t.Run("HasCreatedUpdatedAt", func(t *testing.T) {
|
|
id := 99999 + rand.IntN(10000)
|
|
m := Photo{ID: uint(id), PhotoUID: rnd.GenerateUID(PhotoUID), UpdatedAt: Now(), CreatedAt: Now()}
|
|
|
|
if err := m.Save(); err != nil {
|
|
t.Fatal(err)
|
|
return
|
|
}
|
|
|
|
assert.NotNil(t, FindPhoto(m))
|
|
})
|
|
t.Run("HasCreatedAt", func(t *testing.T) {
|
|
id := 99999 + rand.IntN(10000)
|
|
m := Photo{ID: uint(id), PhotoUID: rnd.GenerateUID(PhotoUID), CreatedAt: Now()}
|
|
|
|
if err := m.Save(); err != nil {
|
|
t.Fatal(err)
|
|
return
|
|
}
|
|
|
|
assert.NotNil(t, FindPhoto(m))
|
|
})
|
|
t.Run("NoCreatedAt", func(t *testing.T) {
|
|
id := 99999 + rand.IntN(10000)
|
|
m := Photo{ID: uint(id), PhotoUID: rnd.GenerateUID(PhotoUID), CreatedAt: Now()}
|
|
|
|
if err := m.Save(); err != nil {
|
|
t.Fatal(err)
|
|
return
|
|
}
|
|
|
|
assert.NotNil(t, FindPhoto(m))
|
|
})
|
|
}
|