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