Skip to content

Commit 525d89a

Browse files
Add tests
1 parent eecc9f0 commit 525d89a

File tree

5 files changed

+216
-2
lines changed

5 files changed

+216
-2
lines changed

spec/models/class_import_row_spec.rb

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,22 @@
146146
expect(parents.first.full_name).to eq("John Smith")
147147
end
148148
end
149+
150+
context "when uploading different caps name" do
151+
let!(:existing_parent) do
152+
create(:parent, full_name: "JENNY SMITH", email: "jenny@example.com")
153+
end
154+
155+
let(:capitalised_parent_2_data) do
156+
{
157+
"PARENT_2_EMAIL" => "jenny@example.com",
158+
"PARENT_2_NAME" => "Jenny Smith"
159+
}
160+
end
161+
let(:data) { valid_data.merge(capitalised_parent_2_data) }
162+
163+
it { should include(existing_parent) }
164+
end
149165
end
150166

151167
describe "#to_patient" do
@@ -216,6 +232,60 @@
216232
end
217233
end
218234
end
235+
236+
context "with an existing patient with different capitalisation" do
237+
let(:data) do
238+
{
239+
"CHILD_ADDRESS_LINE_1" => "10 Downing Street",
240+
"CHILD_ADDRESS_LINE_2" => "",
241+
"CHILD_PREFERRED_FIRST_NAME" => "Jim",
242+
"CHILD_DATE_OF_BIRTH" => "2010-01-01",
243+
"CHILD_FIRST_NAME" => "Jimmy",
244+
"CHILD_GENDER" => "Male",
245+
"CHILD_LAST_NAME" => "Smith",
246+
"CHILD_PREFERRED_LAST_NAME" => "Smithy",
247+
"CHILD_NHS_NUMBER" => "1234567890",
248+
"CHILD_POSTCODE" => "sw1a 1aa",
249+
"CHILD_TOWN" => "London"
250+
}
251+
end
252+
253+
let!(:existing_patient) do
254+
create(
255+
:patient,
256+
address_postcode: "SW1A 1AA",
257+
family_name: "SMITH",
258+
gender_code: "male",
259+
given_name: "JIMMY",
260+
nhs_number: "1234567890",
261+
address_line_1: "10 DOWNING STREET",
262+
preferred_given_name: "JIM",
263+
preferred_family_name: "SMITHY",
264+
date_of_birth: Date.new(2010, 1, 1),
265+
address_town: "LONDON"
266+
)
267+
end
268+
269+
it { should eq(existing_patient) }
270+
271+
it "saves the incoming values" do
272+
expect(patient).to have_attributes(
273+
address_postcode: "SW1A 1AA",
274+
family_name: "Smith",
275+
gender_code: "male",
276+
given_name: "Jimmy",
277+
nhs_number: "1234567890",
278+
address_line_1: "10 Downing Street",
279+
preferred_given_name: "Jim",
280+
preferred_family_name: "Smithy",
281+
address_town: "London"
282+
)
283+
end
284+
285+
it "doesn't stage the capitalisation differences" do
286+
expect(patient.pending_changes).to be_empty
287+
end
288+
end
219289
end
220290

221291
describe "#to_parent_relationships" do

spec/models/class_import_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,21 @@
332332
end
333333
end
334334

335+
context "with an existing parent matching the name but a different case" do
336+
let!(:existing_parent) do
337+
create(:parent, full_name: "JOHN smith", email: "john@example.com")
338+
end
339+
340+
it "doesn't create an additional parent" do
341+
expect { process! }.to change(Parent, :count).by(4)
342+
end
343+
344+
it "changes the parent's name to the incoming version" do
345+
process!
346+
expect(existing_parent.reload.full_name).to eq("John Smith")
347+
end
348+
end
349+
335350
context "with an existing patient in a different school" do
336351
let(:patient) do
337352
create(:patient, nhs_number: "1234567890", school: create(:school))

spec/models/cohort_import_row_spec.rb

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
{
2626
"CHILD_ADDRESS_LINE_1" => "10 Downing Street",
2727
"CHILD_ADDRESS_LINE_2" => "",
28-
"CHILD_PREFERRED_GIVEN_NAME" => "Jim",
28+
"CHILD_PREFERRED_FIRST_NAME" => "Jim",
2929
"CHILD_DATE_OF_BIRTH" => "2010-01-01",
3030
"CHILD_FIRST_NAME" => "Jimmy",
3131
"CHILD_GENDER" => "Male",
@@ -166,6 +166,22 @@
166166
)
167167
end
168168
end
169+
170+
context "when uploading different caps name" do
171+
let(:capitalised_parent_2_data) do
172+
{
173+
"PARENT_2_EMAIL" => "jenny@example.com",
174+
"PARENT_2_NAME" => "Jenny Smith"
175+
}
176+
end
177+
let(:data) { valid_data.merge(capitalised_parent_2_data) }
178+
179+
let!(:existing_parent) do
180+
create(:parent, full_name: "JENNY SMITH", email: "jenny@example.com")
181+
end
182+
183+
it { should eq([existing_parent]) }
184+
end
169185
end
170186

