Skip to content

Commit b6f8b99

Browse files
Add tests
1 parent 05f46b9 commit b6f8b99

File tree

5 files changed

+220
-6
lines changed

5 files changed

+220
-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
@@ -373,6 +389,59 @@
373389
)
374390
end
375391
end
392+
393+
context "with an existing patient with different capitalisation" do
394+
let(:data) do
395+
{
396+
"CHILD_ADDRESS_LINE_1" => "10 Downing Street",
397+
"CHILD_PREFERRED_FIRST_NAME" => "Jim",
398+
"CHILD_DATE_OF_BIRTH" => "2010-01-01",
399+
"CHILD_FIRST_NAME" => "Jimmy",
400+
"CHILD_GENDER" => "Male",
401+
"CHILD_LAST_NAME" => "Smith",
402+
"CHILD_PREFERRED_LAST_NAME" => "Smithy",
403+
"CHILD_NHS_NUMBER" => "9990000018",
404+
"CHILD_POSTCODE" => "sw1a 1aa",
405+
"CHILD_TOWN" => "London"
406+
}
407+
end
408+
409+
let!(:existing_patient) do
410+
create(
411+
:patient,
412+
address_postcode: "SW1A 1AA",
413+
family_name: "SMITH",
414+
gender_code: "male",
415+
given_name: "JIMMY",
416+
nhs_number: "9990000018",
417+
address_line_1: "10 DOWNING STREET",
418+
preferred_given_name: "JIM",
419+
preferred_family_name: "SMITHY",
420+
date_of_birth: Date.new(2010, 1, 1),
421+
address_town: "LONDON"
422+
)
423+
end
424+
425+
it { should eq(existing_patient) }
426+
427+
it "saves the incoming values" do
428+
expect(patient).to have_attributes(
429+
address_postcode: "SW1A 1AA",
430+
family_name: "Smith",
431+
gender_code: "male",
432+
given_name: "Jimmy",
433+
nhs_number: "9990000018",
434+
address_line_1: "10 Downing Street",
435+
preferred_given_name: "Jim",
436+
preferred_family_name: "Smithy",
437+
address_town: "London"
438+
)
439+
end
440+
441+
it "doesn't stage the capitalisation differences" do
442+
expect(patient.pending_changes).to be_empty
443+
end
444+
end
376445
end
377446

378447
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: 77 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"
@@ -362,6 +380,60 @@
362380
)
363381
end
364382
end
383+
384+
context "with an existing patient with different capitalisation" do
385+
let(:data) do
386+
{
387+
"CHILD_ADDRESS_LINE_1" => "10 Downing Street",
388+
"CHILD_PREFERRED_FIRST_NAME" => "Jim",
389+
"CHILD_DATE_OF_BIRTH" => "2010-01-01",
390+
"CHILD_FIRST_NAME" => "Jimmy",
391+
"CHILD_GENDER" => "Male",
392+
"CHILD_LAST_NAME" => "Smith",
393+
"CHILD_PREFERRED_LAST_NAME" => "Smithy",
394+
"CHILD_NHS_NUMBER" => "9990000018",
395+
"CHILD_POSTCODE" => "sw1a 1aa",
396+
"CHILD_SCHOOL_URN" => school_urn,
397+
"CHILD_TOWN" => "London"
398+
}
399+
end
400+
401+
let!(:existing_patient) do
402+
create(
403+
:patient,
404+
address_postcode: "SW1A 1AA",
405+
family_name: "SMITH",
406+
gender_code: "male",
407+
given_name: "JIMMY",
408+
nhs_number: "9990000018",
409+
address_line_1: "10 DOWNING STREET",
410+
preferred_given_name: "JIM",
411+
preferred_family_name: "SMITHY",
412+
date_of_birth: Date.new(2010, 1, 1),
413+
address_town: "LONDON"
414+
)
415+
end
416+
417+
it { should eq(existing_patient) }
418+
419+
it "saves the incoming values" do
420+
expect(patient).to have_attributes(
421+
address_postcode: "SW1A 1AA",
422+
family_name: "Smith",
423+
gender_code: "male",
424+
given_name: "Jimmy",
425+
nhs_number: "9990000018",
426+
address_line_1: "10 Downing Street",
427+
preferred_given_name: "Jim",
428+
preferred_family_name: "Smithy",
429+
address_town: "London"
430+
)
431+
end
432+
433+
it "doesn't stage the capitalisation differences" do
434+
expect(patient.pending_changes).to be_empty
435+
end
436+
end
365437
end
366438

367439
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: "9990000018"
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)