fix(whatsapp): handle partial Brazil phone numbers
This commit is contained in:
@@ -14,7 +14,7 @@ class Whatsapp::PhoneNormalizers::BrazilPhoneNormalizer < Whatsapp::PhoneNormali
|
||||
return waid unless handles_country?(waid)
|
||||
|
||||
ddd = waid[COUNTRY_CODE_LENGTH, DDD_LENGTH]
|
||||
number = waid[COUNTRY_CODE_LENGTH + DDD_LENGTH, waid.length - (COUNTRY_CODE_LENGTH + DDD_LENGTH)]
|
||||
number = waid[(COUNTRY_CODE_LENGTH + DDD_LENGTH)..].to_s
|
||||
return waid unless number.match?(LEGACY_MOBILE_NUMBER_PATTERN)
|
||||
|
||||
"55#{ddd}9#{number}"
|
||||
|
||||
@@ -29,15 +29,6 @@ class Whatsapp::PhoneNumberNormalizationService
|
||||
existing_contact_inbox&.source_id || raw_number
|
||||
end
|
||||
|
||||
# @param clean_number [String] Phone number in clean cloud format, e.g. "5541988887777"
|
||||
# @return [String] Country-normalized number, or the original when no normalizer applies
|
||||
def normalize_number(clean_number)
|
||||
normalizer = find_normalizer_for_country(clean_number)
|
||||
return clean_number unless normalizer
|
||||
|
||||
normalizer.normalize(clean_number)
|
||||
end
|
||||
|
||||
# Keep the provider value first so exact contact matches always win. Each
|
||||
# country normalizer explicitly opts into contact-safe alternatives; source-id
|
||||
# normalization alone is not enough because the alternate may be another
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe Whatsapp::PhoneNormalizers::BrazilPhoneNormalizer do
|
||||
describe '#contact_candidates' do
|
||||
it 'preserves a partial Brazil number without raising' do
|
||||
expect(described_class.new.contact_candidates('55')).to eq(['55'])
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user