From d6a3e305035745962bb8d1eb845eedab9f88b8ba Mon Sep 17 00:00:00 2001 From: Stephen Adamson Date: Sat, 11 Jul 2026 16:25:33 +0100 Subject: [PATCH] fix: compare notification IDs instead of timestamps in upsert test The PoolProxy.Begin routes to the outer test transaction, so PG NOW() returns the same value for both handler invocations. Comparing notification IDs correctly verifies the notification was deleted and recreated. Also removes unused testify/assert import. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus --- .../handlers/bookings/edit_requests_test.go | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) 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) } }