test: add handler and config tests (auth, tasks, habits, savings, profile, interest, freeze)
Some checks failed
CI / lint-test (push) Failing after 1s
Some checks failed
CI / lint-test (push) Failing after 1s
This commit is contained in:
33
internal/handler/interest_test.go
Normal file
33
internal/handler/interest_test.go
Normal file
@@ -0,0 +1,33 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user