Sha256: 3be158a662f66cf5adfd07c2d9d0dc07e404b5b6dc8bb5d18661253b6a503087

Contents?: true

Size: 1.92 KB

Versions: 3

Compression:

Stored size: 1.92 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')

module WhosGotDirt::Requests::Relation
  RSpec.describe OpenCorporates do
    describe '#to_s' do
      it 'should return the URL to request' do
        expect(OpenCorporates.new(subject: [name: 'John Smith']).to_s).to eq('https://api.opencorporates.com/officers/search?q=John+Smith&order=score')
      end
    end

    describe '#convert' do
      context 'when given a name' do
        include_examples 'match', 'q', 'name', ['Smith John', 'John Smith'], scope: 'subject'
      end

      context 'when given a birth date' do
        include_examples 'date_range', 'date_of_birth', 'birth_date', scope: 'subject'
      end

      context 'when given a contact detail' do
        include_examples 'contact_details', 'address', 'address', ['52 London', 'London 52'], scope: 'subject'
      end

      context 'when given a limit' do
        it 'should return a per-page limit' do
          expect(OpenCorporates.new('limit' => 5).convert).to eq('per_page' => 5)
        end

        it 'should override the default authenticated per-page limit' do
          expect(OpenCorporates.new('limit' => 5, 'open_corporates_api_key' => 123).convert).to eq('per_page' => 5, 'api_token' => 123)
        end
      end

      context 'when given an API key' do
        it 'should return an API key parameter' do
          expect(OpenCorporates.new('open_corporates_api_key' => 123).convert).to eq('api_token' => 123, 'per_page' => 100)
        end
      end

      context 'when given a jurisdiction' do
        include_examples 'one_of', 'jurisdiction_code', 'jurisdiction_code', ['GB', 'IE'], '|', transformed: ['gb', 'ie']
      end

      context 'when given a role' do
        include_examples 'equal', 'position', 'role', 'ceo'
      end

      context 'when given an inactivity status' do
        include_examples 'equal', 'inactive', 'inactive', false, valid: [true, false]
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
whos_got_dirt-0.0.4 spec/requests/relation/open_corporates_spec.rb
whos_got_dirt-0.0.3 spec/requests/relation/open_corporates_spec.rb
whos_got_dirt-0.0.2 spec/requests/relation/open_corporates_spec.rb