33require_relative "../../app/lib/mavis_cli"
44
55describe "mavis schools show" do
6+ before do
7+ # To ensure Rainbow doesn't insert escape codes into the output
8+ Rainbow . enabled = false
9+ end
10+
611 context "with just a URN" do
712 it "displays the school details" do
813 given_a_school_exists
914 when_i_run_the_command
1015 then_the_school_details_are_displayed
16+ and_the_programme_year_groups_are_displayed
1117 end
1218 end
1319
2733 end
2834 end
2935
36+ context "with a team that has patients in a variety of states" do
37+ it "displays the school details" do
38+ given_a_school_exists
39+ and_the_school_has_patients_across_academic_years
40+ when_i_run_the_command_with_the_show_patients_option
41+ then_the_correct_patient_counts_are_displayed
42+ end
43+ end
44+
3045 def given_a_school_exists
31- @school = create ( :school , name : "Test School" , urn : "123456" )
46+ team = create ( :team , programme_types : %w[ flu hpv ] )
47+ @school =
48+ create (
49+ :school ,
50+ name : "Test School" ,
51+ urn : "123456" ,
52+ team :
53+ ) . tap do |location |
54+ location . import_year_groups_from_gias! (
55+ academic_year : AcademicYear . previous
56+ )
57+
58+ location . import_default_programme_year_groups! (
59+ [ Programme . flu ] ,
60+ academic_year : AcademicYear . previous
61+ )
62+ end
63+ end
64+
65+ def and_the_school_has_patients_across_academic_years
66+ location = school = @school
67+ session =
68+ create (
69+ :session ,
70+ location :,
71+ team : @school . teams . first ,
72+ programmes : [ Programme . flu ]
73+ )
74+ session_last_year =
75+ create (
76+ :session ,
77+ location :,
78+ team : @school . teams . first ,
79+ date : Date . new ( AcademicYear . previous , 11 , 1 ) ,
80+ programmes : [ Programme . flu ]
81+ )
82+
83+ # patient in current academic years
84+ create ( :patient , school : @school , location : @school )
85+
86+ # patient in previous academic years
87+ create ( :patient , academic_year : AcademicYear . previous , school :, location :)
88+
89+ # patient in current and previous academic years
90+ create (
91+ :patient ,
92+ :in_attendance ,
93+ school :,
94+ location :,
95+ session :
96+ ) . tap do |patient |
97+ create (
98+ :patient_location ,
99+ patient :,
100+ location :,
101+ academic_year : AcademicYear . previous
102+ )
103+ end
104+
105+ # patient with attendance record in previous academic year
106+ create (
107+ :patient ,
108+ academic_year : AcademicYear . previous ,
109+ school :,
110+ location :,
111+ session : session_last_year
112+ ) . tap do |patient |
113+ create (
114+ :attendance_record ,
115+ :present ,
116+ patient :,
117+ session : session_last_year ,
118+ date : session_last_year . dates . first
119+ )
120+ end
121+
122+ # patient with gillick assessment in current academic year
123+ create ( :patient , school :, location :, session :) . tap do |patient |
124+ create ( :gillick_assessment , :competent , patient :, session :)
125+ end
126+
127+ # patient with gillick assessment record in previous academic year
128+ create (
129+ :patient ,
130+ school :,
131+ location :,
132+ session : session_last_year
133+ ) . tap do |patient |
134+ create (
135+ :gillick_assessment ,
136+ :competent ,
137+ patient :,
138+ session : session_last_year
139+ )
140+ end
32141 end
33142
34143 def given_a_school_with_sites_exists
@@ -61,6 +170,15 @@ def when_i_run_the_command_with_the_any_site_option
61170 end
62171 end
63172
173+ def when_i_run_the_command_with_the_show_patients_option
174+ @output =
175+ capture_output do
176+ Dry ::CLI . new ( MavisCLI ) . call (
177+ arguments : %w[ schools show --show-patients ] + [ @school . urn ]
178+ )
179+ end
180+ end
181+
64182 def then_the_school_details_are_displayed
65183 expect ( @output ) . to match ( /name.*Test School/ )
66184 expect ( @output ) . to match ( /urn.*123456/ )
@@ -71,4 +189,19 @@ def then_the_school_details_with_sites_are_displayed
71189 expect ( @output ) . to match ( /urn.*123456/ )
72190 expect ( @output ) . to match ( /site.*B/ )
73191 end
192+
193+ def and_the_programme_year_groups_are_displayed
194+ expect ( @output ) . to match (
195+ /flu:\s *year groups: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11/
196+ )
197+ expect ( @output ) . to match ( /hpv:\s *year groups: 8, 9, 10, 11/ )
198+ end
199+
200+ def then_the_correct_patient_counts_are_displayed
201+ expect ( @output ) . to match ( /^total patients: 7/ )
202+ expect ( @output ) . to match ( /^ in current academic year: 3/ )
203+ expect ( @output ) . to match ( /^ with attendance records: 1/ )
204+ expect ( @output ) . to match ( /^ with gillick assessments: 1/ )
205+ expect ( @output ) . to match ( /^ safe to destroy: 1/ )
206+ end
74207end
0 commit comments