|
| 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