From 895d41cd61208faa1eb6e4551a847dd23e934be6 Mon Sep 17 00:00:00 2001 From: theresa Date: Mon, 20 Sep 2021 14:05:44 +0200 Subject: [PATCH] People: Add unit tests #22 --- internal/entity/photo_fixtures.go | 2 +- internal/search/photos_geo_test.go | 73 +++++++++ internal/search/photos_test.go | 232 +++++++++++++++++++++++++++++ 3 files changed, 306 insertions(+), 1 deletion(-) diff --git a/internal/entity/photo_fixtures.go b/internal/entity/photo_fixtures.go index 253ac1afc..a5c45796a 100644 --- a/internal/entity/photo_fixtures.go +++ b/internal/entity/photo_fixtures.go @@ -1008,7 +1008,7 @@ var PhotoFixtures = PhotoMap{ OriginalName: "", PhotoFavorite: false, PhotoPrivate: false, - PhotoScan: false, + PhotoScan: true, PhotoPanorama: false, TimeZone: "", Place: &UnknownPlace, diff --git a/internal/search/photos_geo_test.go b/internal/search/photos_geo_test.go index 954650be0..2cbf15f19 100644 --- a/internal/search/photos_geo_test.go +++ b/internal/search/photos_geo_test.go @@ -341,4 +341,77 @@ func TestGeo(t *testing.T) { assert.GreaterOrEqual(t, len(photos), 2) }) + t.Run("query: videos", func(t *testing.T) { + var frm form.PhotoSearchGeo + + frm.Query = "videos" + + photos, err := PhotosGeo(frm) + + if err != nil { + t.Fatal(err) + } + + assert.LessOrEqual(t, 1, len(photos)) + + for _, r := range photos { + assert.IsType(t, GeoResult{}, r) + assert.NotEmpty(t, r.ID) + assert.Equal(t, "video", r.PhotoType) + } + }) + t.Run("query: faces", func(t *testing.T) { + var frm form.PhotoSearchGeo + + frm.Query = "faces" + + photos, err := PhotosGeo(frm) + + if err != nil { + t.Fatal(err) + } + assert.LessOrEqual(t, 1, len(photos)) + + for _, r := range photos { + assert.IsType(t, GeoResult{}, r) + assert.NotEmpty(t, r.ID) + } + }) + t.Run("query: people", func(t *testing.T) { + var frm form.PhotoSearchGeo + + frm.Query = "people" + + photos, err := PhotosGeo(frm) + + if err != nil { + t.Fatal(err) + } + + assert.LessOrEqual(t, 1, len(photos)) + + for _, r := range photos { + assert.IsType(t, GeoResult{}, r) + assert.NotEmpty(t, r.ID) + } + }) + t.Run("query: favorites", func(t *testing.T) { + var frm form.PhotoSearchGeo + + frm.Query = "favorites" + + photos, err := PhotosGeo(frm) + + if err != nil { + t.Fatal(err) + } + + assert.LessOrEqual(t, 1, len(photos)) + + for _, r := range photos { + assert.IsType(t, GeoResult{}, r) + assert.NotEmpty(t, r.ID) + assert.True(t, r.PhotoFavorite) + } + }) } diff --git a/internal/search/photos_test.go b/internal/search/photos_test.go index 6607c2de5..40b45ee79 100644 --- a/internal/search/photos_test.go +++ b/internal/search/photos_test.go @@ -864,6 +864,238 @@ func TestPhotos(t *testing.T) { assert.GreaterOrEqual(t, len(photos), 1) }) + t.Run("Subject", func(t *testing.T) { + var frm form.PhotoSearch + + frm.Query = "John" + frm.Subject = "" + frm.Count = 10 + frm.Offset = 0 + + photos, _, err := Photos(frm) + + if err != nil { + t.Fatal(err) + } + + assert.LessOrEqual(t, 1, len(photos)) + + for _, r := range photos { + assert.IsType(t, Photo{}, 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("query: videos", func(t *testing.T) { + var frm form.PhotoSearch + + frm.Query = "videos" + frm.Count = 10 + frm.Offset = 0 + + photos, _, err := Photos(frm) + + if err != nil { + t.Fatal(err) + } + + assert.LessOrEqual(t, 1, len(photos)) + + for _, r := range photos { + assert.IsType(t, Photo{}, r) + assert.NotEmpty(t, r.ID) + assert.Equal(t, "video", r.PhotoType) + assert.NotEmpty(t, r.LensID) + + if fix, ok := entity.PhotoFixtures[r.PhotoName]; ok { + assert.Equal(t, fix.PhotoName, r.PhotoName) + } + } + }) + t.Run("query: faces", func(t *testing.T) { + var frm form.PhotoSearch + + frm.Query = "faces" + frm.Count = 10 + frm.Offset = 0 + + photos, _, err := Photos(frm) + + if err != nil { + t.Fatal(err) + } + assert.LessOrEqual(t, 1, len(photos)) + + for _, r := range photos { + assert.IsType(t, Photo{}, r) + assert.NotEmpty(t, r.ID) + assert.LessOrEqual(t, 1, r.PhotoFaces) + assert.NotEmpty(t, r.LensID) + + if fix, ok := entity.PhotoFixtures[r.PhotoName]; ok { + assert.Equal(t, fix.PhotoName, r.PhotoName) + } + } + }) + t.Run("query: people", func(t *testing.T) { + var frm form.PhotoSearch + + frm.Query = "people" + frm.Count = 10 + frm.Offset = 0 + + photos, _, err := Photos(frm) + + if err != nil { + t.Fatal(err) + } + + assert.LessOrEqual(t, 1, len(photos)) + + for _, r := range photos { + assert.IsType(t, Photo{}, r) + assert.NotEmpty(t, r.ID) + assert.LessOrEqual(t, 1, r.PhotoFaces) + assert.NotEmpty(t, r.LensID) + + if fix, ok := entity.PhotoFixtures[r.PhotoName]; ok { + assert.Equal(t, fix.PhotoName, r.PhotoName) + } + } + }) + t.Run("query: favorites", func(t *testing.T) { + var frm form.PhotoSearch + + frm.Query = "favorites" + frm.Count = 10 + frm.Offset = 0 + + photos, _, err := Photos(frm) + + if err != nil { + t.Fatal(err) + } + + assert.LessOrEqual(t, 1, len(photos)) + + for _, r := range photos { + assert.IsType(t, Photo{}, r) + assert.NotEmpty(t, r.ID) + assert.True(t, r.PhotoFavorite) + assert.NotEmpty(t, r.LensID) + + if fix, ok := entity.PhotoFixtures[r.PhotoName]; ok { + assert.Equal(t, fix.PhotoName, r.PhotoName) + } + } + }) + t.Run("query: stacks", func(t *testing.T) { + var frm form.PhotoSearch + + frm.Query = "stacks" + frm.Count = 10 + frm.Offset = 0 + + photos, _, err := Photos(frm) + + if err != nil { + t.Fatal(err) + } + + assert.LessOrEqual(t, 1, len(photos)) + + for _, r := range photos { + assert.IsType(t, Photo{}, r) + assert.NotEmpty(t, r.ID) + assert.NotEmpty(t, r.LensID) + + if fix, ok := entity.PhotoFixtures[r.PhotoName]; ok { + assert.Equal(t, fix.PhotoName, r.PhotoName) + } + } + }) + t.Run("query: panoramas", func(t *testing.T) { + var frm form.PhotoSearch + + frm.Query = "panoramas" + frm.Count = 10 + frm.Offset = 0 + + photos, _, err := Photos(frm) + + if err != nil { + t.Fatal(err) + } + + assert.LessOrEqual(t, 1, len(photos)) + + for _, r := range photos { + assert.IsType(t, Photo{}, r) + assert.NotEmpty(t, r.ID) + assert.Equal(t, true, r.PhotoPanorama) + assert.NotEmpty(t, r.LensID) + + if fix, ok := entity.PhotoFixtures[r.PhotoName]; ok { + assert.Equal(t, fix.PhotoName, r.PhotoName) + } + } + }) + t.Run("query: scans", func(t *testing.T) { + var frm form.PhotoSearch + + frm.Query = "scans" + frm.Count = 10 + frm.Offset = 0 + + photos, _, err := Photos(frm) + + if err != nil { + t.Fatal(err) + } + + assert.LessOrEqual(t, 1, len(photos)) + + for _, r := range photos { + assert.IsType(t, Photo{}, r) + assert.NotEmpty(t, r.ID) + assert.Equal(t, true, r.PhotoScan) + assert.NotEmpty(t, r.LensID) + + if fix, ok := entity.PhotoFixtures[r.PhotoName]; ok { + assert.Equal(t, fix.PhotoName, r.PhotoName) + } + } + }) + t.Run("query: monochrome", func(t *testing.T) { + var frm form.PhotoSearch + + frm.Query = "monochrome" + frm.Count = 10 + frm.Offset = 0 + + photos, _, err := Photos(frm) + + if err != nil { + t.Fatal(err) + } + + assert.LessOrEqual(t, 1, len(photos)) + + for _, r := range photos { + assert.IsType(t, Photo{}, r) + assert.NotEmpty(t, r.ID) + assert.NotEmpty(t, r.LensID) + + if fix, ok := entity.PhotoFixtures[r.PhotoName]; ok { + assert.Equal(t, fix.PhotoName, r.PhotoName) + } + } + }) t.Run("filename", func(t *testing.T) { var f form.PhotoSearch f.Filename = "1990/04/Quality1FavoriteTrue.jpg"