Tests: Add unit tests for new search filter #3035

This commit is contained in:
theresa 2023-02-14 19:14:03 +01:00
parent 9e85a366c9
commit d3fb420185
3 changed files with 610 additions and 0 deletions

View file

@ -19,6 +19,17 @@ func TestSearchPhotosGeo(t *testing.T) {
assert.Equal(t, "Jens Mander", form.Subjects)
})
t.Run("id", func(t *testing.T) {
form := &SearchPhotosGeo{Query: "id:\"ii3e4567-e89b-hdgtr\""}
err := form.ParseQueryString()
if err != nil {
t.Fatal(err)
}
assert.Equal(t, "ii3e4567-e89b-hdgtr", form.ID)
})
t.Run("aliases", func(t *testing.T) {
form := &SearchPhotosGeo{Query: "people:\"Jens & Mander\" folder:Foo person:Bar"}

View file

@ -662,6 +662,17 @@ func TestParseQueryString(t *testing.T) {
assert.Equal(t, "Could not find format for \"cat\"", err.Error())
})
t.Run("id", func(t *testing.T) {
form := &SearchPhotos{Query: "id:\"ii3e4567-e89b-hdgtr\""}
err := form.ParseQueryString()
if err != nil {
t.Fatal(err)
}
assert.Equal(t, "ii3e4567-e89b-hdgtr", form.ID)
})
}
func TestNewSearchPhotos(t *testing.T) {

View file

@ -0,0 +1,588 @@
package search
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/photoprism/photoprism/internal/form"
)
func TestPhotosFilterId(t *testing.T) {
t.Run("a698ac56-6e7e-42b9-9c3e-a79ec96087uy", func(t *testing.T) {
var f form.SearchPhotos
f.ID = "a698ac56-6e7e-42b9-9c3e-a79ec96087uy"
f.Merged = true
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, len(photos), 1)
})
t.Run("a698ac56-6e7e-42b9-9c3e*", func(t *testing.T) {
var f form.SearchPhotos
f.ID = "a698ac56-6e7e-42b9-9c3e*"
f.Merged = true
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, len(photos), 0)
})
t.Run("StartsWithPercent", func(t *testing.T) {
var f form.SearchPhotos
f.ID = "%gold"
f.Merged = true
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, len(photos), 0)
})
t.Run("CenterPercent", func(t *testing.T) {
var f form.SearchPhotos
f.ID = "I love % dog"
f.Merged = true
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, len(photos), 0)
})
t.Run("EndsWithPercent", func(t *testing.T) {
var f form.SearchPhotos
f.ID = "sale%"
f.Merged = true
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, len(photos), 0)
})
t.Run("StartsWithAmpersand", func(t *testing.T) {
var f form.SearchPhotos
f.ID = "&IlikeFood"
f.Merged = true
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, len(photos), 0)
})
t.Run("CenterAmpersand", func(t *testing.T) {
var f form.SearchPhotos
f.ID = "Pets & Dogs"
f.Merged = true
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, len(photos), 0)
})
t.Run("EndsWithAmpersand", func(t *testing.T) {
var f form.SearchPhotos
f.ID = "Light&"
f.Merged = true
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, len(photos), 0)
})
t.Run("StartsWithSingleQuote", func(t *testing.T) {
var f form.SearchPhotos
f.ID = "'Family"
f.Merged = true
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, len(photos), 0)
})
t.Run("CenterSingleQuote", func(t *testing.T) {
var f form.SearchPhotos
f.ID = "Father's uid"
f.Merged = true
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, len(photos), 0)
})
t.Run("EndsWithSingleQuote", func(t *testing.T) {
var f form.SearchPhotos
f.ID = "Ice Cream'"
f.Merged = true
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, len(photos), 0)
})
t.Run("StartsWithAsterisk", func(t *testing.T) {
var f form.SearchPhotos
f.ID = "*Forrest"
f.Merged = true
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, len(photos), 0)
})
t.Run("CenterAsterisk", func(t *testing.T) {
var f form.SearchPhotos
f.ID = "My*Kids"
f.Merged = true
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, len(photos), 0)
})
t.Run("EndsWithAsterisk", func(t *testing.T) {
var f form.SearchPhotos
f.ID = "Yoga***"
f.Merged = true
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, len(photos), 0)
})
t.Run("StartsWithPipe", func(t *testing.T) {
var f form.SearchPhotos
f.ID = "|Banana"
f.Merged = true
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, len(photos), 0)
})
t.Run("CenterPipe", func(t *testing.T) {
var f form.SearchPhotos
f.ID = "Red|Green"
f.Merged = true
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, len(photos), 0)
})
t.Run("EndsWithPipe", func(t *testing.T) {
var f form.SearchPhotos
f.ID = "Blue|"
f.Merged = true
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, len(photos), 0)
})
t.Run("StartsWithNumber", func(t *testing.T) {
var f form.SearchPhotos
f.ID = "345 Shirt"
f.Merged = true
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, len(photos), 0)
})
t.Run("CenterNumber", func(t *testing.T) {
var f form.SearchPhotos
f.ID = "uid555 Blue"
f.Merged = true
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, len(photos), 0)
})
t.Run("EndsWithNumber", func(t *testing.T) {
var f form.SearchPhotos
f.ID = "Route 66"
f.Merged = true
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, len(photos), 0)
})
}
func TestPhotosQueryId(t *testing.T) {
t.Run("PhotoUID", func(t *testing.T) {
var f form.SearchPhotos
f.Query = "id:a698ac56-6e7e-42b9-9c3e-a79ec96087uy"
f.Merged = true
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, len(photos), 1)
})
t.Run("QuotedPhotoUID", func(t *testing.T) {
var f form.SearchPhotos
f.Query = "id:\"a698ac56-6e7e-42b9-9c3e-a79ec96087uy\""
f.Merged = true
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, len(photos), 1)
})
t.Run("pt9jtdre2lvl0yh*", func(t *testing.T) {
var f form.SearchPhotos
f.Query = "id:\"a698ac56-6e7e-42b9-9c3e-a7*\""
f.Merged = true
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, len(photos), 0)
})
t.Run("StartsWithPercent", func(t *testing.T) {
var f form.SearchPhotos
f.Query = "id:\"%gold\""
f.Merged = true
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, len(photos), 0)
})
t.Run("CenterPercent", func(t *testing.T) {
var f form.SearchPhotos
f.Query = "id:\"I love % dog\""
f.Merged = true
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, len(photos), 0)
})
t.Run("EndsWithPercent", func(t *testing.T) {
var f form.SearchPhotos
f.Query = "id:\"sale%\""
f.Merged = true
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, len(photos), 0)
})
t.Run("StartsWithAmpersand", func(t *testing.T) {
var f form.SearchPhotos
f.Query = "id:\"&IlikeFood\""
f.Merged = true
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, len(photos), 0)
})
t.Run("CenterAmpersand", func(t *testing.T) {
var f form.SearchPhotos
f.Query = "id:\"Pets & Dogs\""
f.Merged = true
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, len(photos), 0)
})
t.Run("EndsWithAmpersand", func(t *testing.T) {
var f form.SearchPhotos
f.Query = "id:\"Light&\""
f.Merged = true
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, len(photos), 0)
})
t.Run("StartsWithSingleQuote", func(t *testing.T) {
var f form.SearchPhotos
f.Query = "id:\"'Family\""
f.Merged = true
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, len(photos), 0)
})
t.Run("CenterSingleQuote", func(t *testing.T) {
var f form.SearchPhotos
f.Query = "id:\"Father's uid\""
f.Merged = true
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, len(photos), 0)
})
t.Run("EndsWithSingleQuote", func(t *testing.T) {
var f form.SearchPhotos
f.Query = "id:\"Ice Cream'\""
f.Merged = true
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, len(photos), 0)
})
t.Run("StartsWithAsterisk", func(t *testing.T) {
var f form.SearchPhotos
f.Query = "id:\"*Forrest\""
f.Merged = true
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, len(photos), 0)
})
t.Run("CenterAsterisk", func(t *testing.T) {
var f form.SearchPhotos
f.Query = "id:\"My*Kids\""
f.Merged = true
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, len(photos), 0)
})
t.Run("EndsWithAsterisk", func(t *testing.T) {
var f form.SearchPhotos
f.Query = "id:\"Yoga***\""
f.Merged = true
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, len(photos), 0)
})
t.Run("StartsWithPipe", func(t *testing.T) {
var f form.SearchPhotos
f.Query = "id:\"|Banana\""
f.Merged = true
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, len(photos), 0)
})
t.Run("CenterPipe", func(t *testing.T) {
var f form.SearchPhotos
f.Query = "id:\"Red|Green\""
f.Merged = true
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, len(photos), 0)
})
t.Run("EndsWithPipe", func(t *testing.T) {
var f form.SearchPhotos
f.Query = "id:\"Blue|\""
f.Merged = true
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, len(photos), 0)
})
t.Run("StartsWithNumber", func(t *testing.T) {
var f form.SearchPhotos
f.Query = "id:\"345 Shirt\""
f.Merged = true
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, len(photos), 0)
})
t.Run("CenterNumber", func(t *testing.T) {
var f form.SearchPhotos
f.Query = "id:\"uid555 Blue\""
f.Merged = true
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, len(photos), 0)
})
t.Run("EndsWithNumber", func(t *testing.T) {
var f form.SearchPhotos
f.Query = "id:\"Route 66\""
f.Merged = true
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, len(photos), 0)
})
}