Skip to content

Commit

Permalink
update integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ckoegel committed Jun 16, 2023
1 parent 2a8301b commit 77545d9
Show file tree
Hide file tree
Showing 16 changed files with 869 additions and 1,644 deletions.
229 changes: 163 additions & 66 deletions spec/api/calls_api_spec.rb
Original file line number Diff line number Diff line change
@@ -1,88 +1,185 @@
=begin
#Bandwidth
#Bandwidth's Communication APIs
The version of the OpenAPI document: 1.0.0
Contact: letstalk@bandwidth.com
Generated by: https://openapi-generator.tech
OpenAPI Generator version: 6.6.0
=end

require 'spec_helper'
require 'json'
require_relative '../call_utils'

# Unit tests for Bandwidth::CallsApi
# Automatically generated by openapi-generator (https://openapi-generator.tech)
# Please update as you see appropriate
describe 'CallsApi' do
before do
# run before each test
@api_instance = Bandwidth::CallsApi.new
end

after do
# run after each test
end

describe 'test an instance of CallsApi' do
it 'should create an instance of CallsApi' do
expect(@api_instance).to be_instance_of(Bandwidth::CallsApi)
# Integration Tests for Bandwidth::CallsApi
describe 'CallsApi Integration Tests' do
before(:all) do
Bandwidth.configure do |config|
config.username = BW_USERNAME
config.password = BW_PASSWORD
end
@api_instance_calls = Bandwidth::CallsApi.new
$call_info_id = ""
end

# unit tests for create_call
# Create Call
# Creates an outbound phone call. All calls are initially queued. Your outbound calls will initiated at a specific dequeueing rate, enabling your application to \"fire and forget\" when creating calls. Queued calls may not be modified until they are dequeued and placed, but may be removed from your queue on demand. <b>Please note:</b> Calls submitted to your queue will be placed approximately in order, but exact ordering is not guaranteed.
# @param account_id Your Bandwidth Account ID.
# @param create_call JSON object containing information to create an outbound call
# @param [Hash] opts the optional parameters
# @return [CreateCallResponse]
describe 'create_call test' do
it 'should work' do
# assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/
describe 'create_call' do
it 'creates a call with amd' do
amd_config = Bandwidth::MachineDetectionConfiguration.new(
mode: "async",
detection_timeout: 5.0,
silence_timeout: 5.0,
speech_threshold: 5.0,
speech_end_threshold: 5.0,
delay_result: true,
callback_url: BASE_CALLBACK_URL + "/machineDetection",
callback_method: Bandwidth::CallbackMethodEnum::POST
)

call_body = Bandwidth::CreateCall.new(
application_id: BW_VOICE_APPLICATION_ID,
to: USER_NUMBER,
from: BW_NUMBER,
answer_url: BASE_CALLBACK_URL + "/callbacks/answer",
answer_method: "POST",
disconnect_url: BASE_CALLBACK_URL + "/callbacks/disconnect",
disconnect_method: "GET",
machine_detection: amd_config,
call_timeout: 30.0,
callback_timeout: 15.0
)

response = @api_instance_calls.create_call_with_http_info(BW_ACCOUNT_ID, call_body)

expect(response[CODE]).to eq(201)
expect(response[DATA]).to be_instance_of(Bandwidth::CreateCallResponse)
expect(response[DATA].call_id.length).to eq(47)
expect(response[DATA].account_id).to eq(BW_ACCOUNT_ID)
expect(response[DATA].application_id).to eq(BW_VOICE_APPLICATION_ID)
expect(response[DATA].to).to eq(USER_NUMBER)
expect(response[DATA].from).to eq(BW_NUMBER)
expect(response[DATA].call_id)
expect(response[DATA].call_timeout).to eq(30.0)
expect(response[DATA].callback_timeout).to eq(15.0)
expect(response[DATA].enqueued_time).to be_instance_of(Time)
expect(response[DATA].answer_method).to eq(Bandwidth::CallbackMethodEnum::POST)
expect(response[DATA].disconnect_method).to eq("GET")
expect(response[DATA].answer_url).to eq(BASE_CALLBACK_URL + "/callbacks/answer")
expect(response[DATA].disconnect_url).to eq(BASE_CALLBACK_URL + "/callbacks/disconnect")

$call_info_id = response[DATA].call_id
$active_calls.append($call_info_id)
end
end

# unit tests for get_call_state
# Get Call State Information
# Retrieve the current state of a specific call. This information is near-realtime, so it may take a few minutes for your call to be accessible using this endpoint. **Note**: Call information is kept for 7 days after the calls are hung up. If you attempt to retrieve information for a call that is older than 7 days, you will get an HTTP 404 response.
# @param account_id Your Bandwidth Account ID.
# @param call_id Programmable Voice API Call ID.
# @param [Hash] opts the optional parameters
# @return [CallState]
describe 'get_call_state test' do
it 'should work' do
# assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/
describe 'get_call_state' do
it 'gets the call state' do
begin
response = @api_instance_calls.get_call_state_with_http_info(BW_ACCOUNT_ID, $call_info_id)

