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 <clio-agent@sisyphuslabs.ai>
This commit is contained in:
2026-07-11 16:25:33 +01:00
co-authored by Sisyphus
parent c8051a76d6
commit d6a3e30503
+10 -17
View File
@@ -39,7 +39,6 @@ import (
"crussell/testutils/jwt" "crussell/testutils/jwt"
"github.com/go-chi/chi/v5" "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) t.Fatalf("first edit request failed: %d", w.Code)
} }
// Capture first notification's created_at var firstNotifID string
var firstCreatedAt time.Time
err := tx.QueryRow(ctx, err := tx.QueryRow(ctx,
"SELECT created_at FROM admin_notifications WHERE booking_id = $1 AND reason = 'edit_requested'", "SELECT id FROM admin_notifications WHERE booking_id = $1 AND reason = 'edit_requested'",
bookingID).Scan(&firstCreatedAt) bookingID).Scan(&firstNotifID)
if err != nil { if err != nil {
t.Fatalf("expected first notification to exist: %v", err) 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) 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 // Create second edit request (upsert) — deletes old notification, inserts new one
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)
w = makeRequest(handler, "POST", "/api/bookings/"+bookingID+"/edit-request", w = makeRequest(handler, "POST", "/api/bookings/"+bookingID+"/edit-request",
map[string]interface{}{"new_start_time": time2.Format(time.RFC3339)}, token, ctx) map[string]interface{}{"new_start_time": time2.Format(time.RFC3339)}, token, ctx)
if w.Code != http.StatusCreated { 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) t.Errorf("expected 1 notification after upsert, got %d", notifCount)
} }
// Verify the notification has a fresh created_at (newer than original) // Verify the notification was recreated (different ID from original)
var secondCreatedAt time.Time var secondNotifID string
err = tx.QueryRow(ctx, err = tx.QueryRow(ctx,
"SELECT created_at FROM admin_notifications WHERE booking_id = $1 AND reason = 'edit_requested'", "SELECT id FROM admin_notifications WHERE booking_id = $1 AND reason = 'edit_requested'",
bookingID).Scan(&secondCreatedAt) bookingID).Scan(&secondNotifID)
if err != nil { if err != nil {
t.Fatalf("expected notification to exist after upsert: %v", err) t.Fatalf("expected notification to exist after upsert: %v", err)
} }
if !secondCreatedAt.After(firstCreatedAt) { if secondNotifID == firstNotifID {
t.Errorf("expected notification created_at to be newer than original: first=%v, second=%v", firstCreatedAt, secondCreatedAt) t.Errorf("expected notification to be recreated (new ID), but got same ID: %s", secondNotifID)
} }
} }