From bce509c88b456f37bc6fd0c6927b9786fec29a0e Mon Sep 17 00:00:00 2001 From: theresa Date: Mon, 5 Sep 2022 14:23:51 +0200 Subject: [PATCH] Tests: Add more tests for city search filter --- internal/search/photos_filter_city_test.go | 885 +++++++++++++++++++++ 1 file changed, 885 insertions(+) create mode 100644 internal/search/photos_filter_city_test.go diff --git a/internal/search/photos_filter_city_test.go b/internal/search/photos_filter_city_test.go new file mode 100644 index 000000000..493cbefde --- /dev/null +++ b/internal/search/photos_filter_city_test.go @@ -0,0 +1,885 @@ +package search + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/photoprism/photoprism/internal/form" +) + +func TestPhotosFilterCity(t *testing.T) { + t.Run("Teotihuacán", func(t *testing.T) { + var f form.SearchPhotos + + f.City = "Teotihuacán" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.GreaterOrEqual(t, len(photos), 7) + }) + t.Run("Neustadt*", func(t *testing.T) { + var f form.SearchPhotos + + f.City = "Neustadt*" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + t.Log(len(photos)) + assert.Equal(t, len(photos), 0) + }) + t.Run("Teotihuacán pipe Neustadt an der Weinstraße", func(t *testing.T) { + var f form.SearchPhotos + + f.City = "Teotihuacán|Neustadt an der Weinstraße" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.GreaterOrEqual(t, len(photos), 8) + }) + t.Run("Teotihuacán whitespace pipe whitespace Neustadt an der Weinstraße", func(t *testing.T) { + var f form.SearchPhotos + + f.City = "Teotihuacán | Neustadt an der Weinstraße" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.GreaterOrEqual(t, len(photos), 8) + }) + t.Run("Teotihuacán or Neustadt an der Weinstraße", func(t *testing.T) { + var f form.SearchPhotos + + f.City = "Teotihuacán or Neustadt an der Weinstraße" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.Equal(t, len(photos), 0) + }) + t.Run("Teotihuacán OR Neustadt an der Weinstraße", func(t *testing.T) { + var f form.SearchPhotos + + f.City = "Teotihuacán OR Neustadt an der Weinstraße" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + 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.City = "%gold" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + 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.City = "I love % dog" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + 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.City = "sale%" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + 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.City = "&IlikeFood" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.Equal(t, 0, len(photos)) + }) + t.Run("CenterAmpersand", func(t *testing.T) { + var f form.SearchPhotos + + f.City = "Pets & Dogs" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + 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.City = "Light&" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + 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.City = "'Family" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + 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.City = "Father's state" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + 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.City = "Ice Cream'" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + 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.City = "*Forrest" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + 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.City = "My*Kids" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + 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.City = "Yoga***" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + 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.City = "|New york" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + + assert.Equal(t, 1, len(photos)) + }) + t.Run("CenterPipe", func(t *testing.T) { + var f form.SearchPhotos + + f.City = "Red|Green" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + + assert.Equal(t, 0, len(photos)) + }) + t.Run("EndsWithPipe", func(t *testing.T) { + var f form.SearchPhotos + + f.City = "Neustadt an der Weinstraße|" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.Equal(t, 1, len(photos)) + }) + t.Run("StartsWithNumber", func(t *testing.T) { + var f form.SearchPhotos + + f.City = "345 Shirt" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.Equal(t, 0, len(photos)) + }) + t.Run("CenterNumber", func(t *testing.T) { + var f form.SearchPhotos + + f.City = "state555 Blue" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + 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.City = "Route 66" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.Equal(t, len(photos), 0) + }) +} + +func TestPhotosQueryCity(t *testing.T) { + t.Run("Teotihuacán", func(t *testing.T) { + var f form.SearchPhotos + + f.Query = "city:\"Teotihuacán\"" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.GreaterOrEqual(t, len(photos), 7) + }) + t.Run("Neustadt*", func(t *testing.T) { + var f form.SearchPhotos + + f.Query = "city:\"Neustadt*\"" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.Equal(t, len(photos), 0) + }) + t.Run("Teotihuacán pipe Neustadt an der Weinstraße", func(t *testing.T) { + var f form.SearchPhotos + + f.Query = "city:\"Teotihuacán|Neustadt an der Weinstraße\"" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.GreaterOrEqual(t, len(photos), 8) + }) + t.Run("Teotihuacán whitespace pipe whitespace Neustadt an der Weinstraße", func(t *testing.T) { + var f form.SearchPhotos + + f.Query = "city:\"Teotihuacán | Neustadt an der Weinstraße\"" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.GreaterOrEqual(t, len(photos), 8) + }) + t.Run("Teotihuacán or Neustadt an der Weinstraße", func(t *testing.T) { + var f form.SearchPhotos + + f.Query = "city:\"Teotihuacán or Neustadt an der Weinstraße\"" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.Equal(t, len(photos), 0) + }) + t.Run("Teotihuacán OR Neustadt an der Weinstraße", func(t *testing.T) { + var f form.SearchPhotos + + f.Query = "city:\"Teotihuacán OR Neustadt an der Weinstraße\"" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + 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 = "city:\"%gold\"" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + 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 = "city:\"I love % dog\"" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + 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 = "city:\"sale%\"" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + 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 = "city:\"&IlikeFood\"" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + 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 = "city:\"Pets & Dogs\"" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + 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 = "city:\"Light&\"" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + 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 = "city:\"'Family\"" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + 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 = "city:\"Father's state\"" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + 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 = "city:\"Ice Cream'\"" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + 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 = "city:\"*Forrest\"" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + 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 = "city:\"My*Kids\"" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + 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 = "city:\"Yoga***\"" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + 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 = "city:\"|Banana\"" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + 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 = "city:\"Red|Green\"" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + 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 = "city:\"Neustadt an der Weinstraße|\"" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.Equal(t, len(photos), 1) + }) + t.Run("StartsWithNumber", func(t *testing.T) { + var f form.SearchPhotos + + f.Query = "city:\"345 Shirt\"" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + 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 = "city:\"state555 Blue\"" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + 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 = "city:\"Route 66\"" + f.Merged = true + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.Equal(t, len(photos), 0) + }) +}