Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect plus prefix for from #317

Merged
merged 2 commits into from
Sep 5, 2023
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
6 changes: 4 additions & 2 deletions components/app/app/models/routing_parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def initialize(options)
end

def address
result = format_number(destination)
result = format_number(destination).gsub(/\D/, "")
result = username.present? ? client_gateway_address(result) : public_gateway_address(result)
result.prepend(dial_string_prefix) if dial_string_prefix.present?
result.prepend("+") if plus_prefix
Expand All @@ -24,7 +24,9 @@ def address
def format_number(value)
result = value.gsub(/\D/, "")
result = Phony.format(result, format: :national, spaces: "") if national_dialing && Phony.plausible?(result)
result.gsub(/\D/, "")
result = result.gsub(/\D/, "")
result.prepend("+") if plus_prefix
result
end

private
Expand Down
7 changes: 3 additions & 4 deletions components/app/spec/models/dial_string_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@
expect(result).to eq("0716100987")
end


it "formats a number in national format for countries without a trunk prefix" do
dial_string = DialString.new(
build_routing_parameters(
Expand All @@ -122,17 +121,17 @@
expect(result).to eq("6505130514")
end


it "formats a number in E.164 format" do
dial_string = DialString.new(
build_routing_parameters(
national_dialing: false
national_dialing: false,
plus_prefix: true
)
)

result = dial_string.format_number("+855 (716)-100-987")

expect(result).to eq("855716100987")
expect(result).to eq("+855716100987")
end
end

Expand Down
Loading