Skip to content

Commit

Permalink
Implementing Verify2 brand validation
Browse files Browse the repository at this point in the history
  • Loading branch information
superchilled committed Apr 23, 2024
1 parent 6469e2f commit 4a3cbb4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
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, ':workflow 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
12 changes: 10 additions & 2 deletions test/vonage/verify2_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,23 @@ def test_start_verification_method_without_brand
end
end

def test_start_verification_method_wit_brand_too_short
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_wit_brand_too_long
def test_start_verification_method_with_brand_too_long
workflow = [{channel: 'sms', to: to_number}]

assert_raises ArgumentError do
Expand Down

0 comments on commit 4a3cbb4

Please sign in to comment.