2020-01-28 20:59:26 +01:00
|
|
|
package query
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/internal/config"
|
|
|
|
)
|
|
|
|
|
2020-03-28 17:17:41 +01:00
|
|
|
func TestQuery_Files(t *testing.T) {
|
2020-01-28 20:59:26 +01:00
|
|
|
conf := config.TestConfig()
|
|
|
|
|
2020-03-28 15:29:17 +01:00
|
|
|
search := New(conf.Db())
|
2020-01-28 20:59:26 +01:00
|
|
|
|
|
|
|
t.Run("files found", func(t *testing.T) {
|
2020-03-28 15:29:17 +01:00
|
|
|
files, err := search.Files(1000, 0)
|
2020-01-28 20:59:26 +01:00
|
|
|
|
|
|
|
assert.Nil(t, err)
|
2020-05-01 14:16:40 +02:00
|
|
|
assert.LessOrEqual(t, 5, len(files))
|
2020-01-28 20:59:26 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-03-28 17:17:41 +01:00
|
|
|
func TestQuery_FilesByUUID(t *testing.T) {
|
2020-01-28 20:59:26 +01:00
|
|
|
conf := config.TestConfig()
|
|
|
|
|
2020-03-28 15:29:17 +01:00
|
|
|
search := New(conf.Db())
|
2020-01-28 20:59:26 +01:00
|
|
|
|
|
|
|
t.Run("files found", func(t *testing.T) {
|
2020-05-01 14:16:40 +02:00
|
|
|
files, err := search.FilesByUUID([]string{"ft8es39w45bnlqdw"}, 100, 0)
|
2020-01-28 20:59:26 +01:00
|
|
|
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, 1, len(files))
|
|
|
|
assert.Equal(t, "exampleFileName.jpg", files[0].FileName)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-03-28 17:17:41 +01:00
|
|
|
func TestQuery_FileByPhotoUUID(t *testing.T) {
|
2020-01-28 20:59:26 +01:00
|
|
|
conf := config.TestConfig()
|
|
|
|
|
2020-03-28 15:29:17 +01:00
|
|
|
search := New(conf.Db())
|
2020-01-28 20:59:26 +01:00
|
|
|
|
|
|
|
t.Run("files found", func(t *testing.T) {
|
2020-05-01 14:16:40 +02:00
|
|
|
file, err := search.FileByPhotoUUID("pt9jtdre2lvl0yh8")
|
2020-01-28 20:59:26 +01:00
|
|
|
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, "exampleDNGFile.dng", file.FileName)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("no files found", func(t *testing.T) {
|
2020-03-28 15:29:17 +01:00
|
|
|
file, err := search.FileByPhotoUUID("111")
|
2020-01-28 20:59:26 +01:00
|
|
|
|
|
|
|
assert.Error(t, err, "record not found")
|
|
|
|
t.Log(file)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-04-08 13:24:06 +02:00
|
|
|
func TestQuery_FileByUUID(t *testing.T) {
|
2020-01-28 20:59:26 +01:00
|
|
|
conf := config.TestConfig()
|
|
|
|
|
2020-03-28 15:29:17 +01:00
|
|
|
search := New(conf.Db())
|
2020-01-28 20:59:26 +01:00
|
|
|
|
|
|
|
t.Run("files found", func(t *testing.T) {
|
2020-05-01 14:16:40 +02:00
|
|
|
file, err := search.FileByUUID("ft8es39w45bnlqdw")
|
2020-01-28 20:59:26 +01:00
|
|
|
|
2020-04-08 13:24:06 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, "exampleFileName.jpg", file.FileName)
|
2020-01-28 20:59:26 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("no files found", func(t *testing.T) {
|
2020-04-08 13:24:06 +02:00
|
|
|
file, err := search.FileByUUID("111")
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("error expected")
|
|
|
|
}
|
2020-01-28 20:59:26 +01:00
|
|
|
|
|
|
|
assert.Error(t, err, "record not found")
|
|
|
|
t.Log(file)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-03-28 17:17:41 +01:00
|
|
|
func TestQuery_FileByHash(t *testing.T) {
|
2020-01-28 20:59:26 +01:00
|
|
|
conf := config.TestConfig()
|
|
|
|
|
2020-03-28 15:29:17 +01:00
|
|
|
search := New(conf.Db())
|
2020-01-28 20:59:26 +01:00
|
|
|
|
|
|
|
t.Run("files found", func(t *testing.T) {
|
2020-05-01 14:16:40 +02:00
|
|
|
file, err := search.FileByHash("2cad9168fa6acc5c5c2965ddf6ec465ca42fd818")
|
2020-01-28 20:59:26 +01:00
|
|
|
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, "exampleFileName.jpg", file.FileName)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("no files found", func(t *testing.T) {
|
2020-03-28 15:29:17 +01:00
|
|
|
file, err := search.FileByHash("111")
|
2020-01-28 20:59:26 +01:00
|
|
|
|
|
|
|
assert.Error(t, err, "record not found")
|
|
|
|
t.Log(file)
|
|
|
|
})
|
|
|
|
}
|