Skip to content

Commit 5e461c8

Browse files
committed
Add a test for uploading twins
This adds a feature test to cover the scenario where twins are uploaded with the same last name, address and date of birth one after the other, ensuring that the separate NHS numbers are shown in the duplicate resolution screen.
1 parent c60e24a commit 5e461c8

File tree

1 file changed

+129
-0
lines changed

1 file changed

+129
-0
lines changed
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
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_cohort_page_for_the_hpv_programme
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+
@organisation = create(:organisation, :with_one_nurse)
31+
sign_in @organisation.users.first
32+
end
33+
34+
def and_an_hpv_programme_is_underway
35+
programme = create(:programme, :hpv, organisations: [@organisation])
36+
37+
@school = create(:school, urn: "123456", organisation: @organisation)
38+
@session =
39+
create(
40+
:session,
41+
organisation: @organisation,
42+
location: @school,
43+
programmes: [programme]
44+
)
45+
end
46+
47+
def and_an_existing_patient_record_exists
48+
@existing_patient =
49+
create(
50+
:patient,
51+
given_name: "John",
52+
family_name: "Doe",
53+
nhs_number: "9000000009",
54+
date_of_birth: Date.new(2010, 1, 3),
55+
gender_code: :male,
56+
address_line_1: "11 Downing Street",
57+
address_line_2: "",
58+
address_town: "London",
59+
address_postcode: "SW1A 1AA",
60+
school: @school,
61+
organisation: @organisation,
62+
session: @session
63+
)
64+
end
65+
66+
def when_i_visit_the_cohort_page_for_the_hpv_programme
67+
visit "/"
68+
click_link "Programmes", match: :first
69+
click_link "HPV"
70+
click_link "Cohorts"
71+
end
72+
73+
def and_i_start_adding_children_to_the_cohort
74+
click_link "Import child records"
75+
end
76+
77+
def and_i_upload_a_file_with_duplicate_records
78+
attach_file("cohort_import[csv]", "spec/fixtures/cohort_import/valid.csv")
79+
click_on "Continue"
80+
end
81+
82+
def then_i_should_see_the_import_page_with_duplicate_records
83+
expect(page).to have_content("1 duplicate record needs review")
84+
end
85+
86+
def then_i_wait_for_the_background_job_to_complete
87+
perform_enqueued_jobs
88+
end
89+
90+
def when_i_review_the_duplicate_record
91+
click_on "Review DOE, John"
92+
end
93+
94+
def then_i_should_see_the_duplicate_record
95+
expect(page).to have_content("This record needs reviewing")
96+
expect(page).to have_content("NHS number944 ‍930 ‍6168\nFull nameDOE, Mark")
97+
expect(page).to have_content("NHS number900 ‍000 ‍0009\nFull nameDOE, John")
98+
end
99+
100+
def when_i_choose_to_keep_both_records
101+
choose "Keep both records"
102+
end
103+
104+
def and_i_confirm_my_selection
105+
click_on "Resolve duplicate"
106+
end
107+
108+
def then_i_should_see_a_success_message
109+
expect(page).to have_content("Record updated")
110+
end
111+
112+
def and_a_new_patient_record_should_be_created
113+
expect(Patient.count).to eq(2)
114+
115+
patient = Patient.last
116+
expect(patient.address_postcode).to eq("SW1A 1AA")
117+
expect(patient.date_of_birth).to eq(Date.new(2010, 1, 3))
118+
expect(patient.family_name).to eq("Doe")
119+
expect(patient.gender_code).to eq("male")
120+
expect(patient.given_name).to eq("Mark")
121+
expect(patient.nhs_number).to eq("9449306168")
122+
expect(patient.pending_changes).to eq({})
123+
expect(patient.school).to eq(@school)
124+
expect(patient.sessions.count).to eq(2)
125+
126+
session = patient.sessions.first
127+
expect(session).to eq(@session)
128+
end
129+
end

0 commit comments

Comments
 (0)