Skip to content

Commit df253f8

Browse files
Merge pull request #4266 from nhsuk/fix-sync-record-on-consent-change
Sync vaccs record to API if `notify_parents` has changed due to consent changes
2 parents 6934ce3 + 89e6fef commit df253f8

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

app/models/concerns/vaccination_record_sync_to_nhs_immunisations_api_concern.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,11 @@ module VaccinationRecordSyncToNHSImmunisationsAPIConcern
55

66
included do
77
scope :syncable_to_nhs_immunisations_api,
8-
-> do
9-
includes(:patient, :programme).where(
10-
notify_parents: true
11-
).recorded_in_service
12-
end
8+
-> { includes(:patient, :programme).recorded_in_service }
139
end
1410

1511
def syncable_to_nhs_immunisations_api?
16-
recorded_in_service? && notify_parents
12+
recorded_in_service?
1713
end
1814

1915
def sync_status

spec/features/invalidate_consent_spec.rb

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,11 @@
5252

5353
scenario "Given self consent, and requested parents aren't notified, and vaccinated, then invalidate" do
5454
given_i_am_signed_in
55-
and_self_consent_has_been_given
56-
and_patient_has_been_vaccinated_with_no_parent_notification
55+
and_the_api_feature_flag_is_enabled
56+
and_self_consent_has_been_given_with_no_parent_notification
57+
58+
when_the_patient_has_been_vaccinated_with_no_parent_notification
59+
then_the_record_is_not_synced_to_the_imms_api
5760

5861
when_i_go_to_the_patient
5962
then_i_see_the_self_consent
@@ -64,7 +67,8 @@
6467
when_i_fill_in_the_notes
6568
and_i_click_invalidate_consent
6669
then_i_see_the_consent_has_been_invalidated
67-
and_the_vaccination_record_is_updated_to_notify_parents
70+
and_the_vaccination_record_is_updated_to_notify_parents_true
71+
and_the_vaccination_record_is_synced_to_the_imms_api
6872
end
6973

7074
def given_i_am_signed_in
@@ -76,6 +80,11 @@ def given_i_am_signed_in
7680
sign_in team.users.first
7781
end
7882

83+
def and_the_api_feature_flag_is_enabled
84+
Flipper.enable(:enqueue_sync_vaccination_records_to_nhs)
85+
Flipper.enable(:immunisations_fhir_api_integration)
86+
end
87+
7988
def and_consent_has_been_given
8089
@consent =
8190
create(:consent, :given, patient: @patient, programme: @programme)
@@ -161,7 +170,7 @@ def and_i_am_not_able_to_record_a_vaccination
161170
expect(page).not_to have_content("ready for their HPV vaccination?")
162171
end
163172

164-
def and_self_consent_has_been_given
173+
def and_self_consent_has_been_given_with_no_parent_notification
165174
@consent =
166175
create(
167176
:consent,
@@ -178,7 +187,7 @@ def and_self_consent_has_been_given
178187
)
179188
end
180189

181-
def and_patient_has_been_vaccinated_with_no_parent_notification
190+
def when_the_patient_has_been_vaccinated_with_no_parent_notification
182191
@vaccination_record =
183192
create(
184193
:vaccination_record,
@@ -197,7 +206,20 @@ def when_i_click_on_the_self_consent
197206
click_on "Child (Gillick competent)"
198207
end
199208

200-
def and_the_vaccination_record_is_updated_to_notify_parents
209+
def and_the_vaccination_record_is_updated_to_notify_parents_true
201210
expect(@vaccination_record.reload.notify_parents).to be true
202211
end
212+
213+
def then_the_record_is_not_synced_to_the_imms_api
214+
@stubbed_post_request =
215+
stub_immunisations_api_post(uuid: @vaccination_record.uuid)
216+
217+
perform_enqueued_jobs(only: SyncVaccinationRecordToNHSJob)
218+
expect(@stubbed_post_request).not_to have_been_requested
219+
end
220+
221+
def and_the_vaccination_record_is_synced_to_the_imms_api
222+
perform_enqueued_jobs(only: SyncVaccinationRecordToNHSJob)
223+
expect(@stubbed_post_request).to have_been_requested
224+
end
203225
end

0 commit comments

Comments
 (0)