2021-09-18 15:32:39 +02:00
|
|
|
package search
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2021-11-29 15:04:13 +01:00
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/internal/entity"
|
|
|
|
"github.com/photoprism/photoprism/internal/form"
|
2021-09-18 15:32:39 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestAlbumPhotos(t *testing.T) {
|
|
|
|
t.Run("search with string", func(t *testing.T) {
|
2022-01-03 12:51:59 +01:00
|
|
|
results, err := AlbumPhotos(entity.AlbumFixtures.Get("april-1990"), 2, true)
|
2021-09-18 15:32:39 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(results) < 2 {
|
|
|
|
t.Errorf("at least 2 results expected: %d", len(results))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAlbums(t *testing.T) {
|
|
|
|
t.Run("search with string", func(t *testing.T) {
|
|
|
|
query := form.NewAlbumSearch("chr")
|
|
|
|
result, err := Albums(query)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, "Christmas 2030", result[0].AlbumTitle)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("search with slug", func(t *testing.T) {
|
2022-08-01 15:57:19 +02:00
|
|
|
query := form.NewAlbumSearch("slug:holiday")
|
2021-09-18 15:32:39 +02:00
|
|
|
result, err := Albums(query)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, "Holiday 2030", result[0].AlbumTitle)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("search with country", func(t *testing.T) {
|
|
|
|
query := form.NewAlbumSearch("country:ca")
|
|
|
|
result, err := Albums(query)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2021-11-29 14:55:06 +01:00
|
|
|
assert.Equal(t, "April 1990", result[0].AlbumTitle)
|
2021-09-18 15:32:39 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("favorites true", func(t *testing.T) {
|
2022-08-01 15:57:19 +02:00
|
|
|
query := form.NewAlbumSearch("favorite:true")
|
|
|
|
query.Count = 100000
|
2021-09-18 15:32:39 +02:00
|
|
|
|
|
|
|
result, err := Albums(query)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, "Holiday 2030", result[0].AlbumTitle)
|
|
|
|
})
|
|
|
|
t.Run("empty query", func(t *testing.T) {
|
2022-08-01 15:57:19 +02:00
|
|
|
query := form.NewAlbumSearch("")
|
2021-09-18 15:32:39 +02:00
|
|
|
|
|
|
|
results, err := Albums(query)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(results) < 3 {
|
|
|
|
t.Errorf("at least 3 results expected: %d", len(results))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
t.Run("search with invalid query string", func(t *testing.T) {
|
|
|
|
query := form.NewAlbumSearch("xxx:bla")
|
|
|
|
result, err := Albums(query)
|
|
|
|
assert.Error(t, err, "unknown filter")
|
|
|
|
t.Log(result)
|
|
|
|
})
|
|
|
|
t.Run("search with invalid query string", func(t *testing.T) {
|
|
|
|
query := form.NewAlbumSearch("xxx:bla")
|
|
|
|
result, err := Albums(query)
|
|
|
|
assert.Error(t, err, "unknown filter")
|
|
|
|
t.Log(result)
|
|
|
|
})
|
|
|
|
t.Run("search for existing ID", func(t *testing.T) {
|
2021-11-26 14:28:50 +01:00
|
|
|
f := form.SearchAlbums{
|
2021-09-18 15:32:39 +02:00
|
|
|
Query: "",
|
2021-12-16 11:42:57 +01:00
|
|
|
UID: "at9lxuqxpogaaba7",
|
2021-09-18 15:32:39 +02:00
|
|
|
Slug: "",
|
|
|
|
Title: "",
|
|
|
|
Favorite: false,
|
|
|
|
Count: 0,
|
|
|
|
Offset: 0,
|
|
|
|
Order: "",
|
|
|
|
}
|
|
|
|
|
|
|
|
result, err := Albums(f)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, 1, len(result))
|
|
|
|
assert.Equal(t, "christmas-2030", result[0].AlbumSlug)
|
|
|
|
})
|
|
|
|
t.Run("search with multiple filters", func(t *testing.T) {
|
2021-11-26 14:28:50 +01:00
|
|
|
f := form.SearchAlbums{
|
2021-09-18 15:32:39 +02:00
|
|
|
Query: "",
|
|
|
|
Type: "moment",
|
|
|
|
Category: "Fun",
|
|
|
|
Location: "Favorite Park",
|
|
|
|
Title: "Empty Moment",
|
|
|
|
Count: 0,
|
|
|
|
Offset: 0,
|
|
|
|
Order: "",
|
|
|
|
}
|
|
|
|
|
|
|
|
result, err := Albums(f)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, 1, len(result))
|
|
|
|
assert.Equal(t, "Empty Moment", result[0].AlbumTitle)
|
|
|
|
})
|
|
|
|
t.Run("search for year/month/day", func(t *testing.T) {
|
2021-11-26 14:28:50 +01:00
|
|
|
f := form.SearchAlbums{
|
2023-01-02 16:17:59 +01:00
|
|
|
Year: "2021",
|
|
|
|
Month: "10",
|
|
|
|
Day: "3",
|
2021-09-18 15:32:39 +02:00
|
|
|
Count: 0,
|
|
|
|
Offset: 0,
|
|
|
|
Order: "",
|
|
|
|
}
|
|
|
|
|
|
|
|
result, err := Albums(f)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, 0, len(result))
|
|
|
|
})
|
2023-01-02 16:31:32 +01:00
|
|
|
t.Run("SearchAlbumForYear", func(t *testing.T) {
|
|
|
|
f := form.SearchAlbums{
|
2023-04-01 14:25:05 +02:00
|
|
|
Type: entity.AlbumManual,
|
2023-01-02 16:31:32 +01:00
|
|
|
Year: "2018",
|
|
|
|
Month: "",
|
|
|
|
Day: "",
|
|
|
|
Count: 10,
|
|
|
|
Offset: 0,
|
|
|
|
Order: "added",
|
|
|
|
}
|
|
|
|
|
|
|
|
result, err := Albums(f)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2023-02-14 19:51:44 +01:00
|
|
|
assert.Equal(t, 2, len(result))
|
|
|
|
})
|
2023-02-14 21:47:31 +01:00
|
|
|
t.Run("Folders", func(t *testing.T) {
|
2023-02-14 19:51:44 +01:00
|
|
|
query := form.NewAlbumSearch("19")
|
|
|
|
result, err := Albums(query)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, "April 1990", result[0].AlbumTitle)
|
|
|
|
})
|
2023-02-14 21:47:31 +01:00
|
|
|
t.Run("California", func(t *testing.T) {
|
2023-02-14 19:51:44 +01:00
|
|
|
query := form.NewAlbumSearch("california")
|
|
|
|
result, err := Albums(query)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2023-02-14 21:47:31 +01:00
|
|
|
t.Logf("albums: %#v", result)
|
|
|
|
|
2023-02-16 15:32:08 +01:00
|
|
|
assert.GreaterOrEqual(t, 3, len(result))
|
2023-02-14 19:51:44 +01:00
|
|
|
})
|
2023-02-14 21:47:31 +01:00
|
|
|
t.Run("Blue", func(t *testing.T) {
|
2023-02-14 19:51:44 +01:00
|
|
|
query := form.NewAlbumSearch("blue")
|
|
|
|
result, err := Albums(query)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2023-01-02 16:31:32 +01:00
|
|
|
assert.Equal(t, 2, len(result))
|
|
|
|
})
|
2021-09-18 15:32:39 +02:00
|
|
|
}
|