photoprism/internal/query/albums_test.go

142 lines
3 KiB
Go
Raw Normal View History

2020-01-27 17:00:36 +01:00
package query
import (
"testing"
"github.com/photoprism/photoprism/internal/entity"
form "github.com/photoprism/photoprism/internal/form"
"github.com/stretchr/testify/assert"
2020-01-27 17:00:36 +01:00
)
func TestAlbumByUID(t *testing.T) {
t.Run("existing uid", func(t *testing.T) {
album, err := AlbumByUID("at9lxuqxpogaaba7")
if err != nil {
t.Fatal(err)
}
assert.Equal(t, "Christmas2030", album.AlbumTitle)
2020-01-27 17:00:36 +01: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")
t.Log(album)
2020-01-27 17:00:36 +01:00
})
}
func TestAlbumThumbByUID(t *testing.T) {
t.Run("existing uid", func(t *testing.T) {
file, err := AlbumCoverByUID("at9lxuqxpogaaba8")
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 uid", func(t *testing.T) {
file, err := AlbumCoverByUID("3765")
2020-01-27 17:00:36 +01:00
assert.Error(t, err, "record not found")
t.Log(file)
})
}
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))
}
})
}
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")
result, err := AlbumSearch(query)
if err != nil {
t.Fatal(err)
}
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")
result, err := AlbumSearch(query)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, "Holiday2030", result[0].AlbumTitle)
2020-01-27 17:00:36 +01:00
})
t.Run("favorites true", func(t *testing.T) {
query := form.NewAlbumSearch("favorite:true count:10000")
2020-01-27 17:00:36 +01:00
result, err := AlbumSearch(query)
if err != nil {
t.Fatal(err)
}
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")
results, err := AlbumSearch(query)
if err != nil {
t.Fatal(err)
}
if len(results) < 3 {
t.Errorf("at least 3 results expected: %d", len(results))
}
2020-01-27 17:00:36 +01:00
})
t.Run("search with invalid query string", func(t *testing.T) {
query := form.NewAlbumSearch("xxx:bla")
result, err := AlbumSearch(query)
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 := 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{
Query: "",
ID: "at9lxuqxpogaaba7",
Slug: "",
Title: "",
Favorite: false,
Count: 0,
Offset: 0,
Order: "",
2020-05-13 10:16:12 +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-01-27 17:00:36 +01:00
}