Backend: Use new fixtures in api tests
This commit is contained in:
parent
6edb578b34
commit
9dbd743452
7 changed files with 25 additions and 28 deletions
|
@ -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)
|
||||
})
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue