From 9dbd74345294aae1f590ba3da8120842fd898485 Mon Sep 17 00:00:00 2001 From: Theresa Gresch Date: Fri, 1 May 2020 14:15:15 +0200 Subject: [PATCH] Backend: Use new fixtures in api tests --- internal/api/account_test.go | 2 +- internal/api/album_test.go | 20 +++++++------------- internal/api/file_test.go | 7 +++++-- internal/api/label_test.go | 6 +++--- internal/api/link_test.go | 4 ++-- internal/api/photo_label_test.go | 6 +++--- internal/api/photo_test.go | 8 ++++---- 7 files changed, 25 insertions(+), 28 deletions(-) diff --git a/internal/api/account_test.go b/internal/api/account_test.go index 77c5c8eaa..425438c18 100644 --- a/internal/api/account_test.go +++ b/internal/api/account_test.go @@ -28,7 +28,7 @@ func TestGetAccount(t *testing.T) { t.Run("successful request", func(t *testing.T) { app, router, conf := NewApiTest() GetAccount(router, conf) - result := PerformRequest(app, "GET", "/api/v1/accounts/1") + result := PerformRequest(app, "GET", "/api/v1/accounts/1000000") assert.Contains(t, result.Body.String(), "Test Account") assert.Equal(t, http.StatusOK, result.Code) }) diff --git a/internal/api/album_test.go b/internal/api/album_test.go index fb9f2bd41..02c12d3ea 100644 --- a/internal/api/album_test.go +++ b/internal/api/album_test.go @@ -28,7 +28,7 @@ func TestGetAlbum(t *testing.T) { t.Run("successful request", func(t *testing.T) { app, router, conf := NewApiTest() GetAlbum(router, conf) - result := PerformRequest(app, "GET", "/api/v1/albums/4") + result := PerformRequest(app, "GET", "/api/v1/albums/at9lxuqxpogaaba8") assert.Contains(t, result.Body.String(), "holiday-2030") assert.Equal(t, http.StatusOK, result.Code) }) @@ -44,7 +44,7 @@ func TestDeleteAlbum(t *testing.T) { t.Run("delete existing album", func(t *testing.T) { app, router, conf := NewApiTest() DeleteAlbum(router, conf) - result := PerformRequest(app, "DELETE", "/api/v1/albums/5") + result := PerformRequest(app, "DELETE", "/api/v1/albums/at9lxuqxpogaaba9") assert.Equal(t, http.StatusOK, result.Code) assert.Contains(t, result.Body.String(), "Berlin2019") GetAlbums(router, conf) @@ -65,7 +65,7 @@ func TestLikeAlbum(t *testing.T) { LikeAlbum(router, ctx) - result := PerformRequest(app, "POST", "/api/v1/albums/98789876/like") + result := PerformRequest(app, "POST", "/api/v1/albums/xxx/like") assert.Equal(t, http.StatusNotFound, result.Code) }) t.Run("like existing album", func(t *testing.T) { @@ -73,7 +73,7 @@ func TestLikeAlbum(t *testing.T) { LikeAlbum(router, ctx) - result := PerformRequest(app, "POST", "/api/v1/albums/3/like") + result := PerformRequest(app, "POST", "/api/v1/albums/at9lxuqxpogaaba7/like") assert.Equal(t, http.StatusOK, result.Code) }) } @@ -92,7 +92,7 @@ func TestDislikeAlbum(t *testing.T) { DislikeAlbum(router, conf) - result := PerformRequest(app, "DELETE", "/api/v1/albums/4/like") + result := PerformRequest(app, "DELETE", "/api/v1/albums/at9lxuqxpogaaba8/like") assert.Equal(t, http.StatusOK, result.Code) }) } @@ -111,22 +111,16 @@ func TestDownloadAlbum(t *testing.T) { DownloadAlbum(router, conf) - result := PerformRequest(app, "GET", "/api/v1/albums/4/download") + result := PerformRequest(app, "GET", "/api/v1/albums/at9lxuqxpogaaba8/download") assert.Equal(t, http.StatusOK, result.Code) }) } func TestAlbumThumbnail(t *testing.T) { - t.Run("could not find original", func(t *testing.T) { - app, router, ctx := NewApiTest() - AlbumThumbnail(router, ctx) - result := PerformRequest(app, "GET", "/api/v1/albums/4/thumbnail/tile_500") - assert.Equal(t, http.StatusNotFound, result.Code) - }) 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") + result := PerformRequest(app, "GET", "/api/v1/albums/at9lxuqxpogaaba7/thumbnail/xxx") assert.Equal(t, http.StatusBadRequest, result.Code) }) diff --git a/internal/api/file_test.go b/internal/api/file_test.go index 8daa006e6..31b982401 100644 --- a/internal/api/file_test.go +++ b/internal/api/file_test.go @@ -1,6 +1,7 @@ package api import ( + "github.com/tidwall/gjson" "net/http" "testing" @@ -11,9 +12,11 @@ func TestGetFile(t *testing.T) { t.Run("search for existing file", func(t *testing.T) { app, router, ctx := NewApiTest() GetFile(router, ctx) - result := PerformRequest(app, "GET", "/api/v1/files/123xxx") + result := PerformRequest(app, "GET", "/api/v1/files/2cad9168fa6acc5c5c2965ddf6ec465ca42fd818") assert.Equal(t, http.StatusOK, result.Code) - assert.Contains(t, result.Body.String(), "\"FileName\":\"exampleFileName.jpg\"") + + val := gjson.Get(result.Body.String(), "FileName") + assert.Equal(t, "exampleFileName.jpg", val.String()) }) t.Run("search for not existing file", func(t *testing.T) { app, router, ctx := NewApiTest() diff --git a/internal/api/label_test.go b/internal/api/label_test.go index e4df7efac..f8ae2d0ab 100644 --- a/internal/api/label_test.go +++ b/internal/api/label_test.go @@ -48,7 +48,7 @@ func TestLikeLabel(t *testing.T) { LikeLabel(router, ctx) - result := PerformRequest(app, "POST", "/api/v1/labels/14/like") + result := PerformRequest(app, "POST", "/api/v1/labels/lt9k3pw1wowuy3c5/like") assert.Equal(t, http.StatusOK, result.Code) }) @@ -68,7 +68,7 @@ func TestDislikeLabel(t *testing.T) { DislikeLabel(router, ctx) - result := PerformRequest(app, "DELETE", "/api/v1/labels/14/like") + result := PerformRequest(app, "DELETE", "/api/v1/labels/lt9k3pw1wowuy3c5/like") assert.Equal(t, http.StatusOK, result.Code) }) } @@ -91,7 +91,7 @@ func TestLabelThumbnail(t *testing.T) { t.Run("could not find original", func(t *testing.T) { app, router, ctx := NewApiTest() LabelThumbnail(router, ctx) - result := PerformRequest(app, "GET", "/api/v1/labels/12/thumbnail/tile_500") + result := PerformRequest(app, "GET", "/api/v1/labels/lt9k3pw1wowuy3c3/thumbnail/tile_500") assert.Equal(t, http.StatusOK, result.Code) }) } diff --git a/internal/api/link_test.go b/internal/api/link_test.go index a27f68242..fd7e39034 100644 --- a/internal/api/link_test.go +++ b/internal/api/link_test.go @@ -17,7 +17,7 @@ func TestLinkAlbum(t *testing.T) { LinkAlbum(router, ctx) - result1 := PerformRequestWithBody(app, "POST", "/api/v1/albums/3/link", `{"password": "foobar", "expires": 0, "edit": true}`) + result1 := PerformRequestWithBody(app, "POST", "/api/v1/albums/at9lxuqxpogaaba7/link", `{"password": "foobar", "expires": 0, "edit": true}`) assert.Equal(t, http.StatusOK, result1.Code) @@ -36,7 +36,7 @@ func TestLinkAlbum(t *testing.T) { assert.False(t, link.CanComment) assert.True(t, link.CanEdit) - result2 := PerformRequestWithBody(app, "POST", "/api/v1/albums/3/link", `{"password": "", "expires": 3600}`) + result2 := PerformRequestWithBody(app, "POST", "/api/v1/albums/at9lxuqxpogaaba7/link", `{"password": "", "expires": 3600}`) assert.Equal(t, http.StatusOK, result2.Code) diff --git a/internal/api/photo_label_test.go b/internal/api/photo_label_test.go index 30bdcc267..48de03fac 100644 --- a/internal/api/photo_label_test.go +++ b/internal/api/photo_label_test.go @@ -12,15 +12,15 @@ func TestRemovePhotoLabel(t *testing.T) { t.Run("photo with label", func(t *testing.T) { app, router, ctx := NewApiTest() RemovePhotoLabel(router, ctx) - result := PerformRequest(app, "DELETE", "/api/v1/photos/654/label/1") + result := PerformRequest(app, "DELETE", "/api/v1/photos/pt9jtdre2lvl0yh7/label/1000001") assert.Equal(t, http.StatusOK, result.Code) - val := gjson.Get(result.Body.String(), "Labels.#(LabelID==1).Uncertainty") + val := gjson.Get(result.Body.String(), "Labels.#(LabelID==1000001).Uncertainty") assert.Equal(t, "100", val.String()) }) t.Run("try to remove wrong label", func(t *testing.T) { app, router, ctx := NewApiTest() RemovePhotoLabel(router, ctx) - result := PerformRequest(app, "DELETE", "/api/v1/photos/654/label/3") + result := PerformRequest(app, "DELETE", "/api/v1/photos/pt9jtdre2lvl0yh7/label/1000000") assert.Equal(t, http.StatusNotFound, result.Code) }) t.Run("not existing photo", func(t *testing.T) { diff --git a/internal/api/photo_test.go b/internal/api/photo_test.go index 79802863a..f9c9e7543 100644 --- a/internal/api/photo_test.go +++ b/internal/api/photo_test.go @@ -12,7 +12,7 @@ func TestGetPhoto(t *testing.T) { t.Run("search for existing photo", func(t *testing.T) { app, router, ctx := NewApiTest() GetPhoto(router, ctx) - result := PerformRequest(app, "GET", "/api/v1/photos/654") + result := PerformRequest(app, "GET", "/api/v1/photos/pt9jtdre2lvl0yh7") assert.Equal(t, http.StatusOK, result.Code) val := gjson.Get(result.Body.String(), "PhotoLat") assert.Equal(t, "48.519234", val.String()) @@ -29,7 +29,7 @@ func TestGetPhotoDownload(t *testing.T) { t.Run("could not find original", func(t *testing.T) { app, router, ctx := NewApiTest() GetPhotoDownload(router, ctx) - result := PerformRequest(app, "GET", "/api/v1/photos/654/download") + result := PerformRequest(app, "GET", "/api/v1/photos/pt9jtdre2lvl0yh7/download") assert.Equal(t, http.StatusNotFound, result.Code) }) t.Run("not existing photo", func(t *testing.T) { @@ -44,7 +44,7 @@ func TestLikePhoto(t *testing.T) { t.Run("existing photo", func(t *testing.T) { app, router, ctx := NewApiTest() LikePhoto(router, ctx) - result := PerformRequest(app, "POST", "/api/v1/photos/654/like") + result := PerformRequest(app, "POST", "/api/v1/photos/pt9jtdre2lvl0yh7/like") assert.Equal(t, http.StatusOK, result.Code) }) t.Run("not existing photo", func(t *testing.T) { @@ -59,7 +59,7 @@ func TestDislikePhoto(t *testing.T) { t.Run("existing photo", func(t *testing.T) { app, router, ctx := NewApiTest() DislikePhoto(router, ctx) - result := PerformRequest(app, "DELETE", "/api/v1/photos/655/like") + result := PerformRequest(app, "DELETE", "/api/v1/photos/pt9jtdre2lvl0yh8/like") assert.Equal(t, http.StatusOK, result.Code) }) t.Run("not existing photo", func(t *testing.T) {