From 01b35d0cf59ba7edb15646739e1def24f946f1af Mon Sep 17 00:00:00 2001 From: Theresa Gresch Date: Wed, 17 Jul 2019 17:38:51 +0200 Subject: [PATCH] Add tests for thumbnail api --- internal/api/thumbnails_test.go | 58 +++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 internal/api/thumbnails_test.go diff --git a/internal/api/thumbnails_test.go b/internal/api/thumbnails_test.go new file mode 100644 index 000000000..d8ac8b137 --- /dev/null +++ b/internal/api/thumbnails_test.go @@ -0,0 +1,58 @@ +package api + +import ( + "github.com/stretchr/testify/assert" + "net/http" + "testing" +) + +func TestGetThumbnail(t *testing.T) { + t.Run("invalid type", func(t *testing.T) { + app, router, ctx := NewApiTest() + GetThumbnail(router, ctx) + result := PerformRequest(app, "GET", "/api/v1/thumbnails/1/xxx") + + assert.Equal(t, http.StatusBadRequest, result.Code) + }) + t.Run("invalid hash", func(t *testing.T) { + app, router, ctx := NewApiTest() + GetThumbnail(router, ctx) + result := PerformRequest(app, "GET", "/api/v1/thumbnails/1/tile_500") + + assert.Equal(t, http.StatusNotFound, result.Code) + }) +} + +func TestLabelThumbnail(t *testing.T) { + t.Run("invalid type", func(t *testing.T) { + app, router, ctx := NewApiTest() + LabelThumbnail(router, ctx) + result := PerformRequest(app, "GET", "/api/v1/labels/dog/thumbnail/xxx") + + assert.Equal(t, http.StatusBadRequest, result.Code) + }) + t.Run("invalid label", func(t *testing.T) { + app, router, ctx := NewApiTest() + LabelThumbnail(router, ctx) + result := PerformRequest(app, "GET", "/api/v1/labels/xxx/thumbnail/tile_500") + + assert.Equal(t, http.StatusNotFound, result.Code) + }) +} + +func TestAlbumThumbnail(t *testing.T) { + t.Run("invalid type", func(t *testing.T) { + app, router, ctx := NewApiTest() + AlbumThumbnail(router, ctx) + result := PerformRequest(app, "GET", "/api/v1/albums/1/thumbnail/xxx") + + assert.Equal(t, http.StatusBadRequest, result.Code) + }) + t.Run("album has no photo (because is not existing)", func(t *testing.T) { + app, router, ctx := NewApiTest() + AlbumThumbnail(router, ctx) + result := PerformRequest(app, "GET", "/api/v1/albums/987-986435/thumbnail/tile_500") + + assert.Equal(t, http.StatusOK, result.Code) + }) +}