feat: some refactoring

This commit is contained in:
2025-11-22 22:23:49 +03:00
parent a247e6213e
commit 51f30b516e
29 changed files with 1094 additions and 129 deletions

View File

@@ -0,0 +1,41 @@
package handlers
import (
"net/http"
"net/http/httptest"
"strings"
"testing"
)
func TestHomeHandler_ServeHTTP(t *testing.T) {
// Create a new home handler
handler := NewHomeHandler()
// Create a test request
req := httptest.NewRequest("GET", "/", nil)
// Create a test response recorder
rr := httptest.NewRecorder()
// Call the handler
handler.ServeHTTP(rr, req)
// Check status code
if status := rr.Code; status != http.StatusOK {
t.Errorf("handler returned wrong status code: got %v want %v",
status, http.StatusOK)
}
// Check content type
if ct := rr.Header().Get("Content-Type"); ct != "application/json" {
t.Errorf("handler returned wrong content type: got %v want %v",
ct, "application/json")
}
// Check response body contains expected data
expectedBody := `"success":true`
if body := rr.Body.String(); !strings.Contains(body, expectedBody) {
t.Errorf("handler returned unexpected body: got %v want %v",
body, expectedBody)
}
}