From ca0c7718263dffc096c2deaf5208e6c3ff628f50 Mon Sep 17 00:00:00 2001 From: Theresa Gresch Date: Mon, 28 Mar 2022 11:28:42 +0200 Subject: [PATCH] Tests: Add unit tests for photo search --- internal/search/photos_test.go | 327 +++++++++++++++++++++++++++++++++ 1 file changed, 327 insertions(+) diff --git a/internal/search/photos_test.go b/internal/search/photos_test.go index 742ca8c80..f4c413dcf 100644 --- a/internal/search/photos_test.go +++ b/internal/search/photos_test.go @@ -1529,3 +1529,330 @@ func TestPhotos(t *testing.T) { assert.Equal(t, photos[0].PhotoTitle, "Neckarbrücke") }) } +func TestPhotosFilterAlbums(t *testing.T) { + t.Run("albums start %", func(t *testing.T) { + var f form.SearchPhotos + + f.Albums = "%gold" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.Equal(t, len(photos), 0) + }) + t.Run("albums middle %", func(t *testing.T) { + var f form.SearchPhotos + + f.Albums = "I love % dog" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.Equal(t, len(photos), 0) + }) + t.Run("albums end %", func(t *testing.T) { + var f form.SearchPhotos + + f.Albums = "sale%" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.Greater(t, len(photos), 0) + }) + t.Run("albums start &", func(t *testing.T) { + var f form.SearchPhotos + + f.Albums = "&IlikeFood" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.Equal(t, len(photos), 0) + }) + t.Run("albums middle &", func(t *testing.T) { + var f form.SearchPhotos + + f.Albums = "Pets & Dogs" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.Equal(t, len(photos), 0) + }) + t.Run("albums end &", func(t *testing.T) { + var f form.SearchPhotos + + f.Albums = "Light&" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.Greater(t, len(photos), 0) + }) +} + +func TestPhotosQueryAlbums(t *testing.T) { + t.Run("albums start %", func(t *testing.T) { + var f form.SearchPhotos + + f.Query = "albums:\"%gold\"" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.Equal(t, len(photos), 0) + }) + t.Run("albums middle %", func(t *testing.T) { + var f form.SearchPhotos + + f.Query = "albums:\"I love % dog\"" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.Equal(t, len(photos), 0) + }) + t.Run("albums end %", func(t *testing.T) { + var f form.SearchPhotos + + f.Query = "albums:\"sale%\"" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.Greater(t, len(photos), 0) + }) + t.Run("albums start &", func(t *testing.T) { + var f form.SearchPhotos + + f.Query = "albums:\"&IlikeFood\"" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.Equal(t, len(photos), 0) + }) + t.Run("albums middle &", func(t *testing.T) { + var f form.SearchPhotos + + f.Query = "albums:\"Pets & Dogs\"" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.Equal(t, len(photos), 0) + }) + t.Run("albums end &", func(t *testing.T) { + var f form.SearchPhotos + + f.Query = "albums:\"Light&\"" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.Greater(t, len(photos), 0) + }) +} + +func TestPhotosFilterAlbum(t *testing.T) { + t.Run("album start %", func(t *testing.T) { + var f form.SearchPhotos + + f.Album = "%gold" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + + assert.Equal(t, len(photos), 0) + }) + t.Run("album middle %", func(t *testing.T) { + var f form.SearchPhotos + + f.Album = "I love % dog" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + + assert.Greater(t, len(photos), 0) + + }) + t.Run("album end %", func(t *testing.T) { + var f form.SearchPhotos + + f.Album = "sale%" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + + assert.Greater(t, len(photos), 0) + }) + t.Run("album start &", func(t *testing.T) { + var f form.SearchPhotos + + f.Album = "&IlikeFood" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + //assert.Equal(t, len(photos), 0) + }) + t.Run("album middle &", func(t *testing.T) { + var f form.SearchPhotos + + f.Album = "Pets & Dogs" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.Greater(t, len(photos), 0) + }) + t.Run("album end &", func(t *testing.T) { + var f form.SearchPhotos + + f.Album = "Light&" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.Greater(t, len(photos), 0) + }) +} + +func TestPhotosQueryAlbum(t *testing.T) { + t.Run("album start %", func(t *testing.T) { + var f form.SearchPhotos + + f.Query = "album:\"%gold\"" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.Equal(t, len(photos), 0) + }) + t.Run("album middle %", func(t *testing.T) { + var f form.SearchPhotos + + f.Query = "album:\"I love % dog\"" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.Equal(t, len(photos), 0) + }) + t.Run("album end %", func(t *testing.T) { + var f form.SearchPhotos + + f.Query = "album:\"sale%\"" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.Greater(t, len(photos), 0) + }) + t.Run("album start &", func(t *testing.T) { + var f form.SearchPhotos + + f.Query = "album:\"&IlikeFood\"" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + //assert.Equal(t, len(photos), 0) + }) + t.Run("album middle &", func(t *testing.T) { + var f form.SearchPhotos + + f.Query = "album:\"Pets & Dogs\"" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.Greater(t, len(photos), 0) + }) + t.Run("album end &", func(t *testing.T) { + var f form.SearchPhotos + + f.Query = "album:\"Light&\"" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.Greater(t, len(photos), 0) + }) +}