Sha256: 99d67ddae75beb746fa251b2584f3132d8b6db44b97f88116f48c0ed071b4c53

Contents?: true

Size: 1.75 KB

Versions: 2

Compression:

Stored size: 1.75 KB

Contents

require 'spec_helper'

RSpec.describe Base::HTTP do
  include Base::HTTP
  let(:uri) { URI.parse('https://api.thebase.in/1/categories?') }
  let(:header_parameter) { { 'Authorization' => 'Bearer 888access_token888' } }

  describe '#generate_uri' do
    it 'returns instance of URI' do
      expect(generate_uri('partial_path')).to be_kind_of URI
    end

    it 'returns uri' do
      %w(apple google/twitter facebook?).each do |partial_path|
        expect(generate_uri(partial_path)).to eq \
          URI.parse("https://api.thebase.in/1/#{partial_path}")
      end
    end
  end

  describe '#generate_request' do
    context 'no header_parameter is given' do
      it 'returns instance of Net::HTTP::Get' do
        expect(generate_request(uri)).to be_kind_of Net::HTTP::Get
      end

      it 'has header_parameter authorization' do
        expect(
          generate_request(uri)
            .instance_variable_get(:@header)['authorization']).to be_nil
      end
    end

    context 'header_parameter is given' do
      it 'returns instance of Net::HTTP::Get' do
        expect(generate_request(uri, header_parameter))
          .to be_kind_of Net::HTTP::Get
      end

      it 'has header_parameter authorization' do
        expect(
          generate_request(uri, header_parameter)
            .instance_variable_get(:@header)['authorization'])
          .to eq ['Bearer 888access_token888']
      end
    end
  end

  describe '#start' do
    let(:request) { generate_request(uri, header_parameter) }
    let(:response) { VCR.use_cassette('HTTP_start') { start(request, uri) } }

    it 'response @code is "200"' do
      expect(response.code).to eq '200'
    end

    it 'response @body contains categories' do
      expect(response.body).to match(/categories/)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
base-api-client-0.3.beta spec/base/http_spec.rb
base-api-client-0.2.5.beta spec/base/http_spec.rb