shiori/internal/http/handlers/api/v1/system_test.go
Felipe Martin 876d27f337
refactor: remove gin and use stdlib http server (#1064)
* refactor: base http server stdlib

* refactor: swagger and frontend routes

* fix: use global middlewares

* refactor: removed gin from testutils

* fix: object references in legacy webserver

* refactor: legacy, swagger and system handlers

* fix: added verbs to handlers

* fix: server handlers ordering

* refactor: bookmarks handlers

* refactor: system api routes

* tests: bookmark handlers

* refactor: migrated api auth routes

* chore: remove unused middlewares

* docs: add swagger docs to refactored system api

* chore: remove old auth routes

* refactor: account apis

* chore: removed old handlers

* fix: api v1 handlers missing middlewares

* refactor: migrated tag list route

* refactor: bookmark routes

* refactor: remove gin

* chore: make styles

* test: fixed tests

* test: generate binary file without text

* fix: global middleware missing from system api handler

* fix: incorrect api handler

* chore: avoid logging screenshot contents

* tests: bookmarks domain

* tests: shortcuts

* test: missing tests

* tests: server tests

* test: remove test using syscall to avoid windows errors

* chore: added middlewares
2025-02-26 20:50:48 +01:00

46 lines
1.2 KiB
Go

package api_v1
import (
"context"
"net/http"
"testing"
"github.com/go-shiori/shiori/internal/testutil"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/require"
)
func TestHandleSystemInfo(t *testing.T) {
logger := logrus.New()
_, deps := testutil.GetTestConfigurationAndDependencies(t, context.Background(), logger)
t.Run("requires authentication", func(t *testing.T) {
c, w := testutil.NewTestWebContext()
HandleSystemInfo(deps, c)
require.Equal(t, http.StatusUnauthorized, w.Code)
})
t.Run("requires admin access", func(t *testing.T) {
c, w := testutil.NewTestWebContext()
testutil.SetFakeUser(c)
HandleSystemInfo(deps, c)
require.Equal(t, http.StatusForbidden, w.Code)
})
t.Run("returns system info for admin", func(t *testing.T) {
c, w := testutil.NewTestWebContext()
testutil.SetFakeAdmin(c)
HandleSystemInfo(deps, c)
require.Equal(t, http.StatusOK, w.Code)
require.Equal(t, "application/json", w.Header().Get("Content-Type"))
response, err := testutil.NewTestResponseFromReader(w.Body)
require.NoError(t, err)
response.AssertOk(t)
response.AssertMessageContains(t, "version")
response.AssertMessageContains(t, "database")
response.AssertMessageContains(t, "os")
})
}