2019-12-11 16:55:18 +01:00
|
|
|
package entity
|
2019-07-16 12:44:13 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2019-12-04 12:11:11 +01:00
|
|
|
"time"
|
2019-12-11 14:10:20 +01:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2021-11-20 16:36:34 +01:00
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/internal/form"
|
|
|
|
"github.com/photoprism/photoprism/pkg/txt"
|
2019-07-16 12:44:13 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewAlbum(t *testing.T) {
|
|
|
|
t.Run("name Christmas 2018", func(t *testing.T) {
|
2020-06-08 18:32:51 +02:00
|
|
|
album := NewAlbum("Christmas 2018", AlbumDefault)
|
2020-05-26 09:02:19 +02:00
|
|
|
assert.Equal(t, "Christmas 2018", album.AlbumTitle)
|
2019-07-16 12:44:13 +02:00
|
|
|
assert.Equal(t, "christmas-2018", album.AlbumSlug)
|
|
|
|
})
|
|
|
|
t.Run("name empty", func(t *testing.T) {
|
2020-06-08 18:32:51 +02:00
|
|
|
album := NewAlbum("", AlbumDefault)
|
2019-12-04 12:11:11 +01:00
|
|
|
|
|
|
|
defaultName := time.Now().Format("January 2006")
|
2022-03-24 21:46:25 +01:00
|
|
|
defaultSlug := txt.Slug(defaultName)
|
2019-12-04 12:11:11 +01:00
|
|
|
|
2020-05-26 09:02:19 +02:00
|
|
|
assert.Equal(t, defaultName, album.AlbumTitle)
|
2019-12-04 12:11:11 +01:00
|
|
|
assert.Equal(t, defaultSlug, album.AlbumSlug)
|
2019-07-16 12:44:13 +02:00
|
|
|
})
|
2020-07-08 17:06:23 +02:00
|
|
|
t.Run("type empty", func(t *testing.T) {
|
|
|
|
album := NewAlbum("Christmas 2018", "")
|
|
|
|
assert.Equal(t, "Christmas 2018", album.AlbumTitle)
|
|
|
|
assert.Equal(t, "christmas-2018", album.AlbumSlug)
|
|
|
|
})
|
2019-07-16 12:44:13 +02:00
|
|
|
}
|
2019-12-17 18:25:13 +01:00
|
|
|
|
2020-04-26 14:31:33 +02:00
|
|
|
func TestAlbum_SetName(t *testing.T) {
|
2019-12-17 18:25:13 +01:00
|
|
|
t.Run("valid name", func(t *testing.T) {
|
2020-06-08 18:32:51 +02:00
|
|
|
album := NewAlbum("initial name", AlbumDefault)
|
2020-05-26 09:02:19 +02:00
|
|
|
assert.Equal(t, "initial name", album.AlbumTitle)
|
2019-12-17 18:25:13 +01:00
|
|
|
assert.Equal(t, "initial-name", album.AlbumSlug)
|
2020-05-26 09:02:19 +02:00
|
|
|
album.SetTitle("New Album Name")
|
|
|
|
assert.Equal(t, "New Album Name", album.AlbumTitle)
|
2019-12-17 18:25:13 +01:00
|
|
|
assert.Equal(t, "new-album-name", album.AlbumSlug)
|
|
|
|
})
|
|
|
|
t.Run("empty name", func(t *testing.T) {
|
2020-06-08 18:32:51 +02:00
|
|
|
album := NewAlbum("initial name", AlbumDefault)
|
2020-05-26 09:02:19 +02:00
|
|
|
assert.Equal(t, "initial name", album.AlbumTitle)
|
2019-12-17 18:25:13 +01:00
|
|
|
assert.Equal(t, "initial-name", album.AlbumSlug)
|
2020-04-26 14:31:33 +02:00
|
|
|
|
2020-05-26 09:02:19 +02:00
|
|
|
album.SetTitle("")
|
2020-04-26 14:31:33 +02:00
|
|
|
expected := album.CreatedAt.Format("January 2006")
|
2020-05-26 09:02:19 +02:00
|
|
|
assert.Equal(t, expected, album.AlbumTitle)
|
2022-03-24 21:46:25 +01:00
|
|
|
assert.Equal(t, txt.Slug(expected), album.AlbumSlug)
|
2020-04-26 14:31:33 +02:00
|
|
|
})
|
|
|
|
t.Run("long name", func(t *testing.T) {
|
|
|
|
longName := `A value in decimal degrees to a precision of 4 decimal places is precise to 11.132 meters at the
|
|
|
|
equator. A value in decimal degrees to 5 decimal places is precise to 1.1132 meter at the equator. Elevation also
|
|
|
|
introduces a small error. At 6,378 m elevation, the radius and surface distance is increased by 0.001 or 0.1%.
|
|
|
|
Because the earth is not flat, the precision of the longitude part of the coordinates increases
|
|
|
|
the further from the equator you get. The precision of the latitude part does not increase so much,
|
|
|
|
more strictly however, a meridian arc length per 1 second depends on the latitude at the point in question.
|
|
|
|
The discrepancy of 1 second meridian arc length between equator and pole is about 0.3 metres because the earth
|
|
|
|
is an oblate spheroid.`
|
2022-03-25 18:01:34 +01:00
|
|
|
expected := txt.Shorten(longName, txt.ClipDefault, txt.Ellipsis)
|
2020-04-26 14:31:33 +02:00
|
|
|
slugExpected := txt.Clip(longName, txt.ClipSlug)
|
2020-06-08 18:32:51 +02:00
|
|
|
album := NewAlbum(longName, AlbumDefault)
|
2020-05-26 09:02:19 +02:00
|
|
|
assert.Equal(t, expected, album.AlbumTitle)
|
2022-03-24 21:46:25 +01:00
|
|
|
assert.Contains(t, album.AlbumSlug, txt.Slug(slugExpected))
|
2019-12-17 18:25:13 +01:00
|
|
|
})
|
|
|
|
}
|
2020-05-07 17:29:35 +02:00
|
|
|
|
2021-11-23 20:25:32 +01:00
|
|
|
func TestAlbum_UpdateSlug(t *testing.T) {
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
album := NewMonthAlbum("Foo ", "foo", 2002, 11)
|
|
|
|
|
|
|
|
assert.Equal(t, "Foo", album.AlbumTitle)
|
|
|
|
assert.Equal(t, "foo", album.AlbumSlug)
|
|
|
|
assert.Equal(t, "", album.AlbumDescription)
|
|
|
|
assert.Equal(t, 2002, album.AlbumYear)
|
|
|
|
assert.Equal(t, 11, album.AlbumMonth)
|
|
|
|
|
|
|
|
if err := album.Create(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := album.UpdateSlug("November / 2002", "november-2002"); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, "November / 2002", album.AlbumTitle)
|
|
|
|
assert.Equal(t, "november-2002", album.AlbumSlug)
|
|
|
|
assert.Equal(t, "", album.AlbumDescription)
|
|
|
|
assert.Equal(t, 2002, album.AlbumYear)
|
|
|
|
assert.Equal(t, 11, album.AlbumMonth)
|
|
|
|
|
|
|
|
if err := album.DeletePermanently(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-11-20 16:36:34 +01:00
|
|
|
func TestAlbum_UpdateState(t *testing.T) {
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
album := NewAlbum("Any State", AlbumState)
|
|
|
|
|
|
|
|
assert.Equal(t, "Any State", album.AlbumTitle)
|
|
|
|
assert.Equal(t, "any-state", album.AlbumSlug)
|
|
|
|
|
|
|
|
if err := album.Create(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2021-11-23 20:25:32 +01:00
|
|
|
if err := album.UpdateState("Alberta", "canada-alberta", "Alberta", "ca"); err != nil {
|
2021-11-20 16:36:34 +01:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, "Alberta", album.AlbumTitle)
|
|
|
|
assert.Equal(t, "", album.AlbumDescription)
|
|
|
|
assert.Equal(t, "Canada", album.AlbumLocation)
|
|
|
|
assert.Equal(t, "Alberta", album.AlbumState)
|
|
|
|
assert.Equal(t, "ca", album.AlbumCountry)
|
|
|
|
|
|
|
|
if err := album.DeletePermanently(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-07-08 17:06:23 +02:00
|
|
|
func TestAlbum_SaveForm(t *testing.T) {
|
2020-05-07 17:29:35 +02:00
|
|
|
t.Run("success", func(t *testing.T) {
|
2020-06-08 18:32:51 +02:00
|
|
|
album := NewAlbum("Old Name", AlbumDefault)
|
2020-05-07 17:29:35 +02:00
|
|
|
|
2020-05-26 09:02:19 +02:00
|
|
|
assert.Equal(t, "Old Name", album.AlbumTitle)
|
2020-05-07 17:29:35 +02:00
|
|
|
assert.Equal(t, "old-name", album.AlbumSlug)
|
|
|
|
|
2020-07-08 17:06:23 +02:00
|
|
|
album2 := Album{ID: 123, AlbumTitle: "New name", AlbumDescription: "new description", AlbumCategory: "family"}
|
2020-05-07 17:29:35 +02:00
|
|
|
|
|
|
|
albumForm, err := form.NewAlbum(album2)
|
|
|
|
|
|
|
|
if err != nil {
|
2020-05-08 19:34:29 +02:00
|
|
|
t.Fatal(err)
|
2020-05-07 17:29:35 +02:00
|
|
|
}
|
|
|
|
|
2020-05-26 11:00:39 +02:00
|
|
|
err = album.SaveForm(albumForm)
|
2020-05-07 17:29:35 +02:00
|
|
|
|
|
|
|
if err != nil {
|
2020-05-08 19:34:29 +02:00
|
|
|
t.Fatal(err)
|
2020-05-07 17:29:35 +02:00
|
|
|
}
|
|
|
|
|
2020-05-26 09:02:19 +02:00
|
|
|
assert.Equal(t, "New name", album.AlbumTitle)
|
2020-05-07 17:29:35 +02:00
|
|
|
assert.Equal(t, "new description", album.AlbumDescription)
|
2020-07-08 17:06:23 +02:00
|
|
|
assert.Equal(t, "Family", album.AlbumCategory)
|
2020-05-07 17:29:35 +02:00
|
|
|
|
2020-07-08 17:06:23 +02:00
|
|
|
})
|
2020-05-07 17:29:35 +02:00
|
|
|
}
|
2020-06-01 09:45:24 +02:00
|
|
|
|
|
|
|
func TestAddPhotoToAlbums(t *testing.T) {
|
2020-07-08 17:06:23 +02:00
|
|
|
t.Run("success one album", func(t *testing.T) {
|
2020-06-01 09:45:24 +02:00
|
|
|
err := AddPhotoToAlbums("pt9jtxrexxvl0yh0", []string{"at6axuzitogaaiax"})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
a := Album{AlbumUID: "at6axuzitogaaiax"}
|
|
|
|
|
|
|
|
if err := a.Find(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-12-17 18:24:55 +01:00
|
|
|
var entries PhotoAlbums
|
2020-06-01 09:45:24 +02:00
|
|
|
|
|
|
|
if err := Db().Where("album_uid = ? AND photo_uid = ?", "at6axuzitogaaiax", "pt9jtxrexxvl0yh0").Find(&entries).Error; err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(entries) < 1 {
|
|
|
|
t.Error("at least one album entry expected")
|
|
|
|
}
|
|
|
|
|
|
|
|
// t.Logf("photo album entries: %+v", entries)
|
|
|
|
})
|
2020-07-08 17:06:23 +02:00
|
|
|
|
|
|
|
t.Run("empty photo", func(t *testing.T) {
|
|
|
|
err := AddPhotoToAlbums("", []string{"at6axuzitogaaiax"})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("invalid photo uid", func(t *testing.T) {
|
|
|
|
assert.Error(t, AddPhotoToAlbums("xxx", []string{"at6axuzitogaaiax"}))
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("success two album", func(t *testing.T) {
|
|
|
|
err := AddPhotoToAlbums("pt9jtxrexxvl0yh0", []string{"at6axuzitogaaiax", ""})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
a := Album{AlbumUID: "at6axuzitogaaiax"}
|
|
|
|
|
|
|
|
if err := a.Find(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-12-17 18:24:55 +01:00
|
|
|
var entries PhotoAlbums
|
2020-07-08 17:06:23 +02:00
|
|
|
|
|
|
|
if err := Db().Where("album_uid = ? AND photo_uid = ?", "at6axuzitogaaiax", "pt9jtxrexxvl0yh0").Find(&entries).Error; err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(entries) < 1 {
|
|
|
|
t.Error("at least one album entry expected")
|
|
|
|
}
|
|
|
|
|
|
|
|
// t.Logf("photo album entries: %+v", entries)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewFolderAlbum(t *testing.T) {
|
|
|
|
t.Run("name Christmas 2018", func(t *testing.T) {
|
2020-12-09 00:44:33 +01:00
|
|
|
album := NewFolderAlbum("Dogs", "dogs", "label:dog")
|
2020-07-08 17:06:23 +02:00
|
|
|
assert.Equal(t, "Dogs", album.AlbumTitle)
|
|
|
|
assert.Equal(t, "dogs", album.AlbumSlug)
|
|
|
|
assert.Equal(t, AlbumFolder, album.AlbumType)
|
|
|
|
assert.Equal(t, SortOrderAdded, album.AlbumOrder)
|
|
|
|
assert.Equal(t, "label:dog", album.AlbumFilter)
|
|
|
|
})
|
|
|
|
t.Run("title empty", func(t *testing.T) {
|
2020-12-09 13:10:21 +01:00
|
|
|
album := NewFolderAlbum("", "dogs", "label:dog")
|
2020-07-08 17:06:23 +02:00
|
|
|
assert.Nil(t, album)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewMomentsAlbum(t *testing.T) {
|
|
|
|
t.Run("name Christmas 2018", func(t *testing.T) {
|
|
|
|
album := NewMomentsAlbum("Dogs", "dogs", "label:dog")
|
|
|
|
assert.Equal(t, "Dogs", album.AlbumTitle)
|
|
|
|
assert.Equal(t, "dogs", album.AlbumSlug)
|
|
|
|
assert.Equal(t, AlbumMoment, album.AlbumType)
|
|
|
|
assert.Equal(t, SortOrderOldest, album.AlbumOrder)
|
|
|
|
assert.Equal(t, "label:dog", album.AlbumFilter)
|
|
|
|
})
|
|
|
|
t.Run("title empty", func(t *testing.T) {
|
|
|
|
album := NewMomentsAlbum("", "dogs", "label:dog")
|
|
|
|
assert.Nil(t, album)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewStateAlbum(t *testing.T) {
|
|
|
|
t.Run("name Christmas 2018", func(t *testing.T) {
|
|
|
|
album := NewStateAlbum("Dogs", "dogs", "label:dog")
|
|
|
|
assert.Equal(t, "Dogs", album.AlbumTitle)
|
|
|
|
assert.Equal(t, "dogs", album.AlbumSlug)
|
|
|
|
assert.Equal(t, AlbumState, album.AlbumType)
|
|
|
|
assert.Equal(t, SortOrderNewest, album.AlbumOrder)
|
|
|
|
assert.Equal(t, "label:dog", album.AlbumFilter)
|
|
|
|
})
|
|
|
|
t.Run("title empty", func(t *testing.T) {
|
|
|
|
album := NewStateAlbum("", "dogs", "label:dog")
|
|
|
|
assert.Nil(t, album)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewMonthAlbum(t *testing.T) {
|
|
|
|
t.Run("name Christmas 2018", func(t *testing.T) {
|
|
|
|
album := NewMonthAlbum("Dogs", "dogs", 2020, 7)
|
|
|
|
assert.Equal(t, "Dogs", album.AlbumTitle)
|
|
|
|
assert.Equal(t, "dogs", album.AlbumSlug)
|
|
|
|
assert.Equal(t, AlbumMonth, album.AlbumType)
|
|
|
|
assert.Equal(t, SortOrderOldest, album.AlbumOrder)
|
|
|
|
assert.Equal(t, "public:true year:2020 month:7", album.AlbumFilter)
|
|
|
|
assert.Equal(t, 7, album.AlbumMonth)
|
|
|
|
assert.Equal(t, 2020, album.AlbumYear)
|
|
|
|
})
|
|
|
|
t.Run("title empty", func(t *testing.T) {
|
|
|
|
album := NewMonthAlbum("", "dogs", 2020, 8)
|
|
|
|
assert.Nil(t, album)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFindAlbumBySlug(t *testing.T) {
|
|
|
|
t.Run("1 result", func(t *testing.T) {
|
|
|
|
album := FindAlbumBySlug("holiday-2030", AlbumDefault)
|
2020-07-20 19:48:31 +02:00
|
|
|
|
|
|
|
if album == nil {
|
|
|
|
t.Fatal("expected to find an album")
|
|
|
|
}
|
|
|
|
|
2021-07-22 13:53:17 +02:00
|
|
|
assert.Equal(t, "Holiday 2030", album.AlbumTitle)
|
2020-07-08 17:06:23 +02:00
|
|
|
assert.Equal(t, "holiday-2030", album.AlbumSlug)
|
|
|
|
})
|
2021-11-22 13:29:19 +01:00
|
|
|
t.Run("state album", func(t *testing.T) {
|
|
|
|
album := FindAlbumBySlug("california-usa", AlbumState)
|
|
|
|
|
|
|
|
if album == nil {
|
|
|
|
t.Fatal("expected to find an album")
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, "California / USA", album.AlbumTitle)
|
|
|
|
assert.Equal(t, "california-usa", album.AlbumSlug)
|
|
|
|
})
|
2020-07-08 17:06:23 +02:00
|
|
|
t.Run("no result", func(t *testing.T) {
|
|
|
|
album := FindAlbumBySlug("holiday-2030", AlbumMonth)
|
2020-07-20 19:48:31 +02:00
|
|
|
|
|
|
|
if album != nil {
|
|
|
|
t.Fatal("album should be nil")
|
|
|
|
}
|
2020-07-08 17:06:23 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAlbum_String(t *testing.T) {
|
|
|
|
t.Run("return slug", func(t *testing.T) {
|
|
|
|
album := Album{
|
|
|
|
AlbumUID: "abc123",
|
|
|
|
AlbumSlug: "test-slug",
|
|
|
|
AlbumType: AlbumDefault,
|
|
|
|
AlbumTitle: "Test Title",
|
|
|
|
}
|
|
|
|
assert.Equal(t, "test-slug", album.String())
|
|
|
|
})
|
|
|
|
t.Run("return title", func(t *testing.T) {
|
|
|
|
album := Album{
|
|
|
|
AlbumUID: "abc123",
|
|
|
|
AlbumSlug: "",
|
|
|
|
AlbumType: AlbumDefault,
|
|
|
|
AlbumTitle: "Test Title",
|
|
|
|
}
|
|
|
|
assert.Contains(t, album.String(), "Test Title")
|
|
|
|
})
|
|
|
|
t.Run("return uid", func(t *testing.T) {
|
|
|
|
album := Album{
|
|
|
|
AlbumUID: "abc123",
|
|
|
|
AlbumSlug: "",
|
|
|
|
AlbumType: AlbumDefault,
|
|
|
|
AlbumTitle: "",
|
|
|
|
}
|
|
|
|
assert.Equal(t, "abc123", album.String())
|
|
|
|
})
|
|
|
|
t.Run("return unknown", func(t *testing.T) {
|
|
|
|
album := Album{
|
|
|
|
AlbumUID: "",
|
|
|
|
AlbumSlug: "",
|
|
|
|
AlbumType: AlbumDefault,
|
|
|
|
AlbumTitle: "",
|
|
|
|
}
|
|
|
|
assert.Equal(t, "[unknown album]", album.String())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAlbum_IsMoment(t *testing.T) {
|
|
|
|
t.Run("false", func(t *testing.T) {
|
|
|
|
album := Album{
|
|
|
|
AlbumUID: "abc123",
|
|
|
|
AlbumSlug: "test-slug",
|
|
|
|
AlbumType: AlbumDefault,
|
|
|
|
AlbumTitle: "Test Title",
|
|
|
|
}
|
|
|
|
assert.False(t, album.IsMoment())
|
|
|
|
})
|
|
|
|
t.Run("true", func(t *testing.T) {
|
|
|
|
album := Album{
|
|
|
|
AlbumUID: "abc123",
|
|
|
|
AlbumSlug: "test-slug",
|
|
|
|
AlbumType: AlbumMoment,
|
|
|
|
AlbumTitle: "Test Title",
|
|
|
|
}
|
|
|
|
assert.True(t, album.IsMoment())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAlbum_Update(t *testing.T) {
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
album := Album{
|
|
|
|
AlbumUID: "abc123",
|
|
|
|
AlbumSlug: "test-slug",
|
|
|
|
AlbumType: AlbumDefault,
|
|
|
|
AlbumTitle: "Test Title",
|
|
|
|
}
|
|
|
|
assert.Equal(t, "test-slug", album.AlbumSlug)
|
|
|
|
|
|
|
|
err := album.Update("AlbumSlug", "new-slug")
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
assert.Equal(t, "new-slug", album.AlbumSlug)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAlbum_Save(t *testing.T) {
|
|
|
|
t.Run("success", func(t *testing.T) {
|
2020-07-08 18:09:18 +02:00
|
|
|
album := NewStateAlbum("Dogs", "dogs", "label:dog")
|
|
|
|
|
2020-07-08 17:06:23 +02:00
|
|
|
initialDate := album.UpdatedAt
|
|
|
|
|
|
|
|
err := album.Save()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
afterDate := album.UpdatedAt
|
|
|
|
t.Log(initialDate)
|
|
|
|
t.Log(afterDate)
|
|
|
|
//TODO Why does it fail?
|
|
|
|
//assert.True(t, afterDate.After(initialDate))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAlbum_Create(t *testing.T) {
|
|
|
|
t.Run("album", func(t *testing.T) {
|
|
|
|
album := Album{
|
|
|
|
AlbumType: AlbumDefault,
|
|
|
|
}
|
|
|
|
|
|
|
|
err := album.Create()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
t.Run("moment", func(t *testing.T) {
|
|
|
|
album := Album{
|
|
|
|
AlbumType: AlbumMoment,
|
|
|
|
}
|
|
|
|
|
|
|
|
err := album.Create()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
t.Run("month", func(t *testing.T) {
|
|
|
|
album := Album{
|
|
|
|
AlbumType: AlbumMonth,
|
|
|
|
}
|
|
|
|
|
|
|
|
err := album.Create()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
t.Run("folder", func(t *testing.T) {
|
|
|
|
album := Album{
|
|
|
|
AlbumType: AlbumFolder,
|
|
|
|
}
|
|
|
|
|
|
|
|
err := album.Create()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAlbum_Title(t *testing.T) {
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
album := Album{
|
|
|
|
AlbumUID: "abc123",
|
|
|
|
AlbumSlug: "test-slug",
|
|
|
|
AlbumType: AlbumDefault,
|
|
|
|
AlbumTitle: "Test Title",
|
|
|
|
}
|
|
|
|
assert.Equal(t, "Test Title", album.Title())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAlbum_Links(t *testing.T) {
|
|
|
|
t.Run("1 result", func(t *testing.T) {
|
|
|
|
album := AlbumFixtures.Get("christmas2030")
|
|
|
|
links := album.Links()
|
|
|
|
assert.Equal(t, "4jxf3jfn2k", links[0].LinkToken)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAlbum_AddPhotos(t *testing.T) {
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
album := Album{
|
|
|
|
AlbumUID: "abc123",
|
|
|
|
AlbumSlug: "test-slug",
|
|
|
|
AlbumType: AlbumDefault,
|
|
|
|
AlbumTitle: "Test Title",
|
|
|
|
}
|
|
|
|
added := album.AddPhotos([]string{"ab", "cd"})
|
|
|
|
assert.Equal(t, 2, len(added))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAlbum_RemovePhotos(t *testing.T) {
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
album := Album{
|
|
|
|
AlbumUID: "abc123",
|
|
|
|
AlbumSlug: "test-slug",
|
|
|
|
AlbumType: AlbumDefault,
|
|
|
|
AlbumTitle: "Test Title",
|
|
|
|
}
|
|
|
|
removed := album.RemovePhotos([]string{"ab", "cd"})
|
|
|
|
assert.Equal(t, 2, len(removed))
|
|
|
|
})
|
2020-06-01 09:45:24 +02:00
|
|
|
}
|
2021-02-24 11:38:28 +01:00
|
|
|
|
|
|
|
func TestAlbum_Find(t *testing.T) {
|
|
|
|
t.Run("existing album", func(t *testing.T) {
|
|
|
|
a := Album{AlbumUID: "at6axuzitogaaiax"}
|
|
|
|
|
|
|
|
if err := a.Find(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
t.Run("invalid id", func(t *testing.T) {
|
|
|
|
a := Album{AlbumUID: "xx"}
|
|
|
|
|
|
|
|
assert.Error(t, a.Find())
|
|
|
|
})
|
|
|
|
t.Run("album not existing", func(t *testing.T) {
|
|
|
|
a := Album{AlbumUID: "at6axuzitogaaxxx"}
|
|
|
|
|
|
|
|
assert.Error(t, a.Find())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAlbum_UpdateFolder(t *testing.T) {
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
a := Album{AlbumUID: "at6axuzitogaaxxx"}
|
|
|
|
assert.Empty(t, a.AlbumPath)
|
|
|
|
assert.Empty(t, a.AlbumFilter)
|
|
|
|
if err := a.UpdateFolder("2222/07", "month:07"); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
assert.Equal(t, "2222/07", a.AlbumPath)
|
|
|
|
assert.Equal(t, "month:07", a.AlbumFilter)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("empty path", func(t *testing.T) {
|
|
|
|
a := Album{AlbumUID: "at6axuzitogaaxxy"}
|
|
|
|
assert.Empty(t, a.AlbumPath)
|
|
|
|
assert.Empty(t, a.AlbumFilter)
|
|
|
|
if err := a.UpdateFolder("", "month:07"); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
assert.Empty(t, a.AlbumPath)
|
|
|
|
assert.Empty(t, a.AlbumFilter)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-08-25 15:29:00 +02:00
|
|
|
func TestFindFolderAlbum(t *testing.T) {
|
|
|
|
/*t.Run("1 result", func(t *testing.T) {
|
|
|
|
album := FindFolderAlbum("2023/04")
|
2021-02-24 11:38:28 +01:00
|
|
|
|
|
|
|
if album == nil {
|
|
|
|
t.Fatal("expected to find an album")
|
|
|
|
}
|
|
|
|
|
2021-08-25 15:29:00 +02:00
|
|
|
assert.Equal(t, "April 2023", album.AlbumTitle)
|
|
|
|
assert.Equal(t, "2023-04", album.AlbumSlug)
|
|
|
|
})*/
|
2021-02-24 11:38:28 +01:00
|
|
|
t.Run("no result because slug empty", func(t *testing.T) {
|
|
|
|
album := FindFolderAlbum("")
|
|
|
|
|
|
|
|
if album != nil {
|
|
|
|
t.Fatal("album should be nil")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
t.Run("no result because not found slug", func(t *testing.T) {
|
2021-08-25 15:29:00 +02:00
|
|
|
album := FindFolderAlbum("3000/04")
|
2021-02-24 11:38:28 +01:00
|
|
|
|
|
|
|
if album != nil {
|
|
|
|
t.Fatal("album should be nil")
|
|
|
|
}
|
|
|
|
})
|
2021-08-25 15:29:00 +02:00
|
|
|
}
|