|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +describe "Child record imports twins" do |
| 4 | + around { |example| travel_to(Date.new(2024, 12, 1)) { example.run } } |
| 5 | + |
| 6 | + scenario "User reviews and selects between duplicate records" do |
| 7 | + stub_pds_get_nhs_number_to_return_a_patient |
| 8 | + stub_pds_search_to_return_a_patient |
| 9 | + |
| 10 | + given_i_am_signed_in |
| 11 | + and_an_hpv_programme_is_underway |
| 12 | + and_an_existing_patient_record_exists |
| 13 | + |
| 14 | + when_i_visit_the_import_page |
| 15 | + and_i_start_adding_children_to_the_cohort |
| 16 | + and_i_upload_a_file_with_duplicate_records |
| 17 | + then_i_should_see_the_import_page_with_duplicate_records |
| 18 | + then_i_wait_for_the_background_job_to_complete |
| 19 | + |
| 20 | + when_i_review_the_duplicate_record |
| 21 | + then_i_should_see_the_duplicate_record |
| 22 | + |
| 23 | + when_i_choose_to_keep_both_records |
| 24 | + and_i_confirm_my_selection |
| 25 | + then_i_should_see_a_success_message |
| 26 | + and_a_new_patient_record_should_be_created |
| 27 | + end |
| 28 | + |
| 29 | + def given_i_am_signed_in |
| 30 | + @programme = create(:programme, :hpv) |
| 31 | + @team = |
| 32 | + create( |
| 33 | + :team, |
| 34 | + :with_one_nurse, |
| 35 | + :with_generic_clinic, |
| 36 | + programmes: [@programme] |
| 37 | + ) |
| 38 | + |
| 39 | + TeamSessionsFactory.call(@team, academic_year: AcademicYear.current) |
| 40 | + |
| 41 | + sign_in @team.users.first |
| 42 | + end |
| 43 | + |
| 44 | + def and_an_hpv_programme_is_underway |
| 45 | + @school = create(:school, urn: "123456", team: @team) |
| 46 | + @session = |
| 47 | + create(:session, team: @team, location: @school, programmes: [@programme]) |
| 48 | + end |
| 49 | + |
| 50 | + def and_an_existing_patient_record_exists |
| 51 | + @existing_patient = |
| 52 | + create( |
| 53 | + :patient, |
| 54 | + given_name: "John", |
| 55 | + family_name: "Doe", |
| 56 | + nhs_number: "9000000009", |
| 57 | + date_of_birth: Date.new(2010, 1, 3), |
| 58 | + gender_code: :male, |
| 59 | + address_line_1: "11 Downing Street", |
| 60 | + address_line_2: "", |
| 61 | + address_town: "London", |
| 62 | + address_postcode: "SW1A 1AA", |
| 63 | + school: @school, |
| 64 | + team: @team, |
| 65 | + session: @session |
| 66 | + ) |
| 67 | + end |
| 68 | + |
| 69 | + def when_i_visit_the_import_page |
| 70 | + visit "/" |
| 71 | + click_link "Import", match: :first |
| 72 | + end |
| 73 | + |
| 74 | + def and_i_start_adding_children_to_the_cohort |
| 75 | + click_button "Import records" |
| 76 | + choose "Child records" |
| 77 | + click_button "Continue" |
| 78 | + end |
| 79 | + |
| 80 | + def and_i_upload_a_file_with_duplicate_records |
| 81 | + attach_file("cohort_import[csv]", "spec/fixtures/cohort_import/valid.csv") |
| 82 | + click_on "Continue" |
| 83 | + end |
| 84 | + |
| 85 | + def then_i_should_see_the_import_page_with_duplicate_records |
| 86 | + expect(page).to have_content("1 duplicate record needs review") |
| 87 | + end |
| 88 | + |
| 89 | + def then_i_wait_for_the_background_job_to_complete |
| 90 | + perform_enqueued_jobs |
| 91 | + end |
| 92 | + |
| 93 | + def when_i_review_the_duplicate_record |
| 94 | + click_on "Review DOE, John" |
| 95 | + end |
| 96 | + |
| 97 | + def then_i_should_see_the_duplicate_record |
| 98 | + expect(page).to have_content("This record needs reviewing") |
| 99 | + expect(page).to have_content("NHS number944 930 6168\nFull nameDOE, Mark") |
| 100 | + expect(page).to have_content("NHS number900 000 0009\nFull nameDOE, John") |
| 101 | + end |
| 102 | + |
| 103 | + def when_i_choose_to_keep_both_records |
| 104 | + choose "Keep both records" |
| 105 | + end |
| 106 | + |
| 107 | + def and_i_confirm_my_selection |
| 108 | + click_on "Resolve duplicate" |
| 109 | + end |
| 110 | + |
| 111 | + def then_i_should_see_a_success_message |
| 112 | + expect(page).to have_content("Record updated") |
| 113 | + end |
| 114 | + |
| 115 | + def and_a_new_patient_record_should_be_created |
| 116 | + expect(Patient.count).to eq(2) |
| 117 | + |
| 118 | + patient = Patient.last |
| 119 | + expect(patient.address_postcode).to eq("SW1A 1AA") |
| 120 | + expect(patient.date_of_birth).to eq(Date.new(2010, 1, 3)) |
| 121 | + expect(patient.family_name).to eq("Doe") |
| 122 | + expect(patient.gender_code).to eq("male") |
| 123 | + expect(patient.given_name).to eq("Mark") |
| 124 | + expect(patient.nhs_number).to eq("9449306168") |
| 125 | + expect(patient.pending_changes).to eq({}) |
| 126 | + expect(patient.school).to eq(@school) |
| 127 | + |
| 128 | + expect(patient.sessions.count).to eq(1) |
| 129 | + expect(patient.sessions).to include(@session) |
| 130 | + end |
| 131 | +end |
0 commit comments