From 2f08b379027dc81be94d1f427c352d58bec9f30d Mon Sep 17 00:00:00 2001 From: Stephen Adamson Date: Mon, 2 Mar 2026 20:25:03 +0000 Subject: [PATCH] Fix tests --- backend/handlers/admin/bookings_test.go | 13 --------- backend/handlers/user/profile_test.go | 35 ++++++++++++++----------- 2 files changed, 19 insertions(+), 29 deletions(-) diff --git a/backend/handlers/admin/bookings_test.go b/backend/handlers/admin/bookings_test.go index ac26508..17bee85 100644 --- a/backend/handlers/admin/bookings_test.go +++ b/backend/handlers/admin/bookings_test.go @@ -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" ) // ============================================================================= diff --git a/backend/handlers/user/profile_test.go b/backend/handlers/user/profile_test.go index 7bed0c9..098da0c 100644 --- a/backend/handlers/user/profile_test.go +++ b/backend/handlers/user/profile_test.go @@ -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") } }