Skip to content

Commit 63b0d93

Browse files
committed
Fix ConsentForm#session
This fixes a couple of issues with the method to get the session for the consent form. Firstly this fixes a regression that was added in c5a5879 where if a parent tells us that their child is actually home schooled, the session remains the school session meaning there's a chance they will see the deadline error message if the school session has no more dates (when actually they should fill in consent for the clinic session). Secondly this fixes an issue that was only partially fixed in c5a5879 where we are trying to pick the most approriate session if there are numerous possible candidates (i.e. multiple sessions at the same location with the same programmes). In the original change we prioritised scheduled session over completed sessions, but not unscheduled ones meaning there was still the chance for the wrong session to be selected. I've also tried to improve test coverage to avoid regressions in the future. Jira-Issue: MAV-2036
1 parent 6fa774f commit 63b0d93

5 files changed

Lines changed: 152 additions & 8 deletions

File tree

app/components/app_consent_confirmation_component.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def full_name
3737
end
3838

3939
def panel_text
40-
location = (@consent_form.session.school? ? " at school" : "")
40+
location = (@consent_form.education_setting_school? ? " at school" : "")
4141

4242
if response_given?
4343
if @consent_form.health_answers_require_triage?

app/models/consent_form.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,16 @@ def session
375375
team:
376376
)
377377

378-
sessions_to_search.find { !it.completed? } ||
379-
sessions_to_search.first ||
378+
if (scheduled_session = sessions_to_search.find(&:scheduled?))
379+
return scheduled_session
380+
end
381+
382+
if education_setting_home? || education_setting_none?
380383
team.generic_clinic_session(academic_year:)
384+
else
385+
sessions_to_search.first ||
386+
team.generic_clinic_session(academic_year:)
387+
end
381388
end
382389
end
383390

spec/factories/consent_forms.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@
122122
health_answers { [] }
123123
end
124124

125+
trait :education_setting_home do
126+
education_setting { "home" }
127+
school { nil }
128+
school_confirmed { false }
129+
end
130+
125131
after(:create) do |consent_form, evaluator|
126132
vaccine_methods = evaluator.response == "given" ? %w[injection] : []
127133

spec/features/parental_consent_home_educated_spec.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

3-
describe "Parental consent school" do
4-
scenario "Child attends a different school" do
3+
describe "Parental consent" do
4+
scenario "Child is home-schooled" do
55
given_an_hpv_programme_is_underway
66
when_i_go_to_the_consent_form
77
when_i_fill_in_my_childs_name_and_birthday
@@ -12,7 +12,7 @@
1212
when_i_click_continue
1313
then_i_see_an_error
1414

15-
when_i_choose_a_school
15+
when_i_choose_home_schooled
1616
then_i_see_the_parent_step
1717

1818
and_i_give_consent
@@ -22,7 +22,13 @@
2222

2323
def given_an_hpv_programme_is_underway
2424
@programme = create(:programme, :hpv)
25-
@team = create(:team, :with_one_nurse, programmes: [@programme])
25+
@team =
26+
create(
27+
:team,
28+
:with_one_nurse,
29+
:with_generic_clinic,
30+
programmes: [@programme]
31+
)
2632
location = create(:school, team: @team, name: "Pilot School")
2733
@session =
2834
create(
@@ -72,7 +78,7 @@ def then_i_see_an_error
7278
expect(page).to have_heading "There is a problem"
7379
end
7480

75-
def when_i_choose_a_school
81+
def when_i_choose_home_schooled
7682
select "Home-schooled"
7783
click_on "Continue"
7884
end

spec/models/consent_form_spec.rb

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,131 @@
548548
end
549549
end
550550

551+
describe "#session" do
552+
subject { consent_form.session }
553+
554+
let(:programmes) { [create(:programme, :hpv)] }
555+
let(:team) { create(:team, programmes:) }
556+
557+
let!(:school) { create(:school, team:) }
558+
let!(:generic_clinic) { create(:generic_clinic, team:) }
559+
560+
let!(:generic_clinic_session) do
561+
create(:session, location: generic_clinic, team:, programmes:)
562+
end
563+
564+
context "with a consent form from a school" do
565+
let(:consent_form) do
566+
create(
567+
:consent_form,
568+
team:,
569+
programmes:,
570+
location: school,
571+
academic_year: AcademicYear.current
572+
)
573+
end
574+
575+
context "with no school session" do
576+
it { should eq(generic_clinic_session) }
577+
end
578+
579+
context "with an unscheduled school session" do
580+
let!(:school_session) do
581+
create(:session, :unscheduled, location: school, team:, programmes:)
582+
end
583+
584+
it { should eq(school_session) }
585+
end
586+
587+
context "with an unscheduled and scheduled school session" do
588+
before do
589+
create(:session, :unscheduled, location: school, team:, programmes:)
590+
end
591+
592+
let!(:scheduled_school_session) do
593+
create(:session, :scheduled, location: school, team:, programmes:)
594+
end
595+
596+
it { should eq(scheduled_school_session) }
597+
end
598+
end
599+
600+
context "with a consent form from a school to the clinic" do
601+
let(:consent_form) do
602+
create(
603+
:consent_form,
604+
:education_setting_home,
605+
team:,
606+
programmes:,
607+
location: school,
608+
academic_year: AcademicYear.current
609+
)
610+
end
611+
612+
context "with no school session" do
613+
it { should eq(generic_clinic_session) }
614+
end
615+
616+
context "with an unscheduled school session" do
617+
before do
618+
create(:session, :unscheduled, location: school, team:, programmes:)
619+
end
620+
621+
it { should eq(generic_clinic_session) }
622+
end
623+
624+
context "with an unscheduled and scheduled school session" do
625+
before do
626+
create(:session, :unscheduled, location: school, team:, programmes:)
627+
end
628+
629+
let!(:scheduled_school_session) do
630+
create(:session, :scheduled, location: school, team:, programmes:)
631+
end
632+
633+
# This intentionally returns the school session because the clinic session
634+
# might not be scheduled with dates yet (which is usually the case early
635+
# on at the beginning of the year), and without a session the user sees
636+
# a page saying the deadline has passed.
637+
it { should eq(scheduled_school_session) }
638+
end
639+
end
640+
641+
context "with a consent form from a clinic" do
642+
let(:consent_form) do
643+
create(
644+
:consent_form,
645+
:education_setting_home,
646+
team:,
647+
programmes:,
648+
location: generic_clinic,
649+
academic_year: AcademicYear.current
650+
)
651+
end
652+
653+
context "with no school session" do
654+
it { should eq(generic_clinic_session) }
655+
end
656+
657+
context "with an unscheduled school session" do
658+
before do
659+
create(:session, :unscheduled, location: school, team:, programmes:)
660+
end
661+
662+
it { should eq(generic_clinic_session) }
663+
end
664+
665+
context "with an unscheduled and scheduled school session" do
666+
before do
667+
create(:session, :unscheduled, location: school, team:, programmes:)
668+
create(:session, :scheduled, location: school, team:, programmes:)
669+
end
670+
671+
it { should eq(generic_clinic_session) }
672+
end
673+
end
674+
end
675+
551676
describe "scope unmatched" do
552677
let(:programme) { create(:programme) }
553678
let(:session) { create(:session, programmes: [programme]) }

0 commit comments

Comments
 (0)