Compare commits

..

2 Commits

Author SHA1 Message Date
413cf51f74 fix: update obsolete repository link 2025-11-11 04:32:25 +01:00
6426419b8b tests: add an unit test for APIHandler MountRoutes() 2025-11-11 04:26:33 +01:00
4 changed files with 51 additions and 3 deletions

View File

@@ -256,7 +256,7 @@ Goyco includes a comprehensive CLI for administration:
### Get the sources
```bash
git clone https://github.com/sandrocazzaniga/goyco.git
git clone https://git.kharec.info/Kharec/goyco.git
cd goyco
```

View File

@@ -13,6 +13,8 @@ import (
"goyco/internal/repositories"
"goyco/internal/services"
"goyco/internal/testutils"
"github.com/go-chi/chi/v5"
)
func TestAPIHandlerGetAPIInfo(t *testing.T) {
@@ -278,3 +280,49 @@ func TestNewAPIHandlerWithMonitoring_NilDB(t *testing.T) {
t.Error("Expected metricsCollector to be nil when db is nil")
}
}
func TestAPIHandlerMountRoutes(t *testing.T) {
mockPostRepo := testutils.NewPostRepositoryStub()
mockUserRepo := testutils.NewUserRepositoryStub()
handler := newAPIHandlerForTest(mockPostRepo, mockUserRepo)
router := chi.NewRouter()
config := RouteModuleConfig{}
router.Route("/api", func(r chi.Router) {
handler.MountRoutes(r, config)
})
t.Run("GET route works", func(t *testing.T) {
request := httptest.NewRequest(http.MethodGet, "/api", nil)
recorder := httptest.NewRecorder()
router.ServeHTTP(recorder, request)
testutils.AssertHTTPStatus(t, recorder, http.StatusOK)
var resp APIInfo
if err := json.NewDecoder(recorder.Body).Decode(&resp); err != nil {
t.Fatalf("failed to decode response: %v", err)
}
if !resp.Success {
t.Fatalf("expected success response, got %+v", resp)
}
})
t.Run("only GET is mounted", func(t *testing.T) {
methods := []string{http.MethodPost, http.MethodPut, http.MethodDelete}
for _, method := range methods {
request := httptest.NewRequest(method, "/api", nil)
recorder := httptest.NewRecorder()
router.ServeHTTP(recorder, request)
if recorder.Code != http.StatusMethodNotAllowed && recorder.Code != http.StatusNotFound {
t.Errorf("expected method not allowed or not found for %s, got %d", method, recorder.Code)
}
}
})
}

View File

@@ -54,7 +54,7 @@
<footer class="site-footer">
<div class="container">
<small>Powered with ❤️ by <a href="https://github.com/sandrocazzaniga/goyco">Goyco</a></small>
<small>Powered with ❤️ by <a href="https://git.kharec.info/Kharec/goyco">Goyco</a></small>
</div>
</footer>

View File

@@ -1,6 +1,6 @@
[Unit]
Description=Goyco - Self-hosted news aggregation platform
Documentation=https://github.com/sandrocazzaniga/goyco
Documentation=https://git.kharec.info/Kharec/goyco
After=network-online.target postgresql.service
[Service]