Skip to content

Commit

Permalink
DEVX-8561/DEVX-8603: Verify API and Voice API updates (#312)
Browse files Browse the repository at this point in the history
* Minor updates to Voice and Verify2 implementations
  • Loading branch information
superchilled authored Aug 7, 2024
1 parent 2c04bc4 commit a488667
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/vonage/verify2/start_verification_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Vonage
class Verify2::StartVerificationOptions
VALID_OPTS = [:locale, :channel_timeout, :client_ref, :code_length, :code, :fraud_check].freeze

MIN_CHANNEL_TIMEOUT, MAX_CHANNEL_TIMEOUT = [60, 900]
MIN_CHANNEL_TIMEOUT, MAX_CHANNEL_TIMEOUT = [15, 900]

MIN_CODE_LENGTH, MAX_CODE_LENGTH = [4, 10]

Expand All @@ -22,6 +22,7 @@ def locale=(locale)
end

def channel_timeout=(channel_timeout)
raise ArgumentError, "Invalid 'channel_timeout' #{channel_timeout}. Must be an integer" unless channel_timeout.is_a?(Integer)
unless channel_timeout.between?(MIN_CHANNEL_TIMEOUT, MAX_CHANNEL_TIMEOUT)
raise ArgumentError, "Invalid 'channel_timeout' #{channel_timeout}. Must be between #{MIN_CHANNEL_TIMEOUT} and #{MAX_CHANNEL_TIMEOUT} (inclusive)"
end
Expand Down
2 changes: 2 additions & 0 deletions lib/vonage/voice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class Voice < Namespace
#
# @option params [required, Array<Hash>] :to
# Connect to a Phone (PSTN) number, SIP Endpoint, Websocket, or VBC extension.
# The `to` Hash can contain a number of different properties depending on the `type`.
# See the API reference for specific details.
#
# @option params [Hash] :from
# Connect to a Phone (PSTN) number. Should not be set if **:random_from_number** is **true**
Expand Down
1 change: 1 addition & 0 deletions lib/vonage/voice/actions/connect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ def sip_endpoint(endpoint_attrs)
}

hash.merge!(headers: endpoint_attrs[:headers]) if endpoint_attrs[:headers]
hash.merge!(standardHeaders: endpoint_attrs[:standardHeaders]) if endpoint_attrs[:standardHeaders]

hash
end
Expand Down
30 changes: 29 additions & 1 deletion test/vonage/verify2/start_verification_options_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,38 @@ def test_channel_timeout_setter_method
assert_equal 90, opts.instance_variable_get(:@channel_timeout)
end

def test_channel_timeout_setter_method_at_min_value
opts = options
opts.channel_timeout = 15

assert_equal 15, opts.instance_variable_get(:@channel_timeout)
end

def test_channel_timeout_setter_method_at_max_value
opts = options
opts.channel_timeout = 900

assert_equal 900, opts.instance_variable_get(:@channel_timeout)
end

def test_channel_timeout_setter_method_below_min_value
opts = options
assert_raises ArgumentError do
opts.channel_timeout = 14
end
end

def test_channel_timeout_setter_method_above_max_value
opts = options
assert_raises ArgumentError do
opts.channel_timeout = 901
end
end

def test_channel_timeout_setter_method_with_invalid_arg
opts = options
assert_raises ArgumentError do
opts.channel_timeout = 0
opts.channel_timeout = '90'
end
end

Expand Down
37 changes: 37 additions & 0 deletions test/vonage/voice/ncco_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,43 @@ def test_ncco_with_valid_action_and_optional_parameters
assert_equal action, [{:action=>"connect", :endpoint=>[{:type=>"phone", :number=>"12129999999"}], :from=>'12129992222'}]
end

def test_ncco_connect_action_sip_endpoint_with_standard_headers
action = ncco.connect(
endpoint: {
type: 'sip',
uri: 'sip:rebekka@sip.mcrussell.com',
headers: {
location: 'New York',
occupation: 'developer'
},
standardHeaders: {
'User-to-User' => '56a390f3d2b7310023a2;encoding=hex;purpose=foo;content=bar'
}
}
)

action_literal = [
{
:action=>"connect",
:endpoint=>[
{
:type=>"sip",
:uri=>"sip:rebekka@sip.mcrussell.com",
:headers=>{
location: 'New York',
occupation: 'developer'
},
:standardHeaders => {
'User-to-User' => '56a390f3d2b7310023a2;encoding=hex;purpose=foo;content=bar'
}
}
]
}
]

assert_equal action_literal, action
end

def test_ncco_with_invalid_action
exception = assert_raises { ncco.gotowarp }

Expand Down
24 changes: 24 additions & 0 deletions test/vonage/voice_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,30 @@ def test_create_method
assert_kind_of Vonage::Response, calls.create(params)
end

def test_create_method_with_connect_to_sip_standard_headers
params = {
to: [
{
type: 'sip',
uri: 'sip:rebekka@sip.example.com',
headers: {
location: 'New York',
occupation: 'developer'
},
standard_headers: {
'User-to-User' => '56a390f3d2b7310023a2;encoding=hex;purpose=foo;content=bar'
}
}
],
from: {type: 'phone', number: '14843335555'},
answer_url: ['https://example.com/answer']
}

stub_request(:post, calls_uri).with(request(body: params)).to_return(response)

assert_kind_of Vonage::Response, calls.create(params)
end

def test_create_method_raises_error_if_from_set_and_random_from_number_true
params = {
to: [{type: 'phone', number: '14843331234'}],
Expand Down

0 comments on commit a488667

Please sign in to comment.