Files
breakpilot-compliance/ai-compliance-sdk/internal/api/handlers/reporting_handlers_test.go
Benjamin Admin a1980cd12d
All checks were successful
CI / go-lint (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / test-go-ai-compliance (push) Successful in 37s
CI / test-python-backend-compliance (push) Successful in 33s
CI / test-python-document-crawler (push) Successful in 23s
CI / test-python-dsms-gateway (push) Successful in 18s
feat(reporting+docs): tenant-ID-Validierung, Go-Tests, 4 MkDocs-Einzelseiten
- reporting_handlers.go: uuid.Nil-Check vor Store-Aufruf (→ 400)
- reporting_handlers_test.go: 4 MissingTenantID-Tests (PASS) + 4 WithTenant-Tests (SKIP)
- docs-src: requirements.md, controls.md, evidence.md, risks.md (je mit API, Schema, Tests)
- mkdocs.yml: 4 neue Nav-Einträge + \n-Bug auf Zeile 91 behoben
- compliance-kern.md: Link-Hinweise zu Detailseiten ergänzt

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-05 18:25:26 +01:00

180 lines
5.0 KiB
Go

package handlers
import (
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
)
// ============================================================================
// ReportingHandlers — Missing Tenant ID Tests (no store required)
// ============================================================================
func TestReportingHandlers_GetExecutiveReport_MissingTenantID(t *testing.T) {
handler := &ReportingHandlers{store: nil}
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
c.Request = httptest.NewRequest("GET", "/reporting/executive", nil)
handler.GetExecutiveReport(c)
if w.Code != http.StatusBadRequest {
t.Errorf("Expected status 400 for missing tenant ID, got %d", w.Code)
}
var resp map[string]interface{}
if err := json.Unmarshal(w.Body.Bytes(), &resp); err != nil {
t.Fatalf("Failed to parse response: %v", err)
}
if _, ok := resp["error"]; !ok {
t.Error("Expected error field in response")
}
}
func TestReportingHandlers_GetComplianceScore_MissingTenantID(t *testing.T) {
handler := &ReportingHandlers{store: nil}
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
c.Request = httptest.NewRequest("GET", "/reporting/score", nil)
handler.GetComplianceScore(c)
if w.Code != http.StatusBadRequest {
t.Errorf("Expected status 400 for missing tenant ID, got %d", w.Code)
}
var resp map[string]interface{}
if err := json.Unmarshal(w.Body.Bytes(), &resp); err != nil {
t.Fatalf("Failed to parse response: %v", err)
}
if _, ok := resp["error"]; !ok {
t.Error("Expected error field in response")
}
}
func TestReportingHandlers_GetUpcomingDeadlines_MissingTenantID(t *testing.T) {
handler := &ReportingHandlers{store: nil}
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
c.Request = httptest.NewRequest("GET", "/reporting/deadlines", nil)
handler.GetUpcomingDeadlines(c)
if w.Code != http.StatusBadRequest {
t.Errorf("Expected status 400 for missing tenant ID, got %d", w.Code)
}
var resp map[string]interface{}
if err := json.Unmarshal(w.Body.Bytes(), &resp); err != nil {
t.Fatalf("Failed to parse response: %v", err)
}
if _, ok := resp["error"]; !ok {
t.Error("Expected error field in response")
}
}
func TestReportingHandlers_GetRiskOverview_MissingTenantID(t *testing.T) {
handler := &ReportingHandlers{store: nil}
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
c.Request = httptest.NewRequest("GET", "/reporting/risks", nil)
handler.GetRiskOverview(c)
if w.Code != http.StatusBadRequest {
t.Errorf("Expected status 400 for missing tenant ID, got %d", w.Code)
}
var resp map[string]interface{}
if err := json.Unmarshal(w.Body.Bytes(), &resp); err != nil {
t.Fatalf("Failed to parse response: %v", err)
}
if _, ok := resp["error"]; !ok {
t.Error("Expected error field in response")
}
}
// ============================================================================
// ReportingHandlers — With Tenant ID (skip if no DB store)
// ============================================================================
func TestReportingHandlers_GetExecutiveReport_WithTenant(t *testing.T) {
t.Skipf("Skipping integration test — requires live DB store")
handler := &ReportingHandlers{store: nil}
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
c.Request = httptest.NewRequest("GET", "/reporting/executive", nil)
c.Set("tenant_id", uuid.New())
c.Set("user_id", uuid.New())
handler.GetExecutiveReport(c)
if w.Code != http.StatusOK {
t.Errorf("Expected status 200, got %d", w.Code)
}
}
func TestReportingHandlers_GetComplianceScore_WithTenant(t *testing.T) {
t.Skipf("Skipping integration test — requires live DB store")
handler := &ReportingHandlers{store: nil}
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
c.Request = httptest.NewRequest("GET", "/reporting/score", nil)
c.Set("tenant_id", uuid.New())
c.Set("user_id", uuid.New())
handler.GetComplianceScore(c)
if w.Code != http.StatusOK {
t.Errorf("Expected status 200, got %d", w.Code)
}
}
func TestReportingHandlers_GetUpcomingDeadlines_WithTenant(t *testing.T) {
t.Skipf("Skipping integration test — requires live DB store")
handler := &ReportingHandlers{store: nil}
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
c.Request = httptest.NewRequest("GET", "/reporting/deadlines", nil)
c.Set("tenant_id", uuid.New())
c.Set("user_id", uuid.New())
handler.GetUpcomingDeadlines(c)
if w.Code != http.StatusOK {
t.Errorf("Expected status 200, got %d", w.Code)
}
}
func TestReportingHandlers_GetRiskOverview_WithTenant(t *testing.T) {
t.Skipf("Skipping integration test — requires live DB store")
handler := &ReportingHandlers{store: nil}
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
c.Request = httptest.NewRequest("GET", "/reporting/risks", nil)
c.Set("tenant_id", uuid.New())
c.Set("user_id", uuid.New())
handler.GetRiskOverview(c)
if w.Code != http.StatusOK {
t.Errorf("Expected status 200, got %d", w.Code)
}
}