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:
@@ -680,7 +680,14 @@ func TestGetCurrentNext_WithData(t *testing.T) {
|
|||||||
func TestGetCurrentNext_WithMultipleDataPoints(t *testing.T) {
|
func TestGetCurrentNext_WithMultipleDataPoints(t *testing.T) {
|
||||||
ctx, tx := testutils.SetupTestTx(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)
|
svcID := createTodayService(t, ctx, tx)
|
||||||
|
|
||||||
user1ID, err := fixtures.CreateTestUser(tx)
|
user1ID, err := fixtures.CreateTestUser(tx)
|
||||||
@@ -693,7 +700,7 @@ func TestGetCurrentNext_WithMultipleDataPoints(t *testing.T) {
|
|||||||
INSERT INTO bookings (user_id, start_time, status)
|
INSERT INTO bookings (user_id, start_time, status)
|
||||||
VALUES ($1, $2, 'completed')
|
VALUES ($1, $2, 'completed')
|
||||||
RETURNING id
|
RETURNING id
|
||||||
`, user1ID, now.Add(-30*time.Minute)).Scan(&booking1ID)
|
`, user1ID, todayAt(10, 0)).Scan(&booking1ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to create booking 1: %v", err)
|
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)
|
INSERT INTO bookings (user_id, start_time, status)
|
||||||
VALUES ($1, $2, 'completed')
|
VALUES ($1, $2, 'completed')
|
||||||
RETURNING id
|
RETURNING id
|
||||||
`, user2ID, now.Add(-15*time.Minute)).Scan(&booking2ID)
|
`, user2ID, todayAt(11, 0)).Scan(&booking2ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to create booking 2: %v", err)
|
t.Fatalf("failed to create booking 2: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user