photoprism/internal/query/label_test.go
Michael Mayer 1d667ada79 Backend: Add account API #225
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
2020-03-28 15:29:17 +01:00

129 lines
2.9 KiB
Go

package query
import (
"github.com/photoprism/photoprism/internal/form"
"github.com/stretchr/testify/assert"
"testing"
"github.com/photoprism/photoprism/internal/config"
)
func TestRepo_FindLabelBySlug(t *testing.T) {
conf := config.TestConfig()
search := New(conf.Db())
t.Run("files found", func(t *testing.T) {
label, err := search.LabelBySlug("flower")
assert.Nil(t, err)
assert.Equal(t, "Flower", label.LabelName)
})
t.Run("no files found", func(t *testing.T) {
label, err := search.LabelBySlug("111")
assert.Error(t, err, "record not found")
t.Log(label)
})
}
func TestRepo_FindLabelByUUID(t *testing.T) {
conf := config.TestConfig()
search := New(conf.Db())
t.Run("files found", func(t *testing.T) {
label, err := search.LabelByUUID("14")
assert.Nil(t, err)
assert.Equal(t, "COW", label.LabelName)
})
t.Run("no files found", func(t *testing.T) {
label, err := search.LabelByUUID("111")
assert.Error(t, err, "record not found")
t.Log(label)
})
}
func TestRepo_FindLabelThumbBySlug(t *testing.T) {
conf := config.TestConfig()
search := New(conf.Db())
t.Run("files found", func(t *testing.T) {
file, err := search.LabelThumbBySlug("flower")
assert.Nil(t, err)
assert.Equal(t, "exampleFileName.jpg", file.FileName)
})
t.Run("no files found", func(t *testing.T) {
file, err := search.LabelThumbBySlug("cow")
assert.Error(t, err, "record not found")
t.Log(file)
})
}
func TestRepo_FindLabelThumbByUUID(t *testing.T) {
conf := config.TestConfig()
search := New(conf.Db())
t.Run("files found", func(t *testing.T) {
file, err := search.LabelThumbByUUID("13")
assert.Nil(t, err)
assert.Equal(t, "exampleFileName.jpg", file.FileName)
})
t.Run("no files found", func(t *testing.T) {
file, err := search.LabelThumbByUUID("14")
assert.Error(t, err, "record not found")
t.Log(file)
})
}
func TestRepo_Labels(t *testing.T) {
conf := config.TestConfig()
search := New(conf.Db())
t.Run("search with query", func(t *testing.T) {
query := form.NewLabelSearch("Query:C Count:1005 Order:slug")
result, err := search.Labels(query)
assert.Nil(t, err)
assert.Equal(t, 2, len(result))
assert.Equal(t, "Cake", result[1].LabelName)
assert.Equal(t, "COW", result[0].LabelName)
})
t.Run("search for favorites", func(t *testing.T) {
query := form.NewLabelSearch("Favorites:true")
result, err := search.Labels(query)
assert.Nil(t, err)
assert.Equal(t, 2, len(result))
assert.Equal(t, "Flower", result[1].LabelName)
assert.Equal(t, "COW", result[0].LabelName)
})
t.Run("search with empty query", func(t *testing.T) {
query := form.NewLabelSearch("")
result, err := search.Labels(query)
assert.Nil(t, err)
assert.Equal(t, 3, len(result))
})
t.Run("search with invalid query string", func(t *testing.T) {
query := form.NewLabelSearch("xxx:bla")
result, err := search.Labels(query)
assert.Error(t, err, "unknown filter")
t.Log(result)
})
}