Skip to content

Commit 70d86d7

Browse files
authored
Merge branch 'main' into SWI-10977
2 parents 43c8dac + 9244158 commit 70d86d7

2 files changed

Lines changed: 320 additions & 0 deletions

File tree

spec/smoke/endpoints_api_spec.rb

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# Integration Tests for Bandwidth::EndpointsApi
2+
describe 'EndpointsApi Integration Tests' do
3+
before(:all) do
4+
config = Bandwidth::Configuration.new
5+
config.configure do |config|
6+
config.client_id = BW_CLIENT_ID
7+
config.client_secret = BW_CLIENT_SECRET
8+
end
9+
client = Bandwidth::ApiClient.new(config)
10+
@endpoints_api_instance = Bandwidth::EndpointsApi.new(client)
11+
12+
unauthorized_config = Bandwidth::Configuration.new
13+
unauthorized_config.configure do |config|
14+
config.username = UNAUTHORIZED_USERNAME
15+
config.password = UNAUTHORIZED_PASSWORD
16+
end
17+
unauthorized_client = Bandwidth::ApiClient.new(unauthorized_config)
18+
@unauthorized_api_instance = Bandwidth::EndpointsApi.new(unauthorized_client)
19+
20+
$endpoint_id = ''
21+
end
22+
23+
# Create Endpoint
24+
describe 'create_endpoint' do
25+
it 'creates a WebRTC endpoint' do
26+
create_endpoint_body = Bandwidth::CreateWebRtcConnectionRequest.new(
27+
type: Bandwidth::EndpointTypeEnum::WEBRTC,
28+
direction: Bandwidth::EndpointDirectionEnum::BIDIRECTIONAL,
29+
event_callback_url: BASE_CALLBACK_URL + '/endpoint/callback',
30+
event_fallback_url: BASE_CALLBACK_URL + '/endpoint/fallback',
31+
tag: 'ruby-sdk-test-endpoint'
32+
)
33+
34+
data, status_code = @endpoints_api_instance.create_endpoint_with_http_info(BW_ACCOUNT_ID, create_endpoint_body)
35+
36+
expect(status_code).to eq(201)
37+
expect(data).to be_instance_of(Bandwidth::CreateEndpointResponse)
38+
expect(data.links).to be_instance_of(Array)
39+
expect(data.errors).to be_instance_of(Array)
40+
expect(data.data).to be_instance_of(Bandwidth::CreateEndpointResponseData)
41+
expect(data.data.endpoint_id).to be_instance_of(String)
42+
expect(data.data.type).to eq(Bandwidth::EndpointTypeEnum::WEBRTC)
43+
expect(data.data.status).to be_one_of(Bandwidth::EndpointStatusEnum.all_vars)
44+
expect(data.data.token).to be_instance_of(String)
45+
expect(data.data.creation_timestamp).to be_instance_of(Time)
46+
expect(data.data.expiration_timestamp).to be_instance_of(Time)
47+
expect(data.data.tag).to eq('ruby-sdk-test-endpoint')
48+
expect(data.data.devices).to be_instance_of(Array)
49+
50+
$endpoint_id = data.data.endpoint_id
51+
end
52+
end
53+
54+
# List Endpoints
55+
describe 'list_endpoints' do
56+
it 'gets a list of endpoints' do
57+
data, status_code = @endpoints_api_instance.list_endpoints_with_http_info(
58+
BW_ACCOUNT_ID,
59+
type: Bandwidth::EndpointTypeEnum::WEBRTC,
60+
limit: 10
61+
)
62+
63+
expect(status_code).to eq(200)
64+
expect(data).to be_instance_of(Bandwidth::ListEndpointsResponse)
65+
expect(data.links).to be_instance_of(Array)
66+
expect(data.errors).to be_instance_of(Array)
67+
expect(data.data).to be_instance_of(Array)
68+
expect(data.data.length).to be > 0
69+
70+
tagged_endpoint = data.data.find { |ep| ep.endpoint_id == $endpoint_id }
71+
expect(tagged_endpoint).not_to be_nil
72+
expect(tagged_endpoint.tag).to eq('ruby-sdk-test-endpoint')
73+
end
74+
end
75+
76+
# Get Endpoint
77+
describe 'get_endpoint' do
78+
it 'gets a specific endpoint' do
79+
data, status_code = @endpoints_api_instance.get_endpoint_with_http_info(BW_ACCOUNT_ID, $endpoint_id)
80+
81+
expect(status_code).to eq(200)
82+
expect(data).to be_instance_of(Bandwidth::EndpointResponse)
83+
expect(data.links).to be_instance_of(Array)
84+
expect(data.errors).to be_instance_of(Array)
85+
expect(data.data).to be_instance_of(Bandwidth::Endpoint)
86+
expect(data.data.endpoint_id).to eq($endpoint_id)
87+
expect(data.data.type).to eq(Bandwidth::EndpointTypeEnum::WEBRTC)
88+
expect(data.data.status).to be_one_of(Bandwidth::EndpointStatusEnum.all_vars)
89+
expect(data.data.creation_timestamp).to be_instance_of(Time)
90+
expect(data.data.expiration_timestamp).to be_instance_of(Time)
91+
expect(data.data.tag).to eq('ruby-sdk-test-endpoint')
92+
expect(data.data.devices).to be_instance_of(Array)
93+
end
94+
end
95+
96+
# Delete Endpoint
97+
describe 'delete_endpoint' do
98+
it 'deletes an endpoint' do
99+
_data, status_code = @endpoints_api_instance.delete_endpoint_with_http_info(BW_ACCOUNT_ID, $endpoint_id)
100+
101+
expect(status_code).to eq(204)
102+
end
103+
end
104+
105+
# HTTP 4XX Errors
106+
describe 'http error' do
107+
it 'causes a 401 error on create' do
108+
create_endpoint_body = Bandwidth::CreateWebRtcConnectionRequest.new(
109+
type: Bandwidth::EndpointTypeEnum::WEBRTC,
110+
direction: Bandwidth::EndpointDirectionEnum::BIDIRECTIONAL
111+
)
112+
113+
expect {
114+
@unauthorized_api_instance.create_endpoint_with_http_info(BW_ACCOUNT_ID, create_endpoint_body)
115+
}.to raise_error { |e|
116+
expect(e).to be_instance_of(Bandwidth::ApiError)
117+
expect(e.code).to eq(401)
118+
}
119+
end
120+
121+
it 'causes a 401 error on list' do
122+
expect {
123+
@unauthorized_api_instance.list_endpoints_with_http_info(BW_ACCOUNT_ID)
124+
}.to raise_error { |e|
125+
expect(e).to be_instance_of(Bandwidth::ApiError)
126+
expect(e.code).to eq(401)
127+
}
128+
end
129+
130+
it 'causes a 404 error on get' do
131+
expect {
132+
@endpoints_api_instance.get_endpoint_with_http_info(BW_ACCOUNT_ID, 'does-not-exist')
133+
}.to raise_error { |e|
134+
expect(e).to be_instance_of(Bandwidth::ApiError)
135+
expect(e.code).to eq(404)
136+
}
137+
end
138+
139+
it 'causes a 404 error on delete' do
140+
expect {
141+
@endpoints_api_instance.delete_endpoint_with_http_info(BW_ACCOUNT_ID, 'does-not-exist')
142+
}.to raise_error { |e|
143+
expect(e).to be_instance_of(Bandwidth::ApiError)
144+
expect(e.code).to eq(404)
145+
}
146+
end
147+
end
148+
end
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
# Unit tests for Bandwidth::EndpointsApi
2+
describe 'EndpointsApi' do
3+
let(:endpoint_id) { 'ep-abc123' }
4+
5+
before(:all) do
6+
Bandwidth.configure do |config|
7+
config.debugging = true
8+
config.username = BW_USERNAME
9+
config.password = BW_PASSWORD
10+
config.ignore_operation_servers = true
11+
config.host = '127.0.0.1:4010'
12+
end
13+
@endpoints_api_instance = Bandwidth::EndpointsApi.new
14+
end
15+
16+
describe 'test an instance of EndpointsApi' do
17+
it 'should create an instance of EndpointsApi' do
18+
expect(@endpoints_api_instance).to be_instance_of(Bandwidth::EndpointsApi)
19+
end
20+
end
21+
22+
# Create Endpoint
23+
describe '#create_endpoint' do
24+
it 'creates a WebRTC endpoint' do
25+
create_endpoint_body = Bandwidth::CreateWebRtcConnectionRequest.new(
26+
type: Bandwidth::EndpointTypeEnum::WEBRTC,
27+
direction: Bandwidth::EndpointDirectionEnum::BIDIRECTIONAL,
28+
event_callback_url: 'https://myServer.com/bandwidth/webhooks/endpoint',
29+
event_fallback_url: 'https://myFallbackServer.com/bandwidth/webhooks/endpoint',
30+
tag: 'test-endpoint',
31+
connection_metadata: { 'key1' => 'value1', 'key2' => 'value2' }
32+
)
33+
34+
data, status_code = @endpoints_api_instance.create_endpoint_with_http_info(BW_ACCOUNT_ID, create_endpoint_body)
35+
36+
expect(status_code).to eq(201)
37+
expect(data).to be_instance_of(Bandwidth::CreateEndpointResponse)
38+
expect(data.links).to be_instance_of(Array)
39+
expect(data.data).to be_instance_of(Bandwidth::CreateEndpointResponseData)
40+
expect(data.data.endpoint_id).to be_instance_of(String)
41+
expect(data.data.type).to be_one_of(Bandwidth::EndpointTypeEnum.all_vars)
42+
expect(data.data.status).to be_one_of(Bandwidth::EndpointStatusEnum.all_vars)
43+
expect(data.data.creation_timestamp).to be_instance_of(Time)
44+
expect(data.data.expiration_timestamp).to be_instance_of(Time)
45+
expect(data.data.token).to be_instance_of(String)
46+
expect(data.data.tag).to be_instance_of(String)
47+
expect(data.data.devices).to be_instance_of(Array)
48+
expect(data.errors).to be_instance_of(Array)
49+
end
50+
51+
it 'causes an ArgumentError for a missing account_id' do
52+
expect {
53+
@endpoints_api_instance.create_endpoint(nil, {})
54+
}.to raise_error(ArgumentError)
55+
end
56+
57+
it 'causes an ArgumentError for a missing body' do
58+
expect {
59+
@endpoints_api_instance.create_endpoint(BW_ACCOUNT_ID, nil)
60+
}.to raise_error(ArgumentError)
61+
end
62+
end
63+
64+
# List Endpoints
65+
describe '#list_endpoints' do
66+
it 'gets a list of endpoints' do
67+
data, status_code = @endpoints_api_instance.list_endpoints_with_http_info(BW_ACCOUNT_ID)
68+
69+
expect(status_code).to eq(200)
70+
expect(data).to be_instance_of(Bandwidth::ListEndpointsResponse)
71+
expect(data.links).to be_instance_of(Array)
72+
expect(data.page).to be_instance_of(Bandwidth::Page)
73+
expect(data.data).to be_instance_of(Array)
74+
expect(data.data[0]).to be_instance_of(Bandwidth::Endpoints)
75+
expect(data.data[0].endpoint_id).to be_instance_of(String)
76+
expect(data.data[0].type).to be_one_of(Bandwidth::EndpointTypeEnum.all_vars)
77+
expect(data.data[0].status).to be_one_of(Bandwidth::EndpointStatusEnum.all_vars)
78+
expect(data.data[0].creation_timestamp).to be_instance_of(Time)
79+
expect(data.data[0].expiration_timestamp).to be_instance_of(Time)
80+
expect(data.data[0].tag).to be_instance_of(String)
81+
expect(data.errors).to be_instance_of(Array)
82+
end
83+
84+
it 'causes an ArgumentError for a missing account_id' do
85+
expect {
86+
@endpoints_api_instance.list_endpoints(nil)
87+
}.to raise_error(ArgumentError)
88+
end
89+
end
90+
91+
# Get Endpoint
92+
describe '#get_endpoint' do
93+
it 'gets an endpoint' do
94+
data, status_code = @endpoints_api_instance.get_endpoint_with_http_info(BW_ACCOUNT_ID, endpoint_id)
95+
96+
expect(status_code).to eq(200)
97+
expect(data).to be_instance_of(Bandwidth::EndpointResponse)
98+
expect(data.links).to be_instance_of(Array)
99+
expect(data.data).to be_instance_of(Bandwidth::Endpoint)
100+
expect(data.data.endpoint_id).to be_instance_of(String)
101+
expect(data.data.type).to be_one_of(Bandwidth::EndpointTypeEnum.all_vars)
102+
expect(data.data.status).to be_one_of(Bandwidth::EndpointStatusEnum.all_vars)
103+
expect(data.data.creation_timestamp).to be_instance_of(Time)
104+
expect(data.data.expiration_timestamp).to be_instance_of(Time)
105+
expect(data.data.tag).to be_instance_of(String)
106+
expect(data.data.devices).to be_instance_of(Array)
107+
expect(data.errors).to be_instance_of(Array)
108+
end
109+
110+
it 'causes an ArgumentError for a missing account_id' do
111+
expect {
112+
@endpoints_api_instance.get_endpoint(nil, '')
113+
}.to raise_error(ArgumentError)
114+
end
115+
116+
it 'causes an ArgumentError for a missing endpoint_id' do
117+
expect {
118+
@endpoints_api_instance.get_endpoint(BW_ACCOUNT_ID, nil)
119+
}.to raise_error(ArgumentError)
120+
end
121+
end
122+
123+
# Update Endpoint BXML
124+
describe '#update_endpoint_bxml' do
125+
it 'updates an endpoint using bxml' do
126+
update_bxml = "<?xml version='1.0' encoding='UTF-8'?><Bxml><SpeakSentence>Hello</SpeakSentence></Bxml>"
127+
128+
_data, status_code = @endpoints_api_instance.update_endpoint_bxml_with_http_info(BW_ACCOUNT_ID, endpoint_id, update_bxml)
129+
130+
expect(status_code).to eq(204)
131+
end
132+
133+
it 'causes an ArgumentError for a missing account_id' do
134+
expect {
135+
@endpoints_api_instance.update_endpoint_bxml(nil, '', {})
136+
}.to raise_error(ArgumentError)
137+
end
138+
139+
it 'causes an ArgumentError for a missing endpoint_id' do
140+
expect {
141+
@endpoints_api_instance.update_endpoint_bxml(BW_ACCOUNT_ID, nil, {})
142+
}.to raise_error(ArgumentError)
143+
end
144+
145+
it 'causes an ArgumentError for a missing body' do
146+
expect {
147+
@endpoints_api_instance.update_endpoint_bxml(BW_ACCOUNT_ID, '', nil)
148+
}.to raise_error(ArgumentError)
149+
end
150+
end
151+
152+
# Delete Endpoint
153+
describe '#delete_endpoint' do
154+
it 'deletes an endpoint' do
155+
_data, status_code = @endpoints_api_instance.delete_endpoint_with_http_info(BW_ACCOUNT_ID, endpoint_id)
156+
157+
expect(status_code).to eq(204)
158+
end
159+
160+
it 'causes an ArgumentError for a missing account_id' do
161+
expect {
162+
@endpoints_api_instance.delete_endpoint(nil, '')
163+
}.to raise_error(ArgumentError)
164+
end
165+
166+
it 'causes an ArgumentError for a missing endpoint_id' do
167+
expect {
168+
@endpoints_api_instance.delete_endpoint(BW_ACCOUNT_ID, nil)
169+
}.to raise_error(ArgumentError)
170+
end
171+
end
172+
end

0 commit comments

Comments
 (0)