2020-01-27 17:00:36 +01:00
|
|
|
package query
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
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-08 15:41:01 +02:00
|
|
|
func TestAlbumByUUID(t *testing.T) {
|
2020-01-27 17:00:36 +01:00
|
|
|
t.Run("existing uuid", func(t *testing.T) {
|
2020-05-08 15:41:01 +02:00
|
|
|
album, err := AlbumByUUID("at9lxuqxpogaaba7")
|
2020-04-09 19:39:09 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, "Christmas2030", album.AlbumName)
|
2020-01-27 17:00:36 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("not existing uuid", func(t *testing.T) {
|
2020-05-08 15:41:01 +02:00
|
|
|
album, err := AlbumByUUID("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-05-08 15:41:01 +02:00
|
|
|
func TestAlbumThumbByUUID(t *testing.T) {
|
2020-01-27 17:00:36 +01:00
|
|
|
t.Run("existing uuid", func(t *testing.T) {
|
2020-05-08 15:41:01 +02:00
|
|
|
file, err := AlbumThumbByUUID("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)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("not existing uuid", func(t *testing.T) {
|
2020-05-08 15:41:01 +02:00
|
|
|
file, err := AlbumThumbByUUID("3765")
|
2020-01-27 17:00:36 +01:00
|
|
|
assert.Error(t, err, "record not found")
|
|
|
|
t.Log(file)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-05-08 15:41:01 +02:00
|
|
|
func TestAlbums(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-08 15:41:01 +02:00
|
|
|
result, err := Albums(query)
|
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, "Christmas2030", result[0].AlbumName)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("search with slug", func(t *testing.T) {
|
|
|
|
query := form.NewAlbumSearch("slug:holiday count:10")
|
2020-05-08 15:41:01 +02:00
|
|
|
result, err := Albums(query)
|
2020-04-17 21:20:38 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-01-27 17:00:36 +01:00
|
|
|
assert.Equal(t, "Holiday2030", result[0].AlbumName)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("favorites true", func(t *testing.T) {
|
|
|
|
query := form.NewAlbumSearch("favorites:true count:10000")
|
|
|
|
|
2020-05-08 15:41:01 +02:00
|
|
|
result, err := Albums(query)
|
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, "Holiday2030", result[0].AlbumName)
|
|
|
|
})
|
|
|
|
t.Run("empty query", func(t *testing.T) {
|
|
|
|
query := form.NewAlbumSearch("order:slug")
|
|
|
|
|
2020-05-08 15:41:01 +02:00
|
|
|
result, err := Albums(query)
|
2020-04-09 19:39:09 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-02-02 15:50:33 +01:00
|
|
|
assert.Equal(t, 3, len(result))
|
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-08 15:41:01 +02:00
|
|
|
result, err := Albums(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")
|
|
|
|
result, err := Albums(query)
|
|
|
|
assert.Error(t, err, "unknown filter")
|
|
|
|
t.Log(result)
|
|
|
|
})
|
|
|
|
t.Run("search for existing ID", func(t *testing.T) {
|
|
|
|
f := form.AlbumSearch{
|
|
|
|
Query: "",
|
|
|
|
ID: "at9lxuqxpogaaba7",
|
|
|
|
Slug: "",
|
|
|
|
Name: "",
|
|
|
|
Favorites: 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, "christmas2030", result[0].AlbumSlug)
|
|
|
|
})
|
2020-01-27 17:00:36 +01:00
|
|
|
}
|