|
42 | 42 | let(:parents) { create_list(:parent, 2) } |
43 | 43 | let(:patient) { create(:patient, parents:, year_group: 10) } |
44 | 44 | let(:programme) { create(:programme, :td_ipv) } |
45 | | - let(:organisation) { create(:organisation, programmes: [programme]) } |
| 45 | + let(:programmes) { [programme] } |
| 46 | + let(:organisation) { create(:organisation, programmes:) } |
46 | 47 | let(:location) { create(:school, organisation:) } |
47 | | - let(:session) do |
48 | | - create(:session, location:, programmes: [programme], organisation:) |
49 | | - end |
| 48 | + let(:session) { create(:session, location:, programmes:, organisation:) } |
50 | 49 | let(:session_date) { session.dates.min } |
51 | 50 | let(:patient_session) { create(:patient_session, patient:, session:) } |
52 | 51 | let(:current_user) { create(:user) } |
|
58 | 57 |
|
59 | 58 | let(:parent) { parents.first } |
60 | 59 |
|
61 | | - before { create(:consent, :given, patient:, parent:, programme:) } |
| 60 | + before do |
| 61 | + create(:consent, :given, patient:, parent:, programme:) |
| 62 | + create(:patient_consent_status, :given, patient:, programme:) |
| 63 | + end |
62 | 64 |
|
63 | 65 | it "creates a record" do |
64 | 66 | expect { create_and_send! }.to change(described_class, :count).by(1) |
|
73 | 75 | it "enqueues an email per parent who gave consent" do |
74 | 76 | expect { create_and_send! }.to have_delivered_email( |
75 | 77 | :session_school_reminder |
76 | | - ).with(parent:, patient:, session:, sent_by: current_user) |
| 78 | + ).with(parent:, patient:, programmes:, session:, sent_by: current_user) |
77 | 79 | end |
78 | 80 |
|
79 | 81 | it "enqueues a text per parent" do |
80 | 82 | expect { create_and_send! }.to have_delivered_sms( |
81 | 83 | :session_school_reminder |
82 | | - ).with(parent:, patient:, session:, sent_by: current_user) |
| 84 | + ).with(parent:, patient:, programmes:, session:, sent_by: current_user) |
83 | 85 | end |
84 | 86 |
|
85 | 87 | context "when parent doesn't want to receive updates by text" do |
86 | | - before { parents.each { _1.update!(phone_receive_updates: false) } } |
| 88 | + before { parents.each { it.update!(phone_receive_updates: false) } } |
87 | 89 |
|
88 | 90 | it "doesn't enqueues a text" do |
89 | 91 | expect { create_and_send! }.not_to have_delivered_sms |
90 | 92 | end |
91 | 93 | end |
| 94 | + |
| 95 | + context "with multiple programmes but only one eligible for vaccination" do |
| 96 | + let(:consented_programmes) { [programme] } |
| 97 | + |
| 98 | + # No consent for MenACWY |
| 99 | + let(:programmes) do |
| 100 | + consented_programmes + [create(:programme, :menacwy)] |
| 101 | + end |
| 102 | + |
| 103 | + it "enqueues an email per parent who gave consent" do |
| 104 | + expect { create_and_send! }.to have_delivered_email( |
| 105 | + :session_school_reminder |
| 106 | + ).with( |
| 107 | + parent:, |
| 108 | + patient:, |
| 109 | + programmes: consented_programmes, |
| 110 | + session:, |
| 111 | + sent_by: current_user |
| 112 | + ) |
| 113 | + end |
| 114 | + |
| 115 | + it "enqueues a text per parent" do |
| 116 | + expect { create_and_send! }.to have_delivered_sms( |
| 117 | + :session_school_reminder |
| 118 | + ).with( |
| 119 | + parent:, |
| 120 | + patient:, |
| 121 | + programmes: consented_programmes, |
| 122 | + session:, |
| 123 | + sent_by: current_user |
| 124 | + ) |
| 125 | + end |
| 126 | + end |
92 | 127 | end |
93 | 128 |
|
94 | 129 | context "with an initial clinic invitation" do |
|
110 | 145 | ).with( |
111 | 146 | parent: parents.first, |
112 | 147 | patient:, |
| 148 | + programmes:, |
113 | 149 | session:, |
114 | 150 | sent_by: current_user |
115 | 151 | ).and have_delivered_email(:session_clinic_initial_invitation).with( |
116 | 152 | parent: parents.second, |
117 | 153 | patient:, |
| 154 | + programmes:, |
118 | 155 | session:, |
119 | 156 | sent_by: current_user |
120 | 157 | ) |
|
126 | 163 | ).with( |
127 | 164 | parent: parents.first, |
128 | 165 | patient:, |
| 166 | + programmes:, |
129 | 167 | session:, |
130 | 168 | sent_by: current_user |
131 | 169 | ).and have_delivered_sms(:session_clinic_initial_invitation).with( |
132 | 170 | parent: parents.second, |
133 | 171 | patient:, |
| 172 | + programmes:, |
134 | 173 | session:, |
135 | 174 | sent_by: current_user |
136 | 175 | ) |
|
144 | 183 | it "still enqueues a text" do |
145 | 184 | expect { create_and_send! }.to have_delivered_sms( |
146 | 185 | :session_clinic_initial_invitation |
147 | | - ).with(parent:, patient:, session:, sent_by: current_user) |
| 186 | + ).with( |
| 187 | + parent:, |
| 188 | + patient:, |
| 189 | + programmes:, |
| 190 | + session:, |
| 191 | + sent_by: current_user |
| 192 | + ) |
148 | 193 | end |
149 | 194 | end |
150 | 195 | end |
|
168 | 213 | ).with( |
169 | 214 | parent: parents.first, |
170 | 215 | patient:, |
| 216 | + programmes:, |
171 | 217 | session:, |
172 | 218 | sent_by: current_user |
173 | 219 | ).and have_delivered_email(:session_clinic_subsequent_invitation).with( |
174 | 220 | parent: parents.second, |
175 | 221 | patient:, |
| 222 | + programmes:, |
176 | 223 | session:, |
177 | 224 | sent_by: current_user |
178 | 225 | ) |
|
184 | 231 | ).with( |
185 | 232 | parent: parents.first, |
186 | 233 | patient:, |
| 234 | + programmes:, |
187 | 235 | session:, |
188 | 236 | sent_by: current_user |
189 | 237 | ).and have_delivered_sms(:session_clinic_subsequent_invitation).with( |
190 | 238 | parent: parents.second, |
191 | 239 | patient:, |
| 240 | + programmes:, |
192 | 241 | session:, |
193 | 242 | sent_by: current_user |
194 | 243 | ) |
|
202 | 251 | it "still enqueues a text" do |
203 | 252 | expect { create_and_send! }.to have_delivered_sms( |
204 | 253 | :session_clinic_subsequent_invitation |
205 | | - ).with(parent:, patient:, session:, sent_by: current_user) |
| 254 | + ).with( |
| 255 | + parent:, |
| 256 | + patient:, |
| 257 | + programmes:, |
| 258 | + session:, |
| 259 | + sent_by: current_user |
| 260 | + ) |
206 | 261 | end |
207 | 262 | end |
208 | 263 | end |
|
0 commit comments