spec/api_client_spec.rb in agrid-client-0.0.3 vs spec/api_client_spec.rb in agrid-client-0.0.4

- old
+ new

@@ -13,11 +13,47 @@ }) end end context "with configuration argument" do + let(:configuration) { AgridClient::Configuration.new { |c| c.host = 'http://test.com' } } + let(:subject) { AgridClient::ApiClient.new(configuration) } it "initialize with configuration received" do - + expect(subject.config.host).to eq('test.com') + end + end + end + + describe "#call_api" do + it 'make a call to API' do + VCR.use_cassette('services') do + response = subject.call_api('GET','services') + expect(response).to be_an(Array) + end + end + + context "with options" do + it "make a call to API with options" do + subject.call_api('GET','services', + header_params: {'A-HEADER': 'olar'}, + query_params: {key: 'value'}) + expect(a_get('services').with( + headers: {'A-HEADER': 'olar'}, + query: {key: 'value'})).to have_been_made + end + end + + context "with return type" do + context "valid primitive type" do + before(:each) do + stub_get('services').to_return(body: '[1,2,3]', + headers: {'Content-Type': 'application/json'}) + end + + it "return deserialized response" do + expect(subject.call_api('GET', 'services', + {return_type: 'Array<Integer>'})[0]).to eq([1,2,3]) + end end end end end