diff options
| author | Saiyed Shizain <saiyedshizain@gmail.com> | 2026-07-22 17:32:55 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-07-22 17:32:55 +0530 |
| commit | 9b541ca2d0a639eebd9610fcd6385e841da68e0a (patch) | |
| tree | d331e8d858f62cf82d0cb6c3ca96400d4e28edca /internal/api/api_test.go | |
| parent | 46d2bf8bb5a0d18bdbe613a9346a5757b39e0a35 (diff) | |
| parent | ddd8a37a0eb5623960e4528802263c7cec23af87 (diff) | |
| download | galleryd-9b541ca2d0a639eebd9610fcd6385e841da68e0a.tar.xz galleryd-9b541ca2d0a639eebd9610fcd6385e841da68e0a.zip | |
Merge pull request #13 from RanXom/feat/api
Feat/api: add sorting support to gallery queries
Diffstat (limited to 'internal/api/api_test.go')
| -rw-r--r-- | internal/api/api_test.go | 63 |
1 files changed, 61 insertions, 2 deletions
diff --git a/internal/api/api_test.go b/internal/api/api_test.go index dce42e4..9a660e3 100644 --- a/internal/api/api_test.go +++ b/internal/api/api_test.go @@ -45,8 +45,14 @@ func (f *fakeGalleryService) Reload(ctx context.Context) error { return f.reloadErr } -func (f fakeGalleryService) Gallery(ctx context.Context) ([]gallery.Photo, error) { - return f.photos, f.err +func (f fakeGalleryService) Gallery( + ctx context.Context, + query gallery.Query, +) ([]gallery.Photo, error) { + return gallery.QueryPhotos( + f.photos, + query, + ), f.err } func (f fakeGalleryService) Photo( @@ -222,3 +228,56 @@ func TestReload(t *testing.T) { ) } } + +func TestPhotosPagination(t *testing.T) { + srv := New(Config{ + Address: ":0", + + Gallery: &fakeGalleryService{ + photos: []gallery.Photo{ + {ID: "0"}, + {ID: "1"}, + {ID: "2"}, + }, + }, + }) + + req := httptest.NewRequest( + http.MethodGet, + "/api/photos?limit=1&offset=1", + nil, + ) + + rec := httptest.NewRecorder() + + srv.mux.ServeHTTP(rec, req) + + if rec.Code != http.StatusOK { + t.Fatalf( + "expected %d, got %d", + http.StatusOK, + rec.Code, + ) + } + + var response []photoResponse + + if err := json.NewDecoder(rec.Body).Decode(&response); err != nil { + t.Fatalf("decode response: %v", err) + } + + if len(response) != 1 { + t.Fatalf( + "expected 1 photo, got %d", + len(response), + ) + } + + if response[0].ID != "1" { + t.Fatalf( + "expected id %q, got %q", + "1", + response[0].ID, + ) + } +} |