Skip to content

Commit 49ca379

Browse files
committed
Normalise parent phone numbers with Phonelib
* format national numbers with spaces * save non-GB numbers in an international format * handle leading zeros being stripped (when handling CSVs in Excel, for instance)
1 parent aa17674 commit 49ca379

11 files changed

+34
-27
lines changed

app/models/parent.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ class Parent < ApplicationRecord
4242
encrypts :email, :full_name, :phone, deterministic: true
4343
encrypts :contact_method_other_details
4444

45-
normalizes :phone, with: -> { _1.blank? ? nil : _1.to_s.gsub(/\s/, "") }
45+
normalizes :phone,
46+
with: ->(phone) do
47+
Phonelib
48+
.parse(phone)
49+
.then { |p| p.country == "GB" ? p.national : p.international }
50+
end
4651
normalizes :email, with: -> { _1.blank? ? nil : _1.to_s.downcase.strip }
4752

4853
validates :phone,

spec/components/app_parent_summary_component_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
let(:parent) { create(:parent, phone: "07987654321") }
3030

3131
it { should have_content("Phone number") }
32-
it { should have_content("07987654321") }
32+
it { should have_content("07987 654321") }
3333
end
3434

3535
context "when the patient is restricted" do

spec/features/scheduled_consent_requests_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ def then_all_four_parents_received_consent_requests
121121
expect_email_to("parent1.child2@example.com", :consent_school_request, :any)
122122
expect_email_to("parent2.child2@example.com", :consent_school_request, :any)
123123

124-
expect_text_to("07700900000", :consent_school_request, :any)
125-
expect_text_to("07700900001", :consent_school_request, :any)
126-
expect_text_to("07700900002", :consent_school_request, :any)
127-
expect_text_to("07700900003", :consent_school_request, :any)
124+
expect_text_to("07700 900000", :consent_school_request, :any)
125+
expect_text_to("07700 900001", :consent_school_request, :any)
126+
expect_text_to("07700 900002", :consent_school_request, :any)
127+
expect_text_to("07700 900003", :consent_school_request, :any)
128128
end
129129
end

spec/features/verbal_consent_given_by_new_parental_contact_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def and_i_can_see_the_parents_details_on_the_consent_response
8080
expect(page).to have_content(["Name", "Jane Smith"].join)
8181
expect(page).to have_content(%w[Relationship Mum].join)
8282
expect(page).to have_content(["Email address", "jsmith@example.com"].join)
83-
expect(page).to have_content(["Phone number", "07987654321"].join)
83+
expect(page).to have_content(["Phone number", "07987 654321"].join)
8484
end
8585

8686
def then_an_email_is_sent_to_the_parent_confirming_their_consent

spec/jobs/text_delivery_job_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
let(:template_name) { GOVUK_NOTIFY_TEXT_TEMPLATES.keys.first }
3939
let(:programme) { create(:programme) }
4040
let(:session) { create(:session, programme:) }
41-
let(:parent) { create(:parent, phone: "01234567890") }
41+
let(:parent) { create(:parent, phone: "01234 567890") }
4242
let(:consent) { nil }
4343
let(:consent_form) { nil }
4444
let(:patient) { create(:patient) }
@@ -62,7 +62,7 @@
6262

6363
it "sends a text using GOV.UK Notify" do
6464
expect(notifications_client).to receive(:send_sms).with(
65-
phone_number: "01234567890",
65+
phone_number: "01234 567890",
6666
template_id: GOVUK_NOTIFY_TEXT_TEMPLATES[template_name],
6767
personalisation: an_instance_of(Hash)
6868
)
@@ -74,7 +74,7 @@
7474

7575
notify_log_entry = NotifyLogEntry.last
7676
expect(notify_log_entry).to be_sms
77-
expect(notify_log_entry.recipient).to eq("01234567890")
77+
expect(notify_log_entry.recipient).to eq("01234 567890")
7878
expect(notify_log_entry.template_id).to eq(
7979
GOVUK_NOTIFY_TEXT_TEMPLATES[template_name]
8080
)

