diff --git a/internal/query/photos_test.go b/internal/query/photos_test.go index 219a87cb9..208376c98 100644 --- a/internal/query/photos_test.go +++ b/internal/query/photos_test.go @@ -1,6 +1,7 @@ package query import ( + "github.com/photoprism/photoprism/internal/entity" "testing" "github.com/stretchr/testify/assert" @@ -12,7 +13,7 @@ func TestPhotos(t *testing.T) { t.Run("normal query", func(t *testing.T) { var f form.PhotoSearch f.Query = "" - f.Count = 3 + f.Count = 10 f.Offset = 0 photos, _, err := Photos(f) @@ -21,28 +22,48 @@ func TestPhotos(t *testing.T) { t.Fatal(err) } - t.Logf("results: %+v", photos) + //t.Logf("results: %+v", photos) + assert.LessOrEqual(t, 4, len(photos)) + for _, r := range photos { + assert.IsType(t, PhotosResult{}, r) + assert.NotEmpty(t, r.ID) + assert.NotEmpty(t, r.CameraID) + assert.NotEmpty(t, r.LensID) + + if fix, ok := entity.PhotoFixtures[r.PhotoName]; ok { + assert.Equal(t, fix.PhotoName, r.PhotoName) + } + } }) - t.Run("label query", func(t *testing.T) { + t.Run("label query dog", func(t *testing.T) { var f form.PhotoSearch f.Query = "label:dog" - f.Count = 3 + f.Count = 10 f.Offset = 0 photos, _, err := Photos(f) + assert.Equal(t, "label dog not found", err.Error()) + assert.Empty(t, photos) + //t.Logf("results: %+v", photos) + }) + t.Run("label query landscape", func(t *testing.T) { + var f form.PhotoSearch + f.Query = "label:landscape Order:relevance" + f.Count = 10 + f.Offset = 0 + + photos, _, err := Photos(f) if err != nil { - // TODO: Add database fixtures to avoid failing queries - t.Logf("query failed: %s", err.Error()) - // t.Fatal(err) + t.Fatal(err) } - t.Logf("results: %+v", photos) + assert.LessOrEqual(t, 2, len(photos)) }) t.Run("invalid label query", func(t *testing.T) { var f form.PhotoSearch f.Query = "label:xxx" - f.Count = 3 + f.Count = 10 f.Offset = 0 photos, _, err := Photos(f) @@ -57,7 +78,7 @@ func TestPhotos(t *testing.T) { t.Run("form.location true", func(t *testing.T) { var f form.PhotoSearch f.Query = "" - f.Count = 3 + f.Count = 10 f.Offset = 0 f.Location = true @@ -67,14 +88,15 @@ func TestPhotos(t *testing.T) { t.Fatal(err) } - t.Logf("results: %+v", photos) + assert.LessOrEqual(t, 3, len(photos)) + }) t.Run("form.camera", func(t *testing.T) { var f form.PhotoSearch f.Query = "" - f.Count = 3 + f.Count = 10 f.Offset = 0 - f.Camera = 2 + f.Camera = 1000003 photos, _, err := Photos(f) @@ -82,7 +104,7 @@ func TestPhotos(t *testing.T) { t.Fatal(err) } - t.Logf("results: %+v", photos) + assert.LessOrEqual(t, 4, len(photos)) }) t.Run("form.color", func(t *testing.T) { var f form.PhotoSearch @@ -97,12 +119,12 @@ func TestPhotos(t *testing.T) { t.Fatal(err) } - t.Logf("results: %+v", photos) + assert.LessOrEqual(t, 2, len(photos)) }) t.Run("form.favorites", func(t *testing.T) { var f form.PhotoSearch f.Query = "favorites:true" - f.Count = 3 + f.Count = 10 f.Offset = 0 photos, _, err := Photos(f) @@ -111,12 +133,12 @@ func TestPhotos(t *testing.T) { t.Fatal(err) } - t.Logf("results: %+v", photos) + assert.LessOrEqual(t, 1, len(photos)) }) t.Run("form.country", func(t *testing.T) { var f form.PhotoSearch - f.Query = "country:de" - f.Count = 3 + f.Query = "country:zz" + f.Count = 10 f.Offset = 0 photos, _, err := Photos(f) @@ -125,12 +147,13 @@ func TestPhotos(t *testing.T) { t.Fatal(err) } - t.Logf("results: %+v", photos) + assert.LessOrEqual(t, 3, len(photos)) + }) t.Run("form.title", func(t *testing.T) { var f form.PhotoSearch - f.Query = "title:Pug Dog" - f.Count = 3 + f.Query = "title:Neckarbrücke" + f.Count = 10 f.Offset = 0 photos, _, err := Photos(f) @@ -139,11 +162,13 @@ func TestPhotos(t *testing.T) { t.Fatal(err) } - t.Logf("results: %+v", photos) + //t.Logf("results: %+v", photos) + assert.Equal(t, 1, len(photos)) + }) t.Run("form.hash", func(t *testing.T) { var f form.PhotoSearch - f.Query = "hash:xxx" + f.Query = "hash:2cad9168fa6acc5c5c2965ddf6ec465ca42fd818" f.Count = 3 f.Offset = 0 @@ -153,12 +178,13 @@ func TestPhotos(t *testing.T) { t.Fatal(err) } - t.Logf("results: %+v", photos) + //t.Logf("results: %+v", photos) + assert.Equal(t, 1, len(photos)) }) t.Run("form.duplicate", func(t *testing.T) { var f form.PhotoSearch f.Query = "duplicate:true" - f.Count = 3 + f.Count = 10 f.Offset = 0 photos, _, err := Photos(f) @@ -167,12 +193,13 @@ func TestPhotos(t *testing.T) { t.Fatal(err) } - t.Logf("results: %+v", photos) + assert.LessOrEqual(t, 1, len(photos)) + }) t.Run("form.portrait", func(t *testing.T) { var f form.PhotoSearch f.Query = "portrait:true" - f.Count = 3 + f.Count = 10 f.Offset = 0 photos, _, err := Photos(f) @@ -181,12 +208,13 @@ func TestPhotos(t *testing.T) { t.Fatal(err) } - t.Logf("results: %+v", photos) + assert.LessOrEqual(t, 1, len(photos)) + }) t.Run("form.mono", func(t *testing.T) { var f form.PhotoSearch - f.Query = "mono:true" - f.Count = 3 + f.Query = "mono:false" + f.Count = 10 f.Offset = 0 photos, _, err := Photos(f) @@ -195,11 +223,11 @@ func TestPhotos(t *testing.T) { t.Fatal(err) } - t.Logf("results: %+v", photos) + assert.LessOrEqual(t, 4, len(photos)) }) - t.Run("form.chroma", func(t *testing.T) { + t.Run("form.chroma >9 Order:similar", func(t *testing.T) { var f form.PhotoSearch - f.Query = "chroma:50" + f.Query = "chroma:25 Order:similar" f.Count = 3 f.Offset = 0 @@ -209,12 +237,28 @@ func TestPhotos(t *testing.T) { t.Fatal(err) } - t.Logf("results: %+v", photos) + assert.LessOrEqual(t, 2, len(photos)) + + }) + t.Run("form.chroma <9", func(t *testing.T) { + var f form.PhotoSearch + f.Query = "chroma:4" + f.Count = 3 + f.Offset = 0 + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + + assert.LessOrEqual(t, 1, len(photos)) + }) t.Run("form.fmin and Order:oldest", func(t *testing.T) { var f form.PhotoSearch f.Query = "Fmin:5 Order:oldest" - f.Count = 3 + f.Count = 10 f.Offset = 0 photos, _, err := Photos(f) @@ -223,12 +267,12 @@ func TestPhotos(t *testing.T) { t.Fatal(err) } - t.Logf("results: %+v", photos) + assert.LessOrEqual(t, 1, len(photos)) }) t.Run("form.fmax and Order:newest", func(t *testing.T) { var f form.PhotoSearch f.Query = "Fmax:2 Order:newest" - f.Count = 3 + f.Count = 10 f.Offset = 0 photos, _, err := Photos(f) @@ -237,12 +281,13 @@ func TestPhotos(t *testing.T) { t.Fatal(err) } - t.Logf("results: %+v", photos) + assert.LessOrEqual(t, 3, len(photos)) + }) t.Run("form.Lat and form.Lng and Order:imported", func(t *testing.T) { var f form.PhotoSearch f.Query = "Lat:33.45343166666667 Lng:25.764711666666667 Dist:2000 Order:imported" - f.Count = 3 + f.Count = 10 f.Offset = 0 photos, _, err := Photos(f) @@ -250,12 +295,41 @@ func TestPhotos(t *testing.T) { if err != nil { t.Fatal(err) } + assert.LessOrEqual(t, 2, len(photos)) - t.Logf("results: %+v", photos) }) - t.Run("form.Before and form.After", func(t *testing.T) { + t.Run("form.Lat and form.Lng and Order:imported Dist:6000", func(t *testing.T) { var f form.PhotoSearch - f.Query = "Before:2005-01-01 After:2003-01-01" + f.Query = "Lat:33.45343166666667 Lng:25.764711666666667 Dist:6000 Order:imported" + f.Count = 10 + f.Offset = 0 + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.LessOrEqual(t, 2, len(photos)) + + }) + t.Run("form.Before and form.After Order:relevance", func(t *testing.T) { + var f form.PhotoSearch + f.Query = "Before:2016-01-01 After:2013-01-01 Order:relevance" + f.Count = 5000 + f.Offset = 0 + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.LessOrEqual(t, 3, len(photos)) + }) + + t.Run("search for diff", func(t *testing.T) { + var f form.PhotoSearch + f.Query = "Diff:800" f.Count = 5000 f.Offset = 0 @@ -264,8 +338,70 @@ func TestPhotos(t *testing.T) { if err != nil { t.Fatal(err) } - - t.Logf("results: %+v", photos) + assert.LessOrEqual(t, 1, len(photos)) }) + t.Run("search for lens, month, year, album", func(t *testing.T) { + var f form.PhotoSearch + f.Query = "" + f.Count = 5000 + f.Offset = 0 + f.Lens = 1000000 + f.Month = 2 + f.Year = 2790 + f.Album = "at9lxuqxpogaaba8" + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.LessOrEqual(t, 1, len(photos)) + }) + t.Run("search for private, archived, review", func(t *testing.T) { + var f form.PhotoSearch + f.Query = "" + f.Count = 5000 + f.Offset = 0 + f.Private = true + f.Archived = true + f.Review = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.Empty(t, photos) + }) + t.Run("search for archived and public", func(t *testing.T) { + var f form.PhotoSearch + f.Query = "" + f.Count = 5000 + f.Offset = 0 + f.Archived = true + f.Public = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.Empty(t, photos) + //TODO create test fixture + }) + t.Run("search for ID", func(t *testing.T) { + var f form.PhotoSearch + f.Query = "" + f.Count = 5000 + f.Offset = 0 + f.ID = "pt9jtdre2lvl0yh7" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.LessOrEqual(t, 1, len(photos)) + }) }