|
| 1 | +# typed: false |
| 2 | +require_relative './test' |
| 3 | + |
| 4 | +class Vonage::NetworkNumberVerificationTest < Vonage::Test |
| 5 | + def network_number_verification |
| 6 | + Vonage::NetworkNumberVerification.new(config) |
| 7 | + end |
| 8 | + |
| 9 | + def uri |
| 10 | + 'https://api-eu.vonage.com/camara/number-verification/v031' |
| 11 | + end |
| 12 | + |
| 13 | + def phone_number |
| 14 | + '+447900000000' |
| 15 | + end |
| 16 | + |
| 17 | + def hashed_phone_number |
| 18 | + '32f67ab4e4312618b09cd23ed8ce41b13e095fe52b73b2e8da8ef49830e50dba' |
| 19 | + end |
| 20 | + |
| 21 | + def example_redirect_uri |
| 22 | + 'https://example.com/callback' |
| 23 | + end |
| 24 | + |
| 25 | + def example_oidc_auth_code |
| 26 | + '0dadaeb4-7c79-4d39-b4b0-5a6cc08bf537' |
| 27 | + end |
| 28 | + |
| 29 | + def test_verify_method |
| 30 | + request_access_token_request_params = { |
| 31 | + grant_type: 'authorization_code', |
| 32 | + code: example_oidc_auth_code, |
| 33 | + redirect_uri: example_redirect_uri |
| 34 | + } |
| 35 | + |
| 36 | + number_verification_verify_params = {phoneNumber: phone_number} |
| 37 | + |
| 38 | + stub_request(:post, "https://api-eu.vonage.com/oauth2/token").with(request(body: request_access_token_request_params, headers: headers)).to_return(network_authentication_token_response) |
| 39 | + stub_request(:post, uri + '/verify').with(body: number_verification_verify_params).to_return(response) |
| 40 | + |
| 41 | + response = network_number_verification.verify( |
| 42 | + phone_number: phone_number, |
| 43 | + auth_data: { |
| 44 | + oidc_auth_code: example_oidc_auth_code, |
| 45 | + redirect_uri: example_redirect_uri |
| 46 | + } |
| 47 | + ) |
| 48 | + |
| 49 | + assert_kind_of Vonage::Response, response |
| 50 | + end |
| 51 | + |
| 52 | + def test_verify_method_with_hashed_phone_number |
| 53 | + request_access_token_request_params = { |
| 54 | + grant_type: 'authorization_code', |
| 55 | + code: example_oidc_auth_code, |
| 56 | + redirect_uri: example_redirect_uri |
| 57 | + } |
| 58 | + |
| 59 | + number_verification_verify_params = {hashedPhoneNumber: hashed_phone_number} |
| 60 | + |
| 61 | + stub_request(:post, "https://api-eu.vonage.com/oauth2/token").with(request(body: request_access_token_request_params, headers: headers)).to_return(network_authentication_token_response) |
| 62 | + stub_request(:post, uri + '/verify').with(body: number_verification_verify_params).to_return(response) |
| 63 | + |
| 64 | + response = network_number_verification.verify( |
| 65 | + phone_number: hashed_phone_number, |
| 66 | + hashed: true, |
| 67 | + auth_data: { |
| 68 | + oidc_auth_code: example_oidc_auth_code, |
| 69 | + redirect_uri: example_redirect_uri |
| 70 | + } |
| 71 | + ) |
| 72 | + |
| 73 | + assert_kind_of Vonage::Response, response |
| 74 | + end |
| 75 | + |
| 76 | + def test_check_method_without_phone_number |
| 77 | + assert_raises(ArgumentError) do |
| 78 | + network_number_verification.verify( |
| 79 | + auth_data: { |
| 80 | + oidc_auth_code: example_oidc_auth_code, |
| 81 | + redirect_uri: example_redirect_uri |
| 82 | + } |
| 83 | + ) |
| 84 | + end |
| 85 | + end |
| 86 | + |
| 87 | + def test_check_method_with_invalid_phone_number |
| 88 | + auth_data = { |
| 89 | + oidc_auth_code: example_oidc_auth_code, |
| 90 | + redirect_uri: example_redirect_uri |
| 91 | + } |
| 92 | + |
| 93 | + assert_raises(TypeError) { network_number_verification.verify(phone_number: 447904603505, auth_data: auth_data) } |
| 94 | + assert_raises(ArgumentError) { network_number_verification.verify(phone_number: '07904603505', auth_data: auth_data) } |
| 95 | + assert_raises(ArgumentError) { network_number_verification.verify(phone_number: '447904603505', auth_data: auth_data) } |
| 96 | + end |
| 97 | + |
| 98 | + def test_check_method_with_invalid_hashed |
| 99 | + auth_data = { |
| 100 | + oidc_auth_code: example_oidc_auth_code, |
| 101 | + redirect_uri: example_redirect_uri |
| 102 | + } |
| 103 | + |
| 104 | + assert_raises(TypeError) { network_number_verification.verify(phone_number: hashed_phone_number, auth_data: auth_data, hashed: 'true') } |
| 105 | + end |
| 106 | + |
| 107 | + def test_check_method_without_auth_data |
| 108 | + assert_raises(ArgumentError) { network_number_verification.verify(phone_number: phone_number) } |
| 109 | + end |
| 110 | + |
| 111 | + def test_check_method_with_invalid_auth_data |
| 112 | + auth_data = [ |
| 113 | + example_oidc_auth_code, |
| 114 | + example_redirect_uri |
| 115 | + ] |
| 116 | + |
| 117 | + assert_raises(TypeError) { network_number_verification.verify(phone_number: phone_number, auth_data: auth_data) } |
| 118 | + end |
| 119 | + |
| 120 | + def test_check_method_without_oidc_auth_code |
| 121 | + auth_data = { |
| 122 | + redirect_uri: example_redirect_uri |
| 123 | + } |
| 124 | + |
| 125 | + assert_raises(ArgumentError) { network_number_verification.verify(phone_number: phone_number, auth_data: auth_data) } |
| 126 | + end |
| 127 | + |
| 128 | + def test_check_method_with_invalid_oidc_auth_code |
| 129 | + auth_data = { |
| 130 | + oidc_auth_code: 12345, |
| 131 | + redirect_uri: example_redirect_uri |
| 132 | + } |
| 133 | + |
| 134 | + assert_raises(ArgumentError) { network_number_verification.verify(phone_number: phone_number, auth_data: auth_data) } |
| 135 | + end |
| 136 | + |
| 137 | + def test_check_method_without_redirect_uri |
| 138 | + auth_data = { |
| 139 | + oidc_auth_code: example_oidc_auth_code |
| 140 | + } |
| 141 | + |
| 142 | + assert_raises(ArgumentError) { network_number_verification.verify(phone_number: phone_number, auth_data: auth_data) } |
| 143 | + end |
| 144 | + |
| 145 | + def test_check_method_with_invalid_redirect_uri |
| 146 | + auth_data = { |
| 147 | + oidc_auth_code: example_oidc_auth_code, |
| 148 | + redirect_uri: 12345 |
| 149 | + } |
| 150 | + |
| 151 | + assert_raises(ArgumentError) { network_number_verification.verify(phone_number: phone_number, auth_data: auth_data) } |
| 152 | + end |
| 153 | +end |
0 commit comments