@@ -9,9 +9,11 @@ class TestRest < Test::Unit::TestCase
99
1010 def setup
1111 @customer_id = 'FFFFFFFF-EEEE-DDDD-1234-AB1234567890'
12- @api_key = 'EXAMPLE----TE8sTgg45yusumoN6BYsBVkh +yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw=='
12+ @api_key = 'ABC12345yusumoN6BYsBVkh +yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw=='
1313 @phone_number = '1234567890'
1414 @reference_id = '0123456789ABCDEF0123456789ABCDEF'
15+ @account_lifecycle_event = 'create'
16+ @score_client = TelesignEnterprise ::ScoreClient . new ( @customer_id , @api_key , rest_endpoint : 'https://detect.telesign.com' )
1517 end
1618
1719 def test_phoneid_standard
@@ -29,39 +31,47 @@ def test_phoneid_standard
2931 assert_requested :get , "http://localhost/v1/phoneid/standard/#{ @phone_number } " , headers : { 'Date' => /.*\S .*/ }
3032 end
3133
32- def test_phoneid_score
33-
34- stub_request ( :get , "localhost/v1/phoneid/score/#{ @phone_number } ?ucid=TOOL" ) . to_return ( body : '{}' )
35-
36- client = TelesignEnterprise ::PhoneIdClient . new ( @customer_id ,
37- @api_key ,
38- rest_endpoint : 'http://localhost' )
39-
40- client . score ( @phone_number , 'TOOL' )
41-
42- assert_requested :get , "http://localhost/v1/phoneid/score/#{ @phone_number } ?ucid=TOOL"
43- assert_not_requested :get , "http://localhost/v1/phoneid/score/#{ @phone_number } ?ucid=TOOL" , headers : { 'Content-Type' => /.*\S .*/ }
44- assert_requested :get , "http://localhost/v1/phoneid/score/#{ @phone_number } ?ucid=TOOL" , headers : { 'x-ts-auth-method' => 'HMAC-SHA256' }
45- assert_requested :get , "http://localhost/v1/phoneid/score/#{ @phone_number } ?ucid=TOOL" , headers : { 'x-ts-nonce' => /.*\S .*/ }
46- assert_requested :get , "http://localhost/v1/phoneid/score/#{ @phone_number } ?ucid=TOOL" , headers : { 'Date' => /.*\S .*/ }
47- end
48-
49- def test_score
50-
51- stub_request ( :post , "localhost/v1/score/#{ @phone_number } " ) . to_return ( body : '{}' )
52-
53- client = TelesignEnterprise ::ScoreClient . new ( @customer_id ,
54- @api_key ,
55- rest_endpoint : 'http://localhost' )
56-
57- client . score ( @phone_number , 'create' )
58-
59- assert_requested :post , "http://localhost/v1/score/#{ @phone_number } "
60- assert_requested :post , "http://localhost/v1/score/#{ @phone_number } " , body : 'account_lifecycle_event=create'
61- assert_requested :post , "http://localhost/v1/score/#{ @phone_number } " , headers : { 'Content-Type' => 'application/x-www-form-urlencoded' }
62- assert_requested :post , "http://localhost/v1/score/#{ @phone_number } " , headers : { 'x-ts-auth-method' => 'HMAC-SHA256' }
63- assert_requested :post , "http://localhost/v1/score/#{ @phone_number } " , headers : { 'x-ts-nonce' => /.*\S .*/ }
64- assert_requested :post , "http://localhost/v1/score/#{ @phone_number } " , headers : { 'Date' => /.*\S .*/ }
34+ def test_score_success
35+
36+ stub_request ( :post , "https://detect.telesign.com/intelligence/phone" )
37+ . with (
38+ body : hash_including ( {
39+ 'phone_number' => @phone_number ,
40+ 'account_lifecycle_event' => @account_lifecycle_event
41+ } ) ,
42+ headers : { 'Content-Type' => 'application/x-www-form-urlencoded' }
43+ )
44+ . to_return (
45+ status : 200 ,
46+ body : '{"risk": {"level": "low", "recommendation": "allow"}}' ,
47+ headers : { 'Content-Type' => 'application/json' }
48+ )
49+
50+ response = @score_client . score ( @phone_number , @account_lifecycle_event )
51+
52+ puts "Response status code: #{ response . status_code } "
53+ puts "Response headers: #{ response . headers } "
54+ puts "Response body: #{ response . body } "
55+ puts "Parsed JSON response: #{ response . json } "
56+
57+ assert response . ok
58+ assert_equal 'low' , response . json [ 'risk' ] [ 'level' ]
59+ assert_equal 'allow' , response . json [ 'risk' ] [ 'recommendation' ]
60+
61+ assert_requested :post , "https://detect.telesign.com/intelligence/phone"
62+ assert_requested :post , "https://detect.telesign.com/intelligence/phone" ,
63+ body : hash_including ( {
64+ 'phone_number' => @phone_number ,
65+ 'account_lifecycle_event' => @account_lifecycle_event
66+ } )
67+ assert_requested :post , "https://detect.telesign.com/intelligence/phone" ,
68+ headers : { 'Content-Type' => 'application/x-www-form-urlencoded' }
69+ assert_requested :post , "https://detect.telesign.com/intelligence/phone" ,
70+ headers : { 'x-ts-auth-method' => 'HMAC-SHA256' }
71+ assert_requested :post , "https://detect.telesign.com/intelligence/phone" ,
72+ headers : { 'x-ts-nonce' => /.*\S .*/ }
73+ assert_requested :post , "https://detect.telesign.com/intelligence/phone" ,
74+ headers : { 'Date' => /.*\S .*/ }
6575 end
6676
6777 def test_messaging
0 commit comments