Skip to content

Commit 6c2dd65

Browse files
Add feature tests
Tests the case where no edits are made to the vaccination record between download and upload, for Imms API records.
1 parent 4aa4dc8 commit 6c2dd65

File tree

1 file changed

+149
-0
lines changed

1 file changed

+149
-0
lines changed

spec/features/hpv_vaccination_offline_spec.rb

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,42 @@
6666
and_the_vaccination_record_is_deleted_from_nhs
6767
end
6868

69+
scenario "User tries to edit vaccination record sourced from NHS immunisations API in offline workflow" do
70+
given_a_flu_programme_is_underway_with_a_single_patient
71+
and_the_patients_record_is_sourced_from_nhs_api
72+
73+
when_i_choose_to_record_offline_from_a_school_session_page
74+
and_alter_an_existing_vaccination_record_to_create_a_duplicate
75+
and_i_upload_the_modified_csv_file
76+
then_i_see_a_duplicate_record_needs_review
77+
78+
when_i_review_the_duplicate_record
79+
then_i_should_see_the_nhs_api_restriction_message
80+
and_i_should_only_see_discard_option
81+
and_i_should_not_see_radio_buttons
82+
83+
when_i_discard_the_incoming_changes
84+
then_i_should_see_a_success_message
85+
and_the_nhs_api_record_should_remain_unchanged
86+
87+
when_i_go_to_the_import_page
88+
then_i_should_see_no_import_issues_with_the_count
89+
end
90+
91+
scenario "User can upload un-edited vaccination records sourced from NHS immunisations API in offline workflow" do
92+
given_a_flu_programme_is_underway_with_a_single_patient
93+
and_the_patients_record_is_sourced_from_nhs_api
94+
95+
when_i_choose_to_record_offline_from_a_school_session_page
96+
and_i_save_the_csv_file
97+
and_i_upload_the_modified_csv_file
98+
then_i_see_that_no_records_need_review
99+
and_the_nhs_api_record_should_remain_unchanged
100+
101+
when_i_go_to_the_import_page
102+
then_i_should_see_no_import_issues_with_the_count
103+
end
104+
69105
def given_an_hpv_programme_is_underway(clinic: false)
70106
programmes = [create(:programme, :hpv)]
71107

@@ -180,6 +216,38 @@ def given_an_hpv_programme_is_underway_with_a_single_patient
180216
)
181217
end
182218

219+
def given_a_flu_programme_is_underway_with_a_single_patient
220+
programmes = [create(:programme, :flu)]
221+
222+
@team = create(:team, :with_one_nurse, :with_generic_clinic, programmes:)
223+
school = create(:school, team: @team)
224+
previous_date = 1.month.ago
225+
226+
vaccine = programmes.first.vaccines.active.first
227+
@batch = create(:batch, :not_expired, team: @team, vaccine:)
228+
229+
@session =
230+
create(:session, :today, team: @team, programmes:, location: school)
231+
232+
@session.session_dates.create!(value: previous_date)
233+
234+
@previously_vaccinated_patient =
235+
create(:patient, session: @session, school:, year_group: 8)
236+
end
237+
238+
def and_the_patients_record_is_sourced_from_nhs_api
239+
fhir_record =
240+
FHIR.from_contents(file_fixture("fhir/fhir_record_full.json").read)
241+
@nhs_api_vaccination_record =
242+
FHIRMapper::VaccinationRecord.from_fhir_record(
243+
fhir_record,
244+
patient: @previously_vaccinated_patient
245+
)
246+
@nhs_api_vaccination_record.performed_at = 1.month.ago
247+
@nhs_api_vaccination_record.notes = "Imported from NHS API"
248+
@nhs_api_vaccination_record.save!
249+
end
250+
183251
def and_imms_api_sync_job_feature_is_enabled
184252
Flipper.enable(:imms_api_sync_job)
185253
Flipper.enable(:imms_api_integration)
@@ -191,6 +259,65 @@ def and_imms_api_sync_job_feature_is_enabled
191259
stub_immunisations_api_delete(uuid: immunisation_uuid)
192260
end
193261

