Skip to content

Commit fb56247

Browse files
Add tests
1 parent 0c79418 commit fb56247

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
@@ -283,6 +299,59 @@
283299
expect(patient.pending_changes).to include("gender_code" => "male")
284300
end
285301
end
302+
303+
context "with an existing patient with different capitalisation" do
304+
let(:data) do
305+
{
306+
"CHILD_ADDRESS_LINE_1" => "10 Downing Street",
307+
"CHILD_PREFERRED_FIRST_NAME" => "Jim",
308+
"CHILD_DATE_OF_BIRTH" => "2010-01-01",
309+
"CHILD_FIRST_NAME" => "Jimmy",
310+
"CHILD_GENDER" => "Male",
311+
"CHILD_LAST_NAME" => "Smith",
312+
"CHILD_PREFERRED_LAST_NAME" => "Smithy",
313+
"CHILD_NHS_NUMBER" => "9990000018",
314+
"CHILD_POSTCODE" => "sw1a 1aa",
315+
"CHILD_TOWN" => "London"
316+
}
317+
end
318+
319+
let!(:existing_patient) do
320+
create(
321+
:patient,
322+
address_postcode: "SW1A 1AA",
323+
family_name: "SMITH",
324+
gender_code: "male",
325+
given_name: "JIMMY",
326+
nhs_number: "9990000018",
327+
address_line_1: "10 DOWNING STREET",
328+
preferred_given_name: "JIM",
329+
preferred_family_name: "SMITHY",
330+
date_of_birth: Date.new(2010, 1, 1),
331+
address_town: "LONDON"
332+
)
333+
end
334+
335+
it { should eq(existing_patient) }
336+
337+
it "saves the incoming values" do
338+
expect(patient).to have_attributes(
339+
address_postcode: "SW1A 1AA",
340+
family_name: "Smith",
341+
gender_code: "male",
342+
given_name: "Jimmy",
343+
nhs_number: "9990000018",
344+
address_line_1: "10 Downing Street",
345+
preferred_given_name: "Jim",
346+
preferred_family_name: "Smithy",
347+
address_town: "London"
348+
)
349+
end
350+
351+
it "doesn't stage the capitalisation differences" do
352+
expect(patient.pending_changes).to be_empty
353+
end
354+
end
286355
end
287356

288357
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
@@ -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",
@@ -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"
@@ -290,6 +308,60 @@
290308
expect(patient.pending_changes).to include("gender_code" => "male")
291309
end
292310
end
311+
312+
context "with an existing patient with different capitalisation" do
313+
let(:data) do
314+
{
315+
"CHILD_ADDRESS_LINE_1" => "10 Downing Street",
316+
"CHILD_PREFERRED_FIRST_NAME" => "Jim",
317+
"CHILD_DATE_OF_BIRTH" => "2010-01-01",
318+
"CHILD_FIRST_NAME" => "Jimmy",
319+
"CHILD_GENDER" => "Male",
320+
"CHILD_LAST_NAME" => "Smith",
321+
"CHILD_PREFERRED_LAST_NAME" => "Smithy",
322+
"CHILD_NHS_NUMBER" => "9990000018",
323+
"CHILD_POSTCODE" => "sw1a 1aa",
324+
"CHILD_SCHOOL_URN" => school_urn,
325+
"CHILD_TOWN" => "London"
326+
}
327+
end
328+
329+
let!(:existing_patient) do
330+
create(
331+
:patient,
332+
address_postcode: "SW1A 1AA",
333+
family_name: "SMITH",
334+
gender_code: "male",
335+
given_name: "JIMMY",
336+
nhs_number: "9990000018",
337+
address_line_1: "10 DOWNING STREET",
338+
preferred_given_name: "JIM",
339+
preferred_family_name: "SMITHY",
340+
date_of_birth: Date.new(2010, 1, 1),
341+
address_town: "LONDON"
342+
)
343+
end
344+
345+
it { should eq(existing_patient) }
346+
347+
it "saves the incoming values" do
348+
expect(patient).to have_attributes(
349+
address_postcode: "SW1A 1AA",
350+
family_name: "Smith",
351+
gender_code: "male",
352+
given_name: "Jimmy",
353+
nhs_number: "9990000018",
354+
address_line_1: "10 Downing Street",
355+
preferred_given_name: "Jim",
356+
preferred_family_name: "Smithy",
357+
address_town: "London"
358+
)
359+
end
360+
361+
it "doesn't stage the capitalisation differences" do
362+
expect(patient.pending_changes).to be_empty
363+
end
364+
end
293365
end
294366

295367
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)