2020-01-27 17:00:36 +01:00
|
|
|
package query
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-05-30 21:31:32 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/entity"
|
2020-05-08 15:41:01 +02:00
|
|
|
form "github.com/photoprism/photoprism/internal/form"
|
|
|
|
"github.com/stretchr/testify/assert"
|
2020-01-27 17:00:36 +01:00
|
|
|
)
|
|
|
|
|
2020-05-23 20:58:58 +02:00
|
|
|
func TestAlbumByUID(t *testing.T) {
|
|
|
|
t.Run("existing uid", func(t *testing.T) {
|
|
|
|
album, err := AlbumByUID("at9lxuqxpogaaba7")
|
2020-04-09 19:39:09 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-05-26 09:02:19 +02:00
|
|
|
assert.Equal(t, "Christmas2030", album.AlbumTitle)
|
2020-01-27 17:00:36 +01:00
|
|
|
})
|
|
|
|
|
2020-05-23 20:58:58 +02:00
|
|
|
t.Run("not existing uid", func(t *testing.T) {
|
|
|
|
album, err := AlbumByUID("3765")
|
2020-01-27 17:00:36 +01:00
|
|
|
assert.Error(t, err, "record not found")
|
2020-04-09 19:39:09 +02:00
|
|
|
t.Log(album)
|
2020-01-27 17:00:36 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-07-13 11:11:52 +02:00
|
|
|
func TestAlbumCoverByUID(t *testing.T) {
|
|
|
|
t.Run("existing uid default album", func(t *testing.T) {
|
2020-05-30 01:41:47 +02:00
|
|
|
file, err := AlbumCoverByUID("at9lxuqxpogaaba8")
|
2020-04-09 19:39:09 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-01-27 17:00:36 +01:00
|
|
|
assert.Equal(t, "exampleFileName.jpg", file.FileName)
|
|
|
|
})
|
|
|
|
|
2020-07-13 11:11:52 +02:00
|
|
|
t.Run("existing uid folder album", func(t *testing.T) {
|
|
|
|
file, err := AlbumCoverByUID("at1lxuqipogaaba1")
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, "bridge2.jpg", file.FileName)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("existing uid empty moment album", func(t *testing.T) {
|
|
|
|
file, err := AlbumCoverByUID("at7axuzitogaaiax")
|
|
|
|
|
2020-11-21 18:05:20 +01:00
|
|
|
assert.EqualError(t, err, "found no cover for moment", err)
|
2020-07-13 11:11:52 +02:00
|
|
|
assert.Equal(t, "", file.FileName)
|
|
|
|
})
|
|
|
|
|
2020-05-23 20:58:58 +02:00
|
|
|
t.Run("not existing uid", func(t *testing.T) {
|
2020-05-30 01:41:47 +02:00
|
|
|
file, err := AlbumCoverByUID("3765")
|
2020-01-27 17:00:36 +01:00
|
|
|
assert.Error(t, err, "record not found")
|
|
|
|
t.Log(file)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-05-30 21:31:32 +02:00
|
|
|
func TestAlbumPhotos(t *testing.T) {
|
|
|
|
t.Run("search with string", func(t *testing.T) {
|
|
|
|
results, err := AlbumPhotos(entity.AlbumFixtures.Get("april-1990"), 2)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(results) < 2 {
|
|
|
|
t.Errorf("at least 2 results expected: %d", len(results))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-06-23 07:55:33 +02:00
|
|
|
func TestAlbumSearch(t *testing.T) {
|
2020-01-27 17:00:36 +01:00
|
|
|
t.Run("search with string", func(t *testing.T) {
|
|
|
|
query := form.NewAlbumSearch("chr")
|
2020-05-25 19:10:44 +02:00
|
|
|
result, err := AlbumSearch(query)
|
2020-04-09 19:39:09 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-05-26 09:02:19 +02:00
|
|
|
assert.Equal(t, "Christmas2030", result[0].AlbumTitle)
|
2020-01-27 17:00:36 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("search with slug", func(t *testing.T) {
|
|
|
|
query := form.NewAlbumSearch("slug:holiday count:10")
|
2020-05-25 19:10:44 +02:00
|
|
|
result, err := AlbumSearch(query)
|
2020-04-17 21:20:38 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-05-26 09:02:19 +02:00
|
|
|
assert.Equal(t, "Holiday2030", result[0].AlbumTitle)
|
2020-01-27 17:00:36 +01:00
|
|
|
})
|
|
|
|
|
2021-01-16 12:48:43 +01:00
|
|
|
t.Run("search with country", func(t *testing.T) {
|
|
|
|
query := form.NewAlbumSearch("country:de")
|
|
|
|
result, err := AlbumSearch(query)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, "Berlin 2019", result[0].AlbumTitle)
|
|
|
|
})
|
|
|
|
|
2020-01-27 17:00:36 +01:00
|
|
|
t.Run("favorites true", func(t *testing.T) {
|
2020-05-14 19:03:12 +02:00
|
|
|
query := form.NewAlbumSearch("favorite:true count:10000")
|
2020-01-27 17:00:36 +01:00
|
|
|
|
2020-05-25 19:10:44 +02:00
|
|
|
result, err := AlbumSearch(query)
|
2020-04-09 19:39:09 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-05-26 09:02:19 +02:00
|
|
|
assert.Equal(t, "Holiday2030", result[0].AlbumTitle)
|
2020-01-27 17:00:36 +01:00
|
|
|
})
|
|
|
|
t.Run("empty query", func(t *testing.T) {
|
|
|
|
query := form.NewAlbumSearch("order:slug")
|
|
|
|
|
2020-05-30 21:34:42 +02:00
|
|
|
results, err := AlbumSearch(query)
|
2020-04-09 19:39:09 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-05-30 21:34:42 +02:00
|
|
|
if len(results) < 3 {
|
|
|
|
t.Errorf("at least 3 results expected: %d", len(results))
|
|
|
|
}
|
2020-01-27 17:00:36 +01:00
|
|
|
})
|
2020-02-02 13:02:14 +01:00
|
|
|
t.Run("search with invalid query string", func(t *testing.T) {
|
|
|
|
query := form.NewAlbumSearch("xxx:bla")
|
2020-05-25 19:10:44 +02:00
|
|
|
result, err := AlbumSearch(query)
|
2020-02-02 13:02:14 +01:00
|
|
|
assert.Error(t, err, "unknown filter")
|
|
|
|
t.Log(result)
|
|
|
|
})
|
2020-05-13 10:16:12 +02:00
|
|
|
t.Run("search with invalid query string", func(t *testing.T) {
|
|
|
|
query := form.NewAlbumSearch("xxx:bla")
|
2020-05-25 19:10:44 +02:00
|
|
|
result, err := AlbumSearch(query)
|
2020-05-13 10:16:12 +02:00
|
|
|
assert.Error(t, err, "unknown filter")
|
|
|
|
t.Log(result)
|
|
|
|
})
|
|
|
|
t.Run("search for existing ID", func(t *testing.T) {
|
|
|
|
f := form.AlbumSearch{
|
2020-05-14 19:03:12 +02:00
|
|
|
Query: "",
|
|
|
|
ID: "at9lxuqxpogaaba7",
|
|
|
|
Slug: "",
|
2020-05-26 09:02:19 +02:00
|
|
|
Title: "",
|
2020-05-14 19:03:12 +02:00
|
|
|
Favorite: false,
|
|
|
|
Count: 0,
|
|
|
|
Offset: 0,
|
|
|
|
Order: "",
|
2020-05-13 10:16:12 +02:00
|
|
|
}
|
|
|
|
|
2020-05-25 19:10:44 +02:00
|
|
|
result, err := AlbumSearch(f)
|
2020-05-13 10:16:12 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, 1, len(result))
|
|
|
|
assert.Equal(t, "christmas2030", result[0].AlbumSlug)
|
|
|
|
})
|
2020-07-13 11:11:52 +02:00
|
|
|
t.Run("search with multiple filters", func(t *testing.T) {
|
|
|
|
f := form.AlbumSearch{
|
|
|
|
Query: "",
|
|
|
|
Type: "moment",
|
|
|
|
Category: "Fun",
|
|
|
|
Location: "Favorite Park",
|
|
|
|
Title: "Empty Moment",
|
|
|
|
Count: 0,
|
|
|
|
Offset: 0,
|
|
|
|
Order: "",
|
|
|
|
}
|
|
|
|
|
|
|
|
result, err := AlbumSearch(f)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, 1, len(result))
|
|
|
|
assert.Equal(t, "Empty Moment", result[0].AlbumTitle)
|
|
|
|
})
|
2020-07-13 11:40:49 +02:00
|
|
|
t.Run("search for year/month/day", func(t *testing.T) {
|
2020-07-13 11:11:52 +02:00
|
|
|
f := form.AlbumSearch{
|
2020-07-13 11:40:49 +02:00
|
|
|
Year: 2021,
|
|
|
|
Month: 10,
|
|
|
|
Day: 3,
|
2020-07-13 11:11:52 +02:00
|
|
|
Count: 0,
|
|
|
|
Offset: 0,
|
|
|
|
Order: "",
|
|
|
|
}
|
|
|
|
|
|
|
|
result, err := AlbumSearch(f)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, 0, len(result))
|
|
|
|
})
|
2020-01-27 17:00:36 +01:00
|
|
|
}
|
2020-12-09 21:44:39 +01:00
|
|
|
|
|
|
|
func TestUpdateAlbumDates(t *testing.T) {
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
if err := UpdateAlbumDates(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
})
|
2020-12-09 21:49:41 +01:00
|
|
|
}
|
2020-12-27 13:11:08 +01:00
|
|
|
|
|
|
|
func TestUpdateMissingAlbumEntries(t *testing.T) {
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
if err := UpdateMissingAlbumEntries(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAlbumEntryFound(t *testing.T) {
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
if err := AlbumEntryFound("pt9jtxrexxvl0yh0"); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2021-03-03 11:49:32 +01:00
|
|
|
|
|
|
|
func TestGetAlbums(t *testing.T) {
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
r, err := GetAlbums(0, 3)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
assert.Equal(t, 3, len(r))
|
|
|
|
})
|
|
|
|
}
|