photoprism/internal/query/album_test.go

87 lines
2.1 KiB
Go
Raw Normal View History

2020-01-27 17:00:36 +01:00
package query
import (
form "github.com/photoprism/photoprism/internal/form"
"github.com/stretchr/testify/assert"
"testing"
"github.com/photoprism/photoprism/internal/config"
)
func TestQuery_AlbumByUUID(t *testing.T) {
2020-01-27 17:00:36 +01:00
conf := config.TestConfig()
search := New(conf.Db())
2020-01-27 17:00:36 +01:00
t.Run("existing uuid", func(t *testing.T) {
albums, err := search.AlbumByUUID("3")
2020-01-27 17:00:36 +01:00
assert.Nil(t, err)
assert.Equal(t, "Christmas2030", albums.AlbumName)
})
t.Run("not existing uuid", func(t *testing.T) {
albums, err := search.AlbumByUUID("3765")
2020-01-27 17:00:36 +01:00
assert.Error(t, err, "record not found")
t.Log(albums)
})
}
func TestQuery_AlbumThumbByUUID(t *testing.T) {
2020-01-27 17:00:36 +01:00
conf := config.TestConfig()
search := New(conf.Db())
2020-01-27 17:00:36 +01:00
t.Run("existing uuid", func(t *testing.T) {
file, err := search.AlbumThumbByUUID("4")
2020-01-27 17:00:36 +01:00
assert.Nil(t, err)
assert.Equal(t, "exampleFileName.jpg", file.FileName)
})
t.Run("not existing uuid", func(t *testing.T) {
file, err := search.AlbumThumbByUUID("3765")
2020-01-27 17:00:36 +01:00
assert.Error(t, err, "record not found")
t.Log(file)
})
}
func TestQuery_Albums(t *testing.T) {
2020-01-27 17:00:36 +01:00
conf := config.TestConfig()
search := New(conf.Db())
2020-01-27 17:00:36 +01:00
t.Run("search with string", func(t *testing.T) {
query := form.NewAlbumSearch("chr")
result, err := search.Albums(query)
assert.Nil(t, err)
assert.Equal(t, "Christmas2030", result[0].AlbumName)
})
t.Run("search with slug", func(t *testing.T) {
query := form.NewAlbumSearch("slug:holiday count:10")
result, err := search.Albums(query)
assert.Nil(t, err)
assert.Equal(t, "Holiday2030", result[0].AlbumName)
})
t.Run("favorites true", func(t *testing.T) {
query := form.NewAlbumSearch("favorites:true count:10000")
result, err := search.Albums(query)
assert.Nil(t, err)
assert.Equal(t, "Holiday2030", result[0].AlbumName)
})
t.Run("empty query", func(t *testing.T) {
query := form.NewAlbumSearch("order:slug")
result, err := search.Albums(query)
assert.Nil(t, err)
2020-02-02 15:50:33 +01:00
assert.Equal(t, 3, len(result))
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 := search.Albums(query)
assert.Error(t, err, "unknown filter")
t.Log(result)
})
2020-01-27 17:00:36 +01:00
}