Skip to content

Commit c6f8b2a

Browse files
committed
Don't show today's date in session reminder
This fixes the session reminder email to ensure that if there's a session date today and one tomorrow, we show tomorrow's date in the email and not today's date.
1 parent cee71df commit c6f8b2a

8 files changed

Lines changed: 33 additions & 17 deletions

File tree

app/components/app_programme_session_table_component.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
Last session completed <%= session.dates.max&.to_fs(:long) %>
3838
<% else %>
3939
<% if session.started? %>
40-
Next session starts <%= session.next_date.to_fs(:long) %>
40+
Next session starts <%= session.next_date(include_today: true).to_fs(:long) %>
4141
<% else %>
42-
First session starts <%= session.next_date.to_fs(:long) %>
42+
First session starts <%= session.next_date(include_today: true).to_fs(:long) %>
4343
<% end %>
4444

4545
<br />

app/controllers/sessions/invite_to_clinic_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def set_generic_clinic_session
4848
end
4949

5050
def set_invitations_to_send
51-
session_date = @generic_clinic_session.next_date
51+
session_date = @generic_clinic_session.next_date(include_today: true)
5252

5353
@invitations_to_send =
5454
if @session.school?

app/jobs/send_clinic_initial_invitations_job.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class SendClinicInitialInvitationsJob < ApplicationJob
88
def perform(session, school:, programmes:)
99
raise InvalidLocation unless session.clinic?
1010

11-
session_date = session.next_date
11+
session_date = session.next_date(include_today: true)
1212
raise NoSessionDates if session_date.nil?
1313

1414
patient_sessions(

app/jobs/send_clinic_subsequent_invitations_job.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class SendClinicSubsequentInvitationsJob < ApplicationJob
88
def perform(session)
99
raise InvalidLocation unless session.clinic?
1010

11-
session_date = session.next_date
11+
session_date = session.next_date(include_today: true)
1212
raise NoSessionDates if session_date.nil?
1313

1414
patient_sessions(session, session_date:).each do |patient_session|

app/lib/govuk_notify_personalisation.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,19 +138,16 @@ def location_name
138138
end
139139

140140
def next_session_date
141-
session.next_date&.to_fs(:short_day_of_week)
141+
session.next_date(include_today: false)&.to_fs(:short_day_of_week)
142142
end
143143

144144
def next_session_dates
145-
session
146-
.today_or_future_dates
147-
.map { _1.to_fs(:short_day_of_week) }
148-
.to_sentence
145+
session.future_dates.map { it.to_fs(:short_day_of_week) }.to_sentence
149146
end
150147

151148
def next_session_dates_or
152149
session
153-
.today_or_future_dates
150+
.future_dates
154151
.map { _1.to_fs(:short_day_of_week) }
155152
.to_sentence(last_word_connector: ", or ", two_words_connector: " or ")
156153
end

app/models/session.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,15 @@ def dates
163163
end
164164

165165
def today_or_future_dates
166-
dates.select { _1.today? || _1.future? }
166+
dates.select { it.today? || it.future? }
167167
end
168168

169169
def future_dates
170170
dates.select(&:future?)
171171
end
172172

173-
def next_date
174-
today_or_future_dates.first
173+
def next_date(include_today:)
174+
(include_today ? today_or_future_dates : future_dates).first
175175
end
176176

177177
def can_change_notification_dates?
@@ -180,9 +180,10 @@ def can_change_notification_dates?
180180

181181
def can_send_clinic_invitations?
182182
if clinic?
183-
next_date && !completed?
183+
next_date(include_today: true) && !completed?
184184
else
185-
completed? && organisation.generic_clinic_session.next_date
185+
completed? &&
186+
organisation.generic_clinic_session.next_date(include_today: true)
186187
end
187188
end
188189

app/views/sessions/invite_to_clinic/edit.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<% end %>
3030
<% end %>
3131

32-
<p>The next clinic is on <%= @generic_clinic_session.next_date.to_fs(:long) %>.</p>
32+
<p>The next clinic is on <%= @generic_clinic_session.next_date(include_today: true).to_fs(:long) %>.</p>
3333

3434
<% if @invitations_to_send == 0 %>
3535
<p><%= link_to "Return to session", session_path(@session) %></p>

spec/lib/govuk_notify_personalisation_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,24 @@
7777
)
7878
end
7979

80+
context "when the session is today" do
81+
let(:session) do
82+
create(
83+
:session,
84+
location:,
85+
organisation:,
86+
programmes:,
87+
dates: [Date.current, Date.tomorrow]
88+
)
89+
end
90+
91+
it "doesn't show today's date" do
92+
expect(to_h).to include(
93+
next_session_date: Date.tomorrow.to_fs(:short_day_of_week)
94+
)
95+
end
96+
end
97+
8098
context "when patient is in Year 9" do
8199
let(:patient) do
82100
create(

0 commit comments

Comments
 (0)