Skip to content

Commit 8079c8d

Browse files
committed
Handle past consent request dates for active sessions
Fixes a QA-reported case where a child added to a session made active today could end up with the programme status "Needs consent - No response" instead of being treated as "Needs consent - Request not scheduled" The issue was that `status_should_be_request_not_scheduled?` only checked whether `send_consent_requests_at` was missing, and did not account for it already being in the past. That can happen when a new session is created and activated on the same day. Jira-Issue: MAV-6059
1 parent 37e3b42 commit 8079c8d

6 files changed

Lines changed: 31 additions & 12 deletions

File tree

app/lib/status_generator/consent.rb

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,23 @@ def parents_contactable? = parents.any?(&:contactable?)
177177

178178
def status_should_be_request_scheduled?
179179
parents_contactable? && consent_notifications.empty? &&
180-
sessions.any? do
181-
# Not using send_consent_requests_at.future?
182-
# because it doesn't work with Timecop.
183-
it.send_consent_requests_at &&
184-
it.send_consent_requests_at > Time.current
185-
end
180+
sessions.any? { consent_request_scheduled_in_future?(it) }
186181
end
187182

188183
def status_should_be_request_not_scheduled?
189184
parents_contactable? && consent_notifications.empty? &&
190-
(sessions.empty? || sessions.any? { it.send_consent_requests_at.nil? })
185+
(sessions.empty? || sessions.any? { consent_request_not_scheduled?(it) })
186+
end
187+
188+
def consent_request_scheduled_in_future?(session)
189+
send_at = session.send_consent_requests_at
190+
191+
# Not using future? because it doesn't work with Timecop
192+
send_at.present? && send_at > Time.current
193+
end
194+
195+
def consent_request_not_scheduled?(session)
196+
send_at = session.send_consent_requests_at
197+
send_at.nil? || send_at < Time.current
191198
end
192199
end

spec/components/app_patient_session_consent_component_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
it { should_not have_content(/Consent (given|refused)/) }
1616
it { should_not have_css("details", text: /Consent (given|refused) by/) }
1717
it { should_not have_css("details", text: "Responses to health questions") }
18-
it { should have_css("p", text: "No requests have been sent.") }
18+
it { should have_css("p", text: "No consent request is scheduled") }
1919
it { should have_css("button", text: "Record a new consent response") }
2020

2121
context "when session is not in progress" do

spec/features/invalidate_consent_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def when_i_click_back
159159
end
160160

161161
def and_i_am_not_able_to_record_a_vaccination
162-
expect(page).to have_content("No response")
162+
expect(page).to have_content("Request not scheduled")
163163
expect(page).not_to have_content("ready for their HPV vaccination?")
164164
end
165165

spec/features/vaccination_programmes_spec.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,10 @@ def and_the_table_shows_other_eligible_vaccinations
110110
"td.nhsuk-table__cell",
111111
text: "Needs consent"
112112
)
113-
expect(row).to have_selector("td.nhsuk-table__cell", text: "No response")
113+
expect(row).to have_selector(
114+
"td.nhsuk-table__cell",
115+
text: "Request not scheduled"
116+
)
114117
end
115118

116119
expect(page).to have_selector(
@@ -121,7 +124,10 @@ def and_the_table_shows_other_eligible_vaccinations
121124
"td.nhsuk-table__cell",
122125
text: "Needs consent"
123126
)
124-
expect(row).to have_selector("td.nhsuk-table__cell", text: "No response")
127+
expect(row).to have_selector(
128+
"td.nhsuk-table__cell",
129+
text: "Request not scheduled"
130+
)
125131
end
126132
end
127133

spec/lib/patient_programme_status_resolver_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
prefix: "MMR",
126126
text: "Needs consent",
127127
colour: "blue",
128-
details_text: "No response"
128+
details_text: "Request not scheduled"
129129
}
130130
)
131131
end

spec/lib/status_generator/consent_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@
4848
context "with consent requests not scheduled" do
4949
it { should be(:request_not_scheduled) }
5050
end
51+
52+
context "when consent requests scheduled date has already passed" do
53+
let(:send_consent_requests_at) { 1.day.ago.to_date }
54+
55+
it { should be(:request_not_scheduled) }
56+
end
5157
end
5258

5359
context "with no contactable parents" do

0 commit comments

Comments
 (0)