photoprism/internal/query/label_test.go

130 lines
2.8 KiB
Go
Raw Normal View History

2020-01-28 20:59:02 +01:00
package query
import (
"github.com/photoprism/photoprism/internal/form"
"github.com/stretchr/testify/assert"
"testing"
"github.com/photoprism/photoprism/internal/config"
)
func TestQuery_LabelBySlug(t *testing.T) {
2020-01-28 20:59:02 +01:00
conf := config.TestConfig()
q := New(conf.Db())
2020-01-28 20:59:02 +01:00
t.Run("files found", func(t *testing.T) {
label, err := q.LabelBySlug("flower")
2020-01-28 20:59:02 +01:00
assert.Nil(t, err)
assert.Equal(t, "Flower", label.LabelName)
})
t.Run("no files found", func(t *testing.T) {
label, err := q.LabelBySlug("111")
2020-01-28 20:59:02 +01:00
assert.Error(t, err, "record not found")
t.Log(label)
})
}
func TestQuery_LabelByUUID(t *testing.T) {
2020-01-28 20:59:02 +01:00
conf := config.TestConfig()
q := New(conf.Db())
2020-01-28 20:59:02 +01:00
t.Run("files found", func(t *testing.T) {
label, err := q.LabelByUUID("14")
2020-01-28 20:59:02 +01:00
assert.Nil(t, err)
assert.Equal(t, "COW", label.LabelName)
})
t.Run("no files found", func(t *testing.T) {
label, err := q.LabelByUUID("111")
2020-01-28 20:59:02 +01:00
assert.Error(t, err, "record not found")
t.Log(label)
})
}
func TestQuery_LabelThumbBySlug(t *testing.T) {
2020-01-28 20:59:02 +01:00
conf := config.TestConfig()
q := New(conf.Db())
2020-01-28 20:59:02 +01:00
t.Run("files found", func(t *testing.T) {
file, err := q.LabelThumbBySlug("flower")
2020-01-28 20:59:02 +01:00
assert.Nil(t, err)
assert.Equal(t, "exampleFileName.jpg", file.FileName)
})
t.Run("no files found", func(t *testing.T) {
file, err := q.LabelThumbBySlug("cow")
2020-01-28 20:59:02 +01:00
assert.Error(t, err, "record not found")
t.Log(file)
})
}
func TestQuery_LabelThumbByUUID(t *testing.T) {
2020-01-28 20:59:02 +01:00
conf := config.TestConfig()
q := New(conf.Db())
2020-01-28 20:59:02 +01:00
t.Run("files found", func(t *testing.T) {
file, err := q.LabelThumbByUUID("13")
2020-01-28 20:59:02 +01:00
assert.Nil(t, err)
assert.Equal(t, "exampleFileName.jpg", file.FileName)
})
t.Run("no files found", func(t *testing.T) {
file, err := q.LabelThumbByUUID("14")
2020-01-28 20:59:02 +01:00
assert.Error(t, err, "record not found")
t.Log(file)
})
}
func TestQuery_Labels(t *testing.T) {
2020-01-28 20:59:02 +01:00
conf := config.TestConfig()
q := New(conf.Db())
2020-01-28 20:59:02 +01:00
t.Run("search with query", func(t *testing.T) {
query := form.NewLabelSearch("Query:C Count:1005 Order:slug")
result, err := q.Labels(query)
2020-01-28 20:59:02 +01:00
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 := q.Labels(query)
2020-01-28 20:59:02 +01:00
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 := q.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 := q.Labels(query)
assert.Error(t, err, "unknown filter")
t.Log(result)
})
2020-01-28 20:59:02 +01:00
}