diff options
| author | Saiyed Shizain <saiyedshizain@gmail.com> | 2026-08-26 16:59:34 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-08-26 16:59:34 +0530 |
| commit | 7c346191ca616d5aef20147c46fd45ee856477aa (patch) | |
| tree | 0535b1eae4cf0fa21d24e2ed3e7ab4875c0e70f6 /internal/gallery/query_photos_test.go | |
| parent | 9b541ca2d0a639eebd9610fcd6385e841da68e0a (diff) | |
| parent | bd8fab9ace7444d1b97a6df7b2d81ef981808a05 (diff) | |
| download | galleryd-7c346191ca616d5aef20147c46fd45ee856477aa.tar.xz galleryd-7c346191ca616d5aef20147c46fd45ee856477aa.zip | |
Merge pull request #14 from RanXom/feat/api
Feat/api: add photo search by relative path
Diffstat (limited to 'internal/gallery/query_photos_test.go')
| -rw-r--r-- | internal/gallery/query_photos_test.go | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/internal/gallery/query_photos_test.go b/internal/gallery/query_photos_test.go index c9bb986..f38c237 100644 --- a/internal/gallery/query_photos_test.go +++ b/internal/gallery/query_photos_test.go @@ -250,3 +250,162 @@ func TestQueryPhotosSortByDateDescending(t *testing.T) { assertIDs(t, got, "new", "mid", "old") } + +func TestQueryPhotosFilterByExtension(t *testing.T) { + photos := []Photo{ + { + ID: "jpg", + File: scanner.File{ + RelativePath: "photo.jpg", + }, + }, + { + ID: "png", + File: scanner.File{ + RelativePath: "photo.png", + }, + }, + { + ID: "jpg2", + File: scanner.File{ + RelativePath: "anotherphoto.jpg", + }, + }, + } + + got := QueryPhotos(photos, Query{ + Extension: "jpg", + }) + + assertIDs(t, got, "jpg", "jpg2") +} + +func TestQueryPhotosFilterThenSortThenPaginate(t *testing.T) { + photos := []Photo{ + { + ID: "1", + File: scanner.File{ + RelativePath: "a.png", + }, + }, + { + ID: "2", + File: scanner.File{ + RelativePath: "c.jpg", + }, + }, + { + ID: "3", + File: scanner.File{ + RelativePath: "a.jpg", + }, + }, + } + + got := QueryPhotos(photos, Query{ + Extension: "jpg", + Sort: SortByPath, + Order: SortAsc, + Limit: 1, + }) + + assertIDs(t, got, "3") +} + +func TestQueryPhotosSearchByRelativePath(t *testing.T) { + photos := []Photo{ + { + ID: "vacation", + File: scanner.File{ + RelativePath: "photos/vacation/beach.jpg", + }, + }, + { + ID: "work", + File: scanner.File{ + RelativePath: "photos/work/meeting.jpg", + }, + }, + { + ID: "vacation2", + File: scanner.File{ + RelativePath: "photos/vacation/mountains.jpg", + }, + }, + } + + got := QueryPhotos(photos, Query{ + Search: "vacation", + }) + + assertIDs(t, got, "vacation", "vacation2") +} + +func TestQueryPhotosSearchIsCaseInsensitive(t *testing.T) { + photos := []Photo{ + { + ID: "1", + File: scanner.File{ + RelativePath: "Photos/Vacation/Beach.jpg", + }, + }, + { + ID: "2", + File: scanner.File{ + RelativePath: "photos/work/meeting.jpg", + }, + }, + } + + got := QueryPhotos(photos, Query{ + Search: "VACATION", + }) + + assertIDs(t, got, "1") +} + +func TestQueryPhotosFilterSearchSortThenPaginate(t *testing.T) { + photos := []Photo{ + { + ID: "1", + File: scanner.File{ + RelativePath: "photos/work/report.jpg", + }, + }, + { + ID: "2", + File: scanner.File{ + RelativePath: "photos/vacation/zebra.jpg", + }, + }, + { + ID: "3", + File: scanner.File{ + RelativePath: "photos/vacation/apple.jpg", + }, + }, + { + ID: "4", + File: scanner.File{ + RelativePath: "photos/vacation/beach.png", + }, + }, + { + ID: "5", + File: scanner.File{ + RelativePath: "photos/vacation/mountains.jpg", + }, + }, + } + + got := QueryPhotos(photos, Query{ + Extension: "jpg", + Search: "vacation", + Sort: SortByPath, + Order: SortAsc, + Offset: 1, + Limit: 1, + }) + + assertIDs(t, got, "5") +} |