Skip to content

Commit 2719233

Browse files
Add tests
1 parent 8198558 commit 2719233

File tree

5 files changed

+222
-6
lines changed

5 files changed

+222
-6
lines changed

spec/models/class_import_row_spec.rb

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,22 @@
157157
expect(parents.first.full_name).to eq("John Smith")
158158
end
159159
end
160+
161+
context "when uploading different caps name" do
162+
let!(:existing_parent) do
163+
create(:parent, full_name: "JENNY SMITH", email: "jenny@example.com")
164+
end
165+
166+
let(:capitalised_parent_2_data) do
167+
{
168+
"PARENT_2_EMAIL" => "jenny@example.com",
169+
"PARENT_2_NAME" => "Jenny Smith"
170+
}
171+
end
172+
let(:data) { valid_data.merge(capitalised_parent_2_data) }
173+
174+
it { should include(existing_parent) }
175+
end
160176
end
161177

162178
describe "#to_patient" do
@@ -416,6 +432,59 @@
416432
expect(patient.pending_changes).to be_empty
417433
end
418434
end
435+
436+
context "with an existing patient with different capitalisation" do
437+
let(:data) do
438+
{
439+
"CHILD_ADDRESS_LINE_1" => "10 Downing Street",
440+
"CHILD_PREFERRED_FIRST_NAME" => "Jim",
441+
"CHILD_DATE_OF_BIRTH" => "2010-01-01",
442+
"CHILD_FIRST_NAME" => "Jimmy",
443+
"CHILD_GENDER" => "Male",
444+
"CHILD_LAST_NAME" => "Smith",
445+
"CHILD_PREFERRED_LAST_NAME" => "Smithy",
446+
"CHILD_NHS_NUMBER" => "9990000018",
447+
"CHILD_POSTCODE" => "sw1a 1aa",
448+
"CHILD_TOWN" => "London"
449+
}
450+
end
451+
452+
let!(:existing_patient) do
453+
create(
454+
:patient,
455+
address_postcode: "SW1A 1AA",
456+
family_name: "SMITH",
457+
gender_code: "male",
458+
given_name: "JIMMY",
459+
nhs_number: "9990000018",
460+
address_line_1: "10 DOWNING STREET",
461+
preferred_given_name: "JIM",
462+
preferred_family_name: "SMITHY",
463+
date_of_birth: Date.new(2010, 1, 1),
464+
address_town: "LONDON"
465+
)
466+
end
467+
468+
it { should eq(existing_patient) }
469+
470+
it "saves the incoming values" do
471+
expect(patient).to have_attributes(
472+
address_postcode: "SW1A 1AA",
473+
family_name: "Smith",
474+
gender_code: "male",
475+
given_name: "Jimmy",
476+
nhs_number: "9990000018",
477+
address_line_1: "10 Downing Street",
478+
preferred_given_name: "Jim",
479+
preferred_family_name: "Smithy",
480+
address_town: "London"
481+
)
482+
end
483+
484+
it "doesn't stage the capitalisation differences" do
485+
expect(patient.pending_changes).to be_empty
486+
end
487+
end
419488
end
420489

421490
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: "9990000018", school: create(:school))

spec/models/cohort_import_row_spec.rb

Lines changed: 79 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"CHILD_ADDRESS_LINE_2" => "",
2828
"CHILD_TOWN" => "London",
2929
"CHILD_POSTCODE" => "SW1A 1AA",
30-
"CHILD_PREFERRED_GIVEN_NAME" => "Jim",
30+
"CHILD_PREFERRED_FIRST_NAME" => "Jim",
3131
"CHILD_DATE_OF_BIRTH" => "2010-01-01",
3232
"CHILD_FIRST_NAME" => "Jimmy",
3333
"CHILD_GENDER" => "Male",
@@ -177,6 +177,22 @@
177177
)
178178
end
179179
end
180+
181+
context "when uploading different caps name" do
182+
let(:capitalised_parent_2_data) do
183+
{
184+
"PARENT_2_EMAIL" => "jenny@example.com",
185+
"PARENT_2_NAME" => "Jenny Smith"
186+
}
187+
end
188+
let(:data) { valid_data.merge(capitalised_parent_2_data) }
189+
190+
let!(:existing_parent) do
191+
create(:parent, full_name: "JENNY SMITH", email: "jenny@example.com")
192+
end
193+
194+
it { should eq([existing_parent]) }
195+
end
180196
end
181197