171187
describe "#to_patient" do
@@ -221,6 +237,61 @@
221237
expect(patient.pending_changes).to include("registration" => "8AB")
222238
end
223239
end
240+
241+
context "with an existing patient with different capitalisation" do
242+
let(:data) do
243+
{
244+
"CHILD_ADDRESS_LINE_1" => "10 Downing Street",
245+
"CHILD_ADDRESS_LINE_2" => "",
246+
"CHILD_PREFERRED_FIRST_NAME" => "Jim",
247+
"CHILD_DATE_OF_BIRTH" => "2010-01-01",
248+
"CHILD_FIRST_NAME" => "Jimmy",
249+
"CHILD_GENDER" => "Male",
250+
"CHILD_LAST_NAME" => "Smith",
251+
"CHILD_PREFERRED_LAST_NAME" => "Smithy",
252+
"CHILD_NHS_NUMBER" => "1234567890",
253+
"CHILD_POSTCODE" => "sw1a 1aa",
254+
"CHILD_SCHOOL_URN" => school_urn,
255+
"CHILD_TOWN" => "London"
256+
}
257+
end
258+
259+
let!(:existing_patient) do
260+
create(
261+
:patient,
262+
address_postcode: "SW1A 1AA",
263+
family_name: "SMITH",
264+
gender_code: "male",
265+
given_name: "JIMMY",
266+
nhs_number: "1234567890",
267+
address_line_1: "10 DOWNING STREET",
268+
preferred_given_name: "JIM",
269+
preferred_family_name: "SMITHY",
270+
date_of_birth: Date.new(2010, 1, 1),
271+
address_town: "LONDON"
272+
)
273+
end
274+
275+
it { should eq(existing_patient) }
276+
277+
it "saves the incoming values" do
278+
expect(patient).to have_attributes(
279+
address_postcode: "SW1A 1AA",
280+
family_name: "Smith",
281+
gender_code: "male",
282+
given_name: "Jimmy",
283+
nhs_number: "1234567890",
284+
address_line_1: "10 Downing Street",
285+
preferred_given_name: "Jim",
286+
preferred_family_name: "Smithy",
287+
address_town: "London"
288+
)
289+
end
290+
291+
it "doesn't stage the capitalisation differences" do
292+
expect(patient.pending_changes).to be_empty
293+
end
294+
end
224295
end
225296

226297
describe "#to_school_move" do

spec/models/cohort_import_spec.rb

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@
298298
end
299299

300300
context "with an existing patient matching the name but a different case" do
301-
before do
301+
let!(:existing_patient) do
302302
create(
303303
:patient,
304304
given_name: "JIMMY",
@@ -312,6 +312,37 @@
312312
it "doesn't create an additional patient" do
313313
expect { process! }.to change(Patient, :count).by(2)
314314
end
315+
316+
it "doesn't stage the changes to the names" do
317+
process!
318+
expect(existing_patient.reload.pending_changes).not_to have_key(
319+
"given_name"
320+
)
321+
expect(existing_patient.reload.pending_changes).not_to have_key(
322+
"family_name"
323+
)
324+
end
325+
326+
it "automatically accepts the incoming case differences" do
327+
process!
328+
expect(existing_patient.reload.given_name).to eq("Jimmy")
329+
expect(existing_patient.reload.family_name).to eq("Smith")
330+
end
331+
end
332+
333+
context "with an existing parent matching the name but a different case" do
334+
let!(:existing_parent) do
335+
create(:parent, full_name: "JOHN smith", email: "john@example.com")
336+
end
337+
338+
it "doesn't create an additional parent" do
339+
expect { process! }.to change(Parent, :count).by(2)
340+
end
341+
342+
it "changes the parent's name to the incoming version" do
343+
process!
344+
expect(existing_parent.reload.full_name).to eq("John Smith")
345+
end
315346
end
316347

317348
context "with an unscheduled session" do

spec/models/immunisation_import_row_spec.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,6 +1497,33 @@
14971497
end
14981498
end
14991499

1500+
context "with an existing matching patient but mismatching capitalisation, without NHS number" do
1501+
let(:data) do
1502+
valid_data.except("NHS_NUMBER").merge(
1503+
{
1504+
"PERSON_FORENAME" => "RON",
1505+
"PERSON_SURNAME" => "WEASLEY",
1506+
"PERSON_POSTCODE" => "sw1a 1aa"
1507+
}
1508+
)
1509+
end
1510+
1511+
let!(:existing_patient) do
1512+
create(
1513+
:patient,
1514+
given_name: "Ron",
1515+
family_name: "Weasley",
1516+
date_of_birth: Date.parse(date_of_birth),
1517+
address_postcode:,
1518+
nhs_number: "1234567890"
1519+
)
1520+
end
1521+
1522+
it "still matches to a patient" do
1523+
expect(patient).to eq(existing_patient)
1524+
end
1525+
end
1526+
15001527
describe "#address_postcode" do
15011528
subject { patient.address_postcode }
15021529

0 commit comments

Comments
 (0)