Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions app/services/phone_number_capabilities.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
class PhoneNumberCapabilities
INTERNATIONAL_CODES = YAML.load_file(
Rails.root.join('config', 'country_dialing_codes.yml'),
).freeze
def self.load_config
YAML.load_file(
Rails.root.join('config', 'country_dialing_codes.yml'),
).deep_merge(IdentityConfig.store.country_phone_number_overrides)
end

INTERNATIONAL_CODES = load_config.freeze
Comment on lines +2 to +8
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it takes an app restart to change feature flags, and this value is read often (meaning changing constant accesses to a method read seems expensive), it seemed easy enough to me to keep it a constant


attr_reader :phone, :phone_confirmed

Expand Down
1 change: 1 addition & 0 deletions config/application.yml.default
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ aws_region: 'us-west-2'
aws_kms_multi_region_enabled: 'false'
backup_code_cost: '2000$8$1$'
backup_code_skip_symmetric_encryption: 'false'
country_phone_number_overrides: '{}'
doc_auth_error_dpi_threshold: '290'
doc_auth_error_sharpness_threshold: '40'
doc_auth_error_glare_threshold: '40'
Expand Down
1 change: 1 addition & 0 deletions lib/identity_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def self.build_store(config_map)
config.add(:aws_region, type: :string)
config.add(:backup_code_cost, type: :string)
config.add(:backup_code_skip_symmetric_encryption, type: :boolean)
config.add(:country_phone_number_overrides, type: :json)
config.add(:dashboard_api_token, type: :string)
config.add(:dashboard_url, type: :string)
config.add(:database_host, type: :string)
Expand Down
28 changes: 28 additions & 0 deletions spec/services/phone_number_capabilities_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,32 @@
expect(support['supports_voice']).to eq true if support['supports_voice_unconfirmed']
end
end

describe '.load_config' do
subject(:config) { PhoneNumberCapabilities.load_config }

it 'loads the config' do
expect(config).to eq(YAML.load_file(Rails.root.join('config', 'country_dialing_codes.yml')))
end

context 'when there are country_phone_number_overrides' do
before do
allow(IdentityConfig.store).to receive(:country_phone_number_overrides).and_return(
'AD' => {
'supports_sms' => false,
},
'AE' => {
'supports_voice' => false,
},
)
end

it 'overrides the YAML but does not erase values', :aggregate_failures do
expect(config['AD']['supports_sms']).to eq(false) # override
expect(config['AD']['supports_voice']).to eq(false) # existing
expect(config['AE']['supports_sms']).to eq(false) # existing
expect(config['AE']['supports_voice']).to eq(false) # override
end
end
end
end