Sha256: cb3d0811ed6744d287d005a657bdd3b854e2ba7ca50c7b518c06efd37d8613db

Contents?: true

Size: 1.74 KB

Versions: 1

Compression:

Stored size: 1.74 KB

Contents

require "spec_helper"

describe 'ApiClient' do
  let(:subject) { AgridClient::ApiClient.new }

  describe "#new" do
    context "without arguments" do
      it "initialize with default configuration" do
        version = AgridClient::VERSION
        expect(subject.default_headers).to eq({
            'Content-Type' => 'application/json',
            'User-Agent' => "agrid_client/#{version}/ruby"
        })
      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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
agrid-client-0.0.4 spec/api_client_spec.rb