From 0bef0f7973945a6a19cafbc60773bfe244be0776 Mon Sep 17 00:00:00 2001 From: Stephen Adamson Date: Sat, 11 Jul 2026 17:45:24 +0100 Subject: [PATCH] fix: remove redundant rollback, document asymmetry in cancellation notifications --- backend/handlers/bookings/bookings.go | 6 ++++-- backend/handlers/bookings/manage.go | 3 +++ backend/handlers/payments/handlers.go | 1 - backend/handlers/payments/payments_test.go | 5 ----- backend/handlers/today/today.go | 6 ++++-- backend/handlers/user/user_coverage_test.go | 12 +++++------- 6 files changed, 16 insertions(+), 17 deletions(-) diff --git a/backend/handlers/bookings/bookings.go b/backend/handlers/bookings/bookings.go index 345396f..6521e65 100644 --- a/backend/handlers/bookings/bookings.go +++ b/backend/handlers/bookings/bookings.go @@ -3173,11 +3173,13 @@ func ConfirmBookingHandler(w http.ResponseWriter, r *http.Request) { log.Printf("ALERT: failed to scan total_duration_minutes for booking %s: %v", bookingID, err) durationMinutes = 60 } - _ = dav.Service.CreateEvent(1, dav.EventInput{ + if err := dav.Service.CreateEvent(1, dav.EventInput{ Summary: "Crussell Booking", Start: booking.StartTime, End: booking.StartTime.Add(time.Duration(durationMinutes) * time.Minute), - }) + }); err != nil { + log.Printf("Failed to create DAV calendar event for booking %s: %v", bookingID, err) + } } w.Header().Set("Content-Type", "application/json") diff --git a/backend/handlers/bookings/manage.go b/backend/handlers/bookings/manage.go index 7ec463a..83eccef 100644 --- a/backend/handlers/bookings/manage.go +++ b/backend/handlers/bookings/manage.go @@ -232,6 +232,9 @@ func AdminCancelBookingHandler(w http.ResponseWriter, r *http.Request) { return } + // No admin notification needed for pending/admin-initiated cancellations — + // the admin is the one performing the cancellation, so notifying them would + // be self-referential. // Only notify on cancellation if booking was not pending (e.g. confirmed, in_progress) if originalStatus != "pending" { notificationQuery := ` diff --git a/backend/handlers/payments/handlers.go b/backend/handlers/payments/handlers.go index 0752132..cf3b23e 100644 --- a/backend/handlers/payments/handlers.go +++ b/backend/handlers/payments/handlers.go @@ -1802,7 +1802,6 @@ func CreateTipPayment(w http.ResponseWriter, r *http.Request) { paymentID, err := service.CreatePaymentRecordTx(r.Context(), tx, record, nil) if err != nil { - _ = tx.Rollback(r.Context()) log.Printf("Failed to create payment record: %v", err) http.Error(w, "internal server error", http.StatusInternalServerError) return diff --git a/backend/handlers/payments/payments_test.go b/backend/handlers/payments/payments_test.go index 6ec9728..c98394f 100644 --- a/backend/handlers/payments/payments_test.go +++ b/backend/handlers/payments/payments_test.go @@ -1019,11 +1019,6 @@ func TestCreateBookingPayment_MultiplePartialAllowed(t *testing.T) { } } -func TestSquareWebhook_DevMode_NoSignature(t *testing.T) { - t.Parallel() - t.Skip("webhook handler tested in webhooks package") -} - // ============================================================ // User Booking Payment Tests — deposit, full, partial, balance // ============================================================ diff --git a/backend/handlers/today/today.go b/backend/handlers/today/today.go index 11193fc..3bb35c8 100644 --- a/backend/handlers/today/today.go +++ b/backend/handlers/today/today.go @@ -322,7 +322,7 @@ func computeAggregateSummary(r *http.Request, rangeStart, rangeEnd time.Time) *D ) sub ON true WHERE b.start_time >= $1 AND b.start_time < $2 ` - _ = db.Conn.QueryRow(r.Context(), query, rangeStart, rangeEnd).Scan( + if err := db.Conn.QueryRow(r.Context(), query, rangeStart, rangeEnd).Scan( &summary.TotalPaymentsToday, &summary.TotalTipsToday, &summary.TotalVATCollected, @@ -335,7 +335,9 @@ func computeAggregateSummary(r *http.Request, rangeStart, rangeEnd time.Time) *D &summary.LastCustomerName, &summary.LastCustomerVisits, &summary.GuestCustomers, - ) + ); err != nil { + log.Printf("Failed to scan today summary: %v", err) + } // Customers served = new + returning + guest (distinct people, not bookings) summary.CustomersServed = summary.NewCustomers + summary.ReturningCustomers + summary.GuestCustomers diff --git a/backend/handlers/user/user_coverage_test.go b/backend/handlers/user/user_coverage_test.go index add11d8..a0f3f9a 100644 --- a/backend/handlers/user/user_coverage_test.go +++ b/backend/handlers/user/user_coverage_test.go @@ -563,10 +563,8 @@ func TestDeleteAccount_WithProfilePicture(t *testing.T) { // Handler returns 204 regardless of goroutine result assert.Equal(t, http.StatusNoContent, w.Code) - // Allow goroutines to start before test cleanup - assert.Eventually(t, func() bool { - return true - }, 100*time.Millisecond, 10*time.Millisecond) + // Best-effort wait for background goroutine to initiate + time.Sleep(50 * time.Millisecond) } // ============================================================================= @@ -592,7 +590,7 @@ func TestDeleteAccount_WithSquareClient(t *testing.T) { handler.ServeHTTP(w, req) assert.Equal(t, http.StatusNoContent, w.Code) - assert.Eventually(t, func() bool { - return true - }, 100*time.Millisecond, 10*time.Millisecond) + // Best-effort wait for background goroutine to initiate + time.Sleep(50 * time.Millisecond) } +