262+
def and_i_upload_a_file_with_duplicate_nhs_api_records
263+
visit "/"
264+
click_on "Import", match: :first
265+
click_on "Import records"
266+
choose "Vaccination records"
267+
click_on "Continue"
268+
269+
attach_file(
270+
"immunisation_import[csv]",
271+
"spec/fixtures/immunisation_import/valid_hpv_offline_spreadsheet.csv"
272+
)
273+
click_on "Continue"
274+
wait_for_import_to_complete(ImmunisationImport)
275+
end
276+
277+
def when_i_review_the_nhs_api_duplicate_record
278+
click_link "Review"
279+
end
280+
281+
def then_i_should_see_the_nhs_api_restriction_message
282+
expect(page).to have_content("You cannot keep the incoming changes")
283+
expect(page).to have_content(
284+
"The existing record was imported automatically from an external source, such as a GP practice, meaning that " \
285+
"Mavis is not the primary source for this vaccination record."
286+
)
287+
end
288+
289+
def and_i_should_only_see_discard_option
290+
expect(page).to have_button("Discard incoming changes")
291+
end
292+
293+
def and_i_should_not_see_radio_buttons
294+
expect(page).not_to have_content("Apply the uploaded changes")
295+
expect(page).not_to have_content("Keep the existing record")
296+
expect(page).not_to have_selector("input[type='radio']")
297+
end
298+
299+
def when_i_discard_the_incoming_changes
300+
click_button "Discard incoming changes"
301+
end
302+
303+
def and_the_nhs_api_record_should_remain_unchanged
304+
@nhs_api_vaccination_record.reload
305+
expect(@nhs_api_vaccination_record.notes).to eq("Imported from NHS API")
306+
expect(@nhs_api_vaccination_record.source).to eq("nhs_immunisations_api")
307+
expect(@nhs_api_vaccination_record.outcome).to eq("administered")
308+
expect(@nhs_api_vaccination_record.delivery_site).to eq(
309+
"left_arm_upper_position"
310+
)
311+
end
312+
313+
def when_i_go_to_the_import_page
314+
click_link "Import", match: :first
315+
end
316+
317+
def then_i_should_see_no_import_issues_with_the_count
318+
expect(page).to have_content("Import issues (0)")
319+
end
320+
194321
def when_i_choose_to_record_offline_from_a_school_session_page
195322
sign_in @team.users.first
196323
visit session_path(@session)
@@ -235,6 +362,24 @@ def and_alter_an_existing_vaccination_record_to_create_a_duplicate
235362
File.write("tmp/modified.csv", csv_table.to_csv)
236363
end
237364

365+
def and_i_save_the_csv_file
366+
expect(page.status_code).to eq(200)
367+
368+
@workbook = RubyXL::Parser.parse_buffer(page.body)
369+
@sheet = @workbook["Vaccinations"]
370+
@headers = @sheet[0].cells.map(&:value)
371+
372+
array = @workbook[0].to_a[1..].map(&:cells).map { it.map(&:value) }
373+
csv_table =
374+
CSV::Table.new(
375+
array.map do |row|
376+
CSV::Row.new(@headers, row.map { |cell| excel_cell_to_csv(cell) })
377+
end
378+
)
379+
380+
File.write("tmp/modified.csv", csv_table.to_csv)
381+
end
382+
238383
def when_i_change_the_vaccination_outcome_to_not_vaccinated
239384
csv_table = CSV.read("tmp/modified.csv", headers: true)
240385

@@ -479,6 +624,10 @@ def then_i_see_a_duplicate_record_needs_review
479624
)
480625
end
481626

627+
def then_i_see_that_no_records_need_review
628+
expect(page).not_to have_content("has import issues")
629+
end
630+
482631
def then_i_should_see_a_success_message
483632
expect(page).to have_content("Record updated")
484633
end

0 commit comments

Comments
 (0)