diff --git a/backend/handlers/admin/settings_test.go b/backend/handlers/admin/settings_test.go index 041faea..71d4414 100644 --- a/backend/handlers/admin/settings_test.go +++ b/backend/handlers/admin/settings_test.go @@ -13,7 +13,6 @@ import ( func intPtr(i int) *int { return &i } func float64Ptr(f float64) *float64 { return &f } -func boolPtr(b bool) *bool { return &b } // ─── Public info ────────────────────────────────────────────────────────────── diff --git a/backend/handlers/bookings/deposit_test.go b/backend/handlers/bookings/deposit_test.go index 2b0da66..c988068 100644 --- a/backend/handlers/bookings/deposit_test.go +++ b/backend/handlers/bookings/deposit_test.go @@ -20,10 +20,6 @@ import ( "crussell/testutils/jwt" ) -func boolPtr(b bool) *bool { - return &b -} - // ============================================================================= // populateDepositFields - DepositProtectedAmount // ============================================================================= diff --git a/backend/handlers/bookings/discount_test.go b/backend/handlers/bookings/discount_test.go index fa20b5c..83eb942 100644 --- a/backend/handlers/bookings/discount_test.go +++ b/backend/handlers/bookings/discount_test.go @@ -250,14 +250,6 @@ func getTotalPaymentCount(t *testing.T, bookingID string, ctx context.Context) i return count } -func getAmountPaid(t *testing.T, bookingID string, ctx context.Context) float64 { - t.Helper() - var amount float64 - err := db.Conn.QueryRow(ctx, `SELECT COALESCE(SUM(amount), 0) FROM payments WHERE booking_id = $1 AND status = 'completed'`, bookingID).Scan(&amount) - require.NoError(t, err) - return amount -} - func applyLoyaltyRedemption(t *testing.T, bookingID, userID string, ctx context.Context) { t.Helper() handler := http.HandlerFunc(payments.ApplyLoyaltyRedemption) diff --git a/backend/handlers/bookings/edit_requests_test.go b/backend/handlers/bookings/edit_requests_test.go index f50fbaf..bd9f8c4 100644 --- a/backend/handlers/bookings/edit_requests_test.go +++ b/backend/handlers/bookings/edit_requests_test.go @@ -156,56 +156,6 @@ func getEditRequestIDFromDB(t *testing.T, ctx context.Context, tx db.Querier, bo return editRequestID } -// createAdminNotification creates an admin notification for an edit request. -func createAdminNotification(t *testing.T, ctx context.Context, tx db.Querier, bookingID, userID string) { - t.Helper() - _, err := tx.Exec(ctx, - `INSERT INTO admin_notifications (reason, booking_id, user_id) - VALUES ('edit_requested', $1, $2)`, bookingID, userID) - if err != nil { - t.Fatalf("failed to create admin notification: %v", err) - } -} - -// makeAdminEditRequest creates an admin request with chi routing context for -// admin edit request endpoints (approve/deny). This is the most robust pattern. -func makeAdminEditRequest(method, path, routePattern string, body interface{}) *httptest.ResponseRecorder { - var req *http.Request - if body != nil { - bodyBytes, _ := json.Marshal(body) - req = httptest.NewRequest(method, path, bytes.NewReader(bodyBytes)) - req.Header.Set("Content-Type", "application/json") - } else { - req = httptest.NewRequest(method, path, nil) - } - - adminToken := jwt.GenerateAdminToken() - req.Header.Set("Authorization", "Bearer "+adminToken) - - rctx := chi.NewRouteContext() - // Parse route pattern like "/api/admin/bookings/{id}/edit-requests/{request_id}/approve" - patternParts := strings.Split(strings.Trim(routePattern, "/"), "/") - pathParts := strings.Split(strings.Trim(path, "/"), "/") - for i, pp := range patternParts { - if strings.HasPrefix(pp, "{") && strings.HasSuffix(pp, "}") { - paramName := pp[1 : len(pp)-1] - if i < len(pathParts) { - rctx.URLParams.Add(paramName, pathParts[i]) - } - } - } - - ctx := context.WithValue(req.Context(), chi.RouteCtxKey, rctx) - ctx = context.WithValue(ctx, mw.UserRoleKey, "admin") - if info := extractUserFromTestJWT(adminToken); info != nil { - ctx = context.WithValue(ctx, mw.UserIDKey, info.userID) - } - req = req.WithContext(ctx) - - w := httptest.NewRecorder() - return w -} - // serveChiHandler sets up a chi router with the given route and serves a request. // Supports an optional JSON body (pass nil for no body). An optional base context // can be provided as the last argument to carry a per-test transaction. @@ -262,15 +212,6 @@ func setupAdminContext(ctx context.Context) context.Context { return ctx } -// setupUserContext adds user JWT to context. -func setupUserContext(ctx context.Context, token string) context.Context { - if info := extractUserFromTestJWT(token); info != nil { - ctx = context.WithValue(ctx, mw.UserIDKey, info.userID) - ctx = context.WithValue(ctx, mw.UserRoleKey, info.role) - } - return ctx -} - // ============================================================================= // 1. User Creates Edit Request (RequestEditHandler) // ============================================================================= diff --git a/backend/handlers/notifications/notifications_test.go b/backend/handlers/notifications/notifications_test.go index c4b15b3..2c079dd 100644 --- a/backend/handlers/notifications/notifications_test.go +++ b/backend/handlers/notifications/notifications_test.go @@ -36,11 +36,6 @@ func makeAdminRequest(handler http.Handler, method, path string, body interface{ return makeRequestWithContext(handler, method, path, body, "admin001", "admin", ctx) } -// makeUserRequest creates a request with regular user context -func makeUserRequest(handler http.Handler, method, path string, body interface{}, ctx context.Context) *httptest.ResponseRecorder { - return makeRequestWithContext(handler, method, path, body, "user001", "verified_email", ctx) -} - // makeRequestWithContext creates a request with specific user context func makeRequestWithContext(handler http.Handler, method, path string, body interface{}, userID, role string, ctx context.Context) *httptest.ResponseRecorder { var req *http.Request diff --git a/backend/handlers/portfolio/images_test.go b/backend/handlers/portfolio/images_test.go index dcec670..cbfb670 100644 --- a/backend/handlers/portfolio/images_test.go +++ b/backend/handlers/portfolio/images_test.go @@ -898,21 +898,6 @@ func jpegBytes(t *testing.T) []byte { return buf.Bytes() } -func webpBytes(t *testing.T) []byte { - t.Helper() - img := image.NewNRGBA(image.Rect(0, 0, 100, 100)) - for y := 0; y < 100; y++ { - for x := 0; x < 100; x++ { - img.Set(x, y, color.RGBA{R: 100, G: 150, B: 200, A: 255}) - } - } - var buf bytes.Buffer - if err := imaging.Encode(&buf, img, imaging.PNG); err != nil { - t.Fatalf("failed to encode test image: %v", err) - } - return buf.Bytes() -} - func multipartUploadBody(t *testing.T, fields map[string][]byte, tags string) (*bytes.Buffer, string) { t.Helper() var buf bytes.Buffer diff --git a/backend/handlers/services/services_test.go b/backend/handlers/services/services_test.go index facb28b..4414f33 100644 --- a/backend/handlers/services/services_test.go +++ b/backend/handlers/services/services_test.go @@ -329,6 +329,4 @@ func TestContact_ReturnsInfo(t *testing.T) { } } -func strPtr(s string) *string { - return &s -} + diff --git a/backend/handlers/user/customer_relationship_test.go b/backend/handlers/user/customer_relationship_test.go index 3dee265..616d803 100644 --- a/backend/handlers/user/customer_relationship_test.go +++ b/backend/handlers/user/customer_relationship_test.go @@ -319,13 +319,4 @@ func createPayment(t *testing.T, ctx context.Context, q db.Querier, bookingID, p } } -func createDiscountPayment(t *testing.T, ctx context.Context, q db.Querier, bookingID string, amount float64) { - t.Helper() - _, err := q.Exec(ctx, ` - INSERT INTO payments (booking_id, payment_type, payment_method, amount, status) - VALUES ($1, 'partial', 'discount', $2, 'completed') - `, bookingID, amount) - if err != nil { - t.Fatalf("failed to create discount payment: %v", err) - } -} +