spec/models/class_import_row_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
expect(parents.count).to eq(1)
6868
expect(parents.first).to have_attributes(
6969
email: "john@example.com",
70-
phone: "07412345678",
70+
phone: "07412 345678",
7171
phone_receive_updates: false
7272
)
7373
end
@@ -79,11 +79,11 @@
7979
expect(parents.count).to eq(2)
8080
expect(parents.first).to have_attributes(
8181
email: "john@example.com",
82-
phone: "07412345678"
82+
phone: "07412 345678"
8383
)
8484
expect(parents.second).to have_attributes(
8585
email: "jenny@example.com",
86-
phone: "07412345678"
86+
phone: "07412 345678"
8787
)
8888
end
8989
end

spec/models/class_import_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@
179179

180180
expect(Patient.first.parents.first).to have_attributes(
181181
full_name: nil,
182-
phone: "07412345678",
182+
phone: "07412 345678",
183183
email: "susan@example.com"
184184
)
185185

@@ -197,7 +197,7 @@
197197

198198
expect(Patient.second.parents.first).to have_attributes(
199199
full_name: "John Smith",
200-
phone: "07412345678",
200+
phone: "07412 345678",
201201
email: "john@example.com"
202202
)
203203

@@ -217,7 +217,7 @@
217217

218218
expect(Patient.third.parents.first).to have_attributes(
219219
full_name: "Jane Doe",
220-
phone: "07412345679",
220+
phone: "07412 345679",
221221
email: "jane@example.com"
222222
)
223223

spec/models/cohort_import_row_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
expect(parents.first).to have_attributes(
9292
full_name: "John Smith",
9393
email: "john@example.com",
94-
phone: "07412345678",
94+
phone: "07412 345678",
9595
phone_receive_updates: false
9696
)
9797
end
@@ -105,12 +105,12 @@
105105
expect(parents.first).to have_attributes(
106106
full_name: "John Smith",
107107
email: "john@example.com",
108-
phone: "07412345678"
108+
phone: "07412 345678"
109109
)
110110
expect(parents.second).to have_attributes(
111111
full_name: "Jenny Smith",
112112
email: "jenny@example.com",
113-
phone: "07412345678"
113+
phone: "07412 345678"
114114
)
115115
end
116116
end

spec/models/cohort_import_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@
185185

186186
expect(Patient.second.parents.first).to have_attributes(
187187
full_name: "John Smith",
188-
phone: "07412345678",
188+
phone: "07412 345678",
189189
email: "john@example.com"
190190
)
191191

@@ -205,13 +205,13 @@
205205

206206
expect(Patient.third.parents.first).to have_attributes(
207207
full_name: "Jane Doe",
208-
phone: "07412345679",
208+
phone: "07412 345679",
209209
email: "jane@example.com"
210210
)
211211

212212
expect(Patient.third.parents.first).to have_attributes(
213213
full_name: "Jane Doe",
214-
phone: "07412345679",
214+
phone: "07412 345679",
215215
email: "jane@example.com"
216216
)
217217

spec/models/consent_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
expect(consent.parent).to have_attributes(
121121
full_name: consent_form.parent_full_name,
122122
email: consent_form.parent_email,
123-
phone: consent_form.parent_phone,
123+
phone: Phonelib.parse(consent_form.parent_phone).national,
124124
phone_receive_updates: consent_form.parent_phone_receive_updates
125125
)
126126
end
@@ -144,7 +144,7 @@
144144
expect(consent.parent).to have_attributes(
145145
full_name: consent_form.parent_full_name,
146146
email: consent_form.parent_email,
147-
phone: consent_form.parent_phone,
147+
phone: Phonelib.parse(consent_form.parent_phone).national,
148148
phone_receive_updates: consent_form.parent_phone_receive_updates
149149
)
150150
end

0 commit comments

Comments
 (0)