diff --git a/internal/api/settings_test.go b/internal/api/settings_test.go index 2bfebea67..88ad99a59 100644 --- a/internal/api/settings_test.go +++ b/internal/api/settings_test.go @@ -21,22 +21,23 @@ func TestGetSettings(t *testing.T) { } func TestSaveSettings(t *testing.T) { - /* t.Run("successful request", func(t *testing.T) { - app, router, conf := NewApiTest() - GetSettings(router, conf) + t.Run("successful request", func(t *testing.T) { + app, router, _ := NewApiTest() + GetSettings(router) r := PerformRequest(app, "GET", "/api/v1/settings") val := gjson.Get(r.Body.String(), "language") - assert.Equal(t, "de", val.String()) + assert.Equal(t, "en", val.String()) assert.Equal(t, http.StatusOK, r.Code) - SaveSettings(router, conf) - r2 := PerformRequestWithBody(app, "POST", "/api/v1/settings", `{"language": "en"}`) - val2 := gjson.Get(r2.Body.String(), "language") - assert.Equal(t, "en", val2.String()) + SaveSettings(router) + r2 := PerformRequestWithBody(app, "POST", "/api/v1/settings", `{"language": "de"}`) assert.Equal(t, http.StatusOK, r2.Code) - r3 := PerformRequestWithBody(app, "POST", "/api/v1/settings", `{"language": "de"}`) + r4 := PerformRequest(app, "GET", "/api/v1/settings") + val2 := gjson.Get(r4.Body.String(), "language") + assert.Equal(t, "de", val2.String()) + r3 := PerformRequestWithBody(app, "POST", "/api/v1/settings", `{"language": "en"}`) assert.Equal(t, http.StatusOK, r3.Code) - }) */ + }) t.Run("bad request", func(t *testing.T) { app, router, _ := NewApiTest() SaveSettings(router) diff --git a/internal/api/share_preview_test.go b/internal/api/share_preview_test.go index 96213e568..d7a9678c2 100644 --- a/internal/api/share_preview_test.go +++ b/internal/api/share_preview_test.go @@ -14,4 +14,10 @@ func TestGetPreview(t *testing.T) { r := PerformRequest(app, "GET", "/a/1jxf3jfn2k/st9lxuqxpogaaba7/preview") assert.Equal(t, http.StatusNotFound, r.Code) }) + t.Run("invalid token", func(t *testing.T) { + app, router, _ := NewApiTest() + SharePreview(router) + r := PerformRequest(app, "GET", "/a/xxx/st9lxuqxpogaaba7/preview") + assert.Equal(t, http.StatusNotFound, r.Code) + }) } diff --git a/internal/api/share_test.go b/internal/api/share_test.go new file mode 100644 index 000000000..c40274a82 --- /dev/null +++ b/internal/api/share_test.go @@ -0,0 +1,36 @@ +package api + +import ( + "github.com/stretchr/testify/assert" + "net/http" + "testing" +) + +func TestGetShares(t *testing.T) { + t.Run("invalid token or share", func(t *testing.T) { + app, router, _ := NewApiTest() + Shares(router) + r := PerformRequest(app, "GET", "/api/v1/1jxf3jfn2k/st9lxuqxpogaaba7") + assert.Equal(t, http.StatusTemporaryRedirect, r.Code) + }) + //TODO Why does it panic? + /*t.Run("valid token and share", func(t *testing.T) { + app, router, _ := NewApiTest() + Shares(router) + r := PerformRequest(app, "GET", "/api/v1/4jxf3jfn2k/at9lxuqxpogaaba7") + assert.Equal(t, http.StatusTemporaryRedirect, r.Code) + })*/ + t.Run("invalid token", func(t *testing.T) { + app, router, _ := NewApiTest() + Shares(router) + r := PerformRequest(app, "GET", "/api/v1/xxx") + assert.Equal(t, http.StatusTemporaryRedirect, r.Code) + }) + //TODO Why does it panic? + /*t.Run("valid token", func(t *testing.T) { + app, router, _ := NewApiTest() + Shares(router) + r := PerformRequest(app, "GET", "/api/v1/4jxf3jfn2k") + assert.Equal(t, http.StatusTemporaryRedirect, r.Code) + })*/ +} diff --git a/internal/api/svg_test.go b/internal/api/svg_test.go index fce10641e..1cb203e9c 100644 --- a/internal/api/svg_test.go +++ b/internal/api/svg_test.go @@ -15,6 +15,30 @@ func TestGetSvg(t *testing.T) { assert.Equal(t, photoIconSvg, r.Body.Bytes()) assert.Equal(t, http.StatusOK, r.Code) }) + t.Run("raw", func(t *testing.T) { + app, router, conf := NewApiTest() + t.Log(conf) + GetSvg(router) + r := PerformRequest(app, "GET", "/api/v1/svg/raw") + assert.Equal(t, rawIconSvg, r.Body.Bytes()) + assert.Equal(t, http.StatusOK, r.Code) + }) + t.Run("file", func(t *testing.T) { + app, router, conf := NewApiTest() + t.Log(conf) + GetSvg(router) + r := PerformRequest(app, "GET", "/api/v1/svg/file") + assert.Equal(t, fileIconSvg, r.Body.Bytes()) + assert.Equal(t, http.StatusOK, r.Code) + }) + t.Run("video", func(t *testing.T) { + app, router, conf := NewApiTest() + t.Log(conf) + GetSvg(router) + r := PerformRequest(app, "GET", "/api/v1/svg/video") + assert.Equal(t, videoIconSvg, r.Body.Bytes()) + assert.Equal(t, http.StatusOK, r.Code) + }) t.Run("label", func(t *testing.T) { app, router, conf := NewApiTest() t.Log(conf) @@ -31,6 +55,14 @@ func TestGetSvg(t *testing.T) { assert.Equal(t, albumIconSvg, r.Body.Bytes()) assert.Equal(t, http.StatusOK, r.Code) }) + t.Run("folder", func(t *testing.T) { + app, router, conf := NewApiTest() + t.Log(conf) + GetSvg(router) + r := PerformRequest(app, "GET", "/api/v1/svg/folder") + assert.Equal(t, albumIconSvg, r.Body.Bytes()) + assert.Equal(t, http.StatusOK, r.Code) + }) t.Run("broken", func(t *testing.T) { app, router, conf := NewApiTest() t.Log(conf)