package handler import ( "net/http" "net/http/httptest" "testing" ) func TestInterestHandler_CalculateInterest_Unauthorized(t *testing.T) { h := &InterestHandler{ service: nil, secretKey: "test-secret", } // No header req := httptest.NewRequest("POST", "/internal/calculate-interest", nil) rr := httptest.NewRecorder() h.CalculateInterest(rr, req) if rr.Code != http.StatusUnauthorized { t.Errorf("expected 401, got %d", rr.Code) } // Wrong header req2 := httptest.NewRequest("POST", "/internal/calculate-interest", nil) req2.Header.Set("X-Internal-Key", "wrong-key") rr2 := httptest.NewRecorder() h.CalculateInterest(rr2, req2) if rr2.Code != http.StatusUnauthorized { t.Errorf("expected 401, got %d", rr2.Code) } }