From abd53baf35abd0140fef8e687e15319b833b4342 Mon Sep 17 00:00:00 2001 From: Stephen Adamson Date: Sat, 11 Jul 2026 10:14:12 +0100 Subject: [PATCH] fix: time-sensitive tests use savepoint pattern, avoid 48h auto-approval boundary --- backend/handlers/bookings/edit_requests_test.go | 2 +- backend/handlers/bookings/overlap_test.go | 2 +- backend/handlers/today/today_test.go | 7 +------ 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/backend/handlers/bookings/edit_requests_test.go b/backend/handlers/bookings/edit_requests_test.go index bd9f8c4..ed99d19 100644 --- a/backend/handlers/bookings/edit_requests_test.go +++ b/backend/handlers/bookings/edit_requests_test.go @@ -1577,7 +1577,7 @@ func TestAdminApproveEditRequestHandler_OverlapWithBooking(t *testing.T) { // Create first booking at time T // Use a start time <48h away so auto-approval doesn't trigger at request- // creation time, allowing us to test the approval-time overlap check. - baseTime := clock.Now().Add(40 * time.Hour).Truncate(time.Second) + baseTime := clock.Now().Add(24 * time.Hour).Truncate(time.Second) baseTime = time.Date(baseTime.Year(), baseTime.Month(), baseTime.Day(), 9, 0, 0, 0, baseTime.Location()) booking1, err := fixtures.CreateTestBooking(tx, userID, serviceID) diff --git a/backend/handlers/bookings/overlap_test.go b/backend/handlers/bookings/overlap_test.go index a27d04f..bfa5599 100644 --- a/backend/handlers/bookings/overlap_test.go +++ b/backend/handlers/bookings/overlap_test.go @@ -1853,7 +1853,7 @@ func TestAdminApproveEditRequest_EvictsPendingRelease(t *testing.T) { dur := durationMinutes(t, ctx, tx, serviceID) // Use a booking <48h from now so RequestEdit does NOT auto-approve - nearTime := clock.Now().Add(40 * time.Hour).Truncate(time.Second) + nearTime := clock.Now().Add(24 * time.Hour).Truncate(time.Second) nearTime = time.Date(nearTime.Year(), nearTime.Month(), nearTime.Day(), 10, 0, 0, 0, nearTime.Location()) bookingA, err := fixtures.CreateTestBookingAtTime(tx, userID, serviceID, nearTime) diff --git a/backend/handlers/today/today_test.go b/backend/handlers/today/today_test.go index 7dae6a8..6cb52d5 100644 --- a/backend/handlers/today/today_test.go +++ b/backend/handlers/today/today_test.go @@ -731,13 +731,8 @@ func TestGetCurrentNext_WithMultipleDataPoints(t *testing.T) { } addBookingService(t, ctx, tx, booking2ID, svcID) - // Commit the transaction so the handler (which manages its own db.Conn tx) can see the data. - if err := tx.(interface{ Commit(context.Context) error }).Commit(context.Background()); err != nil { - t.Fatalf("failed to commit test data: %v", err) - } - req := httptest.NewRequest(http.MethodGet, "/api/admin/today/current-next", nil) - req = req.WithContext(context.Background()) + req = req.WithContext(ctx) rr := httptest.NewRecorder() GetCurrentAndNextHandler(rr, req)