182198
describe "#to_patient" do
@@ -241,6 +257,7 @@
241257
family_name: "Smith",
242258
gender_code: "not_known",
243259
given_name: "Jimmy",
260+
preferred_given_name: "Jim",
244261
nhs_number: "9990000018",
245262
address_line_1: "10 Downing Street",
246263
address_line_2: "",
@@ -266,14 +283,15 @@
266283
let!(:existing_patient) do
267284
create(
268285
:patient,
286+
address_line_1: "10 Downing Street",
287+
address_line_2: "",
288+
address_town: "London",
269289
address_postcode: "SW1A 1AA",
290+
given_name: "Jimmy",
270291
family_name: "Smith",
292+
preferred_given_name: "Jim",
271293
gender_code: "female",
272-
given_name: "Jimmy",
273294
nhs_number: "9990000018",
274-
address_line_1: "10 Downing Street",
275-
address_line_2: "",
276-
address_town: "London",
277295
birth_academic_year: 2009,
278296
date_of_birth: Date.new(2010, 1, 1),
279297
registration: "8AB"
@@ -297,6 +315,7 @@
297315
:patient,
298316
family_name: "Smith",
299317
given_name: "Jimmy",
318+
preferred_given_name: "Jim",
300319
gender_code: "male",
301320
nhs_number: "9990000018",
302321
birth_academic_year: 2009,
@@ -331,6 +350,7 @@
331350
:patient,
332351
family_name: "Smith",
333352
given_name: "Jimmy",
353+
preferred_given_name: "Jim",
334354
gender_code: "male",
335355
nhs_number: "9990000018",
336356
birth_academic_year: 2009,
@@ -396,6 +416,60 @@
396416
)
397417
end
398418
end
419+
420+
context "with an existing patient with different capitalisation" do
421+
let(:data) do
422+
{
423+
"CHILD_ADDRESS_LINE_1" => "10 Downing Street",
424+
"CHILD_PREFERRED_FIRST_NAME" => "Jim",
425+
"CHILD_DATE_OF_BIRTH" => "2010-01-01",
426+
"CHILD_FIRST_NAME" => "Jimmy",
427+
"CHILD_GENDER" => "Male",
428+
"CHILD_LAST_NAME" => "Smith",
429+
"CHILD_PREFERRED_LAST_NAME" => "Smithy",
430+
"CHILD_NHS_NUMBER" => "9990000018",
431+
"CHILD_POSTCODE" => "sw1a 1aa",
432+
"CHILD_SCHOOL_URN" => school_urn,
433+
"CHILD_TOWN" => "London"
434+
}
435+
end
436+
437+
let!(:existing_patient) do
438+
create(
439+
:patient,
440+
address_postcode: "SW1A 1AA",
441+
family_name: "SMITH",
442+
gender_code: "male",
443+
given_name: "JIMMY",
444+
nhs_number: "9990000018",
445+
address_line_1: "10 DOWNING STREET",
446+
preferred_given_name: "JIM",
447+
preferred_family_name: "SMITHY",
448+
date_of_birth: Date.new(2010, 1, 1),
449+
address_town: "LONDON"
450+
)
451+
end
452+
453+
it { should eq(existing_patient) }
454+
455+
it "saves the incoming values" do
456+
expect(patient).to have_attributes(
457+
address_postcode: "SW1A 1AA",
458+
family_name: "Smith",
459+
gender_code: "male",
460+
given_name: "Jimmy",
461+
nhs_number: "9990000018",
462+
address_line_1: "10 Downing Street",
463+
preferred_given_name: "Jim",
464+
preferred_family_name: "Smithy",
465+
address_town: "London"
466+
)
467+
end
468+
469+
it "doesn't stage the capitalisation differences" do
470+
expect(patient.pending_changes).to be_empty
471+
end
472+
end
399473
end
400474

401475
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 existing patient that was previously removed from cohort" do

spec/models/immunisation_import_row_spec.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,6 +1451,33 @@
14511451
end
14521452
end
14531453

1454+
context "with an existing matching patient but mismatching capitalisation, without NHS number" do
1455+
let(:data) do
1456+
valid_data.except("NHS_NUMBER").merge(
1457+
{
1458+
"PERSON_FORENAME" => "RON",
1459+
"PERSON_SURNAME" => "WEASLEY",
1460+
"PERSON_POSTCODE" => "sw1a 1aa"
1461+
}
1462+
)
1463+
end
1464+
1465+
let!(:existing_patient) do
1466+
create(
1467+
:patient,
1468+
given_name: "Ron",
1469+
family_name: "Weasley",
1470+
date_of_birth: Date.parse(date_of_birth),
1471+
address_postcode:,
1472+
nhs_number: "9990000018"
1473+
)
1474+
end
1475+
1476+
it "still matches to a patient" do
1477+
expect(patient).to eq(existing_patient)
1478+
end
1479+
end
1480+
14541481
describe "#address_postcode" do
14551482
subject { patient.address_postcode }
14561483

0 commit comments

Comments
 (0)