Skip to content

Commit

Permalink
Merge 22f9655 into 35e4214
Browse files Browse the repository at this point in the history
  • Loading branch information
superchilled authored May 1, 2024
2 parents 35e4214 + 22f9655 commit 17cb17b
Show file tree
Hide file tree
Showing 13 changed files with 102 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
ruby: [2.5, 2.6, 2.7, 3.0, 3.1]
ruby: [3.0, 3.1, 3.2, 3.3]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
Expand Down
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 7.25.0

* Validation updates to Verify v2 SMS and WhatsApp channels. [#309](https://github.com/Vonage/vonage-ruby-sdk/pull/309)

# 7.24.0

* Updating Video API functionality with methods for Live Captions, Audio Connector, Experience Composer, and a `publisheronly` cleint token role. [#307](https://github.com/Vonage/vonage-ruby-sdk/pull/307)
Expand Down
3 changes: 3 additions & 0 deletions lib/vonage/verify2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Verify2 < Namespace
# )
#
# @param [required, String] :brand The brand that is sending the verification request
# - Must be between 1 and 16 characters in length
#
# @param [required, Array<Hash>] :workflow An array of hashes for channels in the workflow
#
Expand All @@ -32,6 +33,8 @@ class Verify2 < Namespace
# @see https://developer.vonage.com/en/api/verify.v2#newRequest
#
def start_verification(brand:, workflow:, **opts)
raise ArgumentError, ':brand must be a String' unless brand.is_a?(String)
raise ArgumentError, "Invalid 'brand' value #{brand}. Length must be between 1 and 16 characters." unless brand.length.between?(1, 16)
raise ArgumentError, ':workflow must be an Array' unless workflow.is_a?(Array)
raise ArgumentError, ':workflow must not be empty' if workflow.empty?

Expand Down
10 changes: 10 additions & 0 deletions lib/vonage/verify2/channels/sms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def to=(to)
end

def from=(from)
validate_from(from)
@from = from
end

Expand Down Expand Up @@ -49,5 +50,14 @@ def to_h
private

attr_writer :channel

def validate_from(from)
if from.match?(/\D/)
raise ArgumentError, "Invalid alpha-numeric 'from' value #{from}. Length must be between 3 and 11 characters." unless from.length.between?(3, 11)
else
raise ArgumentError, "Invalid numeric 'from' value #{from}. Length must be between 11 and 15 characters." unless from.length.between?(11, 15)
raise ArgumentError, "Invalid 'from' value #{from}. Expected to be in E.164 format" unless Phonelib.parse(from).valid?
end
end
end
end
1 change: 1 addition & 0 deletions lib/vonage/verify2/channels/whats_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def to=(to)
end

def from=(from)
raise ArgumentError, "Invalid 'from' value #{from}. Length must be between 11 and 15 characters." unless from.length.between?(11, 15)
raise ArgumentError, "Invalid 'from' value #{from}. Expected to be in E.164 format" unless Phonelib.parse(from.to_i).valid?
@from = from
end
Expand Down
2 changes: 1 addition & 1 deletion lib/vonage/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# typed: strong

module Vonage
VERSION = '7.24.0'
VERSION = '7.25.0'
end
2 changes: 1 addition & 1 deletion test/vonage/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ def e164_compliant_number
'447000000000'
end

def invalid_number
def non_e164_compliant_number
'abcdefg'
end

Expand Down
4 changes: 2 additions & 2 deletions test/vonage/verify2/channels/silent_auth_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ def test_to_setter_method
assert_equal new_number, sa_workflow.instance_variable_get(:@to)
end

def test_to_setter_method_with_invalid_number
def test_to_setter_method_with_non_e164_compliant_number
assert_raises ArgumentError do
silent_auth_channel.to = invalid_number
silent_auth_channel.to = non_e164_compliant_number
end
end

Expand Down
38 changes: 35 additions & 3 deletions test/vonage/verify2/channels/sms_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,56 @@ def test_to_setter_method
assert_equal new_number, channel.instance_variable_get(:@to)
end

def test_to_setter_method_with_invalid_number
def test_to_setter_method_with_non_e164_compliant_number
assert_raises ArgumentError do
sms_channel.to = invalid_number
sms_channel.to = non_e164_compliant_number
end
end

def test_from_getter_method
assert_nil sms_channel.from
end

def test_from_setter_method
def test_from_setter_method_with_valid_numeric
channel = sms_channel
new_number = '447000000002'
channel.from = new_number

assert_equal new_number, channel.instance_variable_get(:@from)
end

def test_from_setter_method_with_valid_alphanumeric
channel = sms_channel
new_number = 'abc123'
channel.from = new_number

assert_equal new_number, channel.instance_variable_get(:@from)
end

def test_from_setter_method_with_numeric_too_short
assert_raises ArgumentError do
sms_channel.from = '4470000002'
end
end

def test_from_setter_method_with_numeric_too_long
assert_raises ArgumentError do
sms_channel.from = '4470000000000002'
end
end

def test_from_setter_method_with_alphanumeric_too_short
assert_raises ArgumentError do
sms_channel.from = 'ab'
end
end

def test_from_setter_method_with_alphanumeric_too_long
assert_raises ArgumentError do
sms_channel.from = 'abcdefghijkl'
end
end

def test_entity_id_getter_method
assert_nil sms_channel.entity_id
end
Expand Down
4 changes: 2 additions & 2 deletions test/vonage/verify2/channels/voice_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def test_to_setter_method
assert_equal new_number, channel.instance_variable_get(:@to)
end

def test_to_setter_method_with_invalid_number
def test_to_setter_method_with_non_e164_compliant_number
assert_raises ArgumentError do
voice_channel.to = invalid_number
voice_channel.to = non_e164_compliant_number
end
end

Expand Down
4 changes: 2 additions & 2 deletions test/vonage/verify2/channels/whats_app_interactive_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def test_to_setter_method
assert_equal new_number, channel.instance_variable_get(:@to)
end

def test_to_setter_method_with_invalid_number
def test_to_setter_method_with_non_e164_compliant_number
assert_raises ArgumentError do
whatsapp_interactive_channel.to = invalid_number
whatsapp_interactive_channel.to = non_e164_compliant_number
end
end

Expand Down
20 changes: 16 additions & 4 deletions test/vonage/verify2/channels/whats_app_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ def test_to_setter_method
assert_equal new_number, channel.instance_variable_get(:@to)
end

def test_to_setter_method_with_invalid_number
def test_to_setter_method_with_non_e164_compliant_number
assert_raises ArgumentError do
whatsapp_channel.to = invalid_number
whatsapp_channel.to = non_e164_compliant_number
end
end

Expand All @@ -47,9 +47,21 @@ def test_from_setter_method
assert_equal new_number, channel.instance_variable_get(:@from)
end

def test_from_setter_method_with_invalid_number
def test_from_setter_method_with_non_e164_compliant_number
assert_raises ArgumentError do
whatsapp_channel.from = invalid_number
whatsapp_channel.from = non_e164_compliant_number
end
end

def test_from_setter_method_with_number_too_short
assert_raises ArgumentError do
whatsapp_channel.from = '4470000002'
end
end

def test_from_setter_method_with_number_too_long
assert_raises ArgumentError do
whatsapp_channel.from = '4470000000000002'
end
end

Expand Down
24 changes: 24 additions & 0 deletions test/vonage/verify2_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,30 @@ def test_start_verification_method_without_brand
end
end

def test_start_verification_method_with_invalid_brand_type
workflow = [{channel: 'sms', to: to_number}]

assert_raises ArgumentError do
verify2.start_verification(brand: 123, workflow: workflow)
end
end

def test_start_verification_method_with_brand_too_short
workflow = [{channel: 'sms', to: to_number}]

assert_raises ArgumentError do
verify2.start_verification(brand: '', workflow: workflow)
end
end

def test_start_verification_method_with_brand_too_long
workflow = [{channel: 'sms', to: to_number}]

assert_raises ArgumentError do
verify2.start_verification(brand: 'abcdefghijklmnopq', workflow: workflow)
end
end

def test_start_verification_method_without_workflow
assert_raises ArgumentError do
verify2.start_verification(brand: brand)
Expand Down

0 comments on commit 17cb17b

Please sign in to comment.