Skip to content

Commit 867c869

Browse files
committed
smoke test
1 parent c73aed8 commit 867c869

1 file changed

Lines changed: 148 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

0 commit comments

Comments
 (0)