12
12
include Bandwidth ::WebRtc
13
13
14
14
begin
15
- USERNAME = ENV . fetch ( "USERNAME" )
16
- PASSWORD = ENV . fetch ( "PASSWORD" )
17
- ACCOUNT_ID = ENV . fetch ( "ACCOUNT_ID" )
18
- VOICE_APPLICATION_ID = ENV . fetch ( "VOICE_APPLICATION_ID" )
19
- MESSAGING_APPLICATION_ID = ENV . fetch ( "MESSAGING_APPLICATION_ID" )
20
- CALLBACK_URL = ENV . fetch ( "CALLBACK_URL" )
21
- PHONE_NUMBER_OUTBOUND = ENV . fetch ( "PHONE_NUMBER_OUTBOUND" )
22
- PHONE_NUMBER_INBOUND = ENV . fetch ( "PHONE_NUMBER_INBOUND" )
23
- MFA_MESSAGING_APPLICATION_ID = ENV . fetch ( "MFA_MESSAGING_APPLICATION_ID" )
24
- MFA_VOICE_APPLICATION_ID = ENV . fetch ( "MFA_VOICE_APPLICATION_ID" )
25
- PHONE_NUMBER_MFA = ENV . fetch ( "PHONE_NUMBER_MFA" )
15
+ BW_USERNAME = ENV . fetch ( "BW_USERNAME" )
16
+ BW_PASSWORD = ENV . fetch ( "BW_PASSWORD" )
17
+ BW_ACCOUNT_ID = ENV . fetch ( "BW_ACCOUNT_ID" )
18
+ BW_VOICE_APPLICATION_ID = ENV . fetch ( "BW_VOICE_APPLICATION_ID" )
19
+ BW_MESSAGING_APPLICATION_ID = ENV . fetch ( "BW_MESSAGING_APPLICATION_ID" )
20
+ BASE_CALLBACK_URL = ENV . fetch ( "BASE_CALLBACK_URL" )
21
+ BW_NUMBER = ENV . fetch ( "BW_NUMBER" )
22
+ USER_NUMBER = ENV . fetch ( "USER_NUMBER" )
26
23
rescue
27
24
puts "Environmental variables not found"
28
25
exit ( -1 )
31
28
class IntegrationTest < Test ::Unit ::TestCase
32
29
def setup
33
30
@bandwidth_client = Bandwidth ::Client . new (
34
- voice_basic_auth_user_name : USERNAME ,
35
- voice_basic_auth_password : PASSWORD ,
36
- messaging_basic_auth_user_name : USERNAME ,
37
- messaging_basic_auth_password : PASSWORD ,
38
- multi_factor_auth_basic_auth_user_name : USERNAME ,
39
- multi_factor_auth_basic_auth_password : PASSWORD ,
40
- phone_number_lookup_basic_auth_user_name : USERNAME ,
41
- phone_number_lookup_basic_auth_password : PASSWORD
31
+ voice_basic_auth_user_name : BW_USERNAME ,
32
+ voice_basic_auth_password : BW_PASSWORD ,
33
+ messaging_basic_auth_user_name : BW_USERNAME ,
34
+ messaging_basic_auth_password : BW_PASSWORD ,
35
+ multi_factor_auth_basic_auth_user_name : BW_USERNAME ,
36
+ multi_factor_auth_basic_auth_password : BW_PASSWORD ,
37
+ phone_number_lookup_basic_auth_user_name : BW_USERNAME ,
38
+ phone_number_lookup_basic_auth_password : BW_PASSWORD
42
39
)
43
40
end
44
41
45
42
def test_create_message
46
43
body = MessageRequest . new
47
- body . application_id = MESSAGING_APPLICATION_ID
48
- body . to = [ PHONE_NUMBER_INBOUND ]
49
- body . from = PHONE_NUMBER_OUTBOUND
44
+ body . application_id = BW_MESSAGING_APPLICATION_ID
45
+ body . to = [ USER_NUMBER ]
46
+ body . from = BW_NUMBER
50
47
body . text = "Ruby Integration"
51
- response = @bandwidth_client . messaging_client . client . create_message ( ACCOUNT_ID , body )
48
+ response = @bandwidth_client . messaging_client . client . create_message ( BW_ACCOUNT_ID , body )
52
49
assert ( response . data . id . length > 0 , "id value not set" ) #validate that _some_ id was returned
53
50
end
54
51
55
52
def test_create_message_invalid_phone_number
56
53
body = MessageRequest . new
57
- body . application_id = MESSAGING_APPLICATION_ID
54
+ body . application_id = BW_MESSAGING_APPLICATION_ID
58
55
body . to = [ "+1invalid" ]
59
- body . from = PHONE_NUMBER_OUTBOUND
56
+ body . from = BW_NUMBER
60
57
body . text = "Ruby Integration"
61
58
begin
62
- @bandwidth_client . messaging_client . client . create_message ( ACCOUNT_ID , body )
59
+ @bandwidth_client . messaging_client . client . create_message ( BW_ACCOUNT_ID , body )
63
60
#workaround to make sure that if the above error is not raised, the build will fail
64
61
assert ( false , "Expected exception not raised" )
65
62
rescue MessagingException => e
@@ -73,37 +70,37 @@ def test_upload_download_media
73
70
media_file = '12345' #todo: check a binary string
74
71
75
72
#media upload
76
- @bandwidth_client . messaging_client . client . upload_media ( ACCOUNT_ID , media_file_name , media_file , :content_type => "application/octet-stream" , :cache_control => "no-cache" )
73
+ @bandwidth_client . messaging_client . client . upload_media ( BW_ACCOUNT_ID , media_file_name , media_file , :content_type => "application/octet-stream" , :cache_control => "no-cache" )
77
74
78
75
#media download
79
- downloaded_media_file = @bandwidth_client . messaging_client . client . get_media ( ACCOUNT_ID , media_file_name ) . data
76
+ downloaded_media_file = @bandwidth_client . messaging_client . client . get_media ( BW_ACCOUNT_ID , media_file_name ) . data
80
77
81
78
assert_equal ( downloaded_media_file , media_file , "Downloaded media file not equal to upload" )
82
79
end
83
80
84
81
def test_create_call_and_get_call_state
85
82
body = CreateCallRequest . new
86
- body . from = PHONE_NUMBER_OUTBOUND
87
- body . to = PHONE_NUMBER_INBOUND
88
- body . application_id = VOICE_APPLICATION_ID
89
- body . answer_url = CALLBACK_URL
90
- response = @bandwidth_client . voice_client . client . create_call ( ACCOUNT_ID , body )
83
+ body . from = BW_NUMBER
84
+ body . to = USER_NUMBER
85
+ body . application_id = BW_VOICE_APPLICATION_ID
86
+ body . answer_url = BASE_CALLBACK_URL
87
+ response = @bandwidth_client . voice_client . client . create_call ( BW_ACCOUNT_ID , body )
91
88
assert ( response . data . call_id . length > 0 , "call_id value not set" )
92
89
93
90
#Get phone call information
94
- response = @bandwidth_client . voice_client . client . get_call ( ACCOUNT_ID , response . data . call_id )
91
+ response = @bandwidth_client . voice_client . client . get_call ( BW_ACCOUNT_ID , response . data . call_id )
95
92
assert ( response . data . state . length > 0 , "state value not set" )
96
93
end
97
94
98
95
def test_create_call_invalid_phone_number
99
96
body = CreateCallRequest . new
100
- body . from = PHONE_NUMBER_OUTBOUND
97
+ body . from = BW_NUMBER
101
98
body . to = "+1invalid"
102
- body . application_id = VOICE_APPLICATION_ID
103
- body . answer_url = CALLBACK_URL
99
+ body . application_id = BW_VOICE_APPLICATION_ID
100
+ body . answer_url = BASE_CALLBACK_URL
104
101
105
102
begin
106
- @bandwidth_client . voice_client . client . create_call ( ACCOUNT_ID , :body => body )
103
+ @bandwidth_client . voice_client . client . create_call ( BW_ACCOUNT_ID , :body => body )
107
104
#workaround to make sure that if the above error is not raised, the build will fail
108
105
assert ( false , "Expected exception not raised" )
109
106
rescue ApiErrorException => e
@@ -467,38 +464,38 @@ def test_conference_no_coach
467
464
468
465
def test_mfa_messaging
469
466
body = TwoFactorCodeRequestSchema . new
470
- body . from = PHONE_NUMBER_MFA
471
- body . to = PHONE_NUMBER_INBOUND
472
- body . application_id = MFA_MESSAGING_APPLICATION_ID
467
+ body . from = BW_NUMBER
468
+ body . to = USER_NUMBER
469
+ body . application_id = BW_MESSAGING_APPLICATION_ID
473
470
body . scope = "scope"
474
471
body . digits = 6
475
472
body . message = "Your temporary {NAME} {SCOPE} code is {CODE}"
476
473
477
- response = @bandwidth_client . multi_factor_auth_client . mfa . create_messaging_two_factor ( ACCOUNT_ID , body )
474
+ response = @bandwidth_client . multi_factor_auth_client . mfa . create_messaging_two_factor ( BW_ACCOUNT_ID , body )
478
475
assert ( response . data . message_id . length > 0 , "message id value not set" )
479
476
end
480
477
481
478
def test_mfa_voice
482
479
body = TwoFactorCodeRequestSchema . new
483
- body . from = PHONE_NUMBER_MFA
484
- body . to = PHONE_NUMBER_INBOUND
485
- body . application_id = MFA_VOICE_APPLICATION_ID
480
+ body . from = BW_NUMBER
481
+ body . to = USER_NUMBER
482
+ body . application_id = BW_VOICE_APPLICATION_ID
486
483
body . scope = "scope"
487
484
body . digits = 6
488
485
body . message = "Your temporary {NAME} {SCOPE} code is {CODE}"
489
486
490
- response = @bandwidth_client . multi_factor_auth_client . mfa . create_voice_two_factor ( ACCOUNT_ID , body )
487
+ response = @bandwidth_client . multi_factor_auth_client . mfa . create_voice_two_factor ( BW_ACCOUNT_ID , body )
491
488
assert ( response . data . call_id . length > 0 , "call id value not set" )
492
489
end
493
490
494
491
def test_mfa_verify
495
492
body = TwoFactorVerifyRequestSchema . new
496
- body . to = PHONE_NUMBER_INBOUND
497
- body . application_id = MFA_VOICE_APPLICATION_ID
493
+ body . to = USER_NUMBER
494
+ body . application_id = BW_VOICE_APPLICATION_ID
498
495
body . scope = "scope"
499
496
body . code = "123456"
500
497
body . expiration_time_in_minutes = 3
501
- response = @bandwidth_client . multi_factor_auth_client . mfa . create_verify_two_factor ( ACCOUNT_ID , body )
498
+ response = @bandwidth_client . multi_factor_auth_client . mfa . create_verify_two_factor ( BW_ACCOUNT_ID , body )
502
499
#Ruby has no check to see if variables are of type boolean
503
500
#An explicit true/false check is required
504
501
assert ( response . data . valid == true || response . data . valid == false , "'valid' variable is not a boolean" )
@@ -573,12 +570,12 @@ def test_stop_gather
573
570
574
571
def test_tn_lookup
575
572
body = OrderRequest . new
576
- body . tns = [ PHONE_NUMBER_OUTBOUND ]
577
- create_response = @bandwidth_client . phone_number_lookup_client . client . create_lookup_request ( ACCOUNT_ID , body )
573
+ body . tns = [ BW_NUMBER ]
574
+ create_response = @bandwidth_client . phone_number_lookup_client . client . create_lookup_request ( BW_ACCOUNT_ID , body )
578
575
assert ( create_response . data . request_id . length > 0 , "request_id value not set" )
579
576
580
577
request_id = create_response . data . request_id
581
- get_response = @bandwidth_client . phone_number_lookup_client . client . get_lookup_request_status ( ACCOUNT_ID , request_id )
578
+ get_response = @bandwidth_client . phone_number_lookup_client . client . get_lookup_request_status ( BW_ACCOUNT_ID , request_id )
582
579
assert ( get_response . data . status . length > 0 , "status value not set" )
583
580
end
584
581
0 commit comments