diff --git a/backend/handlers/bookings/edit_requests_test.go b/backend/handlers/bookings/edit_requests_test.go index 000967a..f027f05 100644 --- a/backend/handlers/bookings/edit_requests_test.go +++ b/backend/handlers/bookings/edit_requests_test.go @@ -39,7 +39,6 @@ import ( "crussell/testutils/jwt" "github.com/go-chi/chi/v5" - "github.com/stretchr/testify/assert" ) // ============================================================================= @@ -2284,11 +2283,10 @@ func TestRequestEditHandler_NotificationUpsertOnReplace(t *testing.T) { t.Fatalf("first edit request failed: %d", w.Code) } - // Capture first notification's created_at - var firstCreatedAt time.Time + var firstNotifID string err := tx.QueryRow(ctx, - "SELECT created_at FROM admin_notifications WHERE booking_id = $1 AND reason = 'edit_requested'", - bookingID).Scan(&firstCreatedAt) + "SELECT id FROM admin_notifications WHERE booking_id = $1 AND reason = 'edit_requested'", + bookingID).Scan(&firstNotifID) if err != nil { t.Fatalf("expected first notification to exist: %v", err) } @@ -2304,12 +2302,7 @@ func TestRequestEditHandler_NotificationUpsertOnReplace(t *testing.T) { t.Fatalf("expected 1 notification after first request, got %d", notifCount) } - // Ensure time has advanced past firstCreatedAt so the next notification has a distinct timestamp - assert.Eventually(t, func() bool { - return time.Now().After(firstCreatedAt.Add(time.Millisecond)) - }, 5*time.Second, time.Millisecond, "timed out waiting for time to advance") - - // Create second edit request (upsert) + // Create second edit request (upsert) — deletes old notification, inserts new one w = makeRequest(handler, "POST", "/api/bookings/"+bookingID+"/edit-request", map[string]interface{}{"new_start_time": time2.Format(time.RFC3339)}, token, ctx) if w.Code != http.StatusCreated { @@ -2327,16 +2320,16 @@ func TestRequestEditHandler_NotificationUpsertOnReplace(t *testing.T) { t.Errorf("expected 1 notification after upsert, got %d", notifCount) } - // Verify the notification has a fresh created_at (newer than original) - var secondCreatedAt time.Time + // Verify the notification was recreated (different ID from original) + var secondNotifID string err = tx.QueryRow(ctx, - "SELECT created_at FROM admin_notifications WHERE booking_id = $1 AND reason = 'edit_requested'", - bookingID).Scan(&secondCreatedAt) + "SELECT id FROM admin_notifications WHERE booking_id = $1 AND reason = 'edit_requested'", + bookingID).Scan(&secondNotifID) if err != nil { t.Fatalf("expected notification to exist after upsert: %v", err) } - if !secondCreatedAt.After(firstCreatedAt) { - t.Errorf("expected notification created_at to be newer than original: first=%v, second=%v", firstCreatedAt, secondCreatedAt) + if secondNotifID == firstNotifID { + t.Errorf("expected notification to be recreated (new ID), but got same ID: %s", secondNotifID) } }