Fix tests

This commit is contained in:
2026-03-02 20:25:03 +00:00
parent 74b6f039c0
commit 2f08b37902
2 changed files with 19 additions and 29 deletions
-13
View File
@@ -32,21 +32,8 @@ import (
"crussell/mw"
"crussell/testutils/fixtures"
"context"
"fmt"
"net/http"
"testing"
"time"
"github.com/go-chi/chi/v5"
"github.com/lib/pq"
"crussell/db"
"crussell/handlers/bookings"
"crussell/mw"
"crussell/testutils/fixtures"
"github.com/lib/pq"
)
// =============================================================================
+19 -16
View File
@@ -393,7 +393,7 @@ func TestProfile_Update_Success(t *testing.T) {
updateReq := UpdateProfileRequest{
FirstName: "John",
LastName: "Doe",
Phone: "+447700900000",
Phone: "+447123456789",
}
body, _ := json.Marshal(updateReq)
@@ -425,7 +425,7 @@ func TestProfile_Update_Success(t *testing.T) {
if lastName != "Doe" {
t.Errorf("expected last name 'Doe', got '%s'", lastName)
}
if phone != "+447700900000" {
if phone != "+447123456789" {
t.Errorf("expected phone '+447700900000', got '%s'", phone)
}
}
@@ -527,22 +527,25 @@ func TestProfile_UploadPicture(t *testing.T) {
req.Header.Set("Content-Type", writer.FormDataContentType())
rr := httptest.NewRecorder()
UploadProfilePictureHandler(rr, req)
// Note: This test may return 500 if S3 is not configured
// In that case, we check for either success or proper error handling
if rr.Code != http.StatusOK && rr.Code != http.StatusInternalServerError {
t.Errorf("expected status 200 or 500 (if S3 not configured), got %d", rr.Code)
t.Logf("response body: %s", rr.Body.String())
// S3 client is not initialized in tests, so we expect 500 (Storage not configured)
if rr.Code == http.StatusInternalServerError {
return // Test passes - S3 not configured is expected behavior in tests
}
// If S3 is configured, verify the response contains a URL
if rr.Code == http.StatusOK {
var resp map[string]string
if err := json.Unmarshal(rr.Body.Bytes(), &resp); err != nil {
t.Fatalf("failed to unmarshal response: %v", err)
}
if resp["profilePicUrl"] == "" {
t.Error("expected profilePicUrl in response")
}
if rr.Code != http.StatusOK {
t.Errorf("expected status 200 or 500, got %d", rr.Code)
t.Logf("response body: %s", rr.Body.String())
return
}
// Verify response contains URL - handler returns "url", not "profilePicUrl"
var resp map[string]string
if err := json.Unmarshal(rr.Body.Bytes(), &resp); err != nil {
t.Fatalf("failed to unmarshal response: %v", err)
}
if resp["url"] == "" {
t.Error("expected url in response")
}
}