|
29 | 29 | then_i_see_the_secondary_sessions |
30 | 30 | end |
31 | 31 |
|
| 32 | + scenario "Sending clinic invitations to children in no known school" do |
| 33 | + given_a_team_with_no_known_school_children |
| 34 | + and_i_am_signed_in |
| 35 | + |
| 36 | + when_i_visit_the_schools_page |
| 37 | + and_i_click_on_no_known_school |
| 38 | + then_i_see_the_send_invitations_button |
| 39 | + |
| 40 | + when_i_click_send_clinic_invitations |
| 41 | + and_i_select_programmes_and_send |
| 42 | + then_i_see_the_invitation_confirmation |
| 43 | + and_the_parents_receive_invitations |
| 44 | + end |
| 45 | + |
32 | 46 | def given_a_team_exists_with_a_few_schools |
33 | 47 | programmes = [Programme.flu, Programme.hpv] |
34 | 48 |
|
@@ -134,4 +148,82 @@ def when_i_click_on_edit_session |
134 | 148 | def and_i_click_on_back |
135 | 149 | click_on "Back" |
136 | 150 | end |
| 151 | + |
| 152 | + def given_a_team_with_no_known_school_children |
| 153 | + programmes = [Programme.hpv] |
| 154 | + @team = create(:team, :with_generic_clinic, programmes:) |
| 155 | + @generic_clinic = @team.generic_clinic |
| 156 | + |
| 157 | + @patients = |
| 158 | + 10.times.map do |
| 159 | + create( |
| 160 | + :patient, |
| 161 | + :consent_no_response, |
| 162 | + school: nil, |
| 163 | + parents: [build(:parent)], |
| 164 | + programmes:, |
| 165 | + location: @generic_clinic, |
| 166 | + academic_year: AcademicYear.pending |
| 167 | + ) |
| 168 | + end |
| 169 | + |
| 170 | + # We create these to ensure these children aren't invited. |
| 171 | + create( |
| 172 | + :patient, |
| 173 | + :consent_refused, |
| 174 | + school: nil, |
| 175 | + parents: [build(:parent)], |
| 176 | + programmes:, |
| 177 | + location: @generic_clinic, |
| 178 | + academic_year: AcademicYear.pending |
| 179 | + ) |
| 180 | + create( |
| 181 | + :patient, |
| 182 | + :consent_conflicting, |
| 183 | + school: nil, |
| 184 | + parents: [build(:parent)], |
| 185 | + programmes:, |
| 186 | + location: @generic_clinic, |
| 187 | + academic_year: AcademicYear.pending |
| 188 | + ) |
| 189 | + |
| 190 | + @nurse = create(:nurse, team: @team) |
| 191 | + end |
| 192 | + |
| 193 | + def when_i_visit_the_schools_page |
| 194 | + visit schools_path |
| 195 | + end |
| 196 | + |
| 197 | + def and_i_click_on_no_known_school |
| 198 | + click_on "No known school" |
| 199 | + end |
| 200 | + |
| 201 | + def then_i_see_the_send_invitations_button |
| 202 | + expect(page).to have_content("Send clinic invitations") |
| 203 | + end |
| 204 | + |
| 205 | + def when_i_click_send_clinic_invitations |
| 206 | + click_on "Send clinic invitations" |
| 207 | + end |
| 208 | + |
| 209 | + def and_i_select_programmes_and_send |
| 210 | + check "HPV" |
| 211 | + click_on "Send clinic invitations" |
| 212 | + end |
| 213 | + |
| 214 | + def then_i_see_the_invitation_confirmation |
| 215 | + expect(page).to have_content("10 children invited to the clinic") |
| 216 | + end |
| 217 | + |
| 218 | + def and_the_parents_receive_invitations |
| 219 | + perform_enqueued_jobs |
| 220 | + |
| 221 | + expect(email_deliveries.count).to eq(@patients.count) |
| 222 | + |
| 223 | + @patients.each do |patient| |
| 224 | + patient.parents.each do |parent| |
| 225 | + expect_email_to parent.email, :clinic_initial_invitation, :any |
| 226 | + end |
| 227 | + end |
| 228 | + end |
137 | 229 | end |
0 commit comments