expect(response[CODE]).to eq(200)
expect(response[DATA]).to be_instance_of(Bandwidth::CallState)
expect(response[DATA].call_id).to eq($call_info_id)
expect(response[DATA].account_id).to eq(BW_ACCOUNT_ID)
expect(response[DATA].application_id).to eq(BW_VOICE_APPLICATION_ID)
expect(response[DATA].start_time).to be_instance_of(Time)
expect(response[DATA].last_update).to be_instance_of(Time)
expect(response[DATA].state).to be_instance_of(String)
expect(response[DATA].direction).to eq(Bandwidth::CallDirectionEnum::OUTBOUND)
rescue Bandwidth::ApiError => e
if e.code != 404
raise e
end
end
end
end

# unit tests for update_call
# Update Call
# Interrupts and redirects a call to a different URL that should return a BXML document.
# @param account_id Your Bandwidth Account ID.
# @param call_id Programmable Voice API Call ID.
# @param update_call JSON object containing information to redirect an existing call to a new BXML document
# @param [Hash] opts the optional parameters
# @return [nil]
describe 'update_call test' do
it 'should work' do
# assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/
describe 'update_call' do
it 'creates and updates a call' do
update_call_body = Bandwidth::UpdateCall.new(
state: Bandwidth::CallStateEnum::ACTIVE,
redirect_url: MANTECA_BASE_URL + "/bxml/pause"
)

update_call_id = create_manteca_call(@api_instance_calls)
sleep(SLEEP_TIME_S)

update_response = @api_instance_calls.update_call_with_http_info(BW_ACCOUNT_ID, update_call_id, update_call_body)
expect(update_response[CODE]).to eq(200)
sleep(SLEEP_TIME_S)

complete_response = @api_instance_calls.update_call_with_http_info(BW_ACCOUNT_ID, update_call_id, $complete_call_body)
expect(complete_response[CODE]).to eq(200)
end
end

# unit tests for update_call_bxml
# Update Call BXML
# Interrupts and replaces an active call's BXML document.
# @param account_id Your Bandwidth Account ID.
# @param call_id Programmable Voice API Call ID.
# @param body
# @param [Hash] opts the optional parameters
# @return [nil]
describe 'update_call_bxml test' do
it 'should work' do
# assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/
describe 'update_call_bxml' do
it 'updates a call using bxml' do
update_call_id = create_manteca_call(@api_instance_calls)
sleep(SLEEP_TIME_S)

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>";
update_response = @api_instance_calls.update_call_bxml_with_http_info(BW_ACCOUNT_ID, update_call_id, update_bxml)
expect(update_response[CODE]).to eq(204)
sleep(SLEEP_TIME_S)

complete_response = @api_instance_calls.update_call_with_http_info(BW_ACCOUNT_ID, update_call_id, $complete_call_body)
expect(complete_response[CODE]).to eq(200)
end
end

# HTTP 4XX Errors
describe 'http error' do
it 'causes a 400 error' do
call_body_bad = Bandwidth::CreateCall.new(
application_id: BW_VOICE_APPLICATION_ID,
to: "+1invalid",
from: BW_NUMBER,
answer_url: BASE_CALLBACK_URL + "/callbacks/answer",
answer_method: "POST",
disconnect_url: BASE_CALLBACK_URL + "/callbacks/disconnect",
disconnect_method: "GET"
)

expect {
@api_instance_calls.create_call_with_http_info(BW_ACCOUNT_ID, call_body_bad)
}.to raise_error { |e|
expect(e).to be_instance_of(Bandwidth::ApiError)
expect(e.code).to eq(400)
}
end

it 'causes a 404 error' do
dne_id = "does-not-exist"

expect {
@api_instance_calls.get_call_state_with_http_info(BW_ACCOUNT_ID, dne_id)
}.to raise_error { |e|
expect(e).to be_instance_of(Bandwidth::ApiError)
expect(e.code).to eq(404)
}
end

it 'causes a 401 error' do
Bandwidth.configure do |config|
config.username = 'bad_username'
config.password = 'bad_password'
end

expect {
@api_instance_calls.get_call_state_with_http_info(BW_ACCOUNT_ID, $call_info_id)
}.to raise_error { |e|
expect(e).to be_instance_of(Bandwidth::ApiError)
expect(e.code).to eq(401)
}
end

it 'causes a 403 error' do
Bandwidth.configure do |config|
config.username = FORBIDDEN_USERNAME
config.password = FORBIDDEN_PASSWORD
end

expect {
@api_instance_calls.get_call_state_with_http_info(BW_ACCOUNT_ID, $call_info_id)
}.to raise_error { |e|
expect(e).to be_instance_of(Bandwidth::ApiError)
expect(e.code).to eq(403)
}
end
end

Expand Down
Loading

0 comments on commit 77545d9

Please sign in to comment.