gohorsejobs/backend/internal/api/handlers/storage_handler_test.go
Tiago Yamamoto 6cd8c02252 feat: add test coverage and handler improvements
- Add new test files for handlers (storage, payment, settings)
- Add new test files for services (chat, email, storage, settings, admin)
- Add integration tests for services
- Update handler implementations with bug fixes
- Add coverage reports and test documentation
2026-01-02 08:50:29 -03:00

60 lines
1.7 KiB
Go

package handlers
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/rede5/gohorsejobs/backend/internal/services"
)
func TestStorageHandler_GetUploadURL(t *testing.T) {
t.Run("requires authentication context", func(t *testing.T) {
// Create handler with nil credentials service (will fail)
storageService := services.NewStorageService(nil)
handler := NewStorageHandler(storageService)
req := httptest.NewRequest("GET", "/api/v1/storage/upload-url?key=test.png&contentType=image/png", nil)
w := httptest.NewRecorder()
handler.GetUploadURL(w, req)
// Should fail due to nil credentials service
if w.Code == http.StatusOK {
t.Log("Unexpected success with nil credentials")
}
// Main assertion: handler doesn't panic
})
t.Run("requires key parameter", func(t *testing.T) {
storageService := services.NewStorageService(nil)
handler := NewStorageHandler(storageService)
// Missing key parameter
req := httptest.NewRequest("GET", "/api/v1/storage/upload-url?contentType=image/png", nil)
w := httptest.NewRecorder()
handler.GetUploadURL(w, req)
// Should return error for missing key
if w.Code == http.StatusOK {
t.Error("Expected error for missing key parameter")
}
})
t.Run("requires contentType parameter", func(t *testing.T) {
storageService := services.NewStorageService(nil)
handler := NewStorageHandler(storageService)
// Missing contentType parameter
req := httptest.NewRequest("GET", "/api/v1/storage/upload-url?key=test.png", nil)
w := httptest.NewRecorder()
handler.GetUploadURL(w, req)
// Should return error for missing contentType
if w.Code == http.StatusOK {
t.Error("Expected error for missing contentType parameter")
}
})
}