Backend: Add unit tests for internal/api

This commit is contained in:
Theresa Gresch 2020-07-14 17:59:50 +02:00
parent b62af742ae
commit f47256b49f
3 changed files with 45 additions and 0 deletions

View File

@ -0,0 +1,16 @@
package api
import (
"github.com/stretchr/testify/assert"
"net/http"
"testing"
)
func TestUpload(t *testing.T) {
t.Run("forbidden", func(t *testing.T) {
app, router, _ := NewApiTest()
Upload(router)
r := PerformRequest(app, "POST", "/api/v1/upload/xxx")
assert.Equal(t, http.StatusForbidden, r.Code)
})
}

16
internal/api/user_test.go Normal file
View File

@ -0,0 +1,16 @@
package api
import (
"github.com/stretchr/testify/assert"
"net/http"
"testing"
)
func TestChangePassword(t *testing.T) {
t.Run("not existing person", func(t *testing.T) {
app, router, _ := NewApiTest()
ChangePassword(router)
r := PerformRequestWithBody(app, "PUT", "/api/v1/users/xxx/password", `{}`)
assert.Equal(t, http.StatusNotFound, r.Code)
})
}

View File

@ -34,4 +34,17 @@ func TestGetVideo(t *testing.T) {
r := PerformRequest(app, "GET", "/api/v1/videos/acad9168fa6acc5c5c2965ddf6ec465ca42fd832/"+conf.PreviewToken()+"/mp4")
assert.Equal(t, http.StatusOK, r.Code)
})
t.Run("invalid token", func(t *testing.T) {
app, router, _ := NewApiTest()
GetVideo(router)
r := PerformRequest(app, "GET", "/api/v1/videos/acad9168fa6acc5c5c2965ddf6ec465ca42fd832/xxx/mp4")
assert.Equal(t, http.StatusForbidden, r.Code)
})
t.Run("no video file", func(t *testing.T) {
app, router, conf := NewApiTest()
GetVideo(router)
r := PerformRequest(app, "GET", "/api/v1/videos/ocad9168fa6acc5c5c2965ddf6ec465ca42fd818/"+conf.PreviewToken()+"/mp4")
assert.Equal(t, http.StatusOK, r.Code)
})
}