|
1 | 1 | require 'spec_helper' |
2 | 2 | require 'json' |
| 3 | +require_relative '../call_utils' |
3 | 4 |
|
4 | 5 | # Integration Tests for Bandwidth::CallsApi |
5 | 6 | describe 'CallsApi Integration Tests' do |
6 | | - before do |
7 | | - # run before each test |
8 | | - @api_instance = Bandwidth::CallsApi.new |
9 | | - end |
10 | | - |
11 | | - after do |
12 | | - # run after each test |
| 7 | + before(:all) do |
| 8 | + Bandwidth.configure do |config| |
| 9 | + config.username = BW_USERNAME |
| 10 | + config.password = BW_PASSWORD |
| 11 | + end |
| 12 | + @api_instance_calls = Bandwidth::CallsApi.new |
| 13 | + $call_info_id = "" |
13 | 14 | end |
14 | 15 |
|
15 | 16 | # Create Call |
16 | | - describe 'create_call test' do |
17 | | - it 'should work' do |
18 | | - # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers |
| 17 | + describe 'create_call' do |
| 18 | + it 'creates a call with amd' do |
| 19 | + amd_config = Bandwidth::MachineDetectionConfiguration.new( |
| 20 | + mode: "async", |
| 21 | + detection_timeout: 5.0, |
| 22 | + silence_timeout: 5.0, |
| 23 | + speech_threshold: 5.0, |
| 24 | + speech_end_threshold: 5.0, |
| 25 | + delay_result: true, |
| 26 | + callback_url: BASE_CALLBACK_URL + "/machineDetection", |
| 27 | + callback_method: Bandwidth::CallbackMethodEnum::POST |
| 28 | + ) |
| 29 | + |
| 30 | + call_body = Bandwidth::CreateCall.new( |
| 31 | + application_id: BW_VOICE_APPLICATION_ID, |
| 32 | + to: USER_NUMBER, |
| 33 | + from: BW_NUMBER, |
| 34 | + answer_url: BASE_CALLBACK_URL + "/callbacks/answer", |
| 35 | + answer_method: "POST", |
| 36 | + disconnect_url: BASE_CALLBACK_URL + "/callbacks/disconnect", |
| 37 | + disconnect_method: "GET", |
| 38 | + machine_detection: amd_config, |
| 39 | + call_timeout: 30.0, |
| 40 | + callback_timeout: 15.0 |
| 41 | + ) |
| 42 | + |
| 43 | + response = @api_instance_calls.create_call_with_http_info(BW_ACCOUNT_ID, call_body) |
| 44 | + sleep(SLEEP_TIME_S) |
| 45 | + |
| 46 | + expect(response[CODE]).to eq(201) |
| 47 | + expect(response[DATA]).to be_instance_of(Bandwidth::CreateCallResponse) |
| 48 | + expect(response[DATA].call_id.length).to eq(47) |
| 49 | + expect(response[DATA].account_id).to eq(BW_ACCOUNT_ID) |
| 50 | + expect(response[DATA].application_id).to eq(BW_VOICE_APPLICATION_ID) |
| 51 | + expect(response[DATA].to).to eq(USER_NUMBER) |
| 52 | + expect(response[DATA].from).to eq(BW_NUMBER) |
| 53 | + expect(response[DATA].call_id) |
| 54 | + expect(response[DATA].call_timeout).to eq(30.0) |
| 55 | + expect(response[DATA].callback_timeout).to eq(15.0) |
| 56 | + expect(response[DATA].enqueued_time).to be_instance_of(Time) |
| 57 | + expect(response[DATA].answer_method).to eq(Bandwidth::CallbackMethodEnum::POST) |
| 58 | + expect(response[DATA].disconnect_method).to eq("GET") |
| 59 | + expect(response[DATA].answer_url).to eq(BASE_CALLBACK_URL + "/callbacks/answer") |
| 60 | + expect(response[DATA].disconnect_url).to eq(BASE_CALLBACK_URL + "/callbacks/disconnect") |
| 61 | + |
| 62 | + $call_info_id = response[DATA].call_id |
| 63 | + $active_calls.append($call_info_id) |
19 | 64 | end |
20 | 65 | end |
21 | 66 |
|
22 | 67 | # Get Call State Information |
23 | | - describe 'get_call_state test' do |
24 | | - it 'should work' do |
25 | | - # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers |
| 68 | + describe 'get_call_state' do |
| 69 | + it 'gets the call state' do |
| 70 | + response = @api_instance_calls.get_call_state_with_http_info(BW_ACCOUNT_ID, $call_info_id) |
| 71 | + |
| 72 | + expect(response[CODE]).to eq(200) |
| 73 | + expect(response[DATA]).to be_instance_of(Bandwidth::CallState) |
| 74 | + expect(response[DATA].call_id).to eq($call_info_id) |
| 75 | + expect(response[DATA].account_id).to eq(BW_ACCOUNT_ID) |
| 76 | + expect(response[DATA].application_id).to eq(BW_VOICE_APPLICATION_ID) |
| 77 | + expect(response[DATA].start_time).to be_instance_of(Time) |
| 78 | + expect(response[DATA].last_update).to be_instance_of(Time) |
| 79 | + expect(response[DATA].state).to be_instance_of(String) |
| 80 | + expect(response[DATA].direction).to eq(Bandwidth::CallDirectionEnum::OUTBOUND) |
26 | 81 | end |
27 | 82 | end |
28 | 83 |
|
29 | 84 | # Update Call |
30 | | - describe 'update_call test' do |
31 | | - it 'should work' do |
32 | | - # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers |
| 85 | + describe 'update_call' do |
| 86 | + it 'creates and updates a call' do |
| 87 | + update_call_body = Bandwidth::UpdateCall.new( |
| 88 | + state: Bandwidth::CallStateEnum::ACTIVE, |
| 89 | + redirect_url: MANTECA_BASE_URL + "/bxml/pause" |
| 90 | + ) |
| 91 | + |
| 92 | + update_call_id = create_manteca_call(@api_instance_calls) |
| 93 | + sleep(SLEEP_TIME_S) |
| 94 | + |
| 95 | + update_response = @api_instance_calls.update_call_with_http_info(BW_ACCOUNT_ID, update_call_id, update_call_body) |
| 96 | + expect(update_response[CODE]).to eq(200) |
| 97 | + sleep(SLEEP_TIME_S) |
| 98 | + |
| 99 | + complete_response = @api_instance_calls.update_call_with_http_info(BW_ACCOUNT_ID, update_call_id, $complete_call_body) |
| 100 | + expect(complete_response[CODE]).to eq(200) |
33 | 101 | end |
34 | 102 | end |
35 | 103 |
|
36 | 104 | # Update Call BXML |
37 | | - describe 'update_call_bxml test' do |
38 | | - it 'should work' do |
39 | | - # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers |
| 105 | + describe 'update_call_bxml' do |
| 106 | + it 'updates a call using bxml' do |
| 107 | + update_call_id = create_manteca_call(@api_instance_calls) |
| 108 | + sleep(SLEEP_TIME_S) |
| 109 | + |
| 110 | + update_bxml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Bxml><SpeakSentence locale=\"en_US\" gender=\"female\" voice=\"susan\">This is a test bxml response</SpeakSentence><Pause duration=\"3\"/></Bxml>"; |
| 111 | + update_response = @api_instance_calls.update_call_bxml_with_http_info(BW_ACCOUNT_ID, update_call_id, update_bxml) |
| 112 | + expect(update_response[CODE]).to eq(204) |
| 113 | + sleep(SLEEP_TIME_S) |
| 114 | + |
| 115 | + complete_response = @api_instance_calls.update_call_with_http_info(BW_ACCOUNT_ID, update_call_id, $complete_call_body) |
| 116 | + expect(complete_response[CODE]).to eq(200) |
| 117 | + end |
| 118 | + end |
| 119 | + |
| 120 | + # HTTP 4XX Errors |
| 121 | + describe 'http error' do |
| 122 | + it 'causes a 400 error' do |
| 123 | + call_body_bad = Bandwidth::CreateCall.new( |
| 124 | + application_id: BW_VOICE_APPLICATION_ID, |
| 125 | + to: "+1invalid", |
| 126 | + from: BW_NUMBER, |
| 127 | + answer_url: BASE_CALLBACK_URL + "/callbacks/answer", |
| 128 | + answer_method: "POST", |
| 129 | + disconnect_url: BASE_CALLBACK_URL + "/callbacks/disconnect", |
| 130 | + disconnect_method: "GET" |
| 131 | + ) |
| 132 | + |
| 133 | + expect { |
| 134 | + @api_instance_calls.create_call_with_http_info(BW_ACCOUNT_ID, call_body_bad) |
| 135 | + }.to raise_error { |e| |
| 136 | + expect(e).to be_instance_of(Bandwidth::ApiError) |
| 137 | + expect(e.code).to eq(400) |
| 138 | + } |
| 139 | + end |
| 140 | + |
| 141 | + it 'causes a 404 error' do |
| 142 | + dne_id = "does-not-exist" |
| 143 | + |
| 144 | + expect { |
| 145 | + @api_instance_calls.get_call_state_with_http_info(BW_ACCOUNT_ID, dne_id) |
| 146 | + }.to raise_error { |e| |
| 147 | + expect(e).to be_instance_of(Bandwidth::ApiError) |
| 148 | + expect(e.code).to eq(404) |
| 149 | + } |
| 150 | + end |
| 151 | + |
| 152 | + it 'causes a 401 error' do |
| 153 | + Bandwidth.configure do |config| |
| 154 | + config.username = 'bad_username' |
| 155 | + config.password = 'bad_password' |
| 156 | + end |
| 157 | + |
| 158 | + expect { |
| 159 | + @api_instance_calls.get_call_state_with_http_info(BW_ACCOUNT_ID, $call_info_id) |
| 160 | + }.to raise_error { |e| |
| 161 | + expect(e).to be_instance_of(Bandwidth::ApiError) |
| 162 | + expect(e.code).to eq(401) |
| 163 | + } |
| 164 | + end |
| 165 | + |
| 166 | + it 'causes a 403 error' do |
| 167 | + Bandwidth.configure do |config| |
| 168 | + config.username = FORBIDDEN_USERNAME |
| 169 | + config.password = FORBIDDEN_PASSWORD |
| 170 | + end |
| 171 | + |
| 172 | + expect { |
| 173 | + @api_instance_calls.get_call_state_with_http_info(BW_ACCOUNT_ID, $call_info_id) |
| 174 | + }.to raise_error { |e| |
| 175 | + expect(e).to be_instance_of(Bandwidth::ApiError) |
| 176 | + expect(e.code).to eq(403) |
| 177 | + } |
40 | 178 | end |
41 | 179 | end |
42 | 180 |
|
|
0 commit comments