test: fix today_test flakiness with London-timezone-aware booking times

Replace clock.Now() with fixed London-timezone times in TestGetCurrentNext_WithMultipleDataPoints to prevent near-midnight UTC failures where bookings fall outside the London 'today' window.
This commit is contained in:
2026-08-22 00:34:49 +01:00
parent 70613497b4
commit a6cb803ff2
+10 -3
View File
@@ -680,7 +680,14 @@ func TestGetCurrentNext_WithData(t *testing.T) {
func TestGetCurrentNext_WithMultipleDataPoints(t *testing.T) {
ctx, tx := testutils.SetupTestTx(t)
now := clock.Now()
londonNow := clock.Now().In(clock.London)
// Use fixed times within today's London business hours so the handler's
// London-midnight date range always includes both bookings regardless of
// when the test runs (runs near midnight UTC could push one booking
// outside the London "today" window).
todayAt := func(h, m int) time.Time {
return time.Date(londonNow.Year(), londonNow.Month(), londonNow.Day(), h, m, 0, 0, clock.London).UTC()
}
svcID := createTodayService(t, ctx, tx)
user1ID, err := fixtures.CreateTestUser(tx)
@@ -693,7 +700,7 @@ func TestGetCurrentNext_WithMultipleDataPoints(t *testing.T) {
INSERT INTO bookings (user_id, start_time, status)
VALUES ($1, $2, 'completed')
RETURNING id
`, user1ID, now.Add(-30*time.Minute)).Scan(&booking1ID)
`, user1ID, todayAt(10, 0)).Scan(&booking1ID)
if err != nil {
t.Fatalf("failed to create booking 1: %v", err)
}
@@ -725,7 +732,7 @@ func TestGetCurrentNext_WithMultipleDataPoints(t *testing.T) {
INSERT INTO bookings (user_id, start_time, status)
VALUES ($1, $2, 'completed')
RETURNING id
`, user2ID, now.Add(-15*time.Minute)).Scan(&booking2ID)
`, user2ID, todayAt(11, 0)).Scan(&booking2ID)
if err != nil {
t.Fatalf("failed to create booking 2: %v", err)
}