Skip to content

Commit 52da202

Browse files
committed
Fix timezone-dependent appointment notification tests
The tests created appointments using UTC's calendar date, while the schedule interpreted that date in Chicago time. Pin them to noon so the dates agree and the negative case cannot pass against an empty schedule.
1 parent f6d4ea5 commit 52da202

1 file changed

Lines changed: 27 additions & 23 deletions

File tree

test/system/admin/appointments_notifications_test.rb

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,35 +40,39 @@ class AppointmentNotificationsTest < ApplicationSystemTestCase
4040
end
4141

4242
test "a pulled appointment and its late-added items are highlighted in the schedule" do
43-
appointment = create(:appointment, holds: [create(:hold)], starts_at: Time.current, ends_at: 15.minutes.from_now)
44-
appointment.appointment_holds.update_all(created_at: 3.minutes.ago)
45-
appointment.update_column(:pulled_at, 2.minutes.ago)
46-
late_hold = create(:hold, item: create(:item, name: "Circular Saw"))
47-
create(:appointment_hold, appointment: appointment, hold: late_hold, created_at: Time.current)
48-
original_pulled_at = appointment.pulled_at
49-
50-
visit admin_appointments_path(day: appointment.starts_at.to_date)
51-
52-
within "tr.items-added-after-pull" do
53-
assert_text "Circular Saw"
54-
assert_selector ".label.label-error", text: "added after pull"
55-
click_button "mark new items pulled"
43+
Timecop.travel(Time.zone.today.at_noon) do
44+
appointment = create(:appointment, holds: [create(:hold)], starts_at: Time.current, ends_at: 15.minutes.from_now)
45+
appointment.appointment_holds.update_all(created_at: 3.minutes.ago)
46+
appointment.update_column(:pulled_at, 2.minutes.ago)
47+
late_hold = create(:hold, item: create(:item, name: "Circular Saw"))
48+
create(:appointment_hold, appointment: appointment, hold: late_hold, created_at: Time.current)
49+
original_pulled_at = appointment.pulled_at
50+
51+
visit admin_appointments_path(day: appointment.starts_at.to_date)
52+
53+
within "tr.items-added-after-pull" do
54+
assert_text "Circular Saw"
55+
assert_selector ".label.label-error", text: "added after pull"
56+
click_button "mark new items pulled"
57+
end
58+
59+
refute_selector "tr.items-added-after-pull"
60+
refute_selector ".label.label-error", text: "added after pull"
61+
assert_operator appointment.reload.pulled_at, :>, original_pulled_at
5662
end
57-
58-
refute_selector "tr.items-added-after-pull"
59-
refute_selector ".label.label-error", text: "added after pull"
60-
assert_operator appointment.reload.pulled_at, :>, original_pulled_at
6163
end
6264

6365
test "completed appointments with late-added items are not highlighted" do
64-
appointment = create(:appointment, holds: [create(:hold)], starts_at: Time.current, ends_at: 15.minutes.from_now)
65-
appointment.update_columns(pulled_at: Time.current, completed_at: Time.current)
66-
create(:appointment_hold, appointment: appointment, created_at: 1.minute.from_now)
66+
Timecop.travel(Time.zone.today.at_noon) do
67+
appointment = create(:appointment, holds: [create(:hold)], starts_at: Time.current, ends_at: 15.minutes.from_now)
68+
appointment.update_columns(pulled_at: Time.current, completed_at: Time.current)
69+
create(:appointment_hold, appointment: appointment, created_at: 1.minute.from_now)
6770

68-
visit admin_appointments_path(day: appointment.starts_at.to_date)
71+
visit admin_appointments_path(day: appointment.starts_at.to_date)
6972

70-
refute_selector "tr.items-added-after-pull"
71-
refute_selector ".label.label-error", text: "added after pull"
73+
refute_selector "tr.items-added-after-pull"
74+
refute_selector ".label.label-error", text: "added after pull"
75+
end
7276
end
7377
end
7478
end

0 commit comments

Comments
 (0)