2019-12-11 16:55:18 +01:00
|
|
|
package entity
|
2019-12-04 15:14:04 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2019-12-11 14:10:20 +01:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2019-12-04 15:14:04 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewPhotoAlbum(t *testing.T) {
|
|
|
|
t.Run("new album", func(t *testing.T) {
|
|
|
|
m := NewPhotoAlbum("ABC", "EFG")
|
2020-05-23 20:58:58 +02:00
|
|
|
assert.Equal(t, "ABC", m.PhotoUID)
|
|
|
|
assert.Equal(t, "EFG", m.AlbumUID)
|
2019-12-04 15:14:04 +01:00
|
|
|
})
|
|
|
|
}
|
2019-12-17 18:27:25 +01:00
|
|
|
|
|
|
|
func TestPhotoAlbum_TableName(t *testing.T) {
|
|
|
|
photoAlbum := &PhotoAlbum{}
|
|
|
|
tableName := photoAlbum.TableName()
|
|
|
|
|
|
|
|
assert.Equal(t, "photos_albums", tableName)
|
|
|
|
}
|
2020-05-08 14:18:11 +02:00
|
|
|
|
2020-05-26 11:00:39 +02:00
|
|
|
func TestFirstOrCreatePhotoAlbum(t *testing.T) {
|
2020-07-10 15:06:37 +02:00
|
|
|
t.Run("existing album", func(t *testing.T) {
|
|
|
|
model := PhotoAlbumFixtures.Get("1", "pt9jtdre2lvl0yh7", "at9lxuqxpogaaba8")
|
|
|
|
result := FirstOrCreatePhotoAlbum(&model)
|
2020-05-26 11:00:39 +02:00
|
|
|
|
2020-07-10 15:06:37 +02:00
|
|
|
if result == nil {
|
|
|
|
t.Fatal("result should not be nil")
|
|
|
|
}
|
2020-05-26 11:00:39 +02:00
|
|
|
|
2020-07-10 15:06:37 +02:00
|
|
|
if result.AlbumUID != model.AlbumUID {
|
|
|
|
t.Errorf("AlbumUID should be the same: %s %s", result.AlbumUID, model.AlbumUID)
|
|
|
|
}
|
2020-05-26 11:00:39 +02:00
|
|
|
|
2020-07-10 15:06:37 +02:00
|
|
|
if result.PhotoUID != model.PhotoUID {
|
|
|
|
t.Errorf("PhotoUID should be the same: %s %s", result.PhotoUID, model.PhotoUID)
|
|
|
|
}
|
|
|
|
})
|
2022-05-03 15:05:45 +02:00
|
|
|
//TODO fails on mariadb
|
2020-07-10 15:06:37 +02:00
|
|
|
t.Run("not yet existing album", func(t *testing.T) {
|
|
|
|
model := &PhotoAlbum{}
|
|
|
|
result := FirstOrCreatePhotoAlbum(model)
|
|
|
|
|
|
|
|
if result == nil {
|
|
|
|
t.Fatal("result should not be nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
if result.AlbumUID != model.AlbumUID {
|
|
|
|
t.Errorf("AlbumUID should be the same: %s %s", result.AlbumUID, model.AlbumUID)
|
|
|
|
}
|
|
|
|
|
|
|
|
if result.PhotoUID != model.PhotoUID {
|
|
|
|
t.Errorf("PhotoUID should be the same: %s %s", result.PhotoUID, model.PhotoUID)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-05-03 15:05:45 +02:00
|
|
|
//TODO fails on mariadb
|
2020-07-10 15:06:37 +02:00
|
|
|
func TestPhotoAlbum_Save(t *testing.T) {
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
p := PhotoAlbum{}
|
|
|
|
|
|
|
|
err := p.Create()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
})
|
2020-05-08 14:18:11 +02:00
|
|
|
}
|