From 3b1c40b4870b03d8853321d1498a91bf1b57145b Mon Sep 17 00:00:00 2001 From: ckoegel Date: Tue, 25 Jul 2023 17:09:38 -0400 Subject: [PATCH] update tests --- spec/api_client_spec.rb | 2 +- spec/configuration_spec.rb | 26 +++++++++++++++++++------- spec/models/message_spec.rb | 14 ++++++++++---- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/spec/api_client_spec.rb b/spec/api_client_spec.rb index b6ac4cae..9fa7df7a 100644 --- a/spec/api_client_spec.rb +++ b/spec/api_client_spec.rb @@ -288,7 +288,7 @@ describe '#build_request_url' do it 'adds leading and trailing slashes to path' do - expect(api_client_default.build_request_url('test/path')).to eq('/test/path') + expect(api_client_default.build_request_url('test/path')).to eq('http://localhost/test/path') end end diff --git a/spec/configuration_spec.rb b/spec/configuration_spec.rb index c0b3da99..6dd0941d 100644 --- a/spec/configuration_spec.rb +++ b/spec/configuration_spec.rb @@ -53,19 +53,31 @@ end describe '#base_url' do - it 'Returns default base URL when server_index is nil' do - config.server_index = nil - expect(config.base_url).to eq('http://localhost') - end - - it 'returns empty string when invalid operation is passed' do - expect(config.base_url('invalid_operation')).to eq('') + it 'returns default value when invalid operation is passed' do + expect(config.base_url('invalid_operation')).to eq('http://localhost') end it 'returns proper base URL when server index is set' do operation, server = config.operation_server_settings.first expect(config.base_url(operation)).to eq(server[0][:url]) end + + it 'should have the default value' do + expect(config.base_url).to eq("http://localhost") + end + + it 'returns default value when invalid operation is passed' do + expect(config.base_url('invalid_operation')).to eq('http://localhost') + end + + it 'throws argument error when attempting to use a server index that is out of bounds' do + config.server_operation_index = { + :'MediaApi.upload_media' => 10 + } + expect { + config.base_url(:'MediaApi.upload_media') + }.to raise_error(ArgumentError, 'Invalid index 10 when selecting the server. Must not be nil and must be less than 1') + end end describe '#api_key_with_prefix' do diff --git a/spec/models/message_spec.rb b/spec/models/message_spec.rb index 05f04423..bb311e5c 100644 --- a/spec/models/message_spec.rb +++ b/spec/models/message_spec.rb @@ -7,7 +7,7 @@ application_id: '93de2206-9669-4e07-948d-329f4b722ee2', time: '2022-06-16T13:15:07.160Z', segment_count: 2, - direction: 'in', + direction: Bandwidth::MessageDirectionEnum::IN, to: ['+19195551234'], from: '+19195554321', media: ['https://dev.bandwidth.com/images/bandwidth-logo.png'], @@ -37,6 +37,12 @@ end end + describe 'enum validation' do + it 'works' do + + end + end + describe 'EnumAttributeValidator' do it 'validates string enum' do validator = Bandwidth::Message::EnumAttributeValidator.new(String, ['valid']) @@ -65,7 +71,7 @@ applicationId: '93de2206-9669-4e07-948d-329f4b722ee2', time: '2022-06-16T13:15:07.160Z', segmentCount: 2, - direction: 'in', + direction: Bandwidth::MessageDirectionEnum::IN, to: ['+19195551234'], from: '+19195554321', media: ['https://dev.bandwidth.com/images/bandwidth-logo.png'], @@ -80,7 +86,7 @@ expect(message_from_hash.application_id).to eq('93de2206-9669-4e07-948d-329f4b722ee2') expect(message_from_hash.time).to eq(Time.parse('2022-06-16T13:15:07.160Z')) expect(message_from_hash.segment_count).to eq(2) - expect(message_from_hash.direction).to eq('in') + expect(message_from_hash.direction).to eq(Bandwidth::MessageDirectionEnum::IN) expect(message_from_hash.to).to eq(['+19195551234']) expect(message_from_hash.from).to eq('+19195554321') expect(message_from_hash.media).to eq(['https://dev.bandwidth.com/images/bandwidth-logo.png']) @@ -131,7 +137,7 @@ applicationId: '93de2206-9669-4e07-948d-329f4b722ee2', time: '2022-06-16T13:15:07.160Z', segmentCount: 2, - direction: 'in', + direction: Bandwidth::MessageDirectionEnum::IN, to: ['+19195551234'], from: '+19195554321', media: ['https://dev.bandwidth.com/images/bandwidth-logo